LDMX Software
simcore::GenieReweightProducer Class Reference

Public Member Functions

 GenieReweightProducer (const std::string &name, framework::Process &process)
 
virtual void configure (framework::config::Parameters &)
 Callback for the EventProcessor to configure itself from the given set of parameters.
 
virtual void onNewRun (const ldmx::RunHeader &runHeader)
 Callback for the EventProcessor to take any necessary action when the run being processed changes.
 
virtual void produce (framework::Event &event)
 Process the event and put new data products into it.
 
- Public Member Functions inherited from framework::Producer
 Producer (const std::string &name, Process &process)
 Class constructor.
 
virtual void process (Event &event) final
 Processing an event for a Producer is calling produce.
 
- Public Member Functions inherited from framework::EventProcessor
 DECLARE_FACTORY (EventProcessor, EventProcessor *, const std::string &, Process &)
 declare that we have a factory for this class
 
 EventProcessor (const std::string &name, Process &process)
 Class constructor.
 
virtual ~EventProcessor ()=default
 Class destructor.
 
virtual void beforeNewRun (ldmx::RunHeader &run_header)
 Callback for Producers to add parameters to the run header before conditions are initialized.
 
virtual void onFileOpen (EventFile &event_file)
 Callback for the EventProcessor to take any necessary action when a new event input ROOT file is opened.
 
virtual void onFileClose (EventFile &event_file)
 Callback for the EventProcessor to take any necessary action when a event input ROOT file is closed.
 
virtual void onProcessStart ()
 Callback for the EventProcessor to take any necessary action when the processing of events starts, such as creating histograms.
 
virtual void onProcessEnd ()
 Callback for the EventProcessor to take any necessary action when the processing of events finishes, such as calculating job-summary quantities.
 
template<class T >
const T & getCondition (const std::string &condition_name)
 Access a conditions object for the current event.
 
TDirectory * getHistoDirectory ()
 Access/create a directory in the histogram file for this event processor to create histograms and analysis tuples.
 
void setStorageHint (framework::StorageControl::Hint hint)
 Mark the current event as having the given storage control hint from this module_.
 
void setStorageHint (framework::StorageControl::Hint hint, const std::string &purposeString)
 Mark the current event as having the given storage control hint from this module and the given purpose string.
 
int getLogFrequency () const
 Get the current logging frequency from the process.
 
int getRunNumber () const
 Get the run number from the process.
 
std::string getName () const
 Get the processor name.
 
void createHistograms (const std::vector< framework::config::Parameters > &histos)
 Internal function which is used to create histograms passed from the python configuration @parma histos vector of Parameters that configure histograms to create.
 

Private Member Functions

void reinitializeGenieReweight ()
 
void reconfigureGenieReweight (size_t)
 

Static Private Member Functions

static genie::rew::EGSyst variationTypeToGenieDial (const ldmx::EventWeights::VariationType &vtype)
 

Private Attributes

std::string hepmc3_coll_name_
 
std::string hepmc3_pass_name_
 
std::string event_weights_coll_name_
 
int seed_
 
size_t n_weights_
 
std::string message_threshold_file_
 
std::string tune_
 
std::map< ldmx::EventWeights::VariationType, std::vector< double > > variation_map_
 
std::unique_ptr< genie::HepMC3Converter > hep_mc3_converter_
 
std::unique_ptr< genie::rew::GReWeight > genie_rw_
 

Additional Inherited Members

- Protected Member Functions inherited from framework::EventProcessor
void abortEvent ()
 Abort the event immediately.
 
- Protected Attributes inherited from framework::EventProcessor
HistogramPool histograms_
 helper object for making and filling histograms
 
NtupleManagerntuple_ {NtupleManager::getInstance()}
 Manager for any ntuples.
 
logging::logger the_log_
 The logger for this EventProcessor.
 

Detailed Description

Definition at line 27 of file GenieReweightProducer.h.

Constructor & Destructor Documentation

◆ GenieReweightProducer()

simcore::GenieReweightProducer::GenieReweightProducer ( const std::string & name,
framework::Process & process )

Definition at line 47 of file GenieReweightProducer.cxx.

49 : Producer(name, process) {
50 hep_mc3_converter_ = std::make_unique<genie::HepMC3Converter>();
51 genie_rw_ = std::make_unique<genie::rew::GReWeight>();
52}
Producer(const std::string &name, Process &process)
Class constructor.
virtual void process(Event &event) final
Processing an event for a Producer is calling produce.

Member Function Documentation

◆ configure()

void simcore::GenieReweightProducer::configure ( framework::config::Parameters & parameters)
virtual

Callback for the EventProcessor to configure itself from the given set of parameters.

The parameters a processor has access to are the member variables of the python class in the sequence that has className equal to the EventProcessor class name.

For an example, look at MyProcessor.

Parameters
parametersParameters for configuration.

Reimplemented from framework::EventProcessor.

Definition at line 54 of file GenieReweightProducer.cxx.

54 {
55 hepmc3_coll_name_ = ps.get<std::string>("hepmc3CollName");
56 hepmc3_pass_name_ = ps.get<std::string>("hepmc3PassName");
57 event_weights_coll_name_ = ps.get<std::string>("eventWeightsCollName");
58 seed_ = ps.get<int>("seed");
59 n_weights_ = static_cast<size_t>(ps.get<int>("n_weights"));
60 auto var_types_strings = ps.get<std::vector<std::string> >("var_types");
61
62 message_threshold_file_ = ps.get<std::string>("message_threshold_file");
63
64 std::default_random_engine generator(seed_);
65 std::normal_distribution<double> normal_distribution;
66
67 for (auto const& vt_str : var_types_strings) {
68 auto vtype = ldmx::EventWeights::stringToVariationType(vt_str);
69 for (size_t i_w = 0; i_w < n_weights_; ++i_w)
70 variation_map_[vtype].push_back(normal_distribution(generator));
71 }
72}

References framework::config::Parameters::get().

◆ onNewRun()

void simcore::GenieReweightProducer::onNewRun ( const ldmx::RunHeader & run_header)
virtual

Callback for the EventProcessor to take any necessary action when the run being processed changes.

Parameters
run_headerThe RunHeader containing run information.

Reimplemented from framework::EventProcessor.

Definition at line 94 of file GenieReweightProducer.cxx.

94 {
95 const std::string genie_tune_par = "GenieTune";
96 std::string new_tune;
97 for (auto par : runHeader.getStringParameters())
98 if (par.first.size() >= genie_tune_par.size() &&
99 par.first.compare(par.first.size() - genie_tune_par.size(),
100 genie_tune_par.size(), genie_tune_par) == 0) {
101 new_tune = par.second;
102 break;
103 }
104
105 if (tune_ != new_tune) {
106 ldmx_log(debug) << "Found new tune " << new_tune << " (used to be " << tune_
107 << ")" << std::endl;
108 tune_ = new_tune;
109 reinitializeGenieReweight();
110 }
111}

References ldmx::RunHeader::getStringParameters().

◆ produce()

void simcore::GenieReweightProducer::produce ( framework::Event & event)
virtual

Process the event and put new data products into it.

Parameters
eventThe Event to process.

Implements framework::Producer.

Definition at line 153 of file GenieReweightProducer.cxx.

153 {
154 // grab the input hepmc3 event collection
155 auto hepmc3_col = event.getObject<std::vector<ldmx::HepMC3GenEvent> >(
156 hepmc3_coll_name_, hepmc3_pass_name_);
157
158 // create an output weights
159 ldmx::EventWeights ev_weights(variation_map_);
160
161 for (size_t i_w = 0; i_w < n_weights_; ++i_w) {
162 double running_weight = 1;
163
164 reconfigureGenieReweight(i_w);
165
166 // setup a loop here ... but we're going to force only looping over one
167 // interaction if it exists for now.
168 for (size_t i_ev = 0; i_ev < 1; ++i_ev) {
169 auto const& hepmc3_ev = hepmc3_col.at(i_ev);
170 // fill our event data into a HepMC3GenEvent
171 HepMC3::GenEvent hepmc3_genev;
172 hepmc3_genev.read_data(hepmc3_ev);
173
174 // print it out to check it ...
175 if (i_w == 0) ldmx_log(debug) << hepmc3_genev;
176
177 // now convert to genie event record
178 auto genie_ev_record_ptr = hep_mc3_converter_->RetrieveGHEP(hepmc3_genev);
179
180 // print that out too ...
181 if (i_w == 0) ldmx_log(debug) << *genie_ev_record_ptr;
182
183 // auto this_weight = 1.0 + var_value*0.05;
184 auto this_weight = genie_rw_->CalcWeight(*genie_ev_record_ptr);
185
186 running_weight = running_weight * this_weight;
187
188 } // end loop over interactions in event
189
190 ev_weights.addWeight(running_weight);
191
192 } // end loop over weights
193
194 ldmx_log(trace) << ev_weights;
195
196 event.add(event_weights_coll_name_, ev_weights);
197}

◆ reconfigureGenieReweight()

void simcore::GenieReweightProducer::reconfigureGenieReweight ( size_t i_w)
private

Definition at line 113 of file GenieReweightProducer.cxx.

113 {
114 auto& syst = genie_rw_->Systematics();
115 for (auto var : variation_map_) {
116 if (var.first ==
117 ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_MFP_pi)
118 syst.Set(genie::rew::GSyst::FromString("MFP_pi"), var.second[i_w]);
119 else if (var.first ==
120 ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_MFP_N)
121 syst.Set(genie::rew::GSyst::FromString("MFP_N"), var.second[i_w]);
122 else if (var.first ==
123 ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_FrCEx_pi)
124 syst.Set(genie::rew::GSyst::FromString("FrCEx_pi"), var.second[i_w]);
125 else if (var.first ==
126 ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_FrInel_pi)
127 syst.Set(genie::rew::GSyst::FromString("FrInel_pi"), var.second[i_w]);
128 else if (var.first ==
129 ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_FrAbs_pi)
130 syst.Set(genie::rew::GSyst::FromString("FrAbs_pi"), var.second[i_w]);
131 else if (var.first ==
132 ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_FrPiProd_pi)
133 syst.Set(genie::rew::GSyst::FromString("FrPiProd_pi"), var.second[i_w]);
134 else if (var.first ==
135 ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_FrCEx_N)
136 syst.Set(genie::rew::GSyst::FromString("FrCEx_N"), var.second[i_w]);
137 else if (var.first ==
138 ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_FrInel_N)
139 syst.Set(genie::rew::GSyst::FromString("FrInel_N"), var.second[i_w]);
140 else if (var.first ==
141 ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_FrAbs_N)
142 syst.Set(genie::rew::GSyst::FromString("FrAbs_N"), var.second[i_w]);
143 else if (var.first ==
144 ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_FrPiProd_N)
145 syst.Set(genie::rew::GSyst::FromString("FrPiProd_N"), var.second[i_w]);
146 else if (var.first ==
147 ldmx::EventWeights::VariationType::kGENIE_HadrNuclTwkDial_FormZone)
148 syst.Set(genie::rew::GSyst::FromString("FormZone"), var.second[i_w]);
149 }
150 genie_rw_->Reconfigure();
151}

◆ reinitializeGenieReweight()

void simcore::GenieReweightProducer::reinitializeGenieReweight ( )
private

Definition at line 74 of file GenieReweightProducer.cxx.

74 {
75 genie_rw_ = std::make_unique<genie::rew::GReWeight>();
76
77 // set message thresholds
78 genie::utils::app_init::MesgThresholds(message_threshold_file_);
79
80 genie::RunOpt::Instance()->SetTuneName(tune_);
81 if (!genie::RunOpt::Instance()->Tune()) {
82 EXCEPTION_RAISE("ConfigurationException", "No TuneId in RunOption.");
83 }
84 genie::RunOpt::Instance()->BuildTune();
85
86 genie_rw_->AdoptWghtCalc("hadro_fzone", new genie::rew::GReWeightFZone);
87 genie_rw_->AdoptWghtCalc("hadro_intranuke", new genie::rew::GReWeightINuke);
88
89 auto& syst = genie_rw_->Systematics();
90 for (auto var : variation_map_)
91 syst.Init(variationTypeToGenieDial(var.first));
92}

◆ variationTypeToGenieDial()

static genie::rew::EGSyst simcore::GenieReweightProducer::variationTypeToGenieDial ( const ldmx::EventWeights::VariationType & vtype)
inlinestaticprivate

Definition at line 78 of file GenieReweightProducer.h.

79 {
80 switch (vtype) {
81 case ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_MFP_pi:
82 return genie::rew::EGSyst::kINukeTwkDial_MFP_pi;
83 case ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_MFP_N:
84 return genie::rew::EGSyst::kINukeTwkDial_MFP_N;
85 case ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_FrCEx_pi:
86 return genie::rew::EGSyst::kINukeTwkDial_FrCEx_pi;
87 case ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_FrInel_pi:
88 return genie::rew::EGSyst::kINukeTwkDial_FrInel_pi;
89 case ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_FrAbs_pi:
90 return genie::rew::EGSyst::kINukeTwkDial_FrAbs_pi;
91 case ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_FrPiProd_pi:
92 return genie::rew::EGSyst::kINukeTwkDial_FrPiProd_pi;
93 case ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_FrCEx_N:
94 return genie::rew::EGSyst::kINukeTwkDial_FrCEx_N;
95 case ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_FrInel_N:
96 return genie::rew::EGSyst::kINukeTwkDial_FrInel_N;
97 case ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_FrAbs_N:
98 return genie::rew::EGSyst::kINukeTwkDial_FrAbs_N;
99 case ldmx::EventWeights::VariationType::kGENIE_INukeTwkDial_FrPiProd_N:
100 return genie::rew::EGSyst::kINukeTwkDial_FrPiProd_N;
101 case ldmx::EventWeights::VariationType ::kGENIE_HadrNuclTwkDial_FormZone:
102 return genie::rew::EGSyst::kHadrNuclTwkDial_FormZone;
103 default:
104 return genie::rew::EGSyst::kNullSystematic;
105 }
106 return genie::rew::EGSyst::kNullSystematic;
107 }

Member Data Documentation

◆ event_weights_coll_name_

std::string simcore::GenieReweightProducer::event_weights_coll_name_
private

Definition at line 52 of file GenieReweightProducer.h.

◆ genie_rw_

std::unique_ptr<genie::rew::GReWeight> simcore::GenieReweightProducer::genie_rw_
private

Definition at line 73 of file GenieReweightProducer.h.

◆ hep_mc3_converter_

std::unique_ptr<genie::HepMC3Converter> simcore::GenieReweightProducer::hep_mc3_converter_
private

Definition at line 71 of file GenieReweightProducer.h.

◆ hepmc3_coll_name_

std::string simcore::GenieReweightProducer::hepmc3_coll_name_
private

Definition at line 46 of file GenieReweightProducer.h.

◆ hepmc3_pass_name_

std::string simcore::GenieReweightProducer::hepmc3_pass_name_
private

Definition at line 49 of file GenieReweightProducer.h.

◆ message_threshold_file_

std::string simcore::GenieReweightProducer::message_threshold_file_
private

Definition at line 61 of file GenieReweightProducer.h.

◆ n_weights_

size_t simcore::GenieReweightProducer::n_weights_
private

Definition at line 58 of file GenieReweightProducer.h.

◆ seed_

int simcore::GenieReweightProducer::seed_
private

Definition at line 55 of file GenieReweightProducer.h.

◆ tune_

std::string simcore::GenieReweightProducer::tune_
private

Definition at line 64 of file GenieReweightProducer.h.

◆ variation_map_

std::map<ldmx::EventWeights::VariationType, std::vector<double> > simcore::GenieReweightProducer::variation_map_
private

Definition at line 68 of file GenieReweightProducer.h.


The documentation for this class was generated from the following files: