Skip to content

Commit 6c36a3d

Browse files
committed
Fixes two segfaults in CAF processing of SBND v10_06_00_09.
First fix: Added guard in G4 weight calculator against trajectory points outside world volume. Second fix: Added guard in RecoUtils.cc for when a trajectory does not intersect detector walls.
1 parent ece959f commit 6c36a3d

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

sbncode/CAFMaker/RecoUtils/RecoUtils.cc

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

146-
assert(intersections.size() == 2);
146+
//assert(intersections.size() == 2);
147+
/*
148+
* There are either infinity, two, or one, or zero intersection points.
149+
* As per larcorealg/Geometry/BoxBoundedGeo.h documentation:
150+
* If the return std::vector is empty the trajectory does not intersect with the box.
151+
* Normally the return value should have one (if the trajectory originates in the box) or two (else) entries.
152+
* If the return value has two entries the first represents the entry point and the second the exit point
153+
*/
154+
switch( intersections.size() ) {
155+
case 0: // Set kWallNone and return
156+
return caf::kWallNone;
157+
break;
158+
case 1: // Set the second intersection to be the same as the first, and fall through
159+
intersections.emplace_back(intersections.front());
160+
[[fallthrough]];
161+
case 2:
162+
break;
163+
default: // There are infinity points to consider. Just use the first two.
164+
intersections.resize(2);
165+
break;
166+
}
147167

148168
// get the intersection point closer to p0
149169
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)