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)
 
 ~WeightManager ()
 

Private Attributes

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

Detailed Description

Definition at line 20 of file WeightManager.h.

Constructor & Destructor Documentation

◆ WeightManager()

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

Definition at line 12 of file WeightManager.cc.

13  : _useHepMC(iConfig.getParameter<bool>("UseWeightFromHepMC")) {
14  if (_useHepMC) {
15  _hepmcCollection = iConfig.getParameter<InputTag>("hepmcCollection");
17  } else {
18  _genEventInfos = iConfig.getParameter<std::vector<InputTag> >("genEventInfos");
19  for (unsigned int i = 0; i < _genEventInfos.size(); i++)
20  genEventInfosTokens_.push_back(iC.consumes<std::vector<InputTag> >(_genEventInfos[i]));
21  }
22 }

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

◆ ~WeightManager()

WeightManager::~WeightManager ( )
inline

Definition at line 23 of file WeightManager.h.

23 {};

Member Function Documentation

◆ weight()

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

Definition at line 24 of file WeightManager.cc.

24  {
25  if (_useHepMC) {
27  iEvent.getByToken(hepmcCollectionToken_, evt);
28  const HepMC::GenEvent* myGenEvent = evt->GetEvent();
29 
30  double weight = 1.;
31  if (!myGenEvent->weights().empty())
32  weight = myGenEvent->weights()[0];
33  return weight;
34  } else {
35  double weight = 1.;
36  for (unsigned int i = 0; i < genEventInfosTokens_.size(); ++i) {
38  iEvent.getByToken(genEventInfosTokens_[i], info);
39  weight *= info->weight();
40  }
41  return weight;
42  }
43 }

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().

Member Data Documentation

◆ _genEventInfos

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

Definition at line 29 of file WeightManager.h.

Referenced by WeightManager().

◆ _hepmcCollection

edm::InputTag WeightManager::_hepmcCollection
private

Definition at line 30 of file WeightManager.h.

Referenced by WeightManager().

◆ _useHepMC

bool WeightManager::_useHepMC
private

Definition at line 28 of file WeightManager.h.

Referenced by weight(), and WeightManager().

◆ genEventInfosTokens_

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

Definition at line 33 of file WeightManager.h.

Referenced by weight(), and WeightManager().

◆ hepmcCollectionToken_

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

Definition at line 32 of file WeightManager.h.

Referenced by weight(), and WeightManager().

mps_fire.i
i
Definition: mps_fire.py:355
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:152
edm::Handle
Definition: AssociativeIterator.h:50
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
edm::ConsumesCollector::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: ConsumesCollector.h:49
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
WeightManager::_genEventInfos
std::vector< edm::InputTag > _genEventInfos
Definition: WeightManager.h:29
WeightManager::weight
double weight(const edm::Event &)
Definition: WeightManager.cc:24
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
WeightManager::_hepmcCollection
edm::InputTag _hepmcCollection
Definition: WeightManager.h:30
WeightManager::_useHepMC
bool _useHepMC
Definition: WeightManager.h:28
WeightManager::genEventInfosTokens_
std::vector< edm::EDGetTokenT< std::vector< edm::InputTag > > > genEventInfosTokens_
Definition: WeightManager.h:33
edm::HepMCProduct
Definition: HepMCProduct.h:18
edm::InputTag
Definition: InputTag.h:15
weight
Definition: weight.py:1
WeightManager::hepmcCollectionToken_
edm::EDGetTokenT< edm::HepMCProduct > hepmcCollectionToken_
Definition: WeightManager.h:32