Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
larsim
larsim
EventWeight
Base
WeightManager.h
Go to the documentation of this file.
1
/**
2
* \file WeightManager.h
3
*
4
*
5
* \brief Allows to interface to EventWeight calculators
6
*
7
* @author Marco Del Tutto <marco.deltutto@physics.ox.ac.uk>
8
*/
9
10
#ifndef WEIGHTMANAGER_H
11
#define WEIGHTMANAGER_H
12
13
#include "
art/Framework/Principal/fwd.h
"
14
#include "
art/Framework/Services/Registry/ServiceHandle.h
"
15
#include "nurandom/RandomUtils/NuRandomService.h"
16
#include "
lardataobj/Simulation/sim.h
"
17
#include "
fhiclcpp/ParameterSet.h
"
18
19
#include "
Weight_t.h
"
20
#include "
MCEventWeight.h
"
21
#include "
WeightCalc.h
"
22
#include "
WeightCalcFactory.h
"
23
24
namespace
evwgh
{
25
/**
26
\class WeightManager
27
*/
28
class
WeightManager
{
29
30
public
:
31
32
/// Default constructor
33
WeightManager
(
const
std::string
name
=
"WeightManager"
);
34
35
/// Default destructor
36
~WeightManager
(){}
37
38
/// Name getter
39
const
std::string
&
Name
()
const
;
40
41
/**
42
* @brief Configuration function
43
* @param cfg the input parameters for settings
44
* @param the enging creator for the random seed (usually passed with *this)
45
CONFIGURE FUNCTION: created the weights algorithms in the following way: \n
46
0) Looks at the weight_functions fcl parameter to get the name of the calculators \n
47
1) Creates the Calculators requested in step 0, and assigne a different random seed to each one \n
48
3) The future call WeightManager::Run will run the calculators \n
49
*/
50
template
<
typename
Module>
51
size_t
Configure
(
fhicl::ParameterSet
const
& cfg,
Module
& module);
52
53
/**
54
* @brief Core function (previous call to Configure is needed)
55
* @param e the art event
56
* @param inu the index of the simulated neutrino in the event
57
CORE FUNCTION: executes algorithms to assign a weight to the event as requested users. \n
58
WeightManager::Configure needs to be called first \n
59
The execution takes following steps: \n
60
0) Loos over all the previously emplaced calculators \n
61
1) For each of them calculates the weights (more weight can be requested per calculator) \n
62
3) Returns a map from "calculator name" to vector of weights calculated which is available inside MCEventWeight
63
*/
64
MCEventWeight
Run
(
art::Event
&
e
,
const
int
inu
);
65
66
/**
67
* @brief Returns the map between calculator name and Weight_t product
68
*/
69
std::map<std::string, Weight_t*>
GetWeightCalcMap
() {
return
fWeightCalcMap
; }
70
71
/// Reset
72
void
Reset
()
73
{
_configured
=
false
; }
74
75
void
PrintConfig
();
76
77
78
private
:
79
std::map<std::string, Weight_t*>
fWeightCalcMap
;
///< A set of custom weight calculators
80
bool
_configured
{
false
};
///< Readiness flag
81
std::string
_name
;
///< Name
82
};
83
84
template
<
typename
Module>
85
size_t
WeightManager::Configure
(
fhicl::ParameterSet
const
&
p
,
Module
& module)
86
{
87
88
::art::ServiceHandle<rndm::NuRandomService>
seedservice;
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
}
120
121
}
122
123
#endif
name
static QCString name
Definition:
declinfo.cpp:673
art::ServiceHandle
Definition:
ServiceHandle.h:37
evwgh::WeightCalcFactory::Create
static WeightCalc * Create(const std::string &classname)
Definition:
WeightCalcFactory.cxx:6
WeightCalc.h
evwgh::WeightManager::_name
std::string _name
Name.
Definition:
WeightManager.h:81
MCEventWeight.h
string
std::string string
Definition:
nybbler.cc:12
truth_ana.inu
int inu
Definition:
truth_ana.py:132
evwgh::Weight_t::fWeightCalc
WeightCalc * fWeightCalc
Definition:
Weight_t.h:33
evwgh::WeightManager::Reset
void Reset()
Reset.
Definition:
WeightManager.h:72
ParameterSet.h
ServiceHandle.h
evwgh::Weight_t
Definition:
Weight_t.h:9
evwgh::WeightManager
Definition:
WeightManager.h:28
e
const double e
Definition:
gUpMuFluxGen.cxx:165
WeightCalcFactory.h
Module
#define Module
Definition:
fortranscanner.cpp:56721
evwgh::WeightManager::GetWeightCalcMap
std::map< std::string, Weight_t * > GetWeightCalcMap()
Returns the map between calculator name and Weight_t product.
Definition:
WeightManager.h:69
evwgh::Weight_t::fWeightCalcType
std::string fWeightCalcType
Definition:
Weight_t.h:34
fhicl::ParameterSet::get
T get(std::string const &key) const
Definition:
ParameterSet.h:271
evwgh
Definition:
EventWeight_module.cc:31
test.p
p
Definition:
test.py:223
evwgh::WeightManager::Configure
size_t Configure(fhicl::ParameterSet const &cfg, Module &module)
Configuration function.
Definition:
WeightManager.h:85
evwgh::WeightCalc
Definition:
WeightCalc.h:19
evwgh::WeightManager::_configured
bool _configured
Readiness flag.
Definition:
WeightManager.h:80
fwd.h
evwgh::Weight_t::fNmultisims
int fNmultisims
Definition:
Weight_t.h:39
evwgh::WeightManager::WeightManager
WeightManager(const std::string name="WeightManager")
Default constructor.
Definition:
WeightManager.cxx:6
evwgh::MCEventWeight
Definition:
MCEventWeight.h:8
art::Event
Definition:
Event.h:22
evwgh::WeightManager::fWeightCalcMap
std::map< std::string, Weight_t * > fWeightCalcMap
A set of custom weight calculators.
Definition:
WeightManager.h:79
Weight_t.h
docstring.func
def func()
Definition:
docstring.py:7
evwgh::WeightManager::PrintConfig
void PrintConfig()
Definition:
WeightManager.cxx:51
evwgh::WeightManager::~WeightManager
~WeightManager()
Default destructor.
Definition:
WeightManager.h:36
sim.h
Tools and modules for checking out the basics of the Monte Carlo.
evwgh::WeightManager::Run
MCEventWeight Run(art::Event &e, const int inu)
Core function (previous call to Configure is needed)
Definition:
WeightManager.cxx:19
evwgh::WeightManager::Name
const std::string & Name() const
Name getter.
Definition:
WeightManager.cxx:12
fhicl::exception
cet::coded_exception< error, detail::translate > exception
Definition:
exception.h:33
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
fhicl::ParameterSet
Definition:
ParameterSet.h:36
Generated by
1.8.11