LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
evwgh::WeightManager Class Reference

#include "WeightManager.h"

Public Member Functions

 WeightManager (const std::string name="WeightManager")
 Default constructor. More...
 
 ~WeightManager ()
 Default destructor. More...
 
const std::string & Name () const
 Name getter. More...
 
size_t Configure (fhicl::ParameterSet const &cfg, art::EngineCreator &ec)
 Configuration function. More...
 
MCEventWeight Run (art::Event &e, const int inu)
 Core function (previous call to Configure is needed) More...
 
std::map< std::string, Weight_t * > GetWeightCalcMap ()
 Returns the map between calculator name and Weight_t product. More...
 
void Reset ()
 Reset. More...
 
void PrintConfig ()
 

Private Attributes

std::map< std::string, Weight_t * > fWeightCalcMap
 A set of custom weight calculators. More...
 
bool _configured = false
 Readiness flag. More...
 
std::string _name
 Name. More...
 

Detailed Description

Definition at line 39 of file WeightManager.h.

Constructor & Destructor Documentation

evwgh::WeightManager::WeightManager ( const std::string  name = "WeightManager")

Default constructor.

Definition at line 12 of file WeightManager.cxx.

References _configured.

13  : _name(name)
14  {
15  _configured = false;
16  }
std::string _name
Name.
Definition: WeightManager.h:94
bool _configured
Readiness flag.
Definition: WeightManager.h:92
evwgh::WeightManager::~WeightManager ( )
inline

Default destructor.

Definition at line 47 of file WeightManager.h.

References Configure(), e, Name(), and Run().

47 {}

Member Function Documentation

size_t evwgh::WeightManager::Configure ( fhicl::ParameterSet const &  cfg,
art::EngineCreator ec 
)

Configuration function.

Parameters
cfgthe input parameters for settings
theenging creator for the random seed (usually passed with *this) CONFIGURE FUNCTION: created the weights algorithms in the following way:
0) Looks at the weight_functions fcl parameter to get the name of the calculators
1) Creates the Calculators requested in step 0, and assigne a different random seed to each one
3) The future call WeightManager::Run will run the calculators

Definition at line 21 of file WeightManager.cxx.

References _configured, evwgh::WeightCalcFactory::Create(), rndm::NuRandomService::createEngine(), evwgh::Weight_t::fNmultisims, evwgh::Weight_t::fWeightCalc, fWeightCalcMap, evwgh::Weight_t::fWeightCalcType, and fhicl::ParameterSet::get().

Referenced by evwgh::EventWeight::EventWeight(), and ~WeightManager().

22  {
23 
25 
26  // Get list of weight functions
27  std::vector<std::string> rw_func = p.get<std::vector<std::string>>("weight_functions");
28 
29  // Loop over all the functions and register them
30  for (auto ifunc=rw_func.begin(); ifunc!=rw_func.end(); ifunc++)
31  {
32  fhicl::ParameterSet const &ps_func = p.get<fhicl::ParameterSet> (*ifunc);
33  std::string func_type = ps_func.get<std::string>("type");
34 
35  WeightCalc* wcalc=WeightCalcFactory::Create(func_type+"WeightCalc");
36  if ( wcalc == NULL )
37  throw cet::exception(__FUNCTION__) << "Function " << *ifunc << " requested in fcl file has not been registered!" << std::endl;
38  if ( fWeightCalcMap.find(*ifunc)!= fWeightCalcMap.end() )
39  throw cet::exception(__FUNCTION__) << "Function " << *ifunc << " has been requested multiple times in fcl file!" << std::endl;
40 
41  //mf::LogInfo("") << "Configuring weight calculator " << *ifunc;
42 
43  // Create random engine for each rw function (name=*ifunc) (and seed it with random_seed set in the fcl)
44  seedservice->createEngine(engine, "HepJamesRandom", *ifunc, ps_func, "random_seed");
45 
46  wcalc->SetName(*ifunc);
47  wcalc->Configure(p);
48  Weight_t* winfo=new Weight_t();
49  winfo->fWeightCalcType=func_type;
50  winfo->fWeightCalc=wcalc;
51  winfo->fNmultisims=ps_func.get<int>("number_of_multisims");
52 
53  std::pair<std::string, Weight_t*> pwc(*ifunc,winfo);
54  fWeightCalcMap.insert(pwc);
55  }
56 
57  _configured = true;
58 
59  return fWeightCalcMap.size();
60  }
static WeightCalc * Create(const std::string &classname)
T * get() const
Definition: ServiceHandle.h:71
seed_t createEngine(art::EngineCreator &module, std::string type, std::string instance="")
Creates an engine with RandomNumberGenerator service.
T get(std::string const &key) const
Definition: ParameterSet.h:231
bool _configured
Readiness flag.
Definition: WeightManager.h:92
std::map< std::string, Weight_t * > fWeightCalcMap
A set of custom weight calculators.
Definition: WeightManager.h:90
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::map<std::string, Weight_t*> evwgh::WeightManager::GetWeightCalcMap ( )
inline

Returns the map between calculator name and Weight_t product.

Definition at line 79 of file WeightManager.h.

References fWeightCalcMap.

Referenced by evwgh::EventWeight::endJob().

79 { return fWeightCalcMap; }
std::map< std::string, Weight_t * > fWeightCalcMap
A set of custom weight calculators.
Definition: WeightManager.h:90
const std::string & evwgh::WeightManager::Name ( ) const

Name getter.

Definition at line 18 of file WeightManager.cxx.

References _name.

Referenced by ~WeightManager().

19  { return _name; }
std::string _name
Name.
Definition: WeightManager.h:94
void evwgh::WeightManager::PrintConfig ( )

Definition at line 99 of file WeightManager.cxx.

Referenced by Reset().

99  {
100 
101  return;
102  }
void evwgh::WeightManager::Reset ( )
inline

Reset.

Definition at line 82 of file WeightManager.h.

References _configured, and PrintConfig().

83  { _configured = false; }
bool _configured
Readiness flag.
Definition: WeightManager.h:92
MCEventWeight evwgh::WeightManager::Run ( art::Event e,
const int  inu 
)

Core function (previous call to Configure is needed)

Parameters
ethe art event
inuthe index of the simulated neutrino in the event CORE FUNCTION: executes algorithms to assign a weight to the event as requested users.
WeightManager::Configure needs to be called first
The execution takes following steps:
0) Loos over all the previously emplaced calculators
1) For each of them calculates the weights (more weight can be requested per calculator)
3) Returns a map from "calculator name" to vector of weights calculated which is available inside MCEventWeight

Definition at line 67 of file WeightManager.cxx.

References _configured, evwgh::MCEventWeight::fWeight, and fWeightCalcMap.

Referenced by evwgh::EventWeight::produce(), and ~WeightManager().

68  {
69 
70  if (!_configured)
71  throw cet::exception(__PRETTY_FUNCTION__) << "Have not configured yet!" << std::endl;
72 
73  //
74  // Loop over all functions ang calculate weights
75  //
76  MCEventWeight mcwgh;
77  for (auto it = fWeightCalcMap.begin() ;it != fWeightCalcMap.end(); it++) {
78 
79  auto const & weights = it->second->GetWeight(e);
80 
81  if(weights.size() == 0){
82  std::vector<double> empty;
83  std::pair<std::string, std::vector <double> > p("empty",empty);
84  mcwgh.fWeight.insert(p);
85  }
86  else{
87  std::pair<std::string, std::vector<double> >
88  p(it->first+"_"+it->second->fWeightCalcType,
89  weights[inu]);
90  mcwgh.fWeight.insert(p);
91  }
92  }
93 
94  return mcwgh;
95  }
bool _configured
Readiness flag.
Definition: WeightManager.h:92
std::map< std::string, Weight_t * > fWeightCalcMap
A set of custom weight calculators.
Definition: WeightManager.h:90
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33

Member Data Documentation

bool evwgh::WeightManager::_configured = false
private

Readiness flag.

Definition at line 92 of file WeightManager.h.

Referenced by Configure(), Reset(), Run(), and WeightManager().

std::string evwgh::WeightManager::_name
private

Name.

Definition at line 94 of file WeightManager.h.

Referenced by Name().

std::map<std::string, Weight_t*> evwgh::WeightManager::fWeightCalcMap
private

A set of custom weight calculators.

Definition at line 90 of file WeightManager.h.

Referenced by Configure(), GetWeightCalcMap(), and Run().


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