test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
WeightManager.cc
Go to the documentation of this file.
4 
8 
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 
25 double WeightManager::weight(const Event& iEvent){
26  if (_useHepMC){
28  iEvent.getByToken(hepmcCollectionToken_, evt);
29  const HepMC::GenEvent *myGenEvent = evt->GetEvent();
30 
31  double weight = 1.;
32  if (myGenEvent->weights().size() > 0)
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
int i
Definition: DBlmapReader.cc:9
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:464
std::vector< edm::EDGetTokenT< std::vector< edm::InputTag > > > genEventInfosTokens_
Definition: WeightManager.h:35
edm::EDGetTokenT< edm::HepMCProduct > hepmcCollectionToken_
Definition: WeightManager.h:34
int iEvent
Definition: GenABIO.cc:230
WeightManager(const edm::ParameterSet &, edm::ConsumesCollector iC)
double weight(const edm::Event &)