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 
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 }
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 &)