CMS 3D CMS Logo

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

#include <TrackingPFG/PileUp/src/MCVerticesAnalyzer.cc>

Inheritance diagram for MCVerticesAnalyzer:
edm::one::EDAnalyzer< edm::one::SharedResources > edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

 MCVerticesAnalyzer (const edm::ParameterSet &)
 
 ~MCVerticesAnalyzer () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::SharedResources >
 EDAnalyzer ()=default
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase &&)=default
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 

Private Attributes

edm::EDGetTokenT< double > m_doubleToken
 
edm::EDGetTokenT< edm::HepMCProductm_hepMCProductToken
 
TH1F * m_hlumi
 
TH1F * m_hmainvtxx
 
TH1F * m_hmainvtxy
 
TH1F * m_hmainvtxz
 
TH1F * m_hnvtx
 
TH2F * m_hnvtxvsbx
 
TH2F * m_hnvtxvslumi
 
TH1F * m_hnvtxweight
 
TProfile * m_hnvtxweightprof
 
TH1F * m_hpileupvtxz
 
const bool m_useweight
 
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > m_vecPileupSummaryInfoToken
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< B > consumes (edm::InputTag tag) noexcept
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes () noexcept
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag) noexcept
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 

Detailed Description

Description: <one line="" class="" summary>="">

Implementation: <Notes on="" implementation>="">

Definition at line 54 of file MCVerticesAnalyzer.cc.

Constructor & Destructor Documentation

◆ MCVerticesAnalyzer()

MCVerticesAnalyzer::MCVerticesAnalyzer ( const edm::ParameterSet iConfig)
explicit

Definition at line 93 of file MCVerticesAnalyzer.cc.

94  : m_useweight(iConfig.getParameter<bool>("useWeight")),
95  m_doubleToken(consumes<double>(iConfig.getParameter<edm::InputTag>("weightProduct"))),
97  consumes<std::vector<PileupSummaryInfo> >(iConfig.getParameter<edm::InputTag>("pileupSummaryCollection"))),
98  m_hepMCProductToken(consumes<edm::HepMCProduct>(iConfig.getParameter<edm::InputTag>("mcTruthCollection"))) {
99  //now do what ever initialization is needed
100 
101  usesResource("TFileService");
103 
104  m_hnvtx = tfserv->make<TH1F>("nvtx", "Number of pileup vertices", 400, -0.5, 399.5);
105  m_hnvtx->GetXaxis()->SetTitle("Number of Interactions");
106 
107  m_hnvtxvsbx = tfserv->make<TH2F>("nvtxvsbx", "Number of pileup vertices vs BX", 9, -4.5, 4.5, 400, -0.5, 399.5);
108  m_hnvtxvsbx->GetXaxis()->SetTitle("BX number");
109  m_hnvtxvsbx->GetYaxis()->SetTitle("Number of Interactions");
110 
111  m_hlumi = tfserv->make<TH1F>("lumi", "BX luminosity*xsect", 200, 0., 50.);
112  m_hlumi->GetXaxis()->SetTitle("Average Number of Interactions");
113 
114  m_hnvtxvslumi = tfserv->make<TH2F>("nvtxvslumi", "Npileup vs BX luminosity*xsect", 200, 0., 50., 400, -0.5, 399.5);
115  m_hnvtxvslumi->GetXaxis()->SetTitle("Average Number of Interactions");
116  m_hnvtxvslumi->GetYaxis()->SetTitle("Number of Interactions");
117 
118  if (m_useweight) {
119  m_hnvtxweight = tfserv->make<TH1F>("nvtxweight", "Number of pileup vertices (1-w)", 400, -0.5, 399.5);
120  m_hnvtxweight->GetXaxis()->SetTitle("Number of Interactions");
122  tfserv->make<TProfile>("nvtxweightprof", "Mean (1-w) vs Number of pileup interactions", 400, -0.5, 399.5);
123  m_hnvtxweightprof->GetXaxis()->SetTitle("Number of Interactions");
124  }
125 
126  m_hmainvtxx = tfserv->make<TH1F>("mainvtxx", "Main vertex x position", 200, -.5, .5);
127  m_hmainvtxx->GetXaxis()->SetTitle("X (cm)");
128  m_hmainvtxy = tfserv->make<TH1F>("mainvtxy", "Main vertex y position", 200, -.5, .5);
129  m_hmainvtxy->GetXaxis()->SetTitle("Y (cm)");
130  m_hmainvtxz = tfserv->make<TH1F>("mainvtxz", "Main vertex z position", 600, -30., 30.);
131  m_hmainvtxz->GetXaxis()->SetTitle("Z (cm)");
132  m_hpileupvtxz = tfserv->make<TH1F>("pileupvtxz", "PileUp vertices z position", 600, -30., 30.);
133  m_hpileupvtxz->GetXaxis()->SetTitle("Z (cm)");
134 }

References m_hlumi, m_hmainvtxx, m_hmainvtxy, m_hmainvtxz, m_hnvtx, m_hnvtxvsbx, m_hnvtxvslumi, m_hnvtxweight, m_hnvtxweightprof, m_hpileupvtxz, m_useweight, and TFileService::make().

◆ ~MCVerticesAnalyzer()

MCVerticesAnalyzer::~MCVerticesAnalyzer ( )
override

Definition at line 136 of file MCVerticesAnalyzer.cc.

136  {
137  // do anything here that needs to be done at desctruction time
138  // (e.g. close files, deallocate resources etc.)
139 }

Member Function Documentation

◆ analyze()

void MCVerticesAnalyzer::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Implements edm::one::EDAnalyzerBase.

Definition at line 146 of file MCVerticesAnalyzer.cc.

146  {
147  double weight = 1.;
148 
149  if (m_useweight) {
150  edm::Handle<double> weightprod;
151  iEvent.getByToken(m_doubleToken, weightprod);
152 
153  weight = *weightprod;
154  }
155 
157  iEvent.getByToken(m_vecPileupSummaryInfoToken, pileupinfos);
158 
159  //
160 
161  if (pileupinfos.isValid()) {
162  // look for the intime PileupSummaryInfo
163 
164  std::vector<PileupSummaryInfo>::const_iterator pileupinfo;
165 
166  for (pileupinfo = pileupinfos->begin(); pileupinfo != pileupinfos->end(); ++pileupinfo) {
167  m_hnvtxvsbx->Fill(pileupinfo->getBunchCrossing(), pileupinfo->getPU_NumInteractions(), weight);
168  }
169 
170  for (pileupinfo = pileupinfos->begin(); pileupinfo != pileupinfos->end(); ++pileupinfo) {
171  if (pileupinfo->getBunchCrossing() == 0)
172  break;
173  }
174 
175  //
176 
177  if (pileupinfo->getBunchCrossing() != 0) {
178  edm::LogError("NoInTimePileUpInfo") << "Cannot find the in-time pileup info " << pileupinfo->getBunchCrossing();
179  } else {
180  m_hlumi->Fill(pileupinfo->getTrueNumInteractions(), weight);
181  m_hnvtx->Fill(pileupinfo->getPU_NumInteractions(), weight);
182  m_hnvtxvslumi->Fill(pileupinfo->getTrueNumInteractions(), pileupinfo->getPU_NumInteractions(), weight);
183 
184  if (m_useweight) {
185  m_hnvtxweight->Fill(pileupinfo->getPU_NumInteractions(), 1. - weight);
186  m_hnvtxweightprof->Fill(pileupinfo->getPU_NumInteractions(), 1. - weight);
187  }
188 
189  const std::vector<float>& zpositions = pileupinfo->getPU_zpositions();
190 
191  for (std::vector<float>::const_iterator zpos = zpositions.begin(); zpos != zpositions.end(); ++zpos) {
192  m_hpileupvtxz->Fill(*zpos, weight);
193  }
194  }
195  }
196  // main interaction part
197 
199  iEvent.getByToken(m_hepMCProductToken, EvtHandle);
200 
201  if (EvtHandle.isValid()) {
202  const HepMC::GenEvent* Evt = EvtHandle->GetEvent();
203 
204  // get the first vertex
205 
206  if (Evt->vertices_begin() != Evt->vertices_end()) {
207  m_hmainvtxx->Fill((*Evt->vertices_begin())->point3d().x() / 10., weight);
208  m_hmainvtxy->Fill((*Evt->vertices_begin())->point3d().y() / 10., weight);
209  m_hmainvtxz->Fill((*Evt->vertices_begin())->point3d().z() / 10., weight);
210  }
211  }
212 }

References edm::HepMCProduct::GetEvent(), iEvent, edm::HandleBase::isValid(), m_doubleToken, m_hepMCProductToken, m_hlumi, m_hmainvtxx, m_hmainvtxy, m_hmainvtxz, m_hnvtx, m_hnvtxvsbx, m_hnvtxvslumi, m_hnvtxweight, m_hnvtxweightprof, m_hpileupvtxz, m_useweight, m_vecPileupSummaryInfoToken, and mps_merge::weight.

Member Data Documentation

◆ m_doubleToken

edm::EDGetTokenT<double> MCVerticesAnalyzer::m_doubleToken
private

Definition at line 66 of file MCVerticesAnalyzer.cc.

Referenced by analyze().

◆ m_hepMCProductToken

edm::EDGetTokenT<edm::HepMCProduct> MCVerticesAnalyzer::m_hepMCProductToken
private

Definition at line 68 of file MCVerticesAnalyzer.cc.

Referenced by analyze().

◆ m_hlumi

TH1F* MCVerticesAnalyzer::m_hlumi
private

Definition at line 72 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

◆ m_hmainvtxx

TH1F* MCVerticesAnalyzer::m_hmainvtxx
private

Definition at line 76 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

◆ m_hmainvtxy

TH1F* MCVerticesAnalyzer::m_hmainvtxy
private

Definition at line 77 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

◆ m_hmainvtxz

TH1F* MCVerticesAnalyzer::m_hmainvtxz
private

Definition at line 78 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

◆ m_hnvtx

TH1F* MCVerticesAnalyzer::m_hnvtx
private

Definition at line 70 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

◆ m_hnvtxvsbx

TH2F* MCVerticesAnalyzer::m_hnvtxvsbx
private

Definition at line 71 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

◆ m_hnvtxvslumi

TH2F* MCVerticesAnalyzer::m_hnvtxvslumi
private

Definition at line 73 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

◆ m_hnvtxweight

TH1F* MCVerticesAnalyzer::m_hnvtxweight
private

Definition at line 74 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

◆ m_hnvtxweightprof

TProfile* MCVerticesAnalyzer::m_hnvtxweightprof
private

Definition at line 75 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

◆ m_hpileupvtxz

TH1F* MCVerticesAnalyzer::m_hpileupvtxz
private

Definition at line 79 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

◆ m_useweight

const bool MCVerticesAnalyzer::m_useweight
private

Definition at line 64 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

◆ m_vecPileupSummaryInfoToken

edm::EDGetTokenT<std::vector<PileupSummaryInfo> > MCVerticesAnalyzer::m_vecPileupSummaryInfoToken
private

Definition at line 67 of file MCVerticesAnalyzer.cc.

Referenced by analyze().

MCVerticesAnalyzer::m_useweight
const bool m_useweight
Definition: MCVerticesAnalyzer.cc:64
mps_merge.weight
weight
Definition: mps_merge.py:88
edm::Handle< double >
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
MCVerticesAnalyzer::m_hmainvtxz
TH1F * m_hmainvtxz
Definition: MCVerticesAnalyzer.cc:78
MCVerticesAnalyzer::m_doubleToken
edm::EDGetTokenT< double > m_doubleToken
Definition: MCVerticesAnalyzer.cc:66
MCVerticesAnalyzer::m_hlumi
TH1F * m_hlumi
Definition: MCVerticesAnalyzer.cc:72
MCVerticesAnalyzer::m_hmainvtxy
TH1F * m_hmainvtxy
Definition: MCVerticesAnalyzer.cc:77
MCVerticesAnalyzer::m_vecPileupSummaryInfoToken
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > m_vecPileupSummaryInfoToken
Definition: MCVerticesAnalyzer.cc:67
MCVerticesAnalyzer::m_hpileupvtxz
TH1F * m_hpileupvtxz
Definition: MCVerticesAnalyzer.cc:79
edm::Service< TFileService >
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
MCVerticesAnalyzer::m_hnvtx
TH1F * m_hnvtx
Definition: MCVerticesAnalyzer.cc:70
MCVerticesAnalyzer::m_hnvtxvsbx
TH2F * m_hnvtxvsbx
Definition: MCVerticesAnalyzer.cc:71
MCVerticesAnalyzer::m_hnvtxvslumi
TH2F * m_hnvtxvslumi
Definition: MCVerticesAnalyzer.cc:73
MCVerticesAnalyzer::m_hepMCProductToken
edm::EDGetTokenT< edm::HepMCProduct > m_hepMCProductToken
Definition: MCVerticesAnalyzer.cc:68
MCVerticesAnalyzer::m_hnvtxweight
TH1F * m_hnvtxweight
Definition: MCVerticesAnalyzer.cc:74
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: EDConsumerBase.h:153
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::InputTag
Definition: InputTag.h:15
MCVerticesAnalyzer::m_hnvtxweightprof
TProfile * m_hnvtxweightprof
Definition: MCVerticesAnalyzer.cc:75
weight
Definition: weight.py:1
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64
MCVerticesAnalyzer::m_hmainvtxx
TH1F * m_hmainvtxx
Definition: MCVerticesAnalyzer.cc:76