CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MCvsRecoVerticesAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MCvsRecoVerticesAnalyzer
4 // Class: MCvsRecoVerticesAnalyzer
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Thu Dec 16 16:32:56 CEST 2010
16 // $Id: MCvsRecoVerticesAnalyzer.cc,v 1.4 2011/11/26 00:51:42 venturia Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 #include <numeric>
24 
25 #include <vector>
26 
27 // user include files
30 
34 
36 
38 
41 
43 
47 
50 
51 #include "TH1F.h"
52 #include "TH2F.h"
53 #include "TProfile.h"
54 
55 //
56 // class decleration
57 //
58 
59 
61 public:
64 
65 private:
66  virtual void beginJob() ;
67  virtual void beginRun(const edm::Run&, const edm::EventSetup&);
68  virtual void endRun(const edm::Run&, const edm::EventSetup&);
69  virtual void analyze(const edm::Event&, const edm::EventSetup&);
70  virtual void endJob() ;
71 
72  // ----------member data ---------------------------
73 
74 
75 
79  const bool m_useweight;
83 
93 
97 
98 
99 };
100 
101 //
102 // constants, enums and typedefs
103 //
104 
105 //
106 // static data member definitions
107 //
108 
109 //
110 // constructors and destructor
111 //
113  m_pileupcollection(iConfig.getParameter<edm::InputTag>("pileupSummaryCollection")),
114  m_mctruthcollection(iConfig.getParameter<edm::InputTag>("mcTruthCollection")),
115  m_pvcollection(iConfig.getParameter<edm::InputTag>("pvCollection")),
116  m_useweight(iConfig.getParameter<bool>("useWeight")),
117  m_weight(iConfig.getParameter<edm::InputTag>("weightProduct")),
118  m_useVisibleVertices(iConfig.getParameter<bool>("useVisibleVertices")),
119  m_histoParameters(iConfig.getUntrackedParameter<edm::ParameterSet>("histoParameters",edm::ParameterSet()))
120 {
121  //now do what ever initialization is needed
122 
123  if(m_useVisibleVertices) edm::LogInfo("UseVisibleVertices") << "Only visible vertices will be used to compute Npileup";
124 
126 
127  m_hrecovsmcnvtx2d = tfserv->make<TH2F>("recovsmcnvtx2d","Number of reco vertices vs pileup interactions",60,-0.5,59.5,60,-0.5,59.5);
128  m_hrecovsmcnvtx2d->GetXaxis()->SetTitle("Pileup Interactions"); m_hrecovsmcnvtx2d->GetYaxis()->SetTitle("Reco Vertices");
129  m_hrecovsmcnvtxprof = tfserv->make<TProfile>("recovsmcnvtxprof","Mean number of reco vs pileup vertices",60,-0.5,59.5);
130  m_hrecovsmcnvtxprof->GetXaxis()->SetTitle("Pileup Interactions"); m_hrecovsmcnvtxprof->GetYaxis()->SetTitle("Reco Vertices");
131 
132  m_hrecovsmclumi2d = tfserv->make<TH2F>("recovsmclumi2d","Number of reco vertices vs ave pileup interactions",200,0.,50.,60,-0.5,59.5);
133  m_hrecovsmclumi2d->GetXaxis()->SetTitle("Average Pileup Interactions"); m_hrecovsmclumi2d->GetYaxis()->SetTitle("Reco Vertices");
134  m_hrecovsmclumiprof = tfserv->make<TProfile>("recovsmclumiprof","Mean number of reco vs ave pileup vertices",200,0.,50.);
135  m_hrecovsmclumiprof->GetXaxis()->SetTitle("Average Pileup Interactions"); m_hrecovsmclumiprof->GetYaxis()->SetTitle("Reco Vertices");
136 
137  if(m_useweight) {
138  m_hrecovsmcnvtxweightedprof = tfserv->make<TProfile>("recovsmcnvtxweightedprof","Mean number of reco vs pileup vertices (1-w) weight",60,-0.5,59.5);
139  m_hrecovsmcnvtxweightedprof->GetXaxis()->SetTitle("Pileup Interactions"); m_hrecovsmcnvtxweightedprof->GetYaxis()->SetTitle("Reco Vertices (1-w)");
140 
141  m_hrecovsmclumiweightedprof = tfserv->make<TProfile>("recovsmclumiweightedprof","Mean number of reco vs ave pileup vertices (1-w) weight",
142  200,0.,50.);
143  m_hrecovsmclumiweightedprof->GetXaxis()->SetTitle("Average Pileup Interactions");
144  m_hrecovsmclumiweightedprof->GetYaxis()->SetTitle("Reco Vertices (1-w)");
145  }
146 
147  m_hdeltazfirst = tfserv->make<TH1F>("deltazfirst","Reco-MC vertex z position (first vertex)",
148  m_histoParameters.getUntrackedParameter<unsigned int>("zBins",1000),
149  m_histoParameters.getUntrackedParameter<double>("zMin",-1.),
150  m_histoParameters.getUntrackedParameter<double>("zMax",1.));
151  m_hdeltazfirst->GetXaxis()->SetTitle("#Delta z (cm)"); m_hdeltazfirst->GetYaxis()->SetTitle("Events");
152 
153  m_hdeltazclose = tfserv->make<TH1F>("deltazclose","Reco-MC vertex z position (closest vertex)",
154  m_histoParameters.getUntrackedParameter<unsigned int>("zBins",1000),
155  m_histoParameters.getUntrackedParameter<double>("zMin",-1.),
156  m_histoParameters.getUntrackedParameter<double>("zMax",1.));
157  m_hdeltazclose->GetXaxis()->SetTitle("#Delta z (cm)"); m_hdeltazclose->GetYaxis()->SetTitle("Events");
158 
159  m_hclosestvtx = tfserv->make<TH1F>("closestvtx","Closest reco vtx ID",30,-0.5,29.5);
160  m_hclosestvtx->GetXaxis()->SetTitle("Vtx ID"); m_hclosestvtx->GetYaxis()->SetTitle("Events");
161 
162  m_hdeltazfirstvsnpu = tfserv->make<TH2F>("deltazfirstvsnpu","Reco-MC vertex z position (first vertex) vs Npileup",30,-0.5,29.5,
163  m_histoParameters.getUntrackedParameter<unsigned int>("zBins",1000),
164  m_histoParameters.getUntrackedParameter<double>("zMin",-1.),
165  m_histoParameters.getUntrackedParameter<double>("zMax",1.));
166  m_hdeltazfirstvsnpu->GetXaxis()->SetTitle("pileup Interactions"); m_hdeltazfirstvsnpu->GetYaxis()->SetTitle("#Delta z (cm)");
167 
168  m_hdeltazclosevsnpu = tfserv->make<TH2F>("deltazclosevsnpu","Reco-MC vertex z position (closest vertex) v Npileup",30,-0.5,29.5,
169  m_histoParameters.getUntrackedParameter<unsigned int>("zBins",1000),
170  m_histoParameters.getUntrackedParameter<double>("zMin",-1.),
171  m_histoParameters.getUntrackedParameter<double>("zMax",1.));
172  m_hdeltazclosevsnpu->GetXaxis()->SetTitle("Pileup Interactions"); m_hdeltazclosevsnpu->GetYaxis()->SetTitle("#Delta z (cm)");
173 
174  m_hclosestvtxvsnpu = tfserv->make<TH2F>("closestvtxvsnpu","Closest reco vtx ID vs Npileup",30,-0.5,29.5,30,-0.5,29.5);
175  m_hclosestvtxvsnpu->GetXaxis()->SetTitle("Pileup Interactions"); m_hclosestvtxvsnpu->GetYaxis()->SetTitle("Vtx ID");
176 
177 }
178 
179 
181 {
182 
183  // do anything here that needs to be done at desctruction time
184  // (e.g. close files, deallocate resources etc.)
185 
186 }
187 
188 
189 //
190 // member functions
191 //
192 
193 // ------------ method called to for each event ------------
194 void
196 {
197  using namespace edm;
198 
199  double weight = 1.;
200 
201  if(m_useweight) {
202  Handle<double> weightprod;
203  iEvent.getByLabel(m_weight,weightprod);
204 
205  weight = *weightprod;
206 
207  }
208 
210  iEvent.getByLabel(m_pileupcollection,pileupinfos);
211 
212  // look for the intime PileupSummaryInfo
213 
214  std::vector<PileupSummaryInfo>::const_iterator pileupinfo;
215 
216  for(pileupinfo = pileupinfos->begin(); pileupinfo != pileupinfos->end() ; ++pileupinfo) {
217 
218  if(pileupinfo->getBunchCrossing()==0) break;
219 
220  }
221 
222  //
223 
225  iEvent.getByLabel(m_pvcollection,pvcoll);
226 
227 
228  //
229 
230  if(pileupinfo->getBunchCrossing()!=0) {
231 
232  edm::LogError("NoInTimePileUpInfo") << "Cannot find the in-time pileup info " << pileupinfo->getBunchCrossing();
233 
234  }
235  else {
236 
237  int npileup = pileupinfo->getPU_NumInteractions();
238 
239  if(m_useVisibleVertices) npileup = pileupinfo->getPU_zpositions().size();
240 
241  m_hrecovsmcnvtx2d->Fill(npileup,pvcoll->size(),weight);
242  m_hrecovsmcnvtxprof->Fill(npileup,pvcoll->size(),weight);
243 
244  m_hrecovsmclumi2d->Fill(pileupinfo->getTrueNumInteractions(),pvcoll->size(),weight);
245  m_hrecovsmclumiprof->Fill(pileupinfo->getTrueNumInteractions(),pvcoll->size(),weight);
246 
247  if(m_useweight) {
248  m_hrecovsmcnvtxweightedprof->Fill(npileup,pvcoll->size(),1.-weight);
249  m_hrecovsmclumiweightedprof->Fill(pileupinfo->getTrueNumInteractions(),pvcoll->size(),1.-weight);
250  }
251  //
252 
253  Handle< HepMCProduct > EvtHandle ;
254  iEvent.getByLabel(m_mctruthcollection, EvtHandle ) ;
255 
256  const HepMC::GenEvent* Evt = EvtHandle->GetEvent();
257 
258  // compute the difference between the main interaction vertex z position and the first vertex of the collection
259 
260  if(pvcoll->size() !=0) {
261  if(!(*pvcoll)[0].isFake()) {
262  // get the first vertex
263  if(Evt->vertices_begin() != Evt->vertices_end()) {
264  m_hdeltazfirst->Fill((*pvcoll)[0].z()-(*Evt->vertices_begin())->point3d().z()/10.,weight);
265  m_hdeltazfirstvsnpu->Fill(npileup,(*pvcoll)[0].z()-(*Evt->vertices_begin())->point3d().z()/10.,weight);
266  }
267  }
268  }
269 
270  // compute the difference between the main interaction vertex z position and the closest reco vertex
271 
272  double minabsdist = -1.;
273  double mindist = -999.;
274  int closestvtx = -1;
275 
276  for(unsigned int ivtx = 0 ; ivtx < pvcoll->size() ; ++ivtx) {
277 
278  if(closestvtx < 0 || minabsdist > std::abs((*pvcoll)[ivtx].z()-(*Evt->vertices_begin())->point3d().z()/10.)) {
279  mindist = (*pvcoll)[ivtx].z()-(*Evt->vertices_begin())->point3d().z()/10.;
280  closestvtx = ivtx;
281  minabsdist = std::abs(mindist);
282  }
283 
284  }
285  if(closestvtx >= 0) {
286  m_hdeltazclose->Fill(mindist,weight);
287  m_hdeltazclosevsnpu->Fill(npileup,mindist,weight);
288  m_hclosestvtx->Fill(closestvtx,weight);
289  m_hclosestvtxvsnpu->Fill(npileup,closestvtx,weight);
290  }
291 
292  }
293 }
294 
295  void
297 {
298 }
299 
300 void
302 {
303 }
304 
305 
306 
307 // ------------ method called once each job just before starting event loop ------------
308 void
310 {
311 }
312 
313 // ------------ method called once each job just after ending the event loop ------------
314 void
316 {
317 }
318 
319 //define this as a plug-in
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void analyze(const edm::Event &, const edm::EventSetup &)
#define abs(x)
Definition: mlp_lapack.h:159
float float float z
int iEvent
Definition: GenABIO.cc:243
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
MCvsRecoVerticesAnalyzer(const edm::ParameterSet &)
T * make() const
make new ROOT object
const edm::ParameterSet m_histoParameters
int weight
Definition: histoStyle.py:50
virtual void endRun(const edm::Run &, const edm::EventSetup &)
Definition: Run.h:36