Public Member Functions | Private Attributes | List of all members
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::stringName () const
 Name getter. More...
 
template<typename Module >
size_t Configure (fhicl::ParameterSet const &cfg, Module &module)
 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 28 of file WeightManager.h.

Constructor & Destructor Documentation

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

Default constructor.

Definition at line 6 of file WeightManager.cxx.

7  : _name(name)
8  {
9  _configured = false;
10  }
static QCString name
Definition: declinfo.cpp:673
std::string _name
Name.
Definition: WeightManager.h:81
bool _configured
Readiness flag.
Definition: WeightManager.h:80
evwgh::WeightManager::~WeightManager ( )
inline

Default destructor.

Definition at line 36 of file WeightManager.h.

36 {}

Member Function Documentation

template<typename Module >
size_t evwgh::WeightManager::Configure ( fhicl::ParameterSet const &  cfg,
Module module 
)

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 85 of file WeightManager.h.

86  {
87 
89 
90  // Get list of weight functions
91  auto const rw_func = p.get<std::vector<std::string>>("weight_functions");
92 
93  // Loop over all the functions and register them
94  auto const module_label = p.get<std::string>("module_label");
95  for (auto const& func : rw_func) {
96  auto const ps_func = p.get<fhicl::ParameterSet>(func);
97  std::string func_type = ps_func.get<std::string>("type");
98 
99  WeightCalc* wcalc=WeightCalcFactory::Create(func_type+"WeightCalc");
100  if (wcalc == nullptr)
101  throw cet::exception(__FUNCTION__) << "Function " << func << " requested in fcl file has not been registered!" << std::endl;
102  if (fWeightCalcMap.find(func) != fWeightCalcMap.end())
103  throw cet::exception(__FUNCTION__) << "Function " << func << " has been requested multiple times in fcl file!" << std::endl;
104 
105  // Create random engine for each rw function (name=func) (and seed it with random_seed set in the fcl)
106  CLHEP::HepRandomEngine& engine = seedservice->createEngine(module, "HepJamesRandom", func, ps_func, "random_seed");
107  wcalc->SetName(func);
108  wcalc->Configure(p, engine);
109  Weight_t* winfo=new Weight_t();
110  winfo->fWeightCalcType=func_type;
111  winfo->fWeightCalc=wcalc;
112  winfo->fNmultisims=ps_func.get<int>("number_of_multisims", 0);
113 
114  fWeightCalcMap.emplace(func, winfo);
115 }
116 
117  _configured = true;
118  return fWeightCalcMap.size();
119  }
static WeightCalc * Create(const std::string &classname)
std::string string
Definition: nybbler.cc:12
p
Definition: test.py:223
bool _configured
Readiness flag.
Definition: WeightManager.h:80
std::map< std::string, Weight_t * > fWeightCalcMap
A set of custom weight calculators.
Definition: WeightManager.h:79
def func()
Definition: docstring.py:7
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
std::map<std::string, Weight_t*> evwgh::WeightManager::GetWeightCalcMap ( )
inline

Returns the map between calculator name and Weight_t product.

Definition at line 69 of file WeightManager.h.

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

Name getter.

Definition at line 12 of file WeightManager.cxx.

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

Definition at line 51 of file WeightManager.cxx.

51  {
52 
53  return;
54  }
void evwgh::WeightManager::Reset ( void  )
inline

Reset.

Definition at line 72 of file WeightManager.h.

73  { _configured = false; }
bool _configured
Readiness flag.
Definition: WeightManager.h:80
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 19 of file WeightManager.cxx.

20  {
21 
22  if (!_configured)
23  throw cet::exception(__PRETTY_FUNCTION__) << "Have not configured yet!" << std::endl;
24 
25  //
26  // Loop over all functions ang calculate weights
27  //
28  MCEventWeight mcwgh;
29  for (auto it = fWeightCalcMap.begin() ;it != fWeightCalcMap.end(); it++) {
30 
31  auto const & weights = it->second->GetWeight(e);
32 
33  if(weights.size() == 0){
34  std::vector<double> empty;
35  std::pair<std::string, std::vector <double> > p("empty",empty);
36  mcwgh.fWeight.insert(p);
37  }
38  else{
39  std::pair<std::string, std::vector<double> >
40  p(it->first+"_"+it->second->fWeightCalcType,
41  weights[inu]);
42  mcwgh.fWeight.insert(p);
43  }
44  }
45 
46  return mcwgh;
47  }
p
Definition: test.py:223
bool _configured
Readiness flag.
Definition: WeightManager.h:80
std::map< std::string, Weight_t * > fWeightCalcMap
A set of custom weight calculators.
Definition: WeightManager.h:79
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:97
QTextStream & endl(QTextStream &s)

Member Data Documentation

bool evwgh::WeightManager::_configured {false}
private

Readiness flag.

Definition at line 80 of file WeightManager.h.

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

Name.

Definition at line 81 of file WeightManager.h.

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

A set of custom weight calculators.

Definition at line 79 of file WeightManager.h.


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