All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
sbn::evwgh::WeightManager Class Reference

#include <WeightManager.h>

Public Member Functions

 WeightManager ()
 
 ~WeightManager ()
 
template<typename Module >
size_t Configure (fhicl::ParameterSet const &cfg, Module &module)
 
EventWeightMap Run (art::Event &e, const int inu)
 
std::map< std::string,
WeightCalc * > 
GetWeightCalcMap ()
 

Private Attributes

std::map< std::string,
WeightCalc * > 
fWeightCalcMap
 A set of custom weight calculators. More...
 

Detailed Description

Definition at line 24 of file sbncode/sbncode/SBNEventWeight/Base/WeightManager.h.

Constructor & Destructor Documentation

sbn::evwgh::WeightManager::WeightManager ( )
inline

Definition at line 26 of file sbncode/sbncode/SBNEventWeight/Base/WeightManager.h.

26 {}
sbn::evwgh::WeightManager::~WeightManager ( )
inline

Definition at line 27 of file sbncode/sbncode/SBNEventWeight/Base/WeightManager.h.

27 {}

Member Function Documentation

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

CONFIGURE FUNCTION

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

Parameters
cfgthe input parameters for settings
theenging creator for the random seed (usually passed with *this)

Definition at line 66 of file sbncode/sbncode/SBNEventWeight/Base/WeightManager.h.

66  {
67  ::art::ServiceHandle<rndm::NuRandomService> seedservice;
68 
69  // Get list of weight functions
70  auto const rw_func = p.get<std::vector<std::string> >("weight_functions");
71  auto const module_label = p.get<std::string>("module_label");
72 
73  // Loop over all the functions and register them
74  for (auto const& func : rw_func) {
75  auto const ps_func = p.get<fhicl::ParameterSet>(func);
76  std::string func_type = ps_func.get<std::string>("type");
77 
78  WeightCalc* wcalc = WeightCalcFactory::Create(func_type + "WeightCalc");
79  if (wcalc == nullptr)
80  throw cet::exception(__FUNCTION__) << "Function " << func << " requested in fcl file has not been registered!" << std::endl;
81 
82  if (fWeightCalcMap.find(func) != fWeightCalcMap.end())
83  throw cet::exception(__FUNCTION__) << "Function " << func << " has been requested multiple times in fcl file!" << std::endl;
84 
85  // Create random engine for each rw function (name=func) (and seed it with random_seed set in the fcl)
86  CLHEP::HepRandomEngine& engine = seedservice->createEngine(module, "HepJamesRandom", func, ps_func, "random_seed");
87 
88  wcalc->SetName(func);
89  wcalc->SetType(func_type);
90  wcalc->Configure(p, engine);
91 
92  fWeightCalcMap.emplace(func, wcalc);
93  }
94 
95  return fWeightCalcMap.size();
96 }
pdgs p
Definition: selectors.fcl:22
std::map< std::string, WeightCalc * > fWeightCalcMap
A set of custom weight calculators.
static WeightCalc * Create(const std::string &classname)
std::map<std::string, WeightCalc*> sbn::evwgh::WeightManager::GetWeightCalcMap ( )
inline

Returns the map between calculator name and WeightCalcs

Definition at line 58 of file sbncode/sbncode/SBNEventWeight/Base/WeightManager.h.

58 { return fWeightCalcMap; }
std::map< std::string, WeightCalc * > fWeightCalcMap
A set of custom weight calculators.
EventWeightMap sbn::evwgh::WeightManager::Run ( art::Event &  e,
const int  inu 
)

CORE FUNCTION: executes algorithms to assign a weight to the event as requested users.
WeightManager::Configure needs to be called first
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 EventWeightMap

Parameters
ethe art event
inuthe index of the simulated neutrino in the event

Definition at line 9 of file sbncode/sbncode/SBNEventWeight/Base/WeightManager.cxx.

9  {
10  EventWeightMap mcwgh;
11 
12  for (auto it=fWeightCalcMap.begin(); it!=fWeightCalcMap.end(); ++it) {
13  const std::vector<float>& weights = it->second->GetWeight(e, inu);
14  std::string wname = it->first + "_" + it->second->GetType();
15  mcwgh.insert({ wname, weights });
16  }
17 
18  return mcwgh;
19 }
std::map< std::string, std::vector< float > > EventWeightMap
Container for event-level weights.
std::map< std::string, WeightCalc * > fWeightCalcMap
A set of custom weight calculators.
do i e

Member Data Documentation

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

A set of custom weight calculators.

Definition at line 61 of file sbncode/sbncode/SBNEventWeight/Base/WeightManager.h.


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