CMS 3D CMS Logo

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
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
static const TGPicture * info(bool iBackgroundIsBlack)
edm::InputTag _hepmcCollection
Definition: WeightManager.h:32
std::vector< edm::EDGetTokenT< GenEventInfoProduct > > genEventInfosTokens_
Definition: WeightManager.h:35
Definition: weight.py:1
edm::EDGetTokenT< edm::HepMCProduct > hepmcCollectionToken_
Definition: WeightManager.h:34
int iEvent
Definition: GenABIO.cc:224
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
WeightManager(const edm::ParameterSet &, edm::ConsumesCollector iC)
HLT enums.
std::vector< std::vector< double > > weightsCollection(const edm::Event &)
double weight(const edm::Event &)