Skip to content

Commit 0509def

Browse files
author
Jack Smedley
committed
Added G4ReweightManager and collapsed elastic and inelastic weights into one, successfully compiled
1 parent 47810c4 commit 0509def

1 file changed

Lines changed: 34 additions & 15 deletions

File tree

sbncode/SBNEventWeight/Calculators/Geant4/Geant4WeightCalc.cxx

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "sbncode/SBNEventWeight/Base/WeightCalcCreator.h"
3434
#include "sbncode/SBNEventWeight/Base/WeightCalc.h"
3535
#include "larcore/Geometry/Geometry.h"
36+
#include "geant4reweight/ReweightBase/G4ReweightManager.hh"
3637
#include "geant4reweight/ReweightBase/G4ReweighterFactory.hh"
3738
#include "geant4reweight/ReweightBase/G4Reweighter.hh"
3839
#include "geant4reweight/ReweightBase/G4ReweightTraj.hh"
@@ -62,7 +63,8 @@ class Geant4WeightCalc : public WeightCalc {
6263
unsigned fNsims; //!< Number of multisims
6364
int fPdg; //!< PDG value for particles that a given weight calculator should apply to. Note that for now this module can only handle weights for one particle species at a time.
6465
// float fXSUncertainty; //!< Flat cross section uncertainty
65-
G4ReweighterFactory RWFactory; //!< Base class to handle all Geant4Reweighters (right now "all" means pi+, pi-, p)
66+
G4ReweightManager *RWManager; //!< "holds the run manager and creates the detector" according to the commit message (?)
67+
G4ReweighterFactory RWFactory; //!< Base class to handle all Geant4Reweighters
6668
G4Reweighter *theReweighter; //!< Geant4Reweighter -- this is what provides the weights
6769
G4ReweightParameterMaker *ParMaker;
6870
std::vector<std::map<std::string, double>> UniverseVals; //!< Vector of maps relating parameter name to value (defines parameter values that will be evaluated in universes). Each map should have one entry per parameter we are considering
@@ -85,8 +87,12 @@ class Geant4WeightCalc : public WeightCalc {
8587
std::vector< double > p_energies_inel; //!< Variables for by-particle output tree
8688
std::vector< int > p_sliceInts_inel; //!< Variables for by-particle output tree
8789
int p_nElasticScatters; //!< Variables for by-particle output tree
88-
std::vector<double> p_inel_weight; //!< Variables for by-particle output tree
89-
std::vector<double> p_elastic_weight; //!< Variables for by-particle output
90+
std::vector<double> p_weight; //!< Variables for by-particle output tree
91+
92+
93+
// **IF** I understand correctly, then after commit 11077f2 (el_weight*inel_weight) is returned by GetWeight()
94+
//std::vector<double> p_inel_weight; //!< Variables for by-particle output tree
95+
//std::vector<double> p_elastic_weight; //!< Variables for by-particle output
9096

9197
bool fDebug; //!< print debug statements
9298

@@ -121,10 +127,9 @@ void Geant4WeightCalc::Configure(fhicl::ParameterSet const& p,
121127
TFile XSecFile( XSecFileName.c_str(), "OPEN" );
122128

123129
// Configure G4Reweighter
124-
bool totalonly = false;
125-
if (fPdg==2212) totalonly = true;
126-
ParMaker = new G4ReweightParameterMaker( FitParSets, totalonly );
127-
theReweighter = RWFactory.BuildReweighter(fPdg, &XSecFile, &FracsFile, ParMaker->GetFSHists(), ParMaker->GetElasticHist() );
130+
ParMaker = new G4ReweightParameterMaker( FitParSets, true , fPdg ); //TODO:Do we want check_overlap? Maybe a fcl switch?
131+
RWManager = new G4ReweightManager( FitParSets );
132+
theReweighter = RWFactory.BuildReweighter(fPdg, &FracsFile, ParMaker->GetFSHists(), pset, RWManager, ParMaker->GetElasticHist() );
128133

129134
// Make output trees to save things for quick and easy validation
130135
art::ServiceHandle<art::TFileService> tfs;
@@ -136,8 +141,10 @@ void Geant4WeightCalc::Configure(fhicl::ParameterSet const& p,
136141
fOutTree_Particle->Branch("subrun_num",&subrun_num);
137142
fOutTree_Particle->Branch("UniverseVals", &UniverseVals);
138143
fOutTree_Particle->Branch("pdg_to_reweight",&fPdg);
139-
fOutTree_Particle->Branch("inelastic_weight",&p_inel_weight);
140-
fOutTree_Particle->Branch("elastic_weight",&p_elastic_weight);
144+
145+
fOutTree_Particle->Branch("weight",&p_weight);
146+
//fOutTree_Particle->Branch("inelastic_weight",&p_inel_weight);
147+
//fOutTree_Particle->Branch("elastic_weight",&p_elastic_weight);
141148
fOutTree_Particle->Branch("track_length",&p_track_length);
142149
fOutTree_Particle->Branch("PDG",&p_PDG);
143150
fOutTree_Particle->Branch("final_proc",&p_final_proc);
@@ -252,10 +259,12 @@ std::vector<float> Geant4WeightCalc::GetWeight(art::Event& e, size_t itruth ) {
252259
for (size_t i=0; i<mcparticles.size(); i++) {
253260

254261
// Reset things to be saved in the output tree for fast validation
255-
p_inel_weight.clear();
256-
p_inel_weight.resize(fNsims,1.0);
257-
p_elastic_weight.clear();
258-
p_elastic_weight.resize(fNsims,1.0);
262+
p_weight.clear();
263+
p_weight.resize(fNsims,1.0);
264+
//p_inel_weight.clear();
265+
//p_inel_weight.resize(fNsims,1.0);
266+
//p_elastic_weight.clear();
267+
//p_elastic_weight.resize(fNsims,1.0);
259268
p_track_length=-9999;
260269
p_PDG=-9999;
261270
p_final_proc="dummy";
@@ -429,7 +438,7 @@ std::vector<float> Geant4WeightCalc::GetWeight(art::Event& e, size_t itruth ) {
429438

430439
// Loop through universes (j)
431440
for (size_t j=0; j<weight.size(); j++) {
432-
float w, el_w;
441+
float w/*, el_w*/;
433442

434443
// I think this is the only bit that needs to change for different universes -- all the above is jut about the track, which doesn't change based on universe
435444
ParMaker->SetNewVals(UniverseVals.at(j));
@@ -440,6 +449,10 @@ std::vector<float> Geant4WeightCalc::GetWeight(art::Event& e, size_t itruth ) {
440449
// Total weight is the product of track weights in the event
441450
weight[j] *= std::max((float)0.0, w);
442451

452+
// just for the output tree
453+
p_weight[j] = w;
454+
455+
/*
443456
// Do the same for elastic weight (should be 1 unless set to non-nominal )
444457
el_w = theReweighter->GetElasticWeight( &theTraj );
445458
weight[j] *= std::max((float)0.0,el_w);
@@ -453,12 +466,13 @@ std::vector<float> Geant4WeightCalc::GetWeight(art::Event& e, size_t itruth ) {
453466
// std::cout << UniverseVals.at(j) << std::endl;
454467
std::cout << " w = " << w << ", el_w = " << el_w << std::endl;
455468
}
456-
469+
*/
457470

458471
} // loop through universes (j)
459472

460473
if (fDebug){
461474
std::cout << "PDG = " << p_PDG << std::endl;
475+
/*
462476
std::cout << "inel weights by particle: ";
463477
for (unsigned int j=0; j<weight.size(); j++){
464478
std::cout << p_inel_weight[j] << ", ";
@@ -468,6 +482,11 @@ std::vector<float> Geant4WeightCalc::GetWeight(art::Event& e, size_t itruth ) {
468482
for (unsigned int j=0; j<weight.size(); j++){
469483
std::cout << p_elastic_weight[j] << ", ";
470484
}
485+
*/
486+
std::cout << "weights by particle: ";
487+
for (unsigned int j=0; j<weight.size(); j++){
488+
std::cout << p_weight[j] << ", ";
489+
}
471490
std::cout << std::endl;
472491
std::cout << "overall weight saved by event: ";
473492
for (unsigned int j=0; j<weight.size(); j++){

0 commit comments

Comments
 (0)