CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MCVerticesAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MCVerticesAnalyzer
4 // Class: MCVerticesAnalyzer
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Thu Dec 16 16:32:56 CEST 2010
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 #include <numeric>
23 
24 #include <vector>
25 
26 // user include files
29 
33 
35 
37 
40 
42 
46 
47 
48 #include "TH1F.h"
49 #include "TH2F.h"
50 #include "TProfile.h"
51 
52 //
53 // class decleration
54 //
55 
56 
58 public:
59  explicit MCVerticesAnalyzer(const edm::ParameterSet&);
61 
62 private:
63  virtual void beginJob() ;
64  virtual void beginRun(const edm::Run&, const edm::EventSetup&);
65  virtual void endRun(const edm::Run&, const edm::EventSetup&);
66  virtual void analyze(const edm::Event&, const edm::EventSetup&);
67  virtual void endJob() ;
68 
69  // ----------member data ---------------------------
70 
71 
72 
73  const bool m_useweight;
74 
78 
79  TH1F* m_hnvtx;
80  TH1F* m_hlumi;
83  TProfile* m_hnvtxweightprof;
84  TH1F* m_hmainvtxx;
85  TH1F* m_hmainvtxy;
86  TH1F* m_hmainvtxz;
88 
89 };
90 
91 //
92 // constants, enums and typedefs
93 //
94 
95 //
96 // static data member definitions
97 //
98 
99 //
100 // constructors and destructor
101 //
103  : m_useweight( iConfig.getParameter< bool >( "useWeight" ) )
104  , m_doubleToken( consumes< double >( iConfig.getParameter< edm::InputTag >( "weightProduct" ) ) )
105  , m_vecPileupSummaryInfoToken( consumes< std::vector<PileupSummaryInfo> >( iConfig.getParameter< edm::InputTag >( "pileupSummaryCollection" ) ) )
106  , m_hepMCProductToken( consumes< edm::HepMCProduct >( iConfig.getParameter< edm::InputTag >( "mcTruthCollection" ) ) )
107 {
108  //now do what ever initialization is needed
109 
110 
111 
113 
114  m_hnvtx = tfserv->make<TH1F>("nvtx","Number of pileup vertices",60,-0.5,59.5);
115  m_hnvtx->GetXaxis()->SetTitle("Number of Interactions");
116 
117  m_hlumi = tfserv->make<TH1F>("lumi","BX luminosity*xsect",200,0.,50.);
118  m_hlumi->GetXaxis()->SetTitle("Average Number of Interactions");
119 
120  m_hnvtxvslumi = tfserv->make<TH2F>("nvtxvslumi","Npileup vs BX luminosity*xsect",200,0.,50.,60,-0.5,59.5);
121  m_hnvtxvslumi->GetXaxis()->SetTitle("Average Number of Interactions"); m_hnvtxvslumi->GetYaxis()->SetTitle("Number of Interactions");
122 
123  if(m_useweight) {
124  m_hnvtxweight = tfserv->make<TH1F>("nvtxweight","Number of pileup vertices (1-w)",60,-0.5,59.5);
125  m_hnvtxweight->GetXaxis()->SetTitle("Number of Interactions");
126  m_hnvtxweightprof = tfserv->make<TProfile>("nvtxweightprof","Mean (1-w) vs Number of pileup interactions",60,-0.5,59.5);
127  m_hnvtxweightprof->GetXaxis()->SetTitle("Number of Interactions");
128  }
129 
130  m_hmainvtxx = tfserv->make<TH1F>("mainvtxx","Main vertex x position",200,-.5,.5);
131  m_hmainvtxx->GetXaxis()->SetTitle("X (cm)");
132  m_hmainvtxy = tfserv->make<TH1F>("mainvtxy","Main vertex y position",200,-.5,.5);
133  m_hmainvtxy->GetXaxis()->SetTitle("Y (cm)");
134  m_hmainvtxz = tfserv->make<TH1F>("mainvtxz","Main vertex z position",600,-30.,30.);
135  m_hmainvtxz->GetXaxis()->SetTitle("Z (cm)");
136  m_hpileupvtxz = tfserv->make<TH1F>("pileupvtxz","PileUp vertices z position",600,-30.,30.);
137  m_hpileupvtxz->GetXaxis()->SetTitle("Z (cm)");
138 
139 }
140 
141 
143 {
144 
145  // do anything here that needs to be done at desctruction time
146  // (e.g. close files, deallocate resources etc.)
147 
148 }
149 
150 
151 //
152 // member functions
153 //
154 
155 // ------------ method called to for each event ------------
156 void
158 {
159 
160  double weight = 1.;
161 
162  if(m_useweight) {
163  edm::Handle<double> weightprod;
164  iEvent.getByToken( m_doubleToken, weightprod );
165 
166  weight = *weightprod;
167 
168  }
169 
170 
172  iEvent.getByToken( m_vecPileupSummaryInfoToken, pileupinfos );
173 
174  //
175 
176  if(pileupinfos.isValid()) {
177 
178  // look for the intime PileupSummaryInfo
179 
180  std::vector<PileupSummaryInfo>::const_iterator pileupinfo;
181  for(pileupinfo = pileupinfos->begin(); pileupinfo != pileupinfos->end() ; ++pileupinfo) {
182  if(pileupinfo->getBunchCrossing()==0) break;
183  }
184 
185  //
186 
187  if(pileupinfo->getBunchCrossing()!=0) {
188  edm::LogError("NoInTimePileUpInfo") << "Cannot find the in-time pileup info " << pileupinfo->getBunchCrossing();
189  }
190  else {
191 
192  m_hlumi->Fill(pileupinfo->getTrueNumInteractions(),weight);
193  m_hnvtx->Fill(pileupinfo->getPU_NumInteractions(),weight);
194  m_hnvtxvslumi->Fill(pileupinfo->getTrueNumInteractions(),pileupinfo->getPU_NumInteractions(),weight);
195 
196  if(m_useweight) {
197  m_hnvtxweight->Fill(pileupinfo->getPU_NumInteractions(),1.-weight);
198  m_hnvtxweightprof->Fill(pileupinfo->getPU_NumInteractions(),1.-weight);
199  }
200 
201  const std::vector<float>& zpositions = pileupinfo->getPU_zpositions();
202 
203  for(std::vector<float>::const_iterator zpos = zpositions.begin() ; zpos != zpositions.end() ; ++zpos) {
204 
205  m_hpileupvtxz->Fill(*zpos,weight);
206 
207  }
208  }
209  }
210  // main interaction part
211 
213  iEvent.getByToken( m_hepMCProductToken, EvtHandle );
214 
215  if(EvtHandle.isValid()) {
216 
217  const HepMC::GenEvent* Evt = EvtHandle->GetEvent();
218 
219  // get the first vertex
220 
221  if(Evt->vertices_begin() != Evt->vertices_end()) {
222 
223  m_hmainvtxx->Fill((*Evt->vertices_begin())->point3d().x()/10.,weight);
224  m_hmainvtxy->Fill((*Evt->vertices_begin())->point3d().y()/10.,weight);
225  m_hmainvtxz->Fill((*Evt->vertices_begin())->point3d().z()/10.,weight);
226 
227  }
228  }
229 }
230 
231 void
233 {
234 }
235 
236 void
238 {
239 }
240 
241 
242 
243 // ------------ method called once each job just before starting event loop ------------
244 void
246 {
247 }
248 
249 // ------------ method called once each job just after ending the event loop ------------
250 void
252 {
253 }
254 
255 //define this as a plug-in
edm::EDGetTokenT< double > m_doubleToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
int iEvent
Definition: GenABIO.cc:243
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > m_vecPileupSummaryInfoToken
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
bool isValid() const
Definition: HandleBase.h:76
MCVerticesAnalyzer(const edm::ParameterSet &)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
int weight
Definition: histoStyle.py:50
edm::EDGetTokenT< edm::HepMCProduct > m_hepMCProductToken
virtual void endRun(const edm::Run &, const edm::EventSetup &)
Definition: Run.h:41