CMS 3D CMS Logo

WeightManager.cc
Go to the documentation of this file.
4 
9 
10 using namespace edm;
11 
13  : _useHepMC(iConfig.getParameter<bool>("UseWeightFromHepMC")) {
14  if (_useHepMC) {
15  _hepmcCollection = iConfig.getParameter<InputTag>("hepmcCollection");
17  } else {
18  _genEventInfos = iConfig.getParameter<std::vector<InputTag> >("genEventInfos");
19  for (unsigned int i = 0; i < _genEventInfos.size(); i++)
20  genEventInfosTokens_.push_back(iC.consumes<std::vector<InputTag> >(_genEventInfos[i]));
21  }
22 }
23 
25  if (_useHepMC) {
27  iEvent.getByToken(hepmcCollectionToken_, evt);
28  const HepMC::GenEvent* myGenEvent = evt->GetEvent();
29 
30  double weight = 1.;
31  if (!myGenEvent->weights().empty())
32  weight = myGenEvent->weights()[0];
33  return weight;
34  } else {
35  double weight = 1.;
36  for (unsigned int i = 0; i < genEventInfosTokens_.size(); ++i) {
38  iEvent.getByToken(genEventInfosTokens_[i], info);
39  weight *= info->weight();
40  }
41  return weight;
42  }
43 }
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
DQMHelper.h
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