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 {
15  if (_useHepMC){
16  _hepmcCollection = iConfig.getParameter<InputTag>("hepmcCollection");
18  }
19  else{
20  _genEventInfos = iConfig.getParameter<std::vector<InputTag> >("genEventInfos");
21  for(unsigned int i=0; i<_genEventInfos.size();i++) genEventInfosTokens_.push_back(iC.consumes<std::vector<InputTag> >(_genEventInfos[i]));
22  }
23 }
24 
26  if (_useHepMC){
28  iEvent.getByToken(hepmcCollectionToken_, evt);
29  const HepMC::GenEvent *myGenEvent = evt->GetEvent();
30 
31  double weight = 1.;
32  if (!myGenEvent->weights().empty())
33  weight = myGenEvent->weights()[0];
34  return weight;
35  } else {
36  double weight = 1.;
37  for (unsigned int i = 0; i < genEventInfosTokens_.size(); ++i){
39  iEvent.getByToken(genEventInfosTokens_[i], info);
40  weight *= info->weight();
41  }
42  return weight;
43  }
44 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
std::vector< edm::InputTag > _genEventInfos
Definition: WeightManager.h:31
static const TGPicture * info(bool iBackgroundIsBlack)
edm::InputTag _hepmcCollection
Definition: WeightManager.h:32
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
Definition: weight.py:1
std::vector< edm::EDGetTokenT< std::vector< edm::InputTag > > > genEventInfosTokens_
Definition: WeightManager.h:35
double weight() const
edm::EDGetTokenT< edm::HepMCProduct > hepmcCollectionToken_
Definition: WeightManager.h:34
int iEvent
Definition: GenABIO.cc:230
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
WeightManager(const edm::ParameterSet &, edm::ConsumesCollector iC)
HLT enums.
double weight(const edm::Event &)