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++)
20  }
21 }
22 
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 }
43 
44 std::vector<std::vector<double>> WeightManager::weightsCollection(const Event& iEvent) {
45  std::vector<std::vector<double>> weightsCollection;
46  for (unsigned int i = 0; i < genEventInfosTokens_.size(); ++i) {
48  iEvent.getByToken(genEventInfosTokens_[i], info);
49  weightsCollection.push_back(info->weights());
50  }
51 
52  return weightsCollection;
53 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
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:539
std::vector< edm::EDGetTokenT< GenEventInfoProduct > > genEventInfosTokens_
Definition: WeightManager.h:35
edm::EDGetTokenT< edm::HepMCProduct > hepmcCollectionToken_
Definition: WeightManager.h:34
int iEvent
Definition: GenABIO.cc:224
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
WeightManager(const edm::ParameterSet &, edm::ConsumesCollector iC)
std::vector< std::vector< double > > weightsCollection(const edm::Event &)
double weight(const edm::Event &)