Skip to content

Commit 0be9ee4

Browse files
author
Jack Smedley
committed
Add material input; This build ~works~ as long as you only run one particle type at time
1 parent 0509def commit 0be9ee4

3 files changed

Lines changed: 45 additions & 19 deletions

File tree

sbncode/SBNEventWeight/Calculators/Geant4/Geant4WeightCalc.cxx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,15 @@ class Geant4WeightCalc : public WeightCalc {
5959
std::string fMCParticleProducer; //!< Label for the MCParticle producer
6060
std::string fMCTruthProducer; //!< Label for the MCTruth producer
6161
CLHEP::RandGaussQ* fGaussRandom; //!< Random number generator
62+
fhicl::ParameterSet fMaterial; //!< Detector material, i.e. LAr
6263
// std::map<int, ParticleDef> fParticles; //!< Particles to reweight
6364
unsigned fNsims; //!< Number of multisims
6465
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.
6566
// float fXSUncertainty; //!< Flat cross section uncertainty
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
68-
G4Reweighter *theReweighter; //!< Geant4Reweighter -- this is what provides the weights
69-
G4ReweightParameterMaker *ParMaker;
67+
G4ReweightManager *fRWManager; //!< "holds the run manager and creates the detector" according to the commit message (?)
68+
G4ReweighterFactory fRWFactory; //!< Base class to handle all Geant4Reweighters
69+
G4Reweighter *fReweighter; //!< Geant4Reweighter -- this is what provides the weights
70+
G4ReweightParameterMaker *fParMaker;
7071
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
7172

7273
art::ServiceHandle < geo::Geometry > fGeometryService;
@@ -117,6 +118,7 @@ void Geant4WeightCalc::Configure(fhicl::ParameterSet const& p,
117118
std::vector< fhicl::ParameterSet > FitParSets = pset.get< std::vector< fhicl::ParameterSet > >("parameters");
118119
fNsims = pset.get<int> ("number_of_multisims", 0);
119120
fPdg = pset.get<int> ("pdg_to_reweight");
121+
fMaterial = pset.get<fhicl::ParameterSet> ("material");
120122
fDebug = pset.get<bool> ("debug",false);
121123

122124
// Prepare random generator
@@ -127,9 +129,9 @@ void Geant4WeightCalc::Configure(fhicl::ParameterSet const& p,
127129
TFile XSecFile( XSecFileName.c_str(), "OPEN" );
128130

129131
// Configure G4Reweighter
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() );
132+
fParMaker = new G4ReweightParameterMaker( FitParSets, true , fPdg ); //TODO:Do we want check_overlap? Maybe a fcl switch?
133+
fRWManager = new G4ReweightManager( {fMaterial} ); //Constructor asks for a vector, but SBN only cares about one material
134+
fReweighter = fRWFactory.BuildReweighter(fPdg, &FracsFile, fParMaker->GetFSHists(), fMaterial, fRWManager, fParMaker->GetElasticHist() );
133135

134136
// Make output trees to save things for quick and easy validation
135137
art::ServiceHandle<art::TFileService> tfs;
@@ -441,11 +443,11 @@ std::vector<float> Geant4WeightCalc::GetWeight(art::Event& e, size_t itruth ) {
441443
float w/*, el_w*/;
442444

443445
// 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
444-
ParMaker->SetNewVals(UniverseVals.at(j));
445-
theReweighter->SetNewHists(ParMaker->GetFSHists());
446-
theReweighter->SetNewElasticHists(ParMaker->GetElasticHist());
446+
fParMaker->SetNewVals(UniverseVals.at(j));
447+
fReweighter->SetNewHists(fParMaker->GetFSHists());
448+
fReweighter->SetNewElasticHists(fParMaker->GetElasticHist());
447449
//Get the weight from the G4ReweightTraj
448-
w = theReweighter->GetWeight( &theTraj );
450+
w = fReweighter->GetWeight( &theTraj );
449451
// Total weight is the product of track weights in the event
450452
weight[j] *= std::max((float)0.0, w);
451453

@@ -454,7 +456,7 @@ std::vector<float> Geant4WeightCalc::GetWeight(art::Event& e, size_t itruth ) {
454456

455457
/*
456458
// Do the same for elastic weight (should be 1 unless set to non-nominal )
457-
el_w = theReweighter->GetElasticWeight( &theTraj );
459+
el_w = fReweighter->GetElasticWeight( &theTraj );
458460
weight[j] *= std::max((float)0.0,el_w);
459461
460462
// just for the output tree

sbncode/SBNEventWeight/jobs/geant4/eventweight_geant4_sbn.fcl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "piplus_reweight_parameters.fcl"
1515
#include "piminus_reweight_parameters.fcl"
1616
#include "proton_reweight_parameters.fcl"
17+
#include "material_parameters.fcl"
1718

1819
BEGIN_PROLOG
1920

@@ -23,48 +24,53 @@ sbn_eventweight_geant4: {
2324
min_weight: 0.0
2425
max_weight: 100
2526

26-
weight_functions_reint: [ reinteractions_piplus, reinteractions_piminus, reinteractions_proton ]
27+
weight_functions_reint: [ reinteractions_piplus] #, reinteractions_piminus, reinteractions_proton ]
2728

2829
reinteractions_piplus: {
2930
type: Geant4
31+
material: @local::LAr
3032
random_seed: 58
3133
parameters: @local::PiPlusParameters
3234
mode: multisim
3335
number_of_multisims: 1000
3436
fracsfile: "$SBNDATA_DIR/systematics/reint/g4_fracs_piplus.root"
3537
xsecfile: "$SBNDATA_DIR/systematics/reint/g4_cross_section_piplus.root"
36-
makeoutputtree: false
38+
makeoutputtree: true
3739
pdg_to_reweight: 211
38-
debug: false
40+
debug: true
3941
}
4042

4143
reinteractions_piminus: {
4244
type: Geant4
45+
material: @local::LAr
4346
random_seed: 59
4447
parameters: @local::PiMinusParameters
4548
mode: multisim
4649
number_of_multisims: 1000
4750
fracsfile: "$SBNDATA_DIR/systematics/reint/g4_fracs_piminus.root"
4851
xsecfile: "$SBNDATA_DIR/systematics/reint/g4_cross_section_piminus.root"
49-
makeoutputtree: false
52+
makeoutputtree: true
5053
pdg_to_reweight: -211
51-
debug: false
54+
debug: true
5255
}
5356

5457
reinteractions_proton: {
5558
type: Geant4
59+
material: @local::LAr
5660
random_seed: 60
5761
parameters: @local::ProtonParameters
5862
mode: multisim
5963
number_of_multisims: 1000
6064
fracsfile: "$SBNDATA_DIR/systematics/reint/g4_fracs_proton.root"
6165
xsecfile: "$SBNDATA_DIR/systematics/reint/g4_cross_section_proton.root"
62-
makeoutputtree: false
66+
makeoutputtree: true
6367
pdg_to_reweight: 2212
64-
debug: false
68+
debug: true
6569
}
6670
}
6771

72+
# reinteractions_neutron
73+
6874
###
6975
# Reweighting parameters should be defined as
7076
#
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
BEGIN_PROLOG
2+
3+
# LAr parameters for geant4reweight, stolen out of the ND-Lar 2x2 implementation
4+
# A more complete solution would be to get this info out of the geometry instead...
5+
6+
LAr: {
7+
Name: "liquidArgon"
8+
Density: 1.390
9+
Components: [
10+
{
11+
Z: 18
12+
Mass: 39.95
13+
Fraction: 1.
14+
}
15+
]
16+
}
17+
18+
END_PROLOG

0 commit comments

Comments
 (0)