CMS 3D CMS Logo

StandaloneTrackMonitor.cc
Go to the documentation of this file.
1 #include "TFile.h"
2 #include "TH1.h"
3 #include "TMath.h"
4 
12 #include "TPRegexp.h"
23 // -----------------------------
24 // constructors and destructor
25 // -----------------------------
27  parameters_(ps),
28  moduleName_(parameters_.getUntrackedParameter<std::string>("moduleName", "StandaloneTrackMonitor")),
29  folderName_(parameters_.getUntrackedParameter<std::string>("folderName", "highPurityTracks")),
30  trackTag_(parameters_.getUntrackedParameter<edm::InputTag>("trackInputTag", edm::InputTag("generalTracks"))),
31  bsTag_(parameters_.getUntrackedParameter<edm::InputTag>("offlineBeamSpot", edm::InputTag("offlineBeamSpot"))),
32  vertexTag_(parameters_.getUntrackedParameter<edm::InputTag>("vertexTag", edm::InputTag("offlinePrimaryVertices"))),
33  puSummaryTag_(parameters_.getUntrackedParameter<edm::InputTag>("puTag", edm::InputTag("addPileupInfo"))),
34  clusterTag_(parameters_.getUntrackedParameter<edm::InputTag>("clusterTag", edm::InputTag("siStripClusters"))),
35  trackToken_(consumes<reco::TrackCollection>(trackTag_)),
36  bsToken_(consumes<reco::BeamSpot>(bsTag_)),
37  vertexToken_(consumes<reco::VertexCollection>(vertexTag_)),
38  puSummaryToken_(consumes<std::vector<PileupSummaryInfo> >(puSummaryTag_)),
39  clusterToken_(consumes<edmNew::DetSetVector<SiStripCluster> >(clusterTag_)),
40  trackQuality_(parameters_.getUntrackedParameter<std::string>("trackQuality", "highPurity")),
41  doPUCorrection_(parameters_.getUntrackedParameter<bool>("doPUCorrection", false)),
42  isMC_(parameters_.getUntrackedParameter<bool>("isMC", false)),
43  haveAllHistograms_(parameters_.getUntrackedParameter<bool>("haveAllHistograms", false)),
44  puScaleFactorFile_(parameters_.getUntrackedParameter<std::string>("puScaleFactorFile", "PileupScaleFactor_run203002.root")),
45  verbose_(parameters_.getUntrackedParameter<bool>("verbose", false))
46 {
47  trackEtaH_ = nullptr;
48  trackEtaerrH_ = nullptr;
49  trackCosThetaH_ = nullptr;
50  trackThetaerrH_ = nullptr;
51  trackPhiH_ = nullptr;
52  trackPhierrH_ = nullptr;
53  trackPH_ = nullptr;
54  trackPtH_ = nullptr;
55  trackPtUpto2GeVH_ = nullptr;
56  trackPtOver10GeVH_ = nullptr;
57  trackPterrH_ = nullptr;
58  trackqOverpH_ = nullptr;
59  trackqOverperrH_ = nullptr;
60  trackChargeH_ = nullptr;
61  nlostHitsH_ = nullptr;
62  nvalidTrackerHitsH_ = nullptr;
63  nvalidPixelHitsH_ = nullptr;
64  nvalidStripHitsH_ = nullptr;
65  trkLayerwithMeasurementH_ = nullptr;
68  beamSpotXYposH_ = nullptr;
69  beamSpotXYposerrH_ = nullptr;
70  beamSpotZposH_ = nullptr;
71  beamSpotZposerrH_ = nullptr;
72  trackChi2H_ = nullptr;
73  tracknDOFH_ = nullptr;
74  trackd0H_ = nullptr;
75  trackChi2bynDOFH_ = nullptr;
76  vertexXposH_ = nullptr;
77  vertexYposH_ = nullptr;
78  vertexZposH_ = nullptr;
79 
80  nPixBarrelH_ = nullptr;
81  nPixEndcapH_ = nullptr;
82  nStripTIBH_ = nullptr;
83  nStripTOBH_ = nullptr;
84  nStripTECH_ = nullptr;
85  nStripTIDH_ = nullptr;
86  nTracksH_ = nullptr;
87 
88  // for MC only
89  nVertexH_ = nullptr;
90  bunchCrossingH_ = nullptr;
91  nPUH_ = nullptr;
92  trueNIntH_ = nullptr;
93 
94  nHitsVspTH_ = nullptr;
95  nHitsVsEtaH_ = nullptr;
96  nHitsVsCosThetaH_ = nullptr;
97  nHitsVsPhiH_ = nullptr;
98  nHitsVsnVtxH_ = nullptr;
99  nLostHitsVspTH_ = nullptr;
100  nLostHitsVsEtaH_ = nullptr;
101  nLostHitsVsCosThetaH_ = nullptr;
102  nLostHitsVsPhiH_ = nullptr;
103 
104  hOnTrkClusChargeThinH_ = nullptr;
105  hOnTrkClusWidthThinH_ = nullptr;
106  hOnTrkClusChargeThickH_ = nullptr;
107  hOnTrkClusWidthThickH_ = nullptr;
108 
109  hOffTrkClusChargeThinH_ = nullptr;
110  hOffTrkClusWidthThinH_ = nullptr;
111  hOffTrkClusChargeThickH_ = nullptr;
112  hOffTrkClusWidthThickH_ = nullptr;
113 
114  // Read pileup weight factors
115  if (isMC_ && doPUCorrection_) {
116  vpu_.clear();
117  TFile* f1 = TFile::Open(puScaleFactorFile_.c_str());
118  TH1F* h1 = dynamic_cast<TH1F*>(f1->Get("pileupweight"));
119  for (int i = 1; i <= h1->GetNbinsX(); ++i) vpu_.push_back(h1->GetBinContent(i));
120  f1->Close();
121  }
122 }
123 
125 
126  edm::ParameterSet TrackEtaHistoPar = parameters_.getParameter<edm::ParameterSet>("trackEtaH");
127  edm::ParameterSet TrackPtHistoPar = parameters_.getParameter<edm::ParameterSet>("trackPtH");
128 
129  std::string currentFolder = moduleName_ + "/" + folderName_ ;
130  iBook.setCurrentFolder(currentFolder);
131 
132  // The following are common with the official tool
133  if (haveAllHistograms_) {
134  if (!trackEtaH_) trackEtaH_ = iBook.book1D("trackEta", "Track Eta",
135  TrackEtaHistoPar.getParameter<int32_t>("Xbins"),
136  TrackEtaHistoPar.getParameter<double>("Xmin"),
137  TrackEtaHistoPar.getParameter<double>("Xmax"));
138  if (!trackEtaerrH_) trackEtaerrH_ = iBook.book1D("trackEtaerr", "Track Eta Error", 50,0.0,1.0);
139  if (!trackCosThetaH_) trackCosThetaH_ = iBook.book1D("trackCosTheta", "Track Cos(Theta)", 50,-1.0,1.0);
140  if (!trackThetaerrH_) trackThetaerrH_ = iBook.book1D("trackThetaerr", "Track Theta Error", 50,0.0,1.0);
141  if (!trackPhiH_) trackPhiH_ = iBook.book1D("trackPhi", "Track Phi", 70,-3.5,3.5);
142  if (!trackPhierrH_) trackPhierrH_ = iBook.book1D("trackPhierr", "Track Phi Error", 50,0.0,1.0);
143 
144  if (!trackPH_) trackPH_ = iBook.book1D("trackP", "Track 4-momentum", 50,0.0,10.0);
145  if (!trackPtH_) trackPtH_ = iBook.book1D("trackPt", "Track Pt",
146  TrackPtHistoPar.getParameter<int32_t>("Xbins"),
147  TrackPtHistoPar.getParameter<double>("Xmin"),
148  TrackPtHistoPar.getParameter<double>("Xmax"));
149  if (!trackPtUpto2GeVH_) trackPtUpto2GeVH_ = iBook.book1D("trackPtUpto2GeV", "Track Pt upto 2GeV",100,0,2.0);
150  if (!trackPtOver10GeVH_) trackPtOver10GeVH_ = iBook.book1D("trackPtOver10GeV","Track Pt greater than 10 GeV",100,0,100.0);
151  if (!trackPterrH_) trackPterrH_ = iBook.book1D("trackPterr", "Track Pt Error",100,0.0,100.0);
152  if (!trackqOverpH_) trackqOverpH_ = iBook.book1D("trackqOverp", "q Over p",40,-10.0,10.0);
153  if (!trackqOverperrH_) trackqOverperrH_ = iBook.book1D("trackqOverperr","q Over p Error",50,0.0,25.0);
154  if (!trackChargeH_) trackChargeH_ = iBook.book1D("trackCharge", "Track Charge", 50, -5, 5);
155  if (!trackChi2H_) trackChi2H_ = iBook.book1D("trackChi2", "Chi2",100,0.0,100.0);
156  if (!tracknDOFH_) tracknDOFH_ = iBook.book1D("tracknDOF", "nDOF",100,0.0,100.0);
157  if (!trackd0H_) trackd0H_ = iBook.book1D("trackd0", "Track d0",100,-1,1);
158  if (!trackChi2bynDOFH_) trackChi2bynDOFH_ = iBook.book1D("trackChi2bynDOF", "Chi2 Over nDOF",100,0.0,10.0);
159 
160  if (!nlostHitsH_) nlostHitsH_ = iBook.book1D("nlostHits", "No. of Lost Hits",10,0.0,10.0);
161  if (!nvalidTrackerHitsH_) nvalidTrackerHitsH_ = iBook.book1D("nvalidTrackerhits", "No. of Valid Tracker Hits",35,0.0,35.0);
162  if (!nvalidPixelHitsH_) nvalidPixelHitsH_ = iBook.book1D("nvalidPixelHits", "No. of Valid Hits in Pixel",10,0.0,10.0);
163  if (!nvalidStripHitsH_) nvalidStripHitsH_ = iBook.book1D("nvalidStripHits", "No.of Valid Hits in Strip",25,0.0,25.0);
164 
166  trkLayerwithMeasurementH_ = iBook.book1D("trkLayerwithMeasurement", "No. of Layers per Track",25,0.0,25.0);
168  pixelLayerwithMeasurementH_ = iBook.book1D("pixelLayerwithMeasurement", "No. of Pixel Layers per Track",10,0.0,10.0);
170  stripLayerwithMeasurementH_ = iBook.book1D("stripLayerwithMeasurement", "No. of Strip Layers per Track",20,0.0,20.0);
171 
172  if (!beamSpotXYposH_) beamSpotXYposH_ = iBook.book1D("beamSpotXYpos", "XY position of beam spot",40,-4.0,4.0);
173  if (!beamSpotXYposerrH_) beamSpotXYposerrH_ = iBook.book1D("beamSpotXYposerr", "Error in XY position of beam spot",20,0.0,4.0);
174  if (!beamSpotZposH_) beamSpotZposH_ = iBook.book1D("beamSpotZpos", "Z position of beam spot",100,-20.0,20.0);
175  if (!beamSpotZposerrH_) beamSpotZposerrH_ = iBook.book1D("beamSpotZposerr", "Error in Z position of beam spot", 50, 0.0, 5.0);
176 
177  if (!vertexXposH_) vertexXposH_ = iBook.book1D("vertexXpos", "Vertex X position", 50, -1.0, 1.0);
178  if (!vertexYposH_) vertexYposH_ = iBook.book1D("vertexYpos", "Vertex Y position", 50, -1.0, 1.0);
179  if (!vertexZposH_) vertexZposH_ = iBook.book1D("vertexZpos", "Vertex Z position", 100,-20.0,20.0);
180  if (!nVertexH_) nVertexH_ = iBook.book1D("nVertex", "# of vertices", 60, -0.5, 59.5);
181 
182  if (!nPixBarrelH_)
183  nPixBarrelH_ = iBook.book1D("nHitPixelBarrel", "No. of hits in Pixel Barrel per Track", 20, 0, 20.0);
184  if (!nPixEndcapH_)
185  nPixEndcapH_ = iBook.book1D("nHitPixelEndcap", "No. of hits in Pixel Endcap per Track", 20, 0, 20.0);
186  if (!nStripTIBH_)
187  nStripTIBH_ = iBook.book1D("nHitStripTIB", "No. of hits in Strip TIB per Track", 30, 0, 30.0);
188  if (!nStripTOBH_)
189  nStripTOBH_ = iBook.book1D("nHitStripTOB", "No. of hits in Strip TOB per Track", 30, 0, 30.0);
190  if (!nStripTECH_)
191  nStripTECH_ = iBook.book1D("nHitStripTEC", "No. of hits in Strip TEC per Track", 30, 0, 30.0);
192  if (!nStripTIDH_)
193  nStripTIDH_ = iBook.book1D("nHitStripTID", "No. of hits in Strip TID per Tracks", 30, 0, 30.0);
194 
195  if (!nTracksH_) nTracksH_ = iBook.book1D("nTracks", "No. of Tracks", 100, -0.5, 999.5);
196  }
197  if (isMC_) {
198  if (!bunchCrossingH_) bunchCrossingH_ = iBook.book1D("bunchCrossing", "Bunch Crosssing", 60, 0, 60.0);
199  if (!nPUH_) nPUH_ = iBook.book1D("nPU", "No of Pileup", 60, 0, 60.0);
200  if (!trueNIntH_) trueNIntH_ = iBook.book1D("trueNInt", "True no of Interactions", 60, 0, 60.0);
201  }
202  // Exclusive histograms
203  if (!nHitsVspTH_)
204  nHitsVspTH_ = iBook.bookProfile("nHitsVspT", "Number of Hits Vs pT",
205  TrackPtHistoPar.getParameter<int32_t>("Xbins"),
206  TrackPtHistoPar.getParameter<double>("Xmin"),
207  TrackPtHistoPar.getParameter<double>("Xmax"),0.0,0.0,"g");
208  if (!nHitsVsnVtxH_)
209  nHitsVsnVtxH_ = iBook.bookProfile("nHitsVsnVtx", "Number of Hits Vs Number of Vertex", 100,0,50,0.0,0.0,"g");
210  if (!nHitsVsEtaH_)
211  nHitsVsEtaH_ = iBook.bookProfile("nHitsVsEta", "Number of Hits Vs Eta",
212  TrackEtaHistoPar.getParameter<int32_t>("Xbins"),
213  TrackEtaHistoPar.getParameter<double>("Xmin"),
214  TrackEtaHistoPar.getParameter<double>("Xmax"),0.0,0.0,"g");
215  if (!nHitsVsCosThetaH_)
216  nHitsVsCosThetaH_ = iBook.bookProfile("nHitsVsCosTheta", "Number of Hits Vs Cos(Theta)", 50,-1.0,1.0,0.0,0.0,"g");
217  if (!nHitsVsPhiH_)
218  nHitsVsPhiH_ = iBook.bookProfile("nHitsVsPhi", "Number of Hits Vs Phi", 100,-3.5,3.5,0.0,0.0,"g");
219 
220  if (!nLostHitsVspTH_)
221  nLostHitsVspTH_ = iBook.bookProfile("nLostHitsVspT", "Number of Lost Hits Vs pT",
222  TrackPtHistoPar.getParameter<int32_t>("Xbins"),
223  TrackPtHistoPar.getParameter<double>("Xmin"),
224  TrackPtHistoPar.getParameter<double>("Xmax"),0.0,0.0,"g");
225  if (!nLostHitsVsEtaH_)
226  nLostHitsVsEtaH_ = iBook.bookProfile("nLostHitsVsEta", "Number of Lost Hits Vs Eta",
227  TrackEtaHistoPar.getParameter<int32_t>("Xbins"),
228  TrackEtaHistoPar.getParameter<double>("Xmin"),
229  TrackEtaHistoPar.getParameter<double>("Xmax"),0.0,0.0,"g");
230  if (!nLostHitsVsCosThetaH_)
231  nLostHitsVsCosThetaH_ = iBook.bookProfile("nLostHitsVsCosTheta", "Number of Lost Hits Vs Cos(Theta)",50,-1.0,1.0,0.0,0.0,"g");
232  if (!nLostHitsVsPhiH_)
233  nLostHitsVsPhiH_ = iBook.bookProfile("nLostHitsVsPhi", "Number of Lost Hits Vs Phi",100,-3.5,3.5,0.0,0.0,"g");
234 
235  // On and off-track cluster properties
237  hOnTrkClusChargeThinH_ = iBook.book1D("hOnTrkClusChargeThin", "On-track Cluster Charge (Thin Sensor)", 100, 0, 1000);
238  if (!hOnTrkClusWidthThinH_)
239  hOnTrkClusWidthThinH_ = iBook.book1D("hOnTrkClusWidthThin", "On-track Cluster Width (Thin Sensor)", 20, -0.5, 19.5);
241  hOnTrkClusChargeThickH_ = iBook.book1D("hOnTrkClusChargeThick", "On-track Cluster Charge (Thick Sensor)", 100, 0, 1000);
243  hOnTrkClusWidthThickH_ = iBook.book1D("hOnTrkClusWidthThick", "On-track Cluster Width (Thick Sensor)", 20, -0.5, 19.5);
244 
246  hOffTrkClusChargeThinH_ = iBook.book1D("hOffTrkClusChargeThin", "Off-track Cluster Charge (Thin Sensor)", 100, 0, 1000);
248  hOffTrkClusWidthThinH_ = iBook.book1D("hOffTrkClusWidthThin", "Off-track Cluster Width (Thin Sensor)", 20, -0.5, 19.5);
250  hOffTrkClusChargeThickH_ = iBook.book1D("hOffTrkClusChargeThick", "Off-track Cluster Charge (Thick Sensor)", 100, 0, 1000);
252  hOffTrkClusWidthThickH_ = iBook.book1D("hOffTrkClusWidthThick", "Off-track Cluster Width (Thick Sensor)", 20, -0.5, 19.5);
253 }
255  // Get event setup (to get global transformation)
257  iSetup.get<TrackerDigiGeometryRecord>().get(geomHandle);
258  const TrackerGeometry& tkGeom = (*geomHandle);
259 
260  // Primary vertex collection
262  iEvent.getByToken(vertexToken_, vertexColl);
263 
264  // Beam spot
266  iEvent.getByToken(bsToken_, beamSpot);
267 
268  // Track collection
270  iEvent.getByToken(trackToken_, tracks);
271 
272  // Access PU information
273  double wfac = 1.0; // for data
274  if (!iEvent.isRealData()) {
276  iEvent.getByToken(puSummaryToken_, PupInfo);
277 
278  if (verbose_) edm::LogInfo("StandaloneTrackMonitor") << "nPUColl = " << PupInfo->size();
279  for (auto const& v : *PupInfo) {
280  int bx = v.getBunchCrossing();
282  if (bx == 0) {
283  if (nPUH_) nPUH_->Fill(v.getPU_NumInteractions());
284  int ntrueInt = v.getTrueNumInteractions();
285  if (trueNIntH_) trueNIntH_->Fill(ntrueInt);
286  if (doPUCorrection_)
287  if (ntrueInt > -1 && ntrueInt < int(vpu_.size())) wfac = vpu_.at(ntrueInt);
288  }
289  }
290  }
291  if (verbose_) edm::LogInfo("StandaloneTrackMonitor") << "PU reweight factor = " << wfac;
292 
293  if (!vertexColl.isValid())
294  edm::LogError("DqmTrackStudy") << "Error! Failed to get reco::Vertex Collection, " << vertexTag_;
295  if (haveAllHistograms_) {
296  int nvtx = (vertexColl.isValid() ? vertexColl->size() : 0);
297  nVertexH_->Fill(nvtx);
298  }
299 
300  int ntracks = 0;
301  if (tracks.isValid()) {
302  edm::LogInfo("StandaloneTrackMonitor") << "Total # of Tracks: " << tracks->size();
303  if (verbose_) edm::LogInfo("StandaloneTrackMonitor") <<"Total # of Tracks: " << tracks->size();
305  for (auto const& track : *tracks) {
306  if (!track.quality(quality)) continue;
307 
308  ++ntracks;
309 
310  double eta = track.eta();
311  double theta = track.theta();
312  double phi = track.phi();
313  double pt = track.pt();
314 
315  const reco::HitPattern& hitp = track.hitPattern();
316  double nValidTrackerHits = hitp.numberOfValidTrackerHits();
317  nHitsVsEtaH_->Fill(eta, nValidTrackerHits);
318  nHitsVsCosThetaH_->Fill(std::cos(theta), nValidTrackerHits);
319  nHitsVsPhiH_->Fill(phi, nValidTrackerHits);
320  nHitsVspTH_->Fill(pt, nValidTrackerHits);
321  nHitsVsnVtxH_->Fill(vertexColl->size(), nValidTrackerHits);
322 
323  int nLostHits = track.numberOfLostHits();
324  nLostHitsVspTH_->Fill(pt, nLostHits);
325  nLostHitsVsEtaH_->Fill(eta, nLostHits);
326  nLostHitsVsCosThetaH_->Fill(std::cos(theta), nLostHits);
327  nLostHitsVsPhiH_->Fill(phi, nLostHits);
328 
329  double nValidPixelHits = hitp.numberOfValidPixelHits();
330  double nValidStripHits = hitp.numberOfValidStripHits();
331  double pixelLayersWithMeasurement = hitp.pixelLayersWithMeasurement();
332  double stripLayersWithMeasurement = hitp.stripLayersWithMeasurement();
333 
334  if (haveAllHistograms_) {
335  double etaError = track.etaError();
336  double thetaError = track.thetaError();
337  double phiError = track.phiError();
338  double p = track.p();
339  double ptError = track.ptError();
340  double qoverp = track.qoverp();
341  double qoverpError = track.qoverpError();
342  double charge = track.charge();
343 
344  double trackerLayersWithMeasurement = hitp.trackerLayersWithMeasurement();
345 
346  double dxy = track.dxy(beamSpot->position());
347  double dxyError = track.dxyError();
348  double dz = track.dz(beamSpot->position());
349  double dzError = track.dzError();
350 
351  double trkd0 = track.d0();
352  double chi2 = track.chi2();
353  double ndof = track.ndof();
354  double vx = track.vx();
355  double vy = track.vy();
356  double vz = track.vz();
357 
358  // Fill the histograms
359  trackEtaH_->Fill(eta, wfac);
360  trackEtaerrH_->Fill(etaError, wfac);
361  trackCosThetaH_->Fill(std::cos(theta), wfac);
362  trackThetaerrH_->Fill(thetaError, wfac);
363  trackPhiH_->Fill(phi, wfac);
364  trackPhierrH_->Fill(phiError, wfac);
365  trackPH_->Fill(p, wfac);
366  trackPtH_->Fill(pt, wfac);
367  if (pt <= 2) trackPtUpto2GeVH_->Fill(pt, wfac);
368  if (pt >= 10) trackPtOver10GeVH_->Fill(pt, wfac);
369  trackPterrH_->Fill(ptError, wfac);
370  trackqOverpH_->Fill(qoverp, wfac);
371  trackqOverperrH_->Fill(qoverpError, wfac);
372  trackChargeH_->Fill(charge, wfac);
373  trackChi2H_->Fill(chi2, wfac);
374  trackd0H_->Fill(trkd0, wfac);
375  tracknDOFH_->Fill(ndof, wfac);
376  trackChi2bynDOFH_->Fill(chi2/ndof, wfac);
377 
378  nlostHitsH_->Fill(nLostHits, wfac);
379  nvalidTrackerHitsH_->Fill(nValidTrackerHits, wfac);
380  nvalidPixelHitsH_->Fill(nValidPixelHits, wfac);
381  nvalidStripHitsH_->Fill(nValidStripHits, wfac);
382 
383  trkLayerwithMeasurementH_->Fill(trackerLayersWithMeasurement, wfac);
384  pixelLayerwithMeasurementH_->Fill(pixelLayersWithMeasurement, wfac);
385  stripLayerwithMeasurementH_->Fill(stripLayersWithMeasurement, wfac);
386 
387  beamSpotXYposH_->Fill(dxy, wfac);
388  beamSpotXYposerrH_->Fill(dxyError, wfac);
389  beamSpotZposH_->Fill(dz, wfac);
390  beamSpotZposerrH_->Fill(dzError, wfac);
391 
392  vertexXposH_->Fill(vx, wfac);
393  vertexYposH_->Fill(vy, wfac);
394  vertexZposH_->Fill(vz, wfac);
395  }
396  int nPixBarrel = 0, nPixEndcap = 0, nStripTIB = 0, nStripTOB = 0, nStripTEC = 0, nStripTID = 0;
397  for (auto it = track.recHitsBegin(); it != track.recHitsEnd(); ++it) {
398  const TrackingRecHit& hit = (**it);
399  if (hit.isValid()) {
400  if (hit.geographicalId().det() == DetId::Tracker) {
401  int subdetId = hit.geographicalId().subdetId();
402  if (subdetId == PixelSubdetector::PixelBarrel) ++nPixBarrel;
403  else if (subdetId == PixelSubdetector::PixelEndcap) ++nPixEndcap;
404  else if (subdetId == StripSubdetector::TIB) ++nStripTIB;
405  else if (subdetId == StripSubdetector::TOB) ++nStripTOB;
406  else if (subdetId == StripSubdetector::TEC) ++nStripTEC;
407  else if (subdetId == StripSubdetector::TID) ++nStripTID;
408 
409  // Find on-track clusters
410  processHit(hit, iSetup, tkGeom, wfac);
411  }
412  }
413  }
414  if (verbose_) edm::LogInfo("StandaloneTrackMonitor")
415  << " >>> HITs: nPixBarrel: " << nPixBarrel
416  << " nPixEndcap: " << nPixEndcap
417  << " nStripTIB: " << nStripTIB
418  << " nStripTOB: " << nStripTOB
419  << " nStripTEC: " << nStripTEC
420  << " nStripTID: " << nStripTID;
421  if (haveAllHistograms_) {
422  nPixBarrelH_->Fill(nPixBarrel, wfac);
423  nPixEndcapH_->Fill(nPixEndcap, wfac);
424  nStripTIBH_->Fill(nStripTIB, wfac);
425  nStripTOBH_->Fill(nStripTOB, wfac);
426  nStripTECH_->Fill(nStripTEC, wfac);
427  nStripTIDH_->Fill(nStripTID, wfac);
428  }
429  }
430  }
431  else {
432  edm::LogError("DqmTrackStudy") << "Error! Failed to get reco::Track collection, " << trackTag_;
433  }
434  if (haveAllHistograms_) nTracksH_->Fill(ntracks);
435 
436  // off track cluster properties
437  processClusters(iEvent, iSetup, tkGeom, wfac);
438 }
439 void StandaloneTrackMonitor::processClusters(edm::Event const& iEvent, edm::EventSetup const& iSetup, const TrackerGeometry& tkGeom, double wfac)
440 {
441  // SiStripClusters
443  iEvent.getByToken(clusterToken_, clusterHandle);
444 
445  if (clusterHandle.isValid()) {
446  // Loop on Dets
447  for (edmNew::DetSetVector<SiStripCluster>::const_iterator dsvit = clusterHandle->begin();
448  dsvit != clusterHandle->end();
449  ++dsvit)
450  {
451  uint32_t detId = dsvit->id();
452  std::map<uint32_t, std::set<const SiStripCluster*> >::iterator jt = clusterMap_.find(detId);
453  bool detid_found = (jt != clusterMap_.end()) ? true : false;
454 
455  // Loop on Clusters
456  for (edmNew::DetSet<SiStripCluster>::const_iterator clusit = dsvit->begin();
457  clusit != dsvit->end();
458  ++clusit)
459  {
460  if (detid_found) {
461  std::set<const SiStripCluster*>& s = jt->second;
462  if (s.find(&*clusit) != s.end()) continue;
463  }
464 
465  SiStripClusterInfo info(*clusit, iSetup, detId);
466  float charge = info.charge();
467  float width = info.width();
468 
469  const GeomDetUnit* detUnit = tkGeom.idToDetUnit(detId);
470  float thickness = detUnit->surface().bounds().thickness(); // unit cm
471  if (thickness > 0.035) {
472  hOffTrkClusChargeThickH_->Fill(charge, wfac);
473  hOffTrkClusWidthThickH_->Fill(width, wfac);
474  }
475  else {
476  hOffTrkClusChargeThinH_->Fill(charge, wfac);
477  hOffTrkClusWidthThinH_->Fill(width, wfac);
478  }
479  }
480  }
481  }
482  else {
483  edm::LogError("StandaloneTrackMonitor") << "ClusterCollection " << clusterTag_ << " not valid!!" << std::endl;
484  }
485 }
486 void StandaloneTrackMonitor::processHit(const TrackingRecHit& recHit, edm::EventSetup const& iSetup, const TrackerGeometry& tkGeom, double wfac)
487 {
488  uint32_t detid = recHit.geographicalId();
489  const GeomDetUnit* detUnit = tkGeom.idToDetUnit(detid);
490  float thickness = detUnit->surface().bounds().thickness(); // unit cm
491 
492  auto const& thit = static_cast<BaseTrackerRecHit const&>(recHit);
493  if (!thit.isValid()) return;
494 
495  auto const& clus = thit.firstClusterRef();
496  if (!clus.isValid()) return;
497  if (!clus.isStrip()) return;
498 
499  if (thit.isMatched()) {
500  const SiStripMatchedRecHit2D& matchedHit = dynamic_cast<const SiStripMatchedRecHit2D&>(recHit);
501 
502  auto& clusterM = matchedHit.monoCluster();
503  SiStripClusterInfo infoM(clusterM, iSetup, detid);
504  if (thickness > 0.035) {
505  hOnTrkClusChargeThickH_->Fill(infoM.charge(), wfac);
506  hOnTrkClusWidthThickH_->Fill(infoM.width(), wfac);
507  }
508  else {
509  hOnTrkClusChargeThinH_->Fill(infoM.charge(), wfac);
510  hOnTrkClusWidthThinH_->Fill(infoM.width(), wfac);
511  }
512  addClusterToMap(detid, &clusterM);
513 
514  auto& clusterS = matchedHit.stereoCluster();
515  SiStripClusterInfo infoS(clusterS, iSetup, detid);
516  if (thickness > 0.035) {
517  hOnTrkClusChargeThickH_->Fill(infoS.charge(), wfac);
518  hOnTrkClusWidthThickH_->Fill(infoS.width(), wfac );
519  }
520  else {
521  hOnTrkClusChargeThinH_->Fill(infoS.charge(), wfac);
522  hOnTrkClusWidthThinH_->Fill(infoS.width(), wfac);
523  }
524  addClusterToMap(detid, &clusterS);
525  }
526  else {
527  auto& cluster = clus.stripCluster();
528  SiStripClusterInfo info(cluster, iSetup, detid);
529  if (thickness > 0.035) {
530  hOnTrkClusChargeThickH_->Fill(info.charge(), wfac);
531  hOnTrkClusWidthThickH_->Fill(info.width(), wfac);
532  }
533  else {
534  hOnTrkClusChargeThinH_->Fill(info.charge(), wfac);
535  hOnTrkClusWidthThinH_->Fill(info.width(), wfac);
536  }
537  addClusterToMap(detid, &cluster);
538  }
539 }
540 void StandaloneTrackMonitor::addClusterToMap(uint32_t detid, const SiStripCluster* cluster) {
541  std::map<uint32_t, std::set<const SiStripCluster*> >::iterator it = clusterMap_.find(detid);
542  if (it == clusterMap_.end()) {
543  std::set<const SiStripCluster*> s;
544  s.insert(cluster);
545  clusterMap_.insert(std::pair<uint32_t, std::set<const SiStripCluster*> >(detid, s));
546  }
547  else {
548  std::set<const SiStripCluster*>& s = it->second;
549  s.insert(cluster);
550  }
551 }
552 // Define this as a plug-in
MonitorElement * pixelLayerwithMeasurementH_
MonitorElement * hOnTrkClusChargeThickH_
const edm::InputTag trackTag_
T getParameter(std::string const &) const
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
MonitorElement * hOnTrkClusChargeThinH_
static const TGPicture * info(bool iBackgroundIsBlack)
MonitorElement * trackPtOver10GeVH_
const std::string trackQuality_
const edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > clusterToken_
StandaloneTrackMonitor(const edm::ParameterSet &)
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:113
MonitorElement * trackChi2bynDOFH_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
TrackQuality
track quality
Definition: TrackBase.h:151
MonitorElement * hOffTrkClusWidthThickH_
const edm::EDGetTokenT< reco::TrackCollection > trackToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
SiStripCluster const & monoCluster() const
const edm::EDGetTokenT< std::vector< PileupSummaryInfo > > puSummaryToken_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
Geom::Theta< T > theta() const
MonitorElement * stripLayerwithMeasurementH_
int numberOfValidStripHits() const
Definition: HitPattern.h:854
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
const Bounds & bounds() const
Definition: Surface.h:120
data_type const * const_iterator
Definition: DetSetNew.h:30
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:501
MonitorElement * hOnTrkClusWidthThinH_
int trackerLayersWithMeasurement() const
Definition: HitPattern.cc:520
bool isRealData() const
Definition: EventBase.h:64
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
MonitorElement * hOffTrkClusWidthThinH_
const std::string puScaleFactorFile_
MonitorElement * hOffTrkClusChargeThinH_
void Fill(long long x)
const edm::InputTag vertexTag_
MonitorElement * beamSpotXYposH_
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
int iEvent
Definition: GenABIO.cc:230
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
uint16_t charge() const
MonitorElement * hOnTrkClusWidthThickH_
MonitorElement * trackqOverperrH_
MonitorElement * trackThetaerrH_
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
uint16_t width() const
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
MonitorElement * nvalidStripHitsH_
bool isValid() const
Definition: HandleBase.h:74
MonitorElement * beamSpotZposerrH_
MonitorElement * nLostHitsVsCosThetaH_
MonitorElement * beamSpotXYposerrH_
MonitorElement * hOffTrkClusChargeThickH_
MonitorElement * trackCosThetaH_
const edm::InputTag clusterTag_
MonitorElement * nvalidTrackerHitsH_
MonitorElement * nHitsVsCosThetaH_
void addClusterToMap(uint32_t detid, const SiStripCluster *cluster)
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:125
virtual float thickness() const =0
const edm::EDGetTokenT< reco::BeamSpot > bsToken_
MonitorElement * trkLayerwithMeasurementH_
int stripLayersWithMeasurement() const
Definition: HitPattern.h:1036
bool isValid() const
std::map< uint32_t, std::set< const SiStripCluster * > > clusterMap_
int numberOfValidTrackerHits() const
Definition: HitPattern.h:829
SiStripCluster const & stereoCluster() const
fixed size matrix
HLT enums.
const edm::EDGetTokenT< reco::VertexCollection > vertexToken_
void processClusters(edm::Event const &iEvent, edm::EventSetup const &iSetup, const TrackerGeometry &tkGeom, double wfac=1)
T get() const
Definition: EventSetup.h:62
virtual OmniClusterRef const & firstClusterRef() const =0
int numberOfValidPixelHits() const
Definition: HitPattern.h:839
MonitorElement * nvalidPixelHitsH_
const Point & position() const
position
Definition: BeamSpot.h:62
MonitorElement * trackPtUpto2GeVH_
DetId geographicalId() const
void processHit(const TrackingRecHit &recHit, edm::EventSetup const &iSetup, const TrackerGeometry &tkGeom, double wfac=1)
Definition: Run.h:44
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39