Skip to content

Commit aa481b0

Browse files
authored
Merge pull request #609 from SBNSoftware/bugfix/kplows_fix_springProcessingCAFs
Fixes two segfaults in CAF processing of SBND v10_06_00_09.
2 parents ece959f + ebafba0 commit aa481b0

2 files changed

Lines changed: 27 additions & 15 deletions

File tree

sbncode/CAFMaker/RecoUtils/RecoUtils.cc

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -143,38 +143,47 @@ 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+
/*
147+
* There are either two, or one, or zero intersection points.
148+
* As per larcorealg/Geometry/BoxBoundedGeo.h documentation:
149+
* If the return std::vector is empty the trajectory does not intersect with the box.
150+
* Normally the return value should have one (if the trajectory originates in the box) or two (else) entries.
151+
* If the return value has two entries the first represents the entry point and the second the exit point
152+
*/
153+
154+
if( intersections.empty() ) return caf::kWallNone;
147155

148156
// get the intersection point closer to p0
149-
int intersection_i = ((intersections[0] - p0).Mag() < (intersections[1] - p0).Mag()) ? 0 : 1;
157+
TVector3 closestIntersection;
158+
double minDistance2 = std::numeric_limits<double>::max();
159+
160+
for( TVector3 const & point : intersections ) {
161+
const double d2 = (point - p0).Mag2();
162+
if( d2 > minDistance2 ) continue;
163+
minDistance2 = d2;
164+
closestIntersection = point;
165+
}
150166

151167
double eps = 1e-3;
152-
if (abs(intersections[intersection_i].X() - volume.MinX()) < eps) {
153-
//std::cout << "Left\n";
168+
if (abs(closestIntersection.X() - volume.MinX()) < eps) {
154169
return caf::kWallLeft;
155170
}
156-
else if (abs(intersections[intersection_i].X() - volume.MaxX()) < eps) {
157-
//std::cout << "Right\n";
171+
else if (abs(closestIntersection.X() - volume.MaxX()) < eps) {
158172
return caf::kWallRight;
159173
}
160-
else if (abs(intersections[intersection_i].Y() - volume.MinY()) < eps) {
161-
//std::cout << "Bottom\n";
174+
else if (abs(closestIntersection.Y() - volume.MinY()) < eps) {
162175
return caf::kWallBottom;
163176
}
164-
else if (abs(intersections[intersection_i].Y() - volume.MaxY()) < eps) {
165-
//std::cout << "Top\n";
177+
else if (abs(closestIntersection.Y() - volume.MaxY()) < eps) {
166178
return caf::kWallTop;
167179
}
168-
else if (abs(intersections[intersection_i].Z() - volume.MinZ()) < eps) {
169-
//std::cout << "Front\n";
180+
else if (abs(closestIntersection.Z() - volume.MinZ()) < eps) {
170181
return caf::kWallFront;
171182
}
172-
else if (abs(intersections[intersection_i].Z() - volume.MaxZ()) < eps) {
173-
//std::cout << "Back\n";
183+
else if (abs(closestIntersection.Z() - volume.MaxZ()) < eps) {
174184
return caf::kWallBack;
175185
}
176186
else assert(false);
177-
//std::cout << "None\n";
178187

179188
return caf::kWallNone;
180189
}//GetWallCross

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 ) {
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)