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