CMS 3D CMS Logo

SiPixelHitEfficiencySource.cc
Go to the documentation of this file.
1 // Package: SiPixelMonitorTrack
2 // Class: SiPixelHitEfficiencySource
3 //
4 // class SiPixelHitEfficiencyModule SiPixelHitEfficiencyModule.cc
5 // DQM/SiPixelMonitorTrack/src/SiPixelHitEfficiencyModule.cc
6 //
7 // Description: SiPixel hit efficiency data quality monitoring modules
8 // Implementation: prototype -> improved -> never final - end of the 1st step
9 //
10 // Original Authors: Romain Rougny & Luca Mucibello
11 // Created: Mar Nov 10 13:29:00 CET 2009
12 
13 #include <cmath>
14 #include <iostream>
15 #include <map>
16 #include <string>
17 #include <utility>
18 #include <vector>
19 
22 
33 
45 
48 
49 using namespace std;
50 using namespace edm;
51 
53  : pSet_(pSet),
54  modOn(pSet.getUntrackedParameter<bool>("modOn", true)),
55  ladOn(pSet.getUntrackedParameter<bool>("ladOn", false)),
56  layOn(pSet.getUntrackedParameter<bool>("layOn", false)),
57  phiOn(pSet.getUntrackedParameter<bool>("phiOn", false)),
58  ringOn(pSet.getUntrackedParameter<bool>("ringOn", false)),
59  bladeOn(pSet.getUntrackedParameter<bool>("bladeOn", false)),
60  diskOn(pSet.getUntrackedParameter<bool>("diskOn", false)),
61  isUpgrade(pSet.getUntrackedParameter<bool>("isUpgrade", false))
62 // updateEfficiencies(
63 // pSet.getUntrackedParameter<bool>("updateEfficiencies",false) )
64 {
65  pSet_ = pSet;
66  debug_ = pSet_.getUntrackedParameter<bool>("debug", false);
67  applyEdgeCut_ = pSet_.getUntrackedParameter<bool>("applyEdgeCut");
68  nSigma_EdgeCut_ = pSet_.getUntrackedParameter<double>("nSigma_EdgeCut");
69  vtxsrc_ = pSet_.getUntrackedParameter<std::string>("vtxsrc", "offlinePrimaryVertices");
70  vertexCollectionToken_ = consumes<reco::VertexCollection>(vtxsrc_);
71  tracksrc_ = consumes<TrajTrackAssociationCollection>(pSet_.getParameter<edm::InputTag>("trajectoryInput"));
72  clusterCollectionToken_ = consumes<edmNew::DetSetVector<SiPixelCluster>>(std::string("siPixelClusters"));
73 
74  measurementTrackerEventToken_ = consumes<MeasurementTrackerEvent>(std::string("MeasurementTrackerEvent"));
75 
76  trackerTopoToken_ = esConsumes<TrackerTopology, TrackerTopologyRcd>();
77  trackerGeomToken_ = esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>();
78  measurementTrackerToken_ = esConsumes<MeasurementTracker, CkfComponentsRecord>();
80  esConsumes<Chi2MeasurementEstimatorBase, TrackingComponentsRecord>(edm::ESInputTag("", "Chi2"));
81  propagatorToken_ = esConsumes<Propagator, TrackingComponentsRecord>(edm::ESInputTag("", "PropagatorWithMaterial"));
83  esConsumes<PixelClusterParameterEstimator, TkPixelCPERecord>(edm::ESInputTag("", "PixelCPEGeneric"));
84  trackerTopoTokenBeginRun_ = esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>();
85  trackerGeomTokenBeginRun_ = esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>();
86 
87  firstRun = true;
88 
89  LogInfo("PixelDQM") << "SiPixelHitEfficiencySource constructor" << endl;
90  LogInfo("PixelDQM") << "Mod/Lad/Lay/Phi " << modOn << "/" << ladOn << "/" << layOn << "/" << phiOn << std::endl;
91  LogInfo("PixelDQM") << "Blade/Disk/Ring" << bladeOn << "/" << diskOn << "/" << ringOn << std::endl;
92 }
93 
95  LogInfo("PixelDQM") << "SiPixelHitEfficiencySource destructor" << endl;
96 
97  std::map<uint32_t, SiPixelHitEfficiencyModule *>::iterator struct_iter;
98  for (struct_iter = theSiPixelStructure.begin(); struct_iter != theSiPixelStructure.end(); struct_iter++) {
99  delete struct_iter->second;
100  struct_iter->second = nullptr;
101  }
102 }
103 
104 void SiPixelHitEfficiencySource::fillClusterProbability(int layer, int disk, bool plus, double probability) {
105  // barrel
106  if (layer != 0) {
107  if (layer == 1) {
108  if (plus)
109  meClusterProbabilityL1_Plus_->Fill(probability);
110  else
111  meClusterProbabilityL1_Minus_->Fill(probability);
112  }
113 
114  else if (layer == 2) {
115  if (plus)
116  meClusterProbabilityL2_Plus_->Fill(probability);
117  else
118  meClusterProbabilityL2_Minus_->Fill(probability);
119  }
120 
121  else if (layer == 3) {
122  if (plus)
123  meClusterProbabilityL3_Plus_->Fill(probability);
124  else
125  meClusterProbabilityL3_Minus_->Fill(probability);
126  }
127  }
128  // Endcap
129  if (disk != 0) {
130  if (disk == 1) {
131  if (plus)
132  meClusterProbabilityD1_Plus_->Fill(probability);
133  else
134  meClusterProbabilityD1_Minus_->Fill(probability);
135  }
136  if (disk == 2) {
137  if (plus)
138  meClusterProbabilityD2_Plus_->Fill(probability);
139  else
140  meClusterProbabilityD2_Minus_->Fill(probability);
141  }
142  }
143 }
144 
146  LogInfo("PixelDQM") << "SiPixelHitEfficiencySource beginRun()" << endl;
147 
148  if (firstRun) {
149  // retrieve TrackerGeometry for pixel dets
150 
151  nvalid = 0;
152  nmissing = 0;
153 
154  firstRun = false;
155  }
156 
158  if (debug_)
159  LogVerbatim("PixelDQM") << "TrackerGeometry " << &(*TG) << " size is " << TG->dets().size() << endl;
160 
161  // build theSiPixelStructure with the pixel barrel and endcap dets from
162  // TrackerGeometry
163  for (TrackerGeometry::DetContainer::const_iterator pxb = TG->detsPXB().begin(); pxb != TG->detsPXB().end(); pxb++) {
164  if (dynamic_cast<PixelGeomDetUnit const *>((*pxb)) != nullptr) {
165  SiPixelHitEfficiencyModule *module = new SiPixelHitEfficiencyModule((*pxb)->geographicalId().rawId());
166  theSiPixelStructure.insert(
167  pair<uint32_t, SiPixelHitEfficiencyModule *>((*pxb)->geographicalId().rawId(), module));
168  }
169  }
170  for (TrackerGeometry::DetContainer::const_iterator pxf = TG->detsPXF().begin(); pxf != TG->detsPXF().end(); pxf++) {
171  if (dynamic_cast<PixelGeomDetUnit const *>((*pxf)) != nullptr) {
172  SiPixelHitEfficiencyModule *module = new SiPixelHitEfficiencyModule((*pxf)->geographicalId().rawId());
173  theSiPixelStructure.insert(
174  pair<uint32_t, SiPixelHitEfficiencyModule *>((*pxf)->geographicalId().rawId(), module));
175  }
176  }
177  LogInfo("PixelDQM") << "SiPixelStructure size is " << theSiPixelStructure.size() << endl;
178 }
179 
181  edm::Run const &iRun,
182  edm::EventSetup const &iSetup) {
183  // book residual histograms in theSiPixelFolder - one (x,y) pair of histograms
184  // per det
185  SiPixelFolderOrganizer theSiPixelFolder(false);
186 
188  const TrackerTopology *pTT = tTopoHandle.product();
189 
190  for (std::map<uint32_t, SiPixelHitEfficiencyModule *>::iterator pxd = theSiPixelStructure.begin();
191  pxd != theSiPixelStructure.end();
192  pxd++) {
193  if (modOn) {
194  if (theSiPixelFolder.setModuleFolder(iBooker, (*pxd).first, 0, isUpgrade))
195  (*pxd).second->book(pSet_, pTT, iBooker, 0, isUpgrade);
196  else
197  throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource Folder Creation Failed! ";
198  }
199  if (ladOn) {
200  if (theSiPixelFolder.setModuleFolder(iBooker, (*pxd).first, 1, isUpgrade))
201  (*pxd).second->book(pSet_, pTT, iBooker, 1, isUpgrade);
202  else
203  throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource ladder Folder Creation Failed! ";
204  }
205  if (layOn) {
206  if (theSiPixelFolder.setModuleFolder(iBooker, (*pxd).first, 2, isUpgrade))
207  (*pxd).second->book(pSet_, pTT, iBooker, 2, isUpgrade);
208  else
209  throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource layer Folder Creation Failed! ";
210  }
211  if (phiOn) {
212  if (theSiPixelFolder.setModuleFolder(iBooker, (*pxd).first, 3, isUpgrade))
213  (*pxd).second->book(pSet_, pTT, iBooker, 3, isUpgrade);
214  else
215  throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource phi Folder Creation Failed! ";
216  }
217  if (bladeOn) {
218  if (theSiPixelFolder.setModuleFolder(iBooker, (*pxd).first, 4, isUpgrade))
219  (*pxd).second->book(pSet_, pTT, iBooker, 4, isUpgrade);
220  else
221  throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource Blade Folder Creation Failed! ";
222  }
223  if (diskOn) {
224  if (theSiPixelFolder.setModuleFolder(iBooker, (*pxd).first, 5, isUpgrade))
225  (*pxd).second->book(pSet_, pTT, iBooker, 5, isUpgrade);
226  else
227  throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource Disk Folder Creation Failed! ";
228  }
229  if (ringOn) {
230  if (theSiPixelFolder.setModuleFolder(iBooker, (*pxd).first, 6, isUpgrade))
231  (*pxd).second->book(pSet_, pTT, iBooker, 6, isUpgrade);
232  else
233  throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource Ring Folder Creation Failed! ";
234  }
235  }
236 
237  // book cluster probability histos for Barrel and Endcap
238  iBooker.setCurrentFolder("Pixel/Barrel");
239 
241  iBooker.book1D("ClusterProbabilityXY_Layer1_Plus", "ClusterProbabilityXY_Layer1_Plus", 500, -14, 0.1);
242  meClusterProbabilityL1_Plus_->setAxisTitle("Log(ClusterProbability)", 1);
243 
245  iBooker.book1D("ClusterProbabilityXY_Layer1_Minus", "ClusterProbabilityXY_Layer1_Minus", 500, -14, 0.1);
246  meClusterProbabilityL1_Minus_->setAxisTitle("Log(ClusterProbability)", 1);
247 
249  iBooker.book1D("ClusterProbabilityXY_Layer2_Plus", "ClusterProbabilityXY_Layer2_Plus", 500, -14, 0.1);
250  meClusterProbabilityL2_Plus_->setAxisTitle("Log(ClusterProbability)", 1);
251 
253  iBooker.book1D("ClusterProbabilityXY_Layer2_Minus", "ClusterProbabilityXY_Layer2_Minus", 500, -14, 0.1);
254  meClusterProbabilityL2_Minus_->setAxisTitle("Log(ClusterProbability)", 1);
255 
257  iBooker.book1D("ClusterProbabilityXY_Layer3_Plus", "ClusterProbabilityXY_Layer3_Plus", 500, -14, 0.1);
258  meClusterProbabilityL3_Plus_->setAxisTitle("Log(ClusterProbability)", 1);
259 
261  iBooker.book1D("ClusterProbabilityXY_Layer3_Minus", "ClusterProbabilityXY_Layer3_Minus", 500, -14, 0.1);
262  meClusterProbabilityL3_Minus_->setAxisTitle("Log(ClusterProbability)", 1);
263 
264  iBooker.setCurrentFolder("Pixel/Endcap");
265 
267  iBooker.book1D("ClusterProbabilityXY_Disk1_Plus", "ClusterProbabilityXY_Disk1_Plus", 500, -14, 0.1);
268  meClusterProbabilityD1_Plus_->setAxisTitle("Log(ClusterProbability)", 1);
269 
271  iBooker.book1D("ClusterProbabilityXY_Disk1_Minus", "ClusterProbabilityXY_Disk1_Minus", 500, -14, 0.1);
272  meClusterProbabilityD1_Minus_->setAxisTitle("Log(ClusterProbability)", 1);
273 
275  iBooker.book1D("ClusterProbabilityXY_Disk2_Plus", "ClusterProbabilityXY_Disk2_Plus", 500, -14, 0.1);
276  meClusterProbabilityD2_Plus_->setAxisTitle("Log(ClusterProbability)", 1);
277 
279  iBooker.book1D("ClusterProbabilityXY_Disk2_Minus", "ClusterProbabilityXY_Disk2_Minus", 500, -14, 0.1);
280  meClusterProbabilityD2_Minus_->setAxisTitle("Log(ClusterProbability)", 1);
281 }
282 
285  const TrackerTopology *pTT = tTopoHandle.product();
286 
287  edm::Handle<reco::VertexCollection> vertexCollectionHandle;
288  iEvent.getByToken(vertexCollectionToken_, vertexCollectionHandle);
289  if (!vertexCollectionHandle.isValid())
290  return;
291  nvtx_ = 0;
292  vtxntrk_ = -9999;
293  vtxD0_ = -9999.;
294  vtxX_ = -9999.;
295  vtxY_ = -9999.;
296  vtxZ_ = -9999.;
297  vtxndof_ = -9999.;
298  vtxchi2_ = -9999.;
299  const reco::VertexCollection &vertices = *vertexCollectionHandle.product();
300  reco::VertexCollection::const_iterator bestVtx = vertices.end();
301  for (reco::VertexCollection::const_iterator it = vertices.begin(); it != vertices.end(); ++it) {
302  if (!it->isValid())
303  continue;
304  if (vtxntrk_ == -9999 || vtxntrk_ < int(it->tracksSize()) ||
305  (vtxntrk_ == int(it->tracksSize()) && fabs(vtxZ_) > fabs(it->z()))) {
306  vtxntrk_ = it->tracksSize();
307  vtxD0_ = it->position().rho();
308  vtxX_ = it->x();
309  vtxY_ = it->y();
310  vtxZ_ = it->z();
311  vtxndof_ = it->ndof();
312  vtxchi2_ = it->chi2();
313  bestVtx = it;
314  }
315  if (fabs(it->z()) <= 20. && fabs(it->position().rho()) <= 2. && it->ndof() > 4)
316  nvtx_++;
317  }
318  if (nvtx_ < 1)
319  return;
320 
321  // get the map
323  iEvent.getByToken(tracksrc_, match);
324 
325  if (debug_) {
327  labelsForToken(tracksrc_, labels);
328  std::cout << "Trajectories from " << labels.module << std::endl;
329  }
330 
331  if (!match.isValid())
332  return;
333 
334  const TrajTrackAssociationCollection ttac = *(match.product());
335 
336  if (debug_) {
337  std::cout << "+++ NEW EVENT +++" << std::endl;
338  std::cout << "Map entries \t : " << ttac.size() << std::endl;
339  }
340 
341  std::set<SiPixelCluster> clusterSet;
342  // TrajectoryStateCombiner tsoscomb;
343  // define variables for extrapolation
344  int extrapolateFrom_ = 2;
345  int extrapolateTo_ = 1;
346  float maxlxmatch_ = 0.2;
347  float maxlymatch_ = 0.2;
348  bool keepOriginalMissingHit_ = true;
349  edm::ESHandle<MeasurementTracker> measurementTrackerHandle = iSetup.getHandle(measurementTrackerToken_);
350 
352  edm::Handle<MeasurementTrackerEvent> measurementTrackerEventHandle;
353  iEvent.getByToken(measurementTrackerEventToken_, measurementTrackerEventHandle);
355  Propagator *thePropagator = prop.product()->clone();
356  // determines direction of the propagator => inward
357  if (extrapolateFrom_ >= extrapolateTo_) {
359  }
360  TrajectoryStateCombiner trajStateComb;
361  bool debug_ = false;
362 
363  // Loop over track collection
364  for (TrajTrackAssociationCollection::const_iterator it = ttac.begin(); it != ttac.end(); ++it) {
365  // define vector to save extrapolated tracks
366  std::vector<TrajectoryMeasurement> expTrajMeasurements;
367 
368  const edm::Ref<std::vector<Trajectory>> traj_iterator = it->key;
369  // Trajectory Map, extract Trajectory for this track
370  reco::TrackRef trackref = it->val;
371  // tracks++;
372 
373  bool isBpixtrack = false, isFpixtrack = false;
374  int nStripHits = 0;
375  int L1hits = 0;
376  int L2hits = 0;
377  int L3hits = 0;
378  int L4hits = 0;
379  int D1hits = 0;
380  int D2hits = 0;
381  int D3hits = 0;
382  std::vector<TrajectoryMeasurement> tmeasColl = traj_iterator->measurements();
383  std::vector<TrajectoryMeasurement>::const_iterator tmeasIt;
384  // loop on measurements to find out what kind of hits there are
385  for (tmeasIt = tmeasColl.begin(); tmeasIt != tmeasColl.end(); tmeasIt++) {
386  // if(! tmeasIt->updatedState().isValid()) continue; NOT NECESSARY (I
387  // HOPE)
388  TransientTrackingRecHit::ConstRecHitPointer testhit = tmeasIt->recHit();
389  if (testhit->geographicalId().det() != DetId::Tracker)
390  continue;
391  uint testSubDetID = (testhit->geographicalId().subdetId());
392  const DetId &hit_detId = testhit->geographicalId();
393  int hit_layer = 0;
394  int hit_ladder = 0;
395  int hit_mod = 0;
396  int hit_disk = 0;
397 
398  if (testSubDetID == PixelSubdetector::PixelBarrel) {
399  isBpixtrack = true;
400  hit_layer = PixelBarrelName(hit_detId, pTT, isUpgrade).layerName();
401 
402  hit_ladder = PXBDetId(hit_detId).ladder();
403  hit_mod = PXBDetId(hit_detId).module();
404 
405  if (hit_layer == 1)
406  L1hits++;
407  if (hit_layer == 2)
408  L2hits++;
409  if (hit_layer == 3)
410  L3hits++;
411  if (hit_layer == 4)
412  L4hits++;
413  }
414  if (testSubDetID == PixelSubdetector::PixelEndcap) {
415  isFpixtrack = true;
416  hit_disk = PixelEndcapName(hit_detId, pTT, isUpgrade).diskName();
417 
418  if (hit_disk == 1)
419  D1hits++;
420  if (hit_disk == 2)
421  D2hits++;
422  if (hit_disk == 3)
423  D3hits++;
424  }
425  if (testSubDetID == StripSubdetector::TIB)
426  nStripHits++;
427  if (testSubDetID == StripSubdetector::TOB)
428  nStripHits++;
429  if (testSubDetID == StripSubdetector::TID)
430  nStripHits++;
431  if (testSubDetID == StripSubdetector::TEC)
432  nStripHits++;
433  // check if last valid hit is in Layer 2 or Disk 1
434 
435  bool lastValidL2 = false;
436  if ((testSubDetID == PixelSubdetector::PixelBarrel && hit_layer == extrapolateFrom_) ||
437  (testSubDetID == PixelSubdetector::PixelEndcap && hit_disk == 1)) {
438  if (testhit->isValid()) {
439  if (tmeasIt == tmeasColl.end() - 1) {
440  lastValidL2 = true;
441  } else {
442  tmeasIt++;
443  TransientTrackingRecHit::ConstRecHitPointer nextRecHit = tmeasIt->recHit();
444  uint nextSubDetID = (nextRecHit->geographicalId().subdetId());
445  int nextlayer = PixelBarrelName(nextRecHit->geographicalId()).layerName();
446  if (nextSubDetID == PixelSubdetector::PixelBarrel && nextlayer == extrapolateTo_) {
447  lastValidL2 = true; //&& !nextRecHit->isValid()) lastValidL2=true;
448  }
449  tmeasIt--;
450  }
451  }
452  } // end check last valid layer
453  if (lastValidL2) {
454  std::vector<const BarrelDetLayer *> pxbLayers =
455  measurementTrackerHandle->geometricSearchTracker()->pixelBarrelLayers();
456  const DetLayer *pxb1 = pxbLayers[extrapolateTo_ - 1];
457  const MeasurementEstimator *estimator = est.product();
458  const LayerMeasurements *theLayerMeasurements =
459  new LayerMeasurements(*measurementTrackerHandle, *measurementTrackerEventHandle);
460  const TrajectoryStateOnSurface tsosPXB2 = tmeasIt->updatedState();
461  expTrajMeasurements = theLayerMeasurements->measurements(*pxb1, tsosPXB2, *thePropagator, *estimator);
462  delete theLayerMeasurements;
463  if (!expTrajMeasurements.empty()) {
464  for (uint p = 0; p < expTrajMeasurements.size(); p++) {
465  TrajectoryMeasurement pxb1TM(expTrajMeasurements[p]);
466  const auto &pxb1Hit = pxb1TM.recHit();
467  // remove hits with rawID == 0
468  if (pxb1Hit->geographicalId().rawId() == 0) {
469  expTrajMeasurements.erase(expTrajMeasurements.begin() + p);
470  continue;
471  }
472  }
473  }
474  //
475  }
476  // check if extrapolated hit to layer 1 one matches the original hit
477  TrajectoryStateOnSurface chkPredTrajState =
478  trajStateComb(tmeasIt->forwardPredictedState(), tmeasIt->backwardPredictedState());
479  if (!chkPredTrajState.isValid())
480  continue;
481  float chkx = chkPredTrajState.globalPosition().x();
482  float chky = chkPredTrajState.globalPosition().y();
483  float chkz = chkPredTrajState.globalPosition().z();
484  LocalPoint chklp = chkPredTrajState.localPosition();
485  if (testSubDetID == PixelSubdetector::PixelBarrel && hit_layer == extrapolateTo_) {
486  // Here we will drop the extrapolated hits if there is a hit and use
487  // that hit
488  vector<int> imatches;
489  size_t imatch = 0;
490  float glmatch = 9999.;
491  for (size_t iexp = 0; iexp < expTrajMeasurements.size(); iexp++) {
492  const DetId &exphit_detId = expTrajMeasurements[iexp].recHit()->geographicalId();
493  int exphit_ladder = PXBDetId(exphit_detId).ladder();
494  int exphit_mod = PXBDetId(exphit_detId).module();
495  int dladder = abs(exphit_ladder - hit_ladder);
496  if (dladder > 10)
497  dladder = 20 - dladder;
498  int dmodule = abs(exphit_mod - hit_mod);
499  if (dladder != 0 || dmodule != 0) {
500  continue;
501  }
502 
503  TrajectoryStateOnSurface predTrajState = expTrajMeasurements[iexp].updatedState();
504  float x = predTrajState.globalPosition().x();
505  float y = predTrajState.globalPosition().y();
506  float z = predTrajState.globalPosition().z();
507  float dxyz = sqrt((chkx - x) * (chkx - x) + (chky - y) * (chky - y) + (chkz - z) * (chkz - z));
508 
509  if (dxyz <= glmatch) {
510  glmatch = dxyz;
511  imatch = iexp;
512  imatches.push_back(int(imatch));
513  }
514 
515  } // found the propagated traj best matching the hit in data
516 
517  float lxmatch = 9999.0;
518  float lymatch = 9999.0;
519  if (!expTrajMeasurements.empty()) {
520  if (glmatch < 9999.) { // if there is any propagated trajectory for this hit
521  const DetId &matchhit_detId = expTrajMeasurements[imatch].recHit()->geographicalId();
522 
523  int matchhit_ladder = PXBDetId(matchhit_detId).ladder();
524  int dladder = abs(matchhit_ladder - hit_ladder);
525  if (dladder > 10)
526  dladder = 20 - dladder;
527  LocalPoint lp = expTrajMeasurements[imatch].updatedState().localPosition();
528  lxmatch = fabs(lp.x() - chklp.x());
529  lymatch = fabs(lp.y() - chklp.y());
530  }
531  if (lxmatch < maxlxmatch_ && lymatch < maxlymatch_) {
532  if (testhit->getType() != TrackingRecHit::missing || keepOriginalMissingHit_) {
533  expTrajMeasurements.erase(expTrajMeasurements.begin() + imatch);
534  }
535  }
536 
537  } // expected trajectory measurment not empty
538  }
539  } // loop on trajectory measurments tmeasColl
540 
541  // if an extrapolated hit was found but not matched to an exisitng L1 hit
542  // then push the hit back into the collection now keep the first one that is
543  // left
544  if (!expTrajMeasurements.empty()) {
545  for (size_t f = 0; f < expTrajMeasurements.size(); f++) {
546  TrajectoryMeasurement AddHit = expTrajMeasurements[f];
547  if (AddHit.recHit()->getType() == TrackingRecHit::missing) {
548  tmeasColl.push_back(AddHit);
549  isBpixtrack = true;
550  }
551  }
552  }
553 
554  if (isBpixtrack || isFpixtrack) {
555  if (trackref->pt() < 0.6 || nStripHits < 8 || fabs(trackref->dxy(bestVtx->position())) > 0.05 ||
556  fabs(trackref->dz(bestVtx->position())) > 0.5)
557  continue;
558 
559  if (debug_) {
560  std::cout << "isBpixtrack : " << isBpixtrack << std::endl;
561  std::cout << "isFpixtrack : " << isFpixtrack << std::endl;
562  }
563  // std::cout<<"This tracks has so many hits:
564  // "<<tmeasColl.size()<<std::endl;
565  for (std::vector<TrajectoryMeasurement>::const_iterator tmeasIt = tmeasColl.begin(); tmeasIt != tmeasColl.end();
566  tmeasIt++) {
567  // if(! tmeasIt->updatedState().isValid()) continue;
568  TrajectoryStateOnSurface tsos = tmeasIt->updatedState();
569 
571  if (hit->geographicalId().det() != DetId::Tracker)
572  continue;
573  else {
574  // //residual
575  const DetId &hit_detId = hit->geographicalId();
576  // uint IntRawDetID = (hit_detId.rawId());
577  uint IntSubDetID = (hit_detId.subdetId());
578 
579  if (IntSubDetID == 0) {
580  if (debug_)
581  std::cout << "NO IntSubDetID\n";
582  continue;
583  }
584  if (IntSubDetID != PixelSubdetector::PixelBarrel && IntSubDetID != PixelSubdetector::PixelEndcap)
585  continue;
586 
587  int disk = 0;
588  int layer = 0;
589  int panel = 0;
590  int module = 0;
591  bool isHalfModule = false;
592 
593  const SiPixelRecHit *pixhit = dynamic_cast<const SiPixelRecHit *>(hit->hit());
594 
595  if (IntSubDetID == PixelSubdetector::PixelBarrel) { // it's a BPIX hit
596  layer = PixelBarrelName(hit_detId, pTT, isUpgrade).layerName();
597  isHalfModule = PixelBarrelName(hit_detId, pTT, isUpgrade).isHalfModule();
598 
599  if (hit->isValid()) { // fill the cluster probability in barrel
600  bool plus = true;
601  if ((PixelBarrelName(hit_detId, pTT, isUpgrade).shell() == PixelBarrelName::Shell::mO) ||
602  (PixelBarrelName(hit_detId, pTT, isUpgrade).shell() == PixelBarrelName::Shell::mI))
603  plus = false;
604  double clusterProbability = pixhit->clusterProbability(0);
605  if (clusterProbability != 0)
606  fillClusterProbability(layer, 0, plus, log10(clusterProbability));
607  }
608 
609  } else if (IntSubDetID == PixelSubdetector::PixelEndcap) { // it's an FPIX hit
610  disk = PixelEndcapName(hit_detId, pTT, isUpgrade).diskName();
611  panel = PixelEndcapName(hit_detId, pTT, isUpgrade).pannelName();
612  module = PixelEndcapName(hit_detId, pTT, isUpgrade).plaquetteName();
613 
614  if (hit->isValid()) {
615  bool plus = true;
616  if ((PixelEndcapName(hit_detId, pTT, isUpgrade).halfCylinder() == PixelEndcapName::HalfCylinder::mO) ||
617  (PixelEndcapName(hit_detId, pTT, isUpgrade).halfCylinder() == PixelEndcapName::HalfCylinder::mI))
618  plus = false;
619  double clusterProbability = pixhit->clusterProbability(0);
620  if (clusterProbability != 0)
621  fillClusterProbability(0, disk, plus, log10(clusterProbability));
622  }
623  }
624 
625  if (layer == 1) {
626  if (fabs(trackref->dxy(bestVtx->position())) > 0.01 || fabs(trackref->dz(bestVtx->position())) > 0.1)
627  continue;
628  if (!(L2hits > 0 && L3hits > 0) && !(L2hits > 0 && D1hits > 0) && !(D1hits > 0 && D2hits > 0))
629  continue;
630  } else if (layer == 2) {
631  if (fabs(trackref->dxy(bestVtx->position())) > 0.02 || fabs(trackref->dz(bestVtx->position())) > 0.1)
632  continue;
633  if (!(L1hits > 0 && L3hits > 0) && !(L1hits > 0 && D1hits > 0))
634  continue;
635  } else if (layer == 3) {
636  if (fabs(trackref->dxy(bestVtx->position())) > 0.02 || fabs(trackref->dz(bestVtx->position())) > 0.1)
637  continue;
638  if (!(L1hits > 0 && L2hits > 0))
639  continue;
640  } else if (layer == 4) {
641  if (fabs(trackref->dxy(bestVtx->position())) > 0.02 || fabs(trackref->dz(bestVtx->position())) > 0.1)
642  continue;
643  } else if (disk == 1) {
644  if (fabs(trackref->dxy(bestVtx->position())) > 0.05 || fabs(trackref->dz(bestVtx->position())) > 0.5)
645  continue;
646  if (!(L1hits > 0 && D2hits > 0) && !(L2hits > 0 && D2hits > 0))
647  continue;
648  } else if (disk == 2) {
649  if (fabs(trackref->dxy(bestVtx->position())) > 0.05 || fabs(trackref->dz(bestVtx->position())) > 0.5)
650  continue;
651  if (!(L1hits > 0 && D1hits > 0))
652  continue;
653  } else if (disk == 3) {
654  if (fabs(trackref->dxy(bestVtx->position())) > 0.05 || fabs(trackref->dz(bestVtx->position())) > 0.5)
655  continue;
656  }
657 
658  // check whether hit is valid or missing using track algo flag
659  bool isHitValid = hit->hit()->getType() == TrackingRecHit::valid;
660  bool isHitMissing = hit->hit()->getType() == TrackingRecHit::missing;
661 
662  if (debug_)
663  std::cout << "the hit is persistent\n";
664 
665  std::map<uint32_t, SiPixelHitEfficiencyModule *>::iterator pxd =
666  theSiPixelStructure.find((*hit).geographicalId().rawId());
667 
668  // calculate alpha and beta from cluster position
670  // LocalVector localDir = ltp.momentum()/ltp.momentum().mag();
671 
672  //*************** Edge cut ********************
673  double lx = tsos.localPosition().x();
674  double ly = tsos.localPosition().y();
675 
676  if (fabs(lx) > 0.55 || fabs(ly) > 3.0)
677  continue;
678 
679  bool passedFiducial = true;
680 
681  // Module fiducials:
682  if (IntSubDetID == PixelSubdetector::PixelBarrel && fabs(ly) >= 3.1)
683  passedFiducial = false;
684  if (IntSubDetID == PixelSubdetector::PixelEndcap &&
685  !((panel == 1 &&
686  ((module == 1 && fabs(ly) < 0.7) ||
687  ((module == 2 && fabs(ly) < 1.1) && !(disk == -1 && ly > 0.8 && lx > 0.2) &&
688  !(disk == 1 && ly < -0.7 && lx > 0.2) && !(disk == 2 && ly < -0.8)) ||
689  ((module == 3 && fabs(ly) < 1.5) && !(disk == -2 && lx > 0.1 && ly > 1.0) &&
690  !(disk == 2 && lx > 0.1 && ly < -1.0)) ||
691  ((module == 4 && fabs(ly) < 1.9) && !(disk == -2 && ly > 1.5) && !(disk == 2 && ly < -1.5)))) ||
692  (panel == 2 &&
693  ((module == 1 && fabs(ly) < 0.7) ||
694  (module == 2 && fabs(ly) < 1.2 && !(disk > 0 && ly > 1.1) && !(disk < 0 && ly < -1.1)) ||
695  (module == 3 && fabs(ly) < 1.6 && !(disk > 0 && ly > 1.5) && !(disk < 0 && ly < -1.5))))))
696  passedFiducial = false;
697  if (IntSubDetID == PixelSubdetector::PixelEndcap &&
698  ((panel == 1 && (module == 1 || (module >= 3 && abs(disk) == 1))) ||
699  (panel == 2 && ((module == 1 && abs(disk) == 2) || (module == 3 && abs(disk) == 1)))))
700  passedFiducial = false;
701  // ROC fiducials:
702  double ly_mod = fabs(ly);
703  if (IntSubDetID == PixelSubdetector::PixelEndcap && (panel + module) % 2 == 1)
704  ly_mod = ly_mod + 0.405;
705  float d_rocedge = fabs(fmod(ly_mod, 0.81) - 0.405);
706  if (d_rocedge <= 0.0625)
707  passedFiducial = false;
708  if (!((IntSubDetID == PixelSubdetector::PixelBarrel &&
709  ((!isHalfModule && fabs(lx) < 0.6) || (isHalfModule && lx > -0.3 && lx < 0.2))) ||
710  (IntSubDetID == PixelSubdetector::PixelEndcap &&
711  ((panel == 1 &&
712  ((module == 1 && fabs(lx) < 0.2) ||
713  (module == 2 && ((fabs(lx) < 0.55 && abs(disk) == 1) || (lx > -0.5 && lx < 0.2 && disk == -2) ||
714  (lx > -0.5 && lx < 0.0 && disk == 2))) ||
715  (module == 3 && lx > -0.6 && lx < 0.5) || (module == 4 && lx > -0.3 && lx < 0.15))) ||
716  (panel == 2 && ((module == 1 && fabs(lx) < 0.6) ||
717  (module == 2 && ((fabs(lx) < 0.55 && abs(disk) == 1) ||
718  (lx > -0.6 && lx < 0.5 && abs(disk) == 2))) ||
719  (module == 3 && fabs(lx) < 0.5)))))))
720  passedFiducial = false;
721  if (((IntSubDetID == PixelSubdetector::PixelBarrel && !isHalfModule) ||
722  (IntSubDetID == PixelSubdetector::PixelEndcap && !(panel == 1 && (module == 1 || module == 4)))) &&
723  fabs(lx) < 0.06)
724  passedFiducial = false;
725 
726  //*************** find closest clusters ********************
727  float dx_cl[2];
728  float dy_cl[2];
729  dx_cl[0] = dx_cl[1] = dy_cl[0] = dy_cl[1] = -9999.;
732  if (cpEstimator.isValid()) {
733  const PixelClusterParameterEstimator &cpe(*cpEstimator);
735  if (tracker.isValid()) {
736  const TrackerGeometry *tkgeom = &(*tracker);
737  edm::Handle<edmNew::DetSetVector<SiPixelCluster>> clusterCollectionHandle;
738  iEvent.getByToken(clusterCollectionToken_, clusterCollectionHandle);
739  if (clusterCollectionHandle.isValid()) {
740  const edmNew::DetSetVector<SiPixelCluster> &clusterCollection = *clusterCollectionHandle;
742  float minD[2];
743  minD[0] = minD[1] = 10000.;
744  for (; itClusterSet != clusterCollection.end(); itClusterSet++) {
745  DetId detId(itClusterSet->id());
746  if (detId.rawId() != hit->geographicalId().rawId())
747  continue;
748  // unsigned int sdId=detId.subdetId();
749  const PixelGeomDetUnit *pixdet = (const PixelGeomDetUnit *)tkgeom->idToDetUnit(detId);
750  edmNew::DetSet<SiPixelCluster>::const_iterator itCluster = itClusterSet->begin();
751  for (; itCluster != itClusterSet->end(); ++itCluster) {
752  LocalPoint lp(itCluster->x(), itCluster->y(), 0.);
754  lp = std::get<0>(params);
755  float D = sqrt((lp.x() - lx) * (lp.x() - lx) + (lp.y() - ly) * (lp.y() - ly));
756  if (D < minD[0]) {
757  minD[1] = minD[0];
758  dx_cl[1] = dx_cl[0];
759  dy_cl[1] = dy_cl[0];
760  minD[0] = D;
761  dx_cl[0] = lp.x();
762  dy_cl[0] = lp.y();
763  } else if (D < minD[1]) {
764  minD[1] = D;
765  dx_cl[1] = lp.x();
766  dy_cl[1] = lp.y();
767  }
768  } // loop on clusterSets
769  } // loop on clusterCollection
770  for (size_t i = 0; i < 2; i++) {
771  if (minD[i] < 9999.) {
772  dx_cl[i] = fabs(dx_cl[i] - lx);
773  dy_cl[i] = fabs(dy_cl[i] - ly);
774  }
775  }
776  } // valid clusterCollectionHandle
777  } // valid tracker
778  } // valid cpEstimator
779  // distance of hit from closest cluster!
780  float d_cl[2];
781  d_cl[0] = d_cl[1] = -9999.;
782  if (dx_cl[0] != -9999. && dy_cl[0] != -9999.)
783  d_cl[0] = sqrt(dx_cl[0] * dx_cl[0] + dy_cl[0] * dy_cl[0]);
784  if (dx_cl[1] != -9999. && dy_cl[1] != -9999.)
785  d_cl[1] = sqrt(dx_cl[1] * dx_cl[1] + dy_cl[1] * dy_cl[1]);
786  if (isHitMissing && (d_cl[0] < 0.05 || d_cl[1] < 0.05)) {
787  isHitMissing = false;
788  isHitValid = true;
789  }
790 
791  if (debug_) {
792  std::cout << "Ready to add hit in histogram:\n";
793  // std::cout << "detid: "<<hit_detId<<std::endl;
794  std::cout << "isHitValid: " << isHitValid << std::endl;
795  std::cout << "isHitMissing: " << isHitMissing << std::endl;
796  // std::cout << "passedEdgeCut: "<<passedFiducial<<std::endl;
797  }
798 
799  if (nStripHits < 11)
800  continue; // Efficiency plots are filled with hits on tracks that
801  // have at least 11 Strip hits
802 
803  if (pxd != theSiPixelStructure.end() && isHitValid && passedFiducial)
804  ++nvalid;
805  if (pxd != theSiPixelStructure.end() && isHitMissing && passedFiducial)
806  ++nmissing;
807 
808  if (pxd != theSiPixelStructure.end() && passedFiducial && (isHitValid || isHitMissing))
809  (*pxd).second->fill(pTT, ltp, isHitValid, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);
810 
811  //}//end if (persistent hit exists and is pixel hit)
812 
813  } // end of else
814 
815  } // end for (all traj measurements of pixeltrack)
816  } // end if (is pixeltrack)
817  else if (debug_)
818  std::cout << "no pixeltrack:\n";
819 
820  } // end loop on map entries
821 }
822 
823 DEFINE_FWK_MODULE(SiPixelHitEfficiencySource); // define this as a plug-in
edm::EDGetTokenT< MeasurementTrackerEvent > measurementTrackerEventToken_
Log< level::Info, true > LogVerbatim
static constexpr auto TEC
std::map< uint32_t, SiPixelHitEfficiencyModule * > theSiPixelStructure
virtual void setPropagationDirection(PropagationDirection dir)
Definition: Propagator.h:130
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
constexpr char const * layerName[numberOfLayers]
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
edm::ESGetToken< MeasurementTracker, CkfComponentsRecord > measurementTrackerToken_
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerGeomTokenBeginRun_
SiPixelHitEfficiencySource(const edm::ParameterSet &)
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
const DetContainer & detsPXB() const
T z() const
Definition: PV3DBase.h:61
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
unsigned int module() const
det id
Definition: PXBDetId.h:37
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > clusterCollectionToken_
T const * product() const
Definition: Handle.h:70
virtual Propagator * clone() const =0
const DetContainer & detsPXF() const
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerGeomToken_
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > trackerTopoTokenBeginRun_
const LocalTrajectoryParameters & localParameters() const
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
data_type const * const_iterator
Definition: DetSetNew.h:31
virtual void fillClusterProbability(int, int, bool, double)
key_type key() const
Accessor for product key.
Definition: Ref.h:250
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
constexpr std::array< uint8_t, layerIndexSize > layer
edm::EDGetTokenT< reco::VertexCollection > vertexCollectionToken_
const_iterator end(bool update=false) const
virtual ReturnType getParameters(const SiPixelCluster &cl, const GeomDetUnit &det) const =0
const_iterator end() const
last iterator over the map (read only)
T getUntrackedParameter(std::string const &, T const &) const
void Fill(long long x)
size_type size() const
map size
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
int iEvent
Definition: GenABIO.cc:224
T const * product() const
Definition: ESHandle.h:86
GlobalPoint globalPosition() const
bool isHalfModule() const
full or half module
int diskName() const
disk id
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
T sqrt(T t)
Definition: SSEVec.h:19
bool setModuleFolder(const uint32_t &rawdetid=0, int type=0, bool isUpgrade=false)
Set folder name for a module or plaquette.
edm::EDGetTokenT< TrajTrackAssociationCollection > tracksrc_
HalfCylinder halfCylinder() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
id_type id(size_t cell) const
double f[11][100]
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
static constexpr auto TOB
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > trackerTopoToken_
float clusterProbability(unsigned int flags=0) const
Definition: SiPixelRecHit.cc:9
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
bool isValid() const
Definition: ESHandle.h:44
Shell shell() const
Log< level::Info, false > LogInfo
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetId.h:17
void analyze(const edm::Event &, const edm::EventSetup &) override
static constexpr auto TIB
const_iterator begin(bool update=false) const
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:141
int layerName() const
layer id
bool isValid() const
Definition: HandleBase.h:70
edm::ESGetToken< Chi2MeasurementEstimatorBase, TrackingComponentsRecord > chi2MeasurementEstimatorBaseToken_
const_iterator begin() const
first iterator over the map (read only)
HLT enums.
edm::ESGetToken< Propagator, TrackingComponentsRecord > propagatorToken_
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
std::vector< TrajectoryMeasurement > measurements(const DetLayer &layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
modOn
online/offline RawDataErrors
unsigned int ladder() const
ladder id
Definition: PXBDetId.h:34
std::tuple< LocalPoint, LocalError, SiPixelRecHitQuality::QualWordType > ReturnType
static constexpr auto TID
void dqmBeginRun(const edm::Run &r, edm::EventSetup const &iSetup) override
int pannelName() const
pannel id
Definition: Run.h:45
ConstRecHitPointer const & recHit() const
Our base class.
Definition: SiPixelRecHit.h:23
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
edm::ESGetToken< PixelClusterParameterEstimator, TkPixelCPERecord > pixelClusterParameterEstimatorToken_
int plaquetteName() const
plaquetteId (in pannel)