CMS 3D CMS Logo

WeightManager.cc
Go to the documentation of this file.
4 
8 
9 using namespace edm;
10 
12  : _useHepMC(iConfig.getParameter<bool>("UseWeightFromHepMC")) {
13  if (_useHepMC) {
14  _hepmcCollection = iConfig.getParameter<InputTag>("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) {
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) {
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