Skip to content

Commit e5bf134

Browse files
committed
Adds guards to Geant4WeightCalc::GetWeight and sbn::GetWallCross
Geant4WeightCalc::GetWeight gets a guard against trajectory points outside the world volume sbn::GetWallCross gets a guard against lines that don't intersect the detector
1 parent 5ff32f5 commit e5bf134

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

sbncode/CAFMaker/FillTrue.cxx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,27 @@ caf::Wall_t caf::GetWallCross(const geo::BoxBoundedGeo &volume, const TVector3 p
12601260
TVector3 direction = (p1 - p0) * ( 1. / (p1 - p0).Mag());
12611261
std::vector<TVector3> intersections = volume.GetIntersections(p0, direction);
12621262

1263-
assert(intersections.size() == 2);
1263+
//assert(intersections.size() == 2);
1264+
/*
1265+
* There are either infinity, two, or one, or zero intersection points.
1266+
* As per larcorealg/Geometry/BoxBoundedGeo.h documentation:
1267+
* If the return std::vector is empty the trajectory does not intersect with the box.
1268+
* Normally the return value should have one (if the trajectory originates in the box) or two (else) entries.
1269+
* If the return value has two entries the first represents the entry point and the second the exit point
1270+
*/
1271+
switch( intersections.size() ) {
1272+
case 0: // Set kWallNone and return
1273+
return caf::kWallNone;
1274+
break;
1275+
case 1: // Set the second intersection to be the same as the first, and fall through
1276+
intersections.emplace_back(intersections.front());
1277+
[[fallthrough]];
1278+
case 2:
1279+
break;
1280+
default: // There are infinity points to consider. Just use the first two.
1281+
intersections.resize(2);
1282+
break;
1283+
}
12641284

12651285
// get the intersection point closer to p0
12661286
int intersection_i = ((intersections[0] - p0).Mag() < (intersections[1] - p0).Mag()) ? 0 : 1;

sbncode/SBNEventWeight/Calculators/Geant4/Geant4WeightCalc.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ std::vector<float> Geant4WeightCalc::GetWeight(art::Event& e, size_t itruth ) {
297297
double Z = p.Position(i).Z();
298298
geo::Point_t testpoint1 { X, Y, Z };
299299
const TGeoMaterial* testmaterial1 = fGeometryService->Material( testpoint1 );
300+
if( ! testmaterial1 || testmaterial1 == nullptr ) {
301+
break; // The trajectory point is outside the world, or the geometry service is unable to handle the point
302+
}
300303
//For now, just going to reweight the points within the LAr of the TPC
301304
// TODO check if this is right
302305
if ( !strcmp( testmaterial1->GetName(), "LAr" ) ){

0 commit comments

Comments
 (0)