Skip to content

Commit 57e94ce

Browse files
authored
Merge pull request #618 from SBNSoftware/feature/mdeltutt_fluxweight_g4bnb
Make flux calculator compatible with g4bnb flux
2 parents acd7a8b + 5a31e63 commit 57e94ce

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

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"

0 commit comments

Comments
 (0)