CMS 3D CMS Logo

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