Validation
EventGenerator
src
WeightManager.cc
Go to the documentation of this file.
1
#include "
Validation/EventGenerator/interface/WeightManager.h
"
2
#include "
FWCore/Framework/interface/Event.h
"
3
#include "
FWCore/ParameterSet/interface/ParameterSet.h
"
4
5
#include "
DataFormats/Common/interface/Handle.h
"
6
#include "
SimDataFormats/GeneratorProducts/interface/HepMCProduct.h
"
7
#include "
SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h
"
8
9
using namespace
edm
;
10
11
WeightManager::WeightManager
(
const
ParameterSet
& iConfig,
edm::ConsumesCollector
iC)
12
: _useHepMC(iConfig.getParameter<
bool
>(
"UseWeightFromHepMC"
)) {
13
if
(
_useHepMC
) {
14
_hepmcCollection
= iConfig.
getParameter
<
InputTag
>(
"hepmcCollection"
);
15
hepmcCollectionToken_
= iC.
consumes
<
HepMCProduct
>(
_hepmcCollection
);
16
}
else
{
17
_genEventInfos
= iConfig.
getParameter
<std::vector<InputTag> >(
"genEventInfos"
);
18
for
(
unsigned
int
i
= 0;
i
<
_genEventInfos
.size();
i
++)
19
genEventInfosTokens_
.push_back(iC.
consumes
<std::vector<InputTag> >(
_genEventInfos
[
i
]));
20
}
21
}
22
23
double
WeightManager::weight
(
const
Event
&
iEvent
) {
24
if
(
_useHepMC
) {
25
edm::Handle<HepMCProduct>
evt;
26
iEvent
.getByToken(
hepmcCollectionToken_
, evt);
27
const
HepMC::GenEvent
* myGenEvent = evt->
GetEvent
();
28
29
double
weight
= 1.;
30
if
(!myGenEvent->weights().empty())
31
weight
= myGenEvent->weights()[0];
32
return
weight
;
33
}
else
{
34
double
weight
= 1.;
35
for
(
unsigned
int
i
= 0;
i
<
genEventInfosTokens_
.size(); ++
i
) {
36
edm::Handle<GenEventInfoProduct>
info
;
37
iEvent
.getByToken(
genEventInfosTokens_
[
i
],
info
);
38
weight
*=
info
->weight();
39
}
40
return
weight
;
41
}
42
}
Handle.h
electrons_cff.bool
bool
Definition:
electrons_cff.py:366
mps_fire.i
i
Definition:
mps_fire.py:428
edm
HLT enums.
Definition:
AlignableModifier.h:19
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition:
FWCollectionSummaryWidget.cc:153
WeightManager::WeightManager
WeightManager(const edm::ParameterSet &, edm::ConsumesCollector iC)
Definition:
WeightManager.cc:12
edm::Handle
Definition:
AssociativeIterator.h:50
HepMC::GenEvent
Definition:
hepmc_rootio.cc:9
edm::ConsumesCollector::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition:
ConsumesCollector.h:55
WeightManager.h
edm::ParameterSet
Definition:
ParameterSet.h:47
GenEventInfoProduct.h
Event.h
iEvent
int iEvent
Definition:
GenABIO.cc:224
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition:
HepMCProduct.h:37
WeightManager::_genEventInfos
std::vector< edm::InputTag > _genEventInfos
Definition:
WeightManager.h:29
WeightManager::weight
double weight(const edm::Event &)
Definition:
WeightManager.cc:24
WeightManager::_hepmcCollection
edm::InputTag _hepmcCollection
Definition:
WeightManager.h:30
WeightManager::_useHepMC
bool _useHepMC
Definition:
WeightManager.h:28
WeightManager::genEventInfosTokens_
std::vector< edm::EDGetTokenT< std::vector< edm::InputTag > > > genEventInfosTokens_
Definition:
WeightManager.h:33
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition:
ParameterSet.h:303
edm::HepMCProduct
Definition:
HepMCProduct.h:21
ParameterSet.h
HepMCProduct.h
edm::Event
Definition:
Event.h:73
edm::InputTag
Definition:
InputTag.h:15
edm::ConsumesCollector
Definition:
ConsumesCollector.h:45
weight
Definition:
weight.py:1
WeightManager::hepmcCollectionToken_
edm::EDGetTokenT< edm::HepMCProduct > hepmcCollectionToken_
Definition:
WeightManager.h:32
Generated for CMSSW Reference Manual by
1.8.16