Skip to content

Commit 47511c1

Browse files
authored
Merge branch 'develop' into bugfix/ext
2 parents 240b73c + 57e94ce commit 47511c1

File tree

7 files changed

+66
-62
lines changed

7 files changed

+66
-62
lines changed

sbncode/CAFMaker/FillTrue.cxx

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

12651273
// get the intersection point closer to p0
1266-
int intersection_i = ((intersections[0] - p0).Mag() < (intersections[1] - p0).Mag()) ? 0 : 1;
1274+
TVector3 closestIntersection;
1275+
double minDistance2 = std::numeric_limits<double>::max();
1276+
1277+
for( TVector3 const & point : intersections ) {
1278+
const double d2 = (point - p0).Mag2();
1279+
if( d2 > minDistance2 ) continue;
1280+
minDistance2 = d2;
1281+
closestIntersection = point;
1282+
}
12671283

12681284
double eps = 1e-3;
1269-
if (abs(intersections[intersection_i].X() - volume.MinX()) < eps) {
1270-
//std::cout << "Left\n";
1285+
if (abs(closestIntersection.X() - volume.MinX()) < eps) {
12711286
return caf::kWallLeft;
12721287
}
1273-
else if (abs(intersections[intersection_i].X() - volume.MaxX()) < eps) {
1274-
//std::cout << "Right\n";
1288+
else if (abs(closestIntersection.X() - volume.MaxX()) < eps) {
12751289
return caf::kWallRight;
12761290
}
1277-
else if (abs(intersections[intersection_i].Y() - volume.MinY()) < eps) {
1278-
//std::cout << "Bottom\n";
1291+
else if (abs(closestIntersection.Y() - volume.MinY()) < eps) {
12791292
return caf::kWallBottom;
12801293
}
1281-
else if (abs(intersections[intersection_i].Y() - volume.MaxY()) < eps) {
1282-
//std::cout << "Top\n";
1294+
else if (abs(closestIntersection.Y() - volume.MaxY()) < eps) {
12831295
return caf::kWallTop;
12841296
}
1285-
else if (abs(intersections[intersection_i].Z() - volume.MinZ()) < eps) {
1286-
//std::cout << "Front\n";
1297+
else if (abs(closestIntersection.Z() - volume.MinZ()) < eps) {
12871298
return caf::kWallFront;
12881299
}
1289-
else if (abs(intersections[intersection_i].Z() - volume.MaxZ()) < eps) {
1290-
//std::cout << "Back\n";
1300+
else if (abs(closestIntersection.Z() - volume.MaxZ()) < eps) {
12911301
return caf::kWallBack;
12921302
}
12931303
else assert(false);
1294-
//std::cout << "None\n";
12951304

12961305
return caf::kWallNone;
12971306
}//GetWallCross

sbncode/LArG4/CMakeLists.txt

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
add_subdirectory(PhysicsLists)
22

3-
cet_build_plugin(G4InfoReducer art::module
4-
LIBRARIES
5-
larsim::Simulation
6-
larcore::Geometry_Geometry_service
7-
lardata::DetectorInfoServices_DetectorClocksServiceStandard_service
8-
art::Persistency_Common
9-
art::Persistency_Provenance
10-
art::Utilities canvas::canvas
11-
BASENAME_ONLY)
12-
133
set(
144
MODULE_LIBRARIES
155
art::Utilities
@@ -61,14 +51,5 @@ cet_build_plugin(MergeSimSourcesSBN art::EDProducer
6151
BASENAME_ONLY
6252
)
6353

64-
cet_build_plugin(SimpleMerge art::EDProducer
65-
LIBRARIES
66-
lardataobj::MCBase
67-
larcorealg::headers
68-
larcorealg::CoreUtils
69-
messagefacility::MF_MessageLogger
70-
)
71-
7254
install_headers()
73-
install_fhicl()
7455
install_source()

sbncode/LArG4/g4inforeducer.fcl

Lines changed: 0 additions & 12 deletions
This file was deleted.

sbncode/LArG4/simplemerge.fcl

Lines changed: 0 additions & 9 deletions
This file was deleted.

sbncode/SBNEventWeight/Calculators/BNBFlux/FluxCalcPrep.cxx

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,16 @@ namespace sbn {
213213
// std::cout<<"SBNEventWeight : getweight for the "<<inu<<" th particles of an event"<< std::endl;
214214
//MCFlux & MCTruth
215215
art::Handle< std::vector<simb::MCFlux> > mcFluxHandle;
216-
e.getByLabel(fGeneratorModuleLabel,mcFluxHandle);
216+
e.getByLabel(fGeneratorModuleLabel, mcFluxHandle);
217217
std::vector<simb::MCFlux> const& fluxlist = *mcFluxHandle;
218+
219+
art::Handle< std::vector<bsim::Dk2Nu> > dk2nuHandle;
220+
std::vector<bsim::Dk2Nu> const* dk2nu_v = nullptr;
221+
e.getByLabel(fGeneratorModuleLabel, dk2nuHandle);
222+
if (dk2nuHandle.isValid()) {
223+
dk2nu_v = dk2nuHandle.product();
224+
}
225+
218226
//or do the above 3 lines in one line
219227
// auto const& mclist = *e.getValidHandle<std::vector<simb::MCTruth>>(fGeneratorModuleLabel);
220228

@@ -287,7 +295,28 @@ namespace sbn {
287295

288296
// First let's check that the parent of the neutrino we are looking for is
289297
// the particle we intended it to be, if not set all weights to 1
290-
if (std::find(fprimaryHad.begin(), fprimaryHad.end(),(fluxlist[inu].ftptype)) == fprimaryHad.end() ){//if it does not contain any particles we need get 1
298+
299+
simb::MCFlux flux;
300+
flux.ftptype = fluxlist[inu].ftptype;
301+
flux.ftpx = fluxlist[inu].ftpx;
302+
flux.ftpy = fluxlist[inu].ftpy;
303+
flux.ftpz = fluxlist[inu].ftpz;
304+
305+
// If Dk2Nu flux, use ancestors to evaluate tptype
306+
if (fluxlist[inu].fFluxType == simb::kDk2Nu) {
307+
308+
for( const bsim::Ancestor & ancestor : dk2nu_v->at(inu).ancestor ) {
309+
std::string aproc = ancestor.proc;
310+
if( (aproc.find("BooNEHadronInelastic:BooNEpBeInteraction") != std::string::npos) && (aproc.find("QEBooNE") == std::string::npos) ) {
311+
flux.ftptype = ancestor.pdg;
312+
flux.ftpx = ancestor.startpx;
313+
flux.ftpy = ancestor.startpy;
314+
flux.ftpz = ancestor.startpz;
315+
} // found it
316+
} // find first inelastic
317+
}
318+
319+
if (std::find(fprimaryHad.begin(), fprimaryHad.end(),(flux.ftptype)) == fprimaryHad.end() ){//if it does not contain any particles we need get 1
291320
weights.resize( NUni);
292321
std::fill(weights.begin(), weights.end(), 1);
293322
return weights;//done, all 1
@@ -301,19 +330,18 @@ namespace sbn {
301330
std::vector< float > Vrandom = (fParameterSet.fParameterMap.begin())->second;//vector of random #
302331
std::vector< float > subVrandom;//sub-vector of random numbers;
303332
if( CalcType == "PrimaryHadronNormalization"){//Normalization
304-
test_weight = PHNWeightCalc(fluxlist[inu], Vrandom[i]);
333+
test_weight = PHNWeightCalc(flux, Vrandom[i]);
305334

306335
} else {
307336
subVrandom = {Vrandom.begin()+i*FitCov->GetNcols(), Vrandom.begin()+(i+1)*FitCov->GetNcols()};
308337
if( CalcType == "PrimaryHadronFeynmanScaling"){//FeynmanScaling
309-
test_weight = PHFSWeightCalc(fluxlist[inu], subVrandom);
338+
test_weight = PHFSWeightCalc(flux, subVrandom);
310339

311340
} else if( CalcType == "PrimaryHadronSanfordWang"){//SanfordWang
312-
test_weight = PHSWWeightCalc(fluxlist[inu], subVrandom);
341+
test_weight = PHSWWeightCalc(flux, subVrandom);
313342

314343
} else if( CalcType == "PrimaryHadronSWCentralSplineVariation"){//SWCentaralSplineVariation
315-
test_weight = PHSWCSVWeightCalc(fluxlist[inu], subVrandom);
316-
344+
test_weight = PHSWCSVWeightCalc(flux, subVrandom);
317345
} else throw cet::exception(__PRETTY_FUNCTION__) << GetName() << ": this shouldnt happen.."<<std::endl;
318346
}
319347

sbncode/SBNEventWeight/Calculators/BNBFlux/FluxCalcPrep.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#include "nusimdata/SimulationBase/MCFlux.h"
66
#include "nusimdata/SimulationBase/MCTruth.h"
77

8+
#include "dk2nu/tree/NuChoice.h"
9+
#include "dk2nu/tree/dk2nu.h"
10+
#include "dk2nu/tree/dkmeta.h"
11+
812
#include "sbncode/SBNEventWeight/Base/WeightCalc.h"
913
#include "art/Framework/Principal/Event.h"
1014
#include "sbncode/SBNEventWeight/Base/WeightCalcCreator.h"

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)