CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< edm::InputTag > _genEventInfos
Definition: WeightManager.h:29
static const TGPicture * info(bool iBackgroundIsBlack)
edm::InputTag _hepmcCollection
Definition: WeightManager.h:30
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
std::vector< edm::EDGetTokenT< std::vector< edm::InputTag > > > genEventInfosTokens_
Definition: WeightManager.h:33
edm::EDGetTokenT< edm::HepMCProduct > hepmcCollectionToken_
Definition: WeightManager.h:32
int iEvent
Definition: GenABIO.cc:224
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
WeightManager(const edm::ParameterSet &, edm::ConsumesCollector iC)
double weight(const edm::Event &)