CMS 3D CMS Logo

TrackCount.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TrackCount
4 // Class: TrackCount
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Thu Sep 25 16:32:56 CEST 2008
16 // $Id: TrackCount.cc,v 1.15 2011/11/15 10:09:24 venturia Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
27 
32 
34 
35 // my includes
36 
37 #include <iostream>
38 #include <map>
39 #include <string>
40 #include <numeric>
41 
42 #include "TH1F.h"
43 #include "TH1D.h"
44 #include "TH2D.h"
45 #include "TProfile.h"
46 #include "TProfile2D.h"
47 
49 
52 
54 
57 
59 
61 //
62 // class decleration
63 //
64 
65 class TrackCount : public edm::EDAnalyzer {
66 public:
67  explicit TrackCount(const edm::ParameterSet&);
68  ~TrackCount() override;
69 
70 
71 private:
72  void beginRun(const edm::Run&, const edm::EventSetup&) override;
73  void analyze(const edm::Event&, const edm::EventSetup&) override;
74 
75  // ----------member data ---------------------------
76 
77  TH1F* m_ntrk;
78  TProfile* m_ntrkvslumi;
80  TH1F* m_nhptrk;
81  TH1F* m_hhpfrac;
82  TH1F* m_hsqsumptsq;
83  TH1F* m_hphi;
84  TH1F* m_heta;
85  TH1F* m_hcos;
86  TH1F* m_hpt;
87  TH1F* m_chisq;
88  TH1F* m_chisqnorm;
89  TH1F* m_ndof;
90  TH2F* m_chisqvseta;
92  TH2F* m_ndofvseta;
93  TProfile2D* m_hptphieta;
94  TH1D* m_hnlosthits;
95  TH1D* m_hnrhits;
99  TH1D* m_hnlayers;
102  TH1D* m_halgo;
103  TH2D* m_hphieta;
104  TProfile2D* m_hnhitphieta;
105  TProfile2D* m_hnlayerphieta;
106 
107  TProfile** m_ntrkvsorbrun;
108 
109 
110  // std::map<int,int> m_multiplicity;
112  const unsigned int m_maxLS;
113  const unsigned int m_LSfrac;
114  const bool m_2dhistos;
115  const bool m_runHisto;
116  const bool m_dump;
119  const unsigned int m_nptbin;
120  const double m_ptmin;
121  const double m_ptmax;
122 };
123 
124 //
125 // constants, enums and typedefs
126 //
127 
128 //
129 // static data member definitions
130 //
131 
132 //
133 // constructors and destructor
134 //
137  m_maxLS(100),m_LSfrac(16),
138  m_2dhistos(iConfig.getUntrackedParameter<bool>("wanted2DHistos",false)),
139  m_runHisto(iConfig.getUntrackedParameter<bool>("runHisto",false)),
140  m_dump(iConfig.getUntrackedParameter<bool>("dumpTracks",false)),
141  m_trkcollToken(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("trackCollection"))),
142  m_lumiProducerToken(consumes<LumiDetails,edm::InLumi>(edm::InputTag("lumiProducer"))),
143  m_nptbin(iConfig.getUntrackedParameter<unsigned int>("numberPtBins",200)),
144  m_ptmin(iConfig.getUntrackedParameter<double>("ptMin",0.)),
145  m_ptmax(iConfig.getUntrackedParameter<double>("ptMax",20.))
146 
147 
148 {
149  //now do what ever initialization is needed
150 
151  // histogram parameters
152 
153  const unsigned int netabin1d = iConfig.getUntrackedParameter<unsigned int>("netabin1D",120);
154  const unsigned int netabin2d = iConfig.getUntrackedParameter<unsigned int>("netabin2D",40);
155  const float etamin = iConfig.getUntrackedParameter<double>("etaMin",-3.);
156  const float etamax = iConfig.getUntrackedParameter<double>("etaMax",3.);
157  const unsigned int nchisqbin1d = iConfig.getUntrackedParameter<unsigned int>("nchi2bin1D",50);
158  const unsigned int nndofbin1d = iConfig.getUntrackedParameter<unsigned int>("nndofbin1D",50);
159  const unsigned int nchisqbin2d = iConfig.getUntrackedParameter<unsigned int>("nchi2bin2D",50);
160  const unsigned int nndofbin2d = iConfig.getUntrackedParameter<unsigned int>("nndofbin2D",50);
161 
162  edm::LogInfo("TrackCollection") << "Using collection " << iConfig.getParameter<edm::InputTag>("trackCollection").label().c_str() ;
163 
164 
166 
167  m_ntrk = tfserv->make<TH1F>("ntrk","Number of Tracks",2500,-0.5,2499.5);
168  m_ntrk->GetXaxis()->SetTitle("Tracks"); m_ntrk->GetYaxis()->SetTitle("Events");
169  m_ntrkvslumi = tfserv->make<TProfile>("ntrkvslumi","Number of Tracks vs Luminosity",250,0.,10.);
170  m_ntrkvslumi->GetXaxis()->SetTitle("BX lumi [10^{30}cm^{-2}s^{-1}]"); m_ntrkvslumi->GetYaxis()->SetTitle("Ntracks");
171  m_ntrkvslumi2D = tfserv->make<TH2D>("ntrkvslumi2D","Number of Tracks vs Luminosity",80,0.,10.,125,-0.5,2499.5);
172  m_ntrkvslumi2D->GetXaxis()->SetTitle("BX lumi [10^{30}cm^{-2}s^{-1}]"); m_ntrkvslumi2D->GetYaxis()->SetTitle("Ntracks");
173 
174  m_nhptrk = tfserv->make<TH1F>("nhptrk","Number of High Purity Tracks",2500,-0.5,2499.5);
175  m_nhptrk->GetXaxis()->SetTitle("Tracks"); m_nhptrk->GetYaxis()->SetTitle("Events");
176  m_hhpfrac = tfserv->make<TH1F>("hhpfrac","Fraction of High Purity Tracks",51,0.,1.02);
177  m_hhpfrac->GetXaxis()->SetTitle("hp/all"); m_hhpfrac->GetYaxis()->SetTitle("Events");
178  m_hsqsumptsq = tfserv->make<TH1F>("hsqsumptsq","Sqrt(Sum pt**2)",1000,0.,200.);
179  m_hsqsumptsq->GetXaxis()->SetTitle("#sqrt(#Sigma pt^2) (GeV)"); m_hsqsumptsq->GetYaxis()->SetTitle("Events");
180 
181  m_hphi = tfserv->make<TH1F>("phi","Track azimuth",40,-M_PI,M_PI);
182  m_hphi->GetXaxis()->SetTitle("#phi (rad)"); m_hphi->GetYaxis()->SetTitle("Tracks");
183  m_heta = tfserv->make<TH1F>("eta","Track pseudorapidity",netabin1d,etamin,etamax);
184  m_heta->GetXaxis()->SetTitle("#eta"); m_heta->GetYaxis()->SetTitle("Tracks");
185  m_hcos = tfserv->make<TH1F>("cos","Track polar angle",50,-1.,1.);
186  m_hcos->GetXaxis()->SetTitle("cos(#theta)"); m_hcos->GetYaxis()->SetTitle("Tracks");
187  m_hpt = tfserv->make<TH1F>("pt","Track pt",m_nptbin,m_ptmin,m_ptmax);
188  m_hpt->GetXaxis()->SetTitle("pt (GeV)"); m_hpt->GetYaxis()->SetTitle("Tracks");
189 
190  m_chisq = tfserv->make<TH1F>("chisq","Track Chi2",nchisqbin1d,0.,100.);
191  m_chisq->GetXaxis()->SetTitle("chi2"); m_chisq->GetYaxis()->SetTitle("Tracks");
192  m_chisqnorm = tfserv->make<TH1F>("chisqnorm","Track normalized Chi2",nchisqbin1d,0.,10.);
193  m_chisqnorm->GetXaxis()->SetTitle("normalized chi2"); m_chisqnorm->GetYaxis()->SetTitle("Tracks");
194  m_ndof = tfserv->make<TH1F>("ndof","Track ndof",nndofbin1d,0.,100.);
195  m_ndof->GetXaxis()->SetTitle("ndof"); m_ndof->GetYaxis()->SetTitle("Tracks");
196  if(m_2dhistos) {
197  m_chisqvseta = tfserv->make<TH2F>("chisqvseta","Track Chi2 vs #eta",netabin2d,etamin,etamax,nchisqbin2d,0.,100.);
198  m_chisqvseta->GetXaxis()->SetTitle("#eta"); m_chisqvseta->GetYaxis()->SetTitle("#chi2");
199  m_chisqnormvseta = tfserv->make<TH2F>("chisqnormvseta","Track normalized Chi2 vs #eta",netabin2d,etamin,etamax,nchisqbin2d,0.,10.);
200  m_chisqnormvseta->GetXaxis()->SetTitle("#eta"); m_chisqnormvseta->GetYaxis()->SetTitle("normalized #chi2");
201  m_ndofvseta = tfserv->make<TH2F>("ndofvseta","Track ndof vs #eta",netabin2d,etamin,etamax,nndofbin2d,0.,100.);
202  m_ndofvseta->GetXaxis()->SetTitle("#eta"); m_ndofvseta->GetYaxis()->SetTitle("ndof");
203  }
204 
205  m_hptphieta = tfserv->make<TProfile2D>("ptphivseta","Average pt vs #phi vs #eta",netabin2d,etamin,etamax,40,-M_PI,M_PI);
206  m_hptphieta->GetXaxis()->SetTitle("#eta"); m_hptphieta->GetYaxis()->SetTitle("#phi");
207 
208 
209 
210  m_hnlosthits = tfserv->make<TH1D>("nlosthits","Number of Lost Hits",10,-0.5,9.5);
211  m_hnlosthits->GetXaxis()->SetTitle("Nlost"); m_hnlosthits->GetYaxis()->SetTitle("Tracks");
212 
213  m_hnrhits = tfserv->make<TH1D>("nrhits","Number of Valid Hits",55,-0.5,54.5);
214  m_hnrhits->GetXaxis()->SetTitle("Nvalid"); m_hnrhits->GetYaxis()->SetTitle("Tracks");
215  m_hnpixelrhits = tfserv->make<TH1D>("npixelrhits","Number of Valid Pixel Hits",20,-0.5,19.5);
216  m_hnpixelrhits->GetXaxis()->SetTitle("Nvalid"); m_hnpixelrhits->GetYaxis()->SetTitle("Tracks");
217  m_hnstriprhits = tfserv->make<TH1D>("nstriprhits","Number of Valid Strip Hits",45,-0.5,44.5);
218  m_hnstriprhits->GetXaxis()->SetTitle("Nvalid"); m_hnstriprhits->GetYaxis()->SetTitle("Tracks");
219 
220  m_hnlostlayers = tfserv->make<TH1D>("nlostlayers","Number of Layers w/o measurement",10,-0.5,9.5);
221  m_hnlostlayers->GetXaxis()->SetTitle("Nlostlay"); m_hnlostlayers->GetYaxis()->SetTitle("Tracks");
222 
223  m_hnlayers = tfserv->make<TH1D>("nlayers","Number of Layers",20,-0.5,19.5);
224  m_hnlayers->GetXaxis()->SetTitle("Nlayers"); m_hnlayers->GetYaxis()->SetTitle("Tracks");
225  m_hnpixellayers = tfserv->make<TH1D>("npixellayers","Number of Pixel Layers",10,-0.5,9.5);
226  m_hnpixellayers->GetXaxis()->SetTitle("Nlayers"); m_hnpixellayers->GetYaxis()->SetTitle("Tracks");
227  m_hnstriplayers = tfserv->make<TH1D>("nstriplayers","Number of Strip Layers",20,-0.5,19.5);
228  m_hnstriplayers->GetXaxis()->SetTitle("Nlayers"); m_hnstriplayers->GetYaxis()->SetTitle("Tracks");
229 
230  m_hnhitphieta = tfserv->make<TProfile2D>("nhitphivseta","N valid hits vs #phi vs #eta",netabin2d,etamin,etamax,40,-M_PI,M_PI);
231  m_hnhitphieta->GetXaxis()->SetTitle("#eta"); m_hnhitphieta->GetYaxis()->SetTitle("#phi");
232  m_hnlayerphieta = tfserv->make<TProfile2D>("nlayerphivseta","N layers vs #phi vs #eta",netabin2d,etamin,etamax,40,-M_PI,M_PI);
233  m_hnlayerphieta->GetXaxis()->SetTitle("#eta"); m_hnlayerphieta->GetYaxis()->SetTitle("#phi");
234 
235  m_halgo = tfserv->make<TH1D>("algo","Algorithm number",reco::TrackBase::algoSize,-0.5,reco::TrackBase::algoSize-0.5);
236  m_halgo->GetXaxis()->SetTitle("algorithm"); m_halgo->GetYaxis()->SetTitle("Tracks");
237  m_hphieta = tfserv->make<TH2D>("phivseta","#phi vs #eta",netabin2d,etamin,etamax,40,-M_PI,M_PI);
238  m_hphieta->GetXaxis()->SetTitle("#eta"); m_hphieta->GetYaxis()->SetTitle("#phi");
239 
240  if(m_runHisto) {
241  m_ntrkvsorbrun = m_rhm.makeTProfile("ntrkvsorbrun","Number of tracks vs orbit number",m_maxLS*m_LSfrac,0,m_maxLS*262144);
242  }
243 
244 }
245 
246 
248 {
249 
250  // do anything here that needs to be done at desctruction time
251  // (e.g. close files, deallocate resources etc.)
252 
253 }
254 
255 
256 //
257 // member functions
258 //
259 
260 // ------------ method called to for each event ------------
261 void
263 {
264  using namespace edm;
266 
268  iEvent.getByToken(m_trkcollToken,tracks);
269 
270  //
271 
272  m_ntrk->Fill(tracks->size());
273 
274  // get luminosity
275 
278 
279  if(ld.isValid()) {
280  if(ld->isValid()) {
281  float lumi = ld->lumiValue(LumiDetails::kOCC1,iEvent.bunchCrossing())*6.37;
282  m_ntrkvslumi->Fill(lumi,tracks->size());
283  m_ntrkvslumi2D->Fill(lumi,tracks->size());
284  }
285  }
286 
287  if(m_runHisto) {
288  if(m_ntrkvsorbrun && *m_ntrkvsorbrun) (*m_ntrkvsorbrun)->Fill(iEvent.orbitNumber(),tracks->size());
289  }
290 
291  unsigned int nhptrk = 0;
292  double sumptsq = 0.;
293 
295 
296  if(m_dump) edm::LogInfo("TrackDump") << " isHP algo pt eta phi chi2N chi2 ndof nlay npxl n3dl nlost ";
297 
298  for(reco::TrackCollection::const_iterator it = tracks->begin();it!=tracks->end();it++) {
299 
300  if(m_dump) {
301  edm::LogVerbatim("TrackDump") << it->quality(quality) << " "
302  << it->algo() << " "
303  << it->pt() << " "
304  << it->eta() << " "
305  << it->phi() << " "
306  << it->normalizedChi2() << " "
307  << it->chi2() << " "
308  << it->ndof() << " "
309  << it->hitPattern().trackerLayersWithMeasurement() << " "
310  << it->hitPattern().pixelLayersWithMeasurement() << " "
311  << it->hitPattern().numberOfValidStripLayersWithMonoAndStereo() << " "
312  << it->hitPattern().trackerLayersWithoutMeasurement(reco::HitPattern::TRACK_HITS) << " ";
313 
314  }
315 
316  m_hnlosthits->Fill(it->hitPattern().numberOfLostTrackerHits(reco::HitPattern::TRACK_HITS));
317 
318  m_hnrhits->Fill(it->hitPattern().numberOfValidTrackerHits());
319  m_hnpixelrhits->Fill(it->hitPattern().numberOfValidPixelHits());
320  m_hnstriprhits->Fill(it->hitPattern().numberOfValidStripHits());
321  m_hnhitphieta->Fill(it->eta(),it->phi(),it->hitPattern().numberOfValidTrackerHits());
322 
323  m_hnlostlayers->Fill(it->hitPattern().trackerLayersWithoutMeasurement(reco::HitPattern::TRACK_HITS));
324 
325  m_hnlayers->Fill(it->hitPattern().trackerLayersWithMeasurement());
326  m_hnpixellayers->Fill(it->hitPattern().pixelLayersWithMeasurement());
327  m_hnstriplayers->Fill(it->hitPattern().stripLayersWithMeasurement());
328  m_hnlayerphieta->Fill(it->eta(),it->phi(),it->hitPattern().trackerLayersWithMeasurement());
329 
330  m_halgo->Fill(it->algo());
331 
332  m_hphi->Fill(it->phi());
333  m_heta->Fill(it->eta());
334  m_hphieta->Fill(it->eta(),it->phi());
335 
336  double pt = it->pt();
337  m_hpt->Fill(pt);
338  m_chisq->Fill(it->chi2());
339  m_chisqnorm->Fill(it->normalizedChi2());
340  m_ndof->Fill(it->ndof());
341  if(m_2dhistos) {
342  m_chisqvseta->Fill(it->eta(),it->chi2());
343  m_chisqnormvseta->Fill(it->eta(),it->normalizedChi2());
344  m_ndofvseta->Fill(it->eta(),it->ndof());
345  }
346  m_hptphieta->Fill(it->eta(),it->phi(),pt);
347  sumptsq += pt*pt;
348  if(it->p()) m_hcos->Fill(it->pz()/it->p());
349  if(it->quality(quality)) nhptrk++;
350  }
351 
352  m_nhptrk->Fill(nhptrk);
353 
354  const double hpfrac = !tracks->empty() ? double(nhptrk)/double(tracks->size()) : 0.;
355  m_hhpfrac->Fill(hpfrac);
356  m_hsqsumptsq->Fill(sqrt(sumptsq));
357 
358 }
359 
360 void
362 {
363  m_rhm.beginRun(iRun);
364 
365  if(m_runHisto) {
366  (*m_ntrkvsorbrun)->GetXaxis()->SetTitle("time [orbit#]"); (*m_ntrkvsorbrun)->GetYaxis()->SetTitle("Ntracks");
367  (*m_ntrkvsorbrun)->SetCanExtend(TH1::kXaxis);
368  }
369 }
370 
371 
372 //define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
TH1F * m_ntrk
Definition: TrackCount.cc:77
TH2F * m_chisqvseta
Definition: TrackCount.cc:90
RunHistogramManager m_rhm
Definition: TrackCount.cc:111
TProfile2D * m_hnlayerphieta
Definition: TrackCount.cc:105
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
bool getByToken(EDGetToken token, Handle< PROD > &result) const
TrackQuality
track quality
Definition: TrackBase.h:151
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
TProfile2D * m_hnhitphieta
Definition: TrackCount.cc:104
TProfile2D * m_hptphieta
Definition: TrackCount.cc:93
bool isValid() const
Definition: LumiDetails.cc:57
TH1D * m_halgo
Definition: TrackCount.cc:102
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
int bunchCrossing() const
Definition: EventBase.h:66
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
~TrackCount() override
Definition: TrackCount.cc:247
const double m_ptmax
Definition: TrackCount.cc:121
float lumiValue(AlgoType algo, unsigned int bx) const
Definition: LumiDetails.cc:92
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: TrackCount.cc:262
edm::EDGetTokenT< reco::TrackCollection > m_trkcollToken
Definition: TrackCount.cc:117
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
TH1D * m_hnstriplayers
Definition: TrackCount.cc:101
TH1F * m_chisqnorm
Definition: TrackCount.cc:88
int iEvent
Definition: GenABIO.cc:230
TH1F * m_chisq
Definition: TrackCount.cc:87
TH2F * m_chisqnormvseta
Definition: TrackCount.cc:91
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: TrackCount.cc:361
TH1D * m_hnlostlayers
Definition: TrackCount.cc:98
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
T sqrt(T t)
Definition: SSEVec.h:18
TH1F * m_hpt
Definition: TrackCount.cc:86
TProfile ** makeTProfile(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
TProfile ** m_ntrkvsorbrun
Definition: TrackCount.cc:107
TH1F * m_nhptrk
Definition: TrackCount.cc:80
LuminosityBlock const & getLuminosityBlock() const
Definition: Event.h:100
TH1F * m_hsqsumptsq
Definition: TrackCount.cc:82
int orbitNumber() const
Definition: EventBase.h:67
bool isValid() const
Definition: HandleBase.h:74
#define M_PI
const unsigned int m_maxLS
Definition: TrackCount.cc:112
TH1F * m_heta
Definition: TrackCount.cc:84
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:125
TH1D * m_hnlayers
Definition: TrackCount.cc:99
TrackCount(const edm::ParameterSet &)
Definition: TrackCount.cc:135
TH1D * m_hnpixelrhits
Definition: TrackCount.cc:96
void beginRun(const edm::Run &iRun)
TH1D * m_hnrhits
Definition: TrackCount.cc:95
TH1D * m_hnpixellayers
Definition: TrackCount.cc:100
fixed size matrix
HLT enums.
TH2F * m_ndofvseta
Definition: TrackCount.cc:92
TH1D * m_hnstriprhits
Definition: TrackCount.cc:97
const unsigned int m_LSfrac
Definition: TrackCount.cc:113
const double m_ptmin
Definition: TrackCount.cc:120
TH1F * m_hcos
Definition: TrackCount.cc:85
TProfile * m_ntrkvslumi
Definition: TrackCount.cc:78
const bool m_dump
Definition: TrackCount.cc:116
TH2D * m_ntrkvslumi2D
Definition: TrackCount.cc:79
const bool m_2dhistos
Definition: TrackCount.cc:114
TH1D * m_hnlosthits
Definition: TrackCount.cc:94
TH1F * m_ndof
Definition: TrackCount.cc:89
TH1F * m_hphi
Definition: TrackCount.cc:83
TH2D * m_hphieta
Definition: TrackCount.cc:103
Definition: Run.h:43
const bool m_runHisto
Definition: TrackCount.cc:115
edm::EDGetTokenT< LumiDetails > m_lumiProducerToken
Definition: TrackCount.cc:118
const unsigned int m_nptbin
Definition: TrackCount.cc:119
TH1F * m_hhpfrac
Definition: TrackCount.cc:81