CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
WeightManager Class Reference

#include <WeightManager.h>

Public Member Functions

double weight (const edm::Event &)
 
 WeightManager (const edm::ParameterSet &, edm::ConsumesCollector iC)
 
std::vector< std::vector< double > > weightsCollection (const edm::Event &)
 
 ~WeightManager ()
 

Private Attributes

std::vector< edm::InputTag_genEventInfos
 
edm::InputTag _hepmcCollection
 
bool _useHepMC
 
std::vector< edm::EDGetTokenT< GenEventInfoProduct > > genEventInfosTokens_
 
edm::EDGetTokenT< edm::HepMCProducthepmcCollectionToken_
 

Detailed Description

Definition at line 21 of file WeightManager.h.

Constructor & Destructor Documentation

◆ WeightManager()

WeightManager::WeightManager ( const edm::ParameterSet iConfig,
edm::ConsumesCollector  iC 
)

Definition at line 11 of file WeightManager.cc.

References _genEventInfos, _hepmcCollection, _useHepMC, edm::ConsumesCollector::consumes(), genEventInfosTokens_, edm::ParameterSet::getParameter(), hepmcCollectionToken_, and mps_fire::i.

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 }
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
edm::InputTag _hepmcCollection
Definition: WeightManager.h:32
std::vector< edm::EDGetTokenT< GenEventInfoProduct > > genEventInfosTokens_
Definition: WeightManager.h:35
edm::EDGetTokenT< edm::HepMCProduct > hepmcCollectionToken_
Definition: WeightManager.h:34

◆ ~WeightManager()

WeightManager::~WeightManager ( )
inline

Definition at line 24 of file WeightManager.h.

24 {}

Member Function Documentation

◆ weight()

double WeightManager::weight ( const edm::Event iEvent)

Definition at line 23 of file WeightManager.cc.

References _useHepMC, genEventInfosTokens_, edm::HepMCProduct::GetEvent(), hepmcCollectionToken_, mps_fire::i, iEvent, and info().

Referenced by WValidation::analyze(), BasicHepMCHeavyIonValidation::analyze(), DrellYanValidation::analyze(), BasicGenParticleValidation::analyze(), BasicHepMCValidation::analyze(), MBUEandQCDValidation::analyze(), HiggsValidation::analyze(), and DuplicationChecker::analyze().

23  {
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 }
static const TGPicture * info(bool iBackgroundIsBlack)
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
double weight(const edm::Event &)

◆ weightsCollection()

std::vector< std::vector< double > > WeightManager::weightsCollection ( const edm::Event iEvent)

Definition at line 44 of file WeightManager.cc.

References genEventInfosTokens_, mps_fire::i, iEvent, and info().

Referenced by GenWeightValidation::analyze().

44  {
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 }
static const TGPicture * info(bool iBackgroundIsBlack)
std::vector< edm::EDGetTokenT< GenEventInfoProduct > > genEventInfosTokens_
Definition: WeightManager.h:35
int iEvent
Definition: GenABIO.cc:224
std::vector< std::vector< double > > weightsCollection(const edm::Event &)

Member Data Documentation

◆ _genEventInfos

std::vector<edm::InputTag> WeightManager::_genEventInfos
private

Definition at line 31 of file WeightManager.h.

Referenced by WeightManager().

◆ _hepmcCollection

edm::InputTag WeightManager::_hepmcCollection
private

Definition at line 32 of file WeightManager.h.

Referenced by WeightManager().

◆ _useHepMC

bool WeightManager::_useHepMC
private

Definition at line 30 of file WeightManager.h.

Referenced by weight(), and WeightManager().

◆ genEventInfosTokens_

std::vector<edm::EDGetTokenT<GenEventInfoProduct> > WeightManager::genEventInfosTokens_
private

Definition at line 35 of file WeightManager.h.

Referenced by weight(), WeightManager(), and weightsCollection().

◆ hepmcCollectionToken_

edm::EDGetTokenT<edm::HepMCProduct> WeightManager::hepmcCollectionToken_
private

Definition at line 34 of file WeightManager.h.

Referenced by weight(), and WeightManager().