Skip to content

Commit a8d06c2

Browse files
committed
Make flux calculator compatible with g4bnb flux
1 parent fb929f3 commit a8d06c2

2 files changed

Lines changed: 44 additions & 7 deletions

File tree

sbncode/SBNEventWeight/Calculators/BNBFlux/FluxCalcPrep.cxx

Lines changed: 40 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,9 +295,35 @@ 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+
// int tptype = fluxlist[inu].ftptype;
306+
307+
// If Dk2Nu flux, use ancestors to evaluate tptype
308+
if (fluxlist[inu].fFluxType == simb::kDk2Nu) {
309+
310+
// Find the first inelastic interaction
311+
int firstInelastic = 0;
312+
while (dk2nu_v->at(inu).ancestor[firstInelastic].proc.find("HadronInelastic")==std::string::npos||dk2nu_v->at(inu).ancestor[firstInelastic].proc.find("QEBooNE")!=std::string::npos) firstInelastic++;
313+
314+
// Get the parent/ancestor (this should be the secondary in the p+Be interaction)
315+
flux.ftptype = dk2nu_v->at(inu).ancestor[firstInelastic].pdg;
316+
flux.ftpx = dk2nu_v->at(inu).ancestor[firstInelastic].startpx;
317+
flux.ftpy = dk2nu_v->at(inu).ancestor[firstInelastic].startpy;
318+
flux.ftpz = dk2nu_v->at(inu).ancestor[firstInelastic].startpz;
319+
320+
}
321+
322+
323+
if (std::find(fprimaryHad.begin(), fprimaryHad.end(),(flux.ftptype)) == fprimaryHad.end() ){//if it does not contain any particles we need get 1
291324
weights.resize( NUni);
292325
std::fill(weights.begin(), weights.end(), 1);
326+
std::cout << "We don't need this parent, returning." << std::endl;
293327
return weights;//done, all 1
294328
}// Hadronic parent check
295329

@@ -301,19 +335,18 @@ namespace sbn {
301335
std::vector< float > Vrandom = (fParameterSet.fParameterMap.begin())->second;//vector of random #
302336
std::vector< float > subVrandom;//sub-vector of random numbers;
303337
if( CalcType == "PrimaryHadronNormalization"){//Normalization
304-
test_weight = PHNWeightCalc(fluxlist[inu], Vrandom[i]);
338+
test_weight = PHNWeightCalc(flux, Vrandom[i]);
305339

306340
} else {
307341
subVrandom = {Vrandom.begin()+i*FitCov->GetNcols(), Vrandom.begin()+(i+1)*FitCov->GetNcols()};
308342
if( CalcType == "PrimaryHadronFeynmanScaling"){//FeynmanScaling
309-
test_weight = PHFSWeightCalc(fluxlist[inu], subVrandom);
343+
test_weight = PHFSWeightCalc(flux, subVrandom);
310344

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

314348
} else if( CalcType == "PrimaryHadronSWCentralSplineVariation"){//SWCentaralSplineVariation
315-
test_weight = PHSWCSVWeightCalc(fluxlist[inu], subVrandom);
316-
349+
test_weight = PHSWCSVWeightCalc(flux, subVrandom);
317350
} else throw cet::exception(__PRETTY_FUNCTION__) << GetName() << ": this shouldnt happen.."<<std::endl;
318351
}
319352

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"

0 commit comments

Comments
 (0)