CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::EDAnalyzer edm::EDConsumerBase

Public Member Functions

 MCVerticesAnalyzer (const edm::ParameterSet &)
 
 ~MCVerticesAnalyzer ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
virtual void beginJob ()
 
virtual void beginRun (const edm::Run &, const edm::EventSetup &)
 
virtual void endJob ()
 
virtual void endRun (const edm::Run &, const edm::EventSetup &)
 

Private Attributes

edm::EDGetTokenT< double > m_doubleToken
 
edm::EDGetTokenT
< edm::HepMCProduct
m_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::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
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 ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

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

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

Definition at line 57 of file MCVerticesAnalyzer.cc.

Constructor & Destructor Documentation

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

Definition at line 103 of file MCVerticesAnalyzer.cc.

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

104  : m_useweight( iConfig.getParameter< bool >( "useWeight" ) )
105  , m_doubleToken( consumes< double >( iConfig.getParameter< edm::InputTag >( "weightProduct" ) ) )
106  , m_vecPileupSummaryInfoToken( consumes< std::vector<PileupSummaryInfo> >( iConfig.getParameter< edm::InputTag >( "pileupSummaryCollection" ) ) )
107  , m_hepMCProductToken( consumes< edm::HepMCProduct >( iConfig.getParameter< edm::InputTag >( "mcTruthCollection" ) ) )
108 {
109  //now do what ever initialization is needed
110 
111 
112 
114 
115  m_hnvtx = tfserv->make<TH1F>("nvtx","Number of pileup vertices",60,-0.5,59.5);
116  m_hnvtx->GetXaxis()->SetTitle("Number of Interactions");
117 
118  m_hnvtxvsbx = tfserv->make<TH2F>("nvtxvsbx","Number of pileup vertices vs BX",9,-4.5,4.5,60,-0.5,59.5);
119  m_hnvtxvsbx->GetXaxis()->SetTitle("BX number");
120  m_hnvtxvsbx->GetYaxis()->SetTitle("Number of Interactions");
121 
122  m_hlumi = tfserv->make<TH1F>("lumi","BX luminosity*xsect",200,0.,50.);
123  m_hlumi->GetXaxis()->SetTitle("Average Number of Interactions");
124 
125  m_hnvtxvslumi = tfserv->make<TH2F>("nvtxvslumi","Npileup vs BX luminosity*xsect",200,0.,50.,60,-0.5,59.5);
126  m_hnvtxvslumi->GetXaxis()->SetTitle("Average Number of Interactions"); m_hnvtxvslumi->GetYaxis()->SetTitle("Number of Interactions");
127 
128  if(m_useweight) {
129  m_hnvtxweight = tfserv->make<TH1F>("nvtxweight","Number of pileup vertices (1-w)",60,-0.5,59.5);
130  m_hnvtxweight->GetXaxis()->SetTitle("Number of Interactions");
131  m_hnvtxweightprof = tfserv->make<TProfile>("nvtxweightprof","Mean (1-w) vs Number of pileup interactions",60,-0.5,59.5);
132  m_hnvtxweightprof->GetXaxis()->SetTitle("Number of Interactions");
133  }
134 
135  m_hmainvtxx = tfserv->make<TH1F>("mainvtxx","Main vertex x position",200,-.5,.5);
136  m_hmainvtxx->GetXaxis()->SetTitle("X (cm)");
137  m_hmainvtxy = tfserv->make<TH1F>("mainvtxy","Main vertex y position",200,-.5,.5);
138  m_hmainvtxy->GetXaxis()->SetTitle("Y (cm)");
139  m_hmainvtxz = tfserv->make<TH1F>("mainvtxz","Main vertex z position",600,-30.,30.);
140  m_hmainvtxz->GetXaxis()->SetTitle("Z (cm)");
141  m_hpileupvtxz = tfserv->make<TH1F>("pileupvtxz","PileUp vertices z position",600,-30.,30.);
142  m_hpileupvtxz->GetXaxis()->SetTitle("Z (cm)");
143 
144 }
T getParameter(std::string const &) const
edm::EDGetTokenT< double > m_doubleToken
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > m_vecPileupSummaryInfoToken
edm::EDGetTokenT< edm::HepMCProduct > m_hepMCProductToken
MCVerticesAnalyzer::~MCVerticesAnalyzer ( )

Definition at line 147 of file MCVerticesAnalyzer.cc.

148 {
149 
150  // do anything here that needs to be done at desctruction time
151  // (e.g. close files, deallocate resources etc.)
152 
153 }

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 162 of file MCVerticesAnalyzer.cc.

References edm::Event::getByToken(), 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 histoStyle::weight.

163 {
164 
165  double weight = 1.;
166 
167  if(m_useweight) {
168  edm::Handle<double> weightprod;
169  iEvent.getByToken( m_doubleToken, weightprod );
170 
171  weight = *weightprod;
172 
173  }
174 
175 
177  iEvent.getByToken( m_vecPileupSummaryInfoToken, pileupinfos );
178 
179  //
180 
181  if(pileupinfos.isValid()) {
182 
183  // look for the intime PileupSummaryInfo
184 
185  std::vector<PileupSummaryInfo>::const_iterator pileupinfo;
186 
187  for(pileupinfo = pileupinfos->begin(); pileupinfo != pileupinfos->end() ; ++pileupinfo) {
188  m_hnvtxvsbx->Fill(pileupinfo->getBunchCrossing(),pileupinfo->getPU_NumInteractions(),weight);
189  }
190 
191 
192  for(pileupinfo = pileupinfos->begin(); pileupinfo != pileupinfos->end() ; ++pileupinfo) {
193  if(pileupinfo->getBunchCrossing()==0) break;
194  }
195 
196  //
197 
198  if(pileupinfo->getBunchCrossing()!=0) {
199  edm::LogError("NoInTimePileUpInfo") << "Cannot find the in-time pileup info " << pileupinfo->getBunchCrossing();
200  }
201  else {
202 
203  m_hlumi->Fill(pileupinfo->getTrueNumInteractions(),weight);
204  m_hnvtx->Fill(pileupinfo->getPU_NumInteractions(),weight);
205  m_hnvtxvslumi->Fill(pileupinfo->getTrueNumInteractions(),pileupinfo->getPU_NumInteractions(),weight);
206 
207  if(m_useweight) {
208  m_hnvtxweight->Fill(pileupinfo->getPU_NumInteractions(),1.-weight);
209  m_hnvtxweightprof->Fill(pileupinfo->getPU_NumInteractions(),1.-weight);
210  }
211 
212  const std::vector<float>& zpositions = pileupinfo->getPU_zpositions();
213 
214  for(std::vector<float>::const_iterator zpos = zpositions.begin() ; zpos != zpositions.end() ; ++zpos) {
215 
216  m_hpileupvtxz->Fill(*zpos,weight);
217 
218  }
219  }
220  }
221  // main interaction part
222 
224  iEvent.getByToken( m_hepMCProductToken, EvtHandle );
225 
226  if(EvtHandle.isValid()) {
227 
228  const HepMC::GenEvent* Evt = EvtHandle->GetEvent();
229 
230  // get the first vertex
231 
232  if(Evt->vertices_begin() != Evt->vertices_end()) {
233 
234  m_hmainvtxx->Fill((*Evt->vertices_begin())->point3d().x()/10.,weight);
235  m_hmainvtxy->Fill((*Evt->vertices_begin())->point3d().y()/10.,weight);
236  m_hmainvtxz->Fill((*Evt->vertices_begin())->point3d().z()/10.,weight);
237 
238  }
239  }
240 }
edm::EDGetTokenT< double > m_doubleToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > m_vecPileupSummaryInfoToken
bool isValid() const
Definition: HandleBase.h:75
int weight
Definition: histoStyle.py:50
edm::EDGetTokenT< edm::HepMCProduct > m_hepMCProductToken
void MCVerticesAnalyzer::beginJob ( void  )
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 256 of file MCVerticesAnalyzer.cc.

257 {
258 }
void MCVerticesAnalyzer::beginRun ( const edm::Run iRun,
const edm::EventSetup  
)
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 243 of file MCVerticesAnalyzer.cc.

244 {
245 }
void MCVerticesAnalyzer::endJob ( void  )
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 262 of file MCVerticesAnalyzer.cc.

263 {
264 }
void MCVerticesAnalyzer::endRun ( const edm::Run iRun,
const edm::EventSetup  
)
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 248 of file MCVerticesAnalyzer.cc.

249 {
250 }

Member Data Documentation

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

Definition at line 75 of file MCVerticesAnalyzer.cc.

Referenced by analyze().

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

Definition at line 77 of file MCVerticesAnalyzer.cc.

Referenced by analyze().

TH1F* MCVerticesAnalyzer::m_hlumi
private

Definition at line 81 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

TH1F* MCVerticesAnalyzer::m_hmainvtxx
private

Definition at line 85 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

TH1F* MCVerticesAnalyzer::m_hmainvtxy
private

Definition at line 86 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

TH1F* MCVerticesAnalyzer::m_hmainvtxz
private

Definition at line 87 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

TH1F* MCVerticesAnalyzer::m_hnvtx
private

Definition at line 79 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

TH2F* MCVerticesAnalyzer::m_hnvtxvsbx
private

Definition at line 80 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

TH2F* MCVerticesAnalyzer::m_hnvtxvslumi
private

Definition at line 82 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

TH1F* MCVerticesAnalyzer::m_hnvtxweight
private

Definition at line 83 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

TProfile* MCVerticesAnalyzer::m_hnvtxweightprof
private

Definition at line 84 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

TH1F* MCVerticesAnalyzer::m_hpileupvtxz
private

Definition at line 88 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

const bool MCVerticesAnalyzer::m_useweight
private

Definition at line 73 of file MCVerticesAnalyzer.cc.

Referenced by analyze(), and MCVerticesAnalyzer().

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

Definition at line 76 of file MCVerticesAnalyzer.cc.

Referenced by analyze().