CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
14 #include <iostream>
15 #include <map>
16 #include <string>
17 #include <vector>
18 #include <utility>
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 
71 
73  pSet_(pSet),
74  modOn( pSet.getUntrackedParameter<bool>("modOn",true) ),
75  ladOn( pSet.getUntrackedParameter<bool>("ladOn",false) ),
76  layOn( pSet.getUntrackedParameter<bool>("layOn",false) ),
77  phiOn( pSet.getUntrackedParameter<bool>("phiOn",false) ),
78  ringOn( pSet.getUntrackedParameter<bool>("ringOn",false) ),
79  bladeOn( pSet.getUntrackedParameter<bool>("bladeOn",false) ),
80  diskOn( pSet.getUntrackedParameter<bool>("diskOn",false) ),
81  isUpgrade( pSet.getUntrackedParameter<bool>("isUpgrade",false) )
82  //updateEfficiencies( 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  vertexCollectionToken_ = consumes<reco::VertexCollection>(std::string("offlinePrimaryVertices"));
89  tracksrc_ = consumes<TrajTrackAssociationCollection>(pSet_.getParameter<edm::InputTag>("trajectoryInput"));
90  clusterCollectionToken_ = consumes<edmNew::DetSetVector<SiPixelCluster> >(std::string("siPixelClusters"));
91 
92  measurementTrackerEventToken_ = consumes<MeasurementTrackerEvent>(std::string("MeasurementTrackerEvent"));
93 
94  firstRun = true;
95 
96  LogInfo("PixelDQM") << "SiPixelHitEfficiencySource constructor" << endl;
97  LogInfo ("PixelDQM") << "Mod/Lad/Lay/Phi " << modOn << "/" << ladOn << "/"
98  << layOn << "/" << phiOn << std::endl;
99  LogInfo ("PixelDQM") << "Blade/Disk/Ring" << bladeOn << "/" << diskOn << "/"
100  << ringOn << std::endl;
101 }
102 
103 
105  LogInfo("PixelDQM") << "SiPixelHitEfficiencySource destructor" << endl;
106 
107  std::map<uint32_t,SiPixelHitEfficiencyModule*>::iterator struct_iter;
108  for (struct_iter = theSiPixelStructure.begin() ; struct_iter != theSiPixelStructure.end() ; struct_iter++){
109  delete struct_iter->second;
110  struct_iter->second = 0;
111  }
112 }
113 
114 
116  LogInfo("PixelDQM") << "SiPixelHitEfficiencySource beginRun()" << endl;
117 
118  if(firstRun){
119  // retrieve TrackerGeometry for pixel dets
120 
121  nvalid=0;
122  nmissing=0;
123 
124  firstRun = false;
125  }
126 
128  iSetup.get<TrackerDigiGeometryRecord>().get(TG);
129  if (debug_) LogVerbatim("PixelDQM") << "TrackerGeometry "<< &(*TG) <<" size is "<< TG->dets().size() << endl;
130 
131  // build theSiPixelStructure with the pixel barrel and endcap dets from TrackerGeometry
132  for (TrackerGeometry::DetContainer::const_iterator pxb = TG->detsPXB().begin();
133  pxb!=TG->detsPXB().end(); pxb++) {
134  if (dynamic_cast<PixelGeomDetUnit const *>((*pxb))!=0) {
135  SiPixelHitEfficiencyModule* module = new SiPixelHitEfficiencyModule((*pxb)->geographicalId().rawId());
136  theSiPixelStructure.insert(pair<uint32_t, SiPixelHitEfficiencyModule*>((*pxb)->geographicalId().rawId(), module));
137  }
138  }
139  for (TrackerGeometry::DetContainer::const_iterator pxf = TG->detsPXF().begin();
140  pxf!=TG->detsPXF().end(); pxf++) {
141  if (dynamic_cast<PixelGeomDetUnit const *>((*pxf))!=0) {
142  SiPixelHitEfficiencyModule* module = new SiPixelHitEfficiencyModule((*pxf)->geographicalId().rawId());
143  theSiPixelStructure.insert(pair<uint32_t, SiPixelHitEfficiencyModule*>((*pxf)->geographicalId().rawId(), module));
144  }
145  }
146  LogInfo("PixelDQM") << "SiPixelStructure size is " << theSiPixelStructure.size() << endl;
147 
148 }
149 
151 
152  // book residual histograms in theSiPixelFolder - one (x,y) pair of histograms per det
153  SiPixelFolderOrganizer theSiPixelFolder;
154  for (std::map<uint32_t, SiPixelHitEfficiencyModule*>::iterator pxd = theSiPixelStructure.begin();
155  pxd!=theSiPixelStructure.end(); pxd++) {
156 
157  if(modOn){
158  if (theSiPixelFolder.setModuleFolder((*pxd).first,0,isUpgrade)) (*pxd).second->book(pSet_,iBooker,0,isUpgrade);
159  else throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource Folder Creation Failed! ";
160  }
161  if(ladOn){
162  if (theSiPixelFolder.setModuleFolder((*pxd).first,1,isUpgrade)) (*pxd).second->book(pSet_,iBooker,1,isUpgrade);
163  else throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource ladder Folder Creation Failed! ";
164  }
165  if(layOn){
166  if (theSiPixelFolder.setModuleFolder((*pxd).first,2,isUpgrade)) (*pxd).second->book(pSet_,iBooker,2,isUpgrade);
167  else throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource layer Folder Creation Failed! ";
168  }
169  if(phiOn){
170  if (theSiPixelFolder.setModuleFolder((*pxd).first,3,isUpgrade)) (*pxd).second->book(pSet_,iBooker,3,isUpgrade);
171  else throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource phi Folder Creation Failed! ";
172  }
173  if(bladeOn){
174  if (theSiPixelFolder.setModuleFolder((*pxd).first,4,isUpgrade)) (*pxd).second->book(pSet_,iBooker,4,isUpgrade);
175  else throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource Blade Folder Creation Failed! ";
176  }
177  if(diskOn){
178  if (theSiPixelFolder.setModuleFolder((*pxd).first,5,isUpgrade)) (*pxd).second->book(pSet_,iBooker,5,isUpgrade);
179  else throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource Disk Folder Creation Failed! ";
180  }
181  if(ringOn){
182  if (theSiPixelFolder.setModuleFolder((*pxd).first,6,isUpgrade)) (*pxd).second->book(pSet_,iBooker,6,isUpgrade);
183  else throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource Ring Folder Creation Failed! ";
184  }
185  }
186 
187 
188 }
189 
191 
192  edm::Handle<reco::VertexCollection> vertexCollectionHandle;
193  iEvent.getByToken( vertexCollectionToken_, vertexCollectionHandle );
194  if(!vertexCollectionHandle.isValid()) return;
195  nvtx_=0;
196  vtxntrk_=-9999;
197  vtxD0_=-9999.; vtxX_=-9999.; vtxY_=-9999.; vtxZ_=-9999.; vtxndof_=-9999.; vtxchi2_=-9999.;
198  const reco::VertexCollection & vertices = *vertexCollectionHandle.product();
199  reco::VertexCollection::const_iterator bestVtx=vertices.end();
200  for(reco::VertexCollection::const_iterator it=vertices.begin(); it!=vertices.end(); ++it){
201  if(!it->isValid()) continue;
202  if(vtxntrk_==-9999 ||
203  vtxntrk_<int(it->tracksSize()) ||
204  (vtxntrk_==int(it->tracksSize()) && fabs(vtxZ_)>fabs(it->z()))){
205  vtxntrk_=it->tracksSize();
206  vtxD0_=it->position().rho();
207  vtxX_=it->x();
208  vtxY_=it->y();
209  vtxZ_=it->z();
210  vtxndof_=it->ndof();
211  vtxchi2_=it->chi2();
212  bestVtx=it;
213  }
214  if(fabs(it->z())<=20. && fabs(it->position().rho())<=2. && it->ndof()>4) nvtx_++;
215  }
216  if(nvtx_<1) return;
217 
218  //get the map
220  iEvent.getByToken( tracksrc_, match );
221  const TrajTrackAssociationCollection ttac = *(match.product());
222 
223  if(debug_){
224  std::cout << "+++ NEW EVENT +++"<< std::endl;
225  std::cout << "Map entries \t : " << ttac.size() << std::endl;
226  }
227 
228  std::set<SiPixelCluster> clusterSet;
229  // TrajectoryStateCombiner tsoscomb;
230  //define variables for extrapolation
231  int extrapolateFrom_ = 2;
232  int extrapolateTo_ = 1;
233  float maxlxmatch_=0.2;
234  float maxlymatch_=0.2;
235  bool keepOriginalMissingHit_=true;
236  ESHandle<MeasurementTracker> measurementTrackerHandle;
237 
238  iSetup.get<CkfComponentsRecord>().get(measurementTrackerHandle);
239 
241  iSetup.get<TrackingComponentsRecord>().get("Chi2",est);
242  edm::Handle<MeasurementTrackerEvent> measurementTrackerEventHandle;
243  iEvent.getByToken(measurementTrackerEventToken_, measurementTrackerEventHandle);
245  iSetup.get<TrackingComponentsRecord>().get("PropagatorWithMaterial",prop);
246  Propagator* thePropagator = prop.product()->clone();
247  //determines direction of the propagator => inward
248  if (extrapolateFrom_>=extrapolateTo_) {
250  }
251  TrajectoryStateCombiner trajStateComb;
252  bool debug_ = false;
253 
254  //Loop over track collection
255  for(TrajTrackAssociationCollection::const_iterator it = ttac.begin();it != ttac.end(); ++it){
256  //define vector to save extrapolated tracks
257  std::vector<TrajectoryMeasurement> expTrajMeasurements;
258 
259  const edm::Ref<std::vector<Trajectory> > traj_iterator = it->key;
260  // Trajectory Map, extract Trajectory for this track
261  reco::TrackRef trackref = it->val;
262  //tracks++;
263 
264  bool isBpixtrack = false, isFpixtrack = false;
265  int nStripHits=0; int L1hits=0; int L2hits=0; int L3hits=0; int L4hits=0; int D1hits=0; int D2hits=0; int D3hits=0;
266  std::vector<TrajectoryMeasurement> tmeasColl =traj_iterator->measurements();
267  std::vector<TrajectoryMeasurement>::const_iterator tmeasIt;
268  //loop on measurements to find out what kind of hits there are
269  for(tmeasIt = tmeasColl.begin();tmeasIt!=tmeasColl.end();tmeasIt++){
270  //if(! tmeasIt->updatedState().isValid()) continue; NOT NECESSARY (I HOPE)
271  TransientTrackingRecHit::ConstRecHitPointer testhit = tmeasIt->recHit();
272  if(testhit->geographicalId().det() != DetId::Tracker) continue;
273  uint testSubDetID = (testhit->geographicalId().subdetId());
274  const DetId & hit_detId = testhit->geographicalId();
275  int hit_layer = 0;
276  int hit_ladder = 0;
277  int hit_mod = 0;
278  int hit_disk = 0;
279 
280  if(testSubDetID==PixelSubdetector::PixelBarrel){
281  isBpixtrack = true;
282  if (!isUpgrade) {
283  hit_layer = PixelBarrelName(hit_detId).layerName();
284  } else if (isUpgrade) {
285  hit_layer = PixelBarrelNameUpgrade(hit_detId).layerName();
286  }
287 
288  hit_ladder = PXBDetId(hit_detId).ladder();
289  hit_mod = PXBDetId(hit_detId).module();
290 
291  if(hit_layer==1) L1hits++;
292  if(hit_layer==2) L2hits++;
293  if(hit_layer==3) L3hits++;
294  if(isUpgrade && hit_layer==4) L4hits++;
295  }
296  if(testSubDetID==PixelSubdetector::PixelEndcap){
297  isFpixtrack = true;
298  if (!isUpgrade) { hit_disk = PixelEndcapName(hit_detId).diskName(); }
299  else if (isUpgrade) { hit_disk = PixelEndcapNameUpgrade(hit_detId).diskName(); }
300 
301  if(hit_disk==1) D1hits++;
302  if(hit_disk==2) D2hits++;
303  if(isUpgrade && hit_disk==3) D3hits++;
304  }
305  if(testSubDetID==StripSubdetector::TIB) nStripHits++;
306  if(testSubDetID==StripSubdetector::TOB) nStripHits++;
307  if(testSubDetID==StripSubdetector::TID) nStripHits++;
308  if(testSubDetID==StripSubdetector::TEC) nStripHits++;
309  //check if last valid hit is in Layer 2 or Disk 1
310 
311  bool lastValidL2 = false;
312  if ((testSubDetID == PixelSubdetector::PixelBarrel && hit_layer == extrapolateFrom_)
313  || (testSubDetID == PixelSubdetector::PixelEndcap && hit_disk == 1)) {
314  if (testhit->isValid()) {
315  if (tmeasIt == tmeasColl.end()-1) {
316  lastValidL2=true;
317  } else {
318  tmeasIt++;
319  TransientTrackingRecHit::ConstRecHitPointer nextRecHit = tmeasIt->recHit();
320  uint nextSubDetID = (nextRecHit->geographicalId().subdetId());
321  int nextlayer = PixelBarrelName(nextRecHit->geographicalId()).layerName();
322  if (nextSubDetID == PixelSubdetector::PixelBarrel && nextlayer==extrapolateTo_ ) {
323  lastValidL2=true; //&& !nextRecHit->isValid()) lastValidL2=true;
324  }
325  tmeasIt--;
326  }
327  }
328  }//end check last valid layer
329  if (lastValidL2) {
330  std::vector< const BarrelDetLayer*> pxbLayers = measurementTrackerHandle->geometricSearchTracker()->pixelBarrelLayers();
331  const DetLayer* pxb1 = pxbLayers[extrapolateTo_-1];
332  const MeasurementEstimator* estimator = est.product();
333  const LayerMeasurements* theLayerMeasurements = new LayerMeasurements(*measurementTrackerHandle, *measurementTrackerEventHandle);
334  const TrajectoryStateOnSurface tsosPXB2 = tmeasIt->updatedState();
335  expTrajMeasurements = theLayerMeasurements->measurements(*pxb1, tsosPXB2, *thePropagator, *estimator);
336  delete theLayerMeasurements;
337  if ( !expTrajMeasurements.empty()) {
338  for(uint p=0; p<expTrajMeasurements.size();p++){
339  TrajectoryMeasurement pxb1TM(expTrajMeasurements[p]);
340  auto pxb1Hit = pxb1TM.recHit();
341  //remove hits with rawID == 0
342  if(pxb1Hit->geographicalId().rawId()==0){
343  expTrajMeasurements.erase(expTrajMeasurements.begin()+p);
344  continue;
345  }
346  }
347  }
348  //
349  }
350  //check if extrapolated hit to layer 1 one matches the original hit
351  TrajectoryStateOnSurface chkPredTrajState=trajStateComb(tmeasIt->forwardPredictedState(), tmeasIt->backwardPredictedState());
352  float chkx=chkPredTrajState.globalPosition().x();
353  float chky=chkPredTrajState.globalPosition().y();
354  float chkz=chkPredTrajState.globalPosition().z();
355  LocalPoint chklp=chkPredTrajState.localPosition();
356  if (testSubDetID == PixelSubdetector::PixelBarrel && hit_layer == extrapolateTo_) {
357  // Here we will drop the extrapolated hits if there is a hit and use that hit
358  vector<int > imatches;
359  size_t imatch=0;
360  float glmatch=9999.;
361  for (size_t iexp=0; iexp<expTrajMeasurements.size(); iexp++) {
362  const DetId & exphit_detId = expTrajMeasurements[iexp].recHit()->geographicalId();
363  int exphit_ladder = PXBDetId(exphit_detId).ladder();
364  int exphit_mod = PXBDetId(exphit_detId).module();
365  int dladder = abs( exphit_ladder - hit_ladder );
366  if (dladder > 10) dladder = 20 - dladder;
367  int dmodule = abs( exphit_mod - hit_mod);
368  if (dladder != 0 || dmodule != 0) {
369  continue;
370  }
371 
372  TrajectoryStateOnSurface predTrajState=expTrajMeasurements[iexp].updatedState();
373  float x=predTrajState.globalPosition().x();
374 float y=predTrajState.globalPosition().y();
375  float z=predTrajState.globalPosition().z();
376  float dxyz=sqrt((chkx-x)*(chkx-x)+(chky-y)*(chky-y)+(chkz-z)*(chkz-z));
377 
378  if (dxyz<=glmatch) {
379  glmatch=dxyz;
380  imatch=iexp;
381  imatches.push_back(int(imatch));
382  }
383 
384  } // found the propagated traj best matching the hit in data
385 
386  float lxmatch = 9999.0;
387  float lymatch = 9999.0;
388  if(!expTrajMeasurements.empty()){
389  if (glmatch<9999.) { // if there is any propagated trajectory for this hit
390  const DetId & matchhit_detId = expTrajMeasurements[imatch].recHit()->geographicalId();
391 
392  int matchhit_ladder = PXBDetId(matchhit_detId).ladder();
393  int dladder = abs(matchhit_ladder-hit_ladder);
394  if (dladder > 10) dladder = 20 - dladder;
395  LocalPoint lp = expTrajMeasurements[imatch].updatedState().localPosition();
396  lxmatch=fabs(lp.x() - chklp.x());
397  lymatch=fabs(lp.y() - chklp.y());
398  }
399  if (lxmatch < maxlxmatch_ && lymatch < maxlymatch_) {
400 
401  if (testhit->getType()!=TrackingRecHit::missing || keepOriginalMissingHit_) {
402  expTrajMeasurements.erase(expTrajMeasurements.begin()+imatch);
403  }
404 
405  }
406 
407  } //expected trajectory measurment not empty
408  }
409  }//loop on trajectory measurments tmeasColl
410 
411  //if an extrapolated hit was found but not matched to an exisitng L1 hit then push the hit back into the collection
412  //now keep the first one that is left
413  if(!expTrajMeasurements.empty()){
414  for (size_t f=0; f<expTrajMeasurements.size(); f++) {
415  TrajectoryMeasurement AddHit=expTrajMeasurements[f];
416  if (AddHit.recHit()->getType()==TrackingRecHit::missing){
417  tmeasColl.push_back(AddHit);
418  isBpixtrack = true;
419 
420  }
421 
422  }
423 
424 
425 
426  }
427  if(isBpixtrack || isFpixtrack){
428  if(trackref->pt()<0.6 ||
429  nStripHits<11 ||
430  fabs(trackref->dxy(bestVtx->position()))>0.05 ||
431  fabs(trackref->dz(bestVtx->position()))>0.5) continue;
432 
433  if(debug_){
434  std::cout << "isBpixtrack : " << isBpixtrack << std::endl;
435  std::cout << "isFpixtrack : " << isFpixtrack << std::endl;
436  }
437  //std::cout<<"This tracks has so many hits: "<<tmeasColl.size()<<std::endl;
438  for(std::vector<TrajectoryMeasurement>::const_iterator tmeasIt = tmeasColl.begin(); tmeasIt!=tmeasColl.end(); tmeasIt++){
439  //if(! tmeasIt->updatedState().isValid()) continue;
440  TrajectoryStateOnSurface tsos = tmeasIt->updatedState();
441 
443  if(hit->geographicalId().det() != DetId::Tracker )
444  continue;
445  else {
446 
447 // //residual
448  const DetId & hit_detId = hit->geographicalId();
449  //uint IntRawDetID = (hit_detId.rawId());
450  uint IntSubDetID = (hit_detId.subdetId());
451 
452  if(IntSubDetID == 0 ){
453  if(debug_) std::cout << "NO IntSubDetID\n";
454  continue;
455  }
456  if(IntSubDetID!=PixelSubdetector::PixelBarrel && IntSubDetID!=PixelSubdetector::PixelEndcap)
457  continue;
458 
459  int disk=0; int layer=0; int panel=0; int module=0; bool isHalfModule=false;
460  if(IntSubDetID==PixelSubdetector::PixelBarrel){ // it's a BPIX hit
461  if (!isUpgrade) {
462  layer = PixelBarrelName(hit_detId).layerName();
463  isHalfModule = PixelBarrelName(hit_detId).isHalfModule();
464  } else if (isUpgrade) {
465  layer = PixelBarrelNameUpgrade(hit_detId).layerName();
466  isHalfModule = PixelBarrelNameUpgrade(hit_detId).isHalfModule();
467  }
468  }else if(IntSubDetID==PixelSubdetector::PixelEndcap){ // it's an FPIX hit
469  if (!isUpgrade) {
470  disk = PixelEndcapName(hit_detId).diskName();
471  panel = PixelEndcapName(hit_detId).pannelName();
472  module = PixelEndcapName(hit_detId).plaquetteName();
473  } else if (isUpgrade) {
474  disk = PixelEndcapNameUpgrade(hit_detId).diskName();
475  panel = PixelEndcapNameUpgrade(hit_detId).pannelName();
476  module = PixelEndcapNameUpgrade(hit_detId).plaquetteName();
477  }
478  }
479 
480  if (!isUpgrade) {
481  if(layer==1){
482  if(fabs(trackref->dxy(bestVtx->position()))>0.01 ||
483  fabs(trackref->dz(bestVtx->position()))>0.1) continue;
484  if(!(L2hits>0&&L3hits>0) && !(L2hits>0&&D1hits>0) && !(D1hits>0&&D2hits>0)) continue;
485  }else if(layer==2){
486  if(fabs(trackref->dxy(bestVtx->position()))>0.02 ||
487  fabs(trackref->dz(bestVtx->position()))>0.1) continue;
488  if(!(L1hits>0&&L3hits>0) && !(L1hits>0&&D1hits>0)) continue;
489  }else if(layer==3){
490  if(fabs(trackref->dxy(bestVtx->position()))>0.02 ||
491  fabs(trackref->dz(bestVtx->position()))>0.1) continue;
492  if(!(L1hits>0&&L2hits>0)) continue;
493  }else if(disk==1){
494  if(fabs(trackref->dxy(bestVtx->position()))>0.05 ||
495  fabs(trackref->dz(bestVtx->position()))>0.5) continue;
496  if(!(L1hits>0&&D2hits>0) && !(L2hits>0&&D2hits>0)) continue;
497  }else if(disk==2){
498  if(fabs(trackref->dxy(bestVtx->position()))>0.05 ||
499  fabs(trackref->dz(bestVtx->position()))>0.5) continue;
500  if(!(L1hits>0&&D1hits>0)) continue;
501  }
502  } else if (isUpgrade) {
503  if(layer==1){
504  if(fabs(trackref->dxy(bestVtx->position()))>0.01 ||
505  fabs(trackref->dz(bestVtx->position()))>0.1) continue;
506  if(!(L2hits>0&&L3hits>0&&L4hits>0) && !(L2hits>0&&D1hits>0&&D2hits) && !(D1hits>0&&D2hits>0&&D3hits>0)) continue;
507  }else if(layer==2){
508  if(fabs(trackref->dxy(bestVtx->position()))>0.02 ||
509  fabs(trackref->dz(bestVtx->position()))>0.1) continue;
510  if(!(L1hits>0&&L3hits>0&&L4hits>0) && !(L1hits>0&&L3hits>0&&D1hits>0) && !(L1hits>0&&D1hits>0&&D2hits>0)) continue;
511  }else if(layer==3){
512  if(fabs(trackref->dxy(bestVtx->position()))>0.02 ||
513  fabs(trackref->dz(bestVtx->position()))>0.1) continue;
514  if(!(L1hits>0&&L2hits>0&&L4hits>0) && !(L1hits>0&&L2hits>0&&D1hits>0)) continue;
515  }else if(isUpgrade && layer==4){
516  if(fabs(trackref->dxy(bestVtx->position()))>0.02 ||
517  fabs(trackref->dz(bestVtx->position()))>0.1) continue;
518  if(!(L1hits>0&&L2hits>0&&L3hits>0)) continue;
519  }else if(disk==1){
520  if(fabs(trackref->dxy(bestVtx->position()))>0.05 ||
521  fabs(trackref->dz(bestVtx->position()))>0.5) continue;
522  if(!(L1hits>0&&L2hits>0&&D2hits>0) && !(L1hits>0&&D2hits>0&&D3hits>0) && !(L2hits>0&&D2hits>0&&D3hits>0)) continue;
523  }else if(disk==2){
524  if(fabs(trackref->dxy(bestVtx->position()))>0.05 ||
525  fabs(trackref->dz(bestVtx->position()))>0.5) continue;
526  if(!(L1hits>0&&L2hits>0&&D1hits>0) && !(L1hits>0&&D1hits>0&&D3hits>0) && !(L2hits>0&&D1hits>0&&D3hits>0)) continue;
527  }else if(disk==3){
528  if(fabs(trackref->dxy(bestVtx->position()))>0.05 ||
529  fabs(trackref->dz(bestVtx->position()))>0.5) continue;
530  if(!(L1hits>0&&D1hits>0&&D2hits>0) && !(L2hits>0&&D1hits>0&&D2hits>0)) continue;
531  }
532  }//endif(isUpgrade)
533 
534  //check whether hit is valid or missing using track algo flag
535  bool isHitValid =hit->hit()->getType()==TrackingRecHit::valid;
536  bool isHitMissing =hit->hit()->getType()==TrackingRecHit::missing;
537 
538  if(debug_) std::cout << "the hit is persistent\n";
539 
540  std::map<uint32_t, SiPixelHitEfficiencyModule*>::iterator pxd = theSiPixelStructure.find((*hit).geographicalId().rawId());
541 
542  // calculate alpha and beta from cluster position
544  //LocalVector localDir = ltp.momentum()/ltp.momentum().mag();
545 
546  //*************** Edge cut ********************
547  double lx=tsos.localPosition().x();
548  double ly=tsos.localPosition().y();
549 
550  if(fabs(lx)>0.55 || fabs(ly)>3.0) continue;
551 
552  bool passedFiducial=true;
553  // Module fiducials:
554  if(IntSubDetID==PixelSubdetector::PixelBarrel && fabs(ly)>=3.1) passedFiducial=false;
555  if(IntSubDetID==PixelSubdetector::PixelEndcap &&
556  !((panel==1 &&
557  ((module==1 && fabs(ly)<0.7) ||
558  ((module==2 && fabs(ly)<1.1) &&
559  !(disk==-1 && ly>0.8 && lx>0.2) &&
560  !(disk==1 && ly<-0.7 && lx>0.2) &&
561  !(disk==2 && ly<-0.8)) ||
562  ((module==3 && fabs(ly)<1.5) &&
563  !(disk==-2 && lx>0.1 && ly>1.0) &&
564  !(disk==2 && lx>0.1 && ly<-1.0)) ||
565  ((module==4 && fabs(ly)<1.9) &&
566  !(disk==-2 && ly>1.5) &&
567  !(disk==2 && ly<-1.5)))) ||
568  (panel==2 &&
569  ((module==1 && fabs(ly)<0.7) ||
570  (module==2 && fabs(ly)<1.2 &&
571  !(disk>0 && ly>1.1) &&
572  !(disk<0 && ly<-1.1)) ||
573  (module==3 && fabs(ly)<1.6 &&
574  !(disk>0 && ly>1.5) &&
575  !(disk<0 && ly<-1.5)))))) passedFiducial=false;
576  if(IntSubDetID==PixelSubdetector::PixelEndcap &&
577  ((panel==1 && (module==1 || (module>=3 && abs(disk)==1))) ||
578  (panel==2 && ((module==1 && abs(disk)==2) ||
579  (module==3 && abs(disk)==1))))) passedFiducial=false;
580  // ROC fiducials:
581  double ly_mod = fabs(ly);
582  if(IntSubDetID==PixelSubdetector::PixelEndcap && (panel+module)%2==1) ly_mod=ly_mod+0.405;
583  float d_rocedge = fabs(fmod(ly_mod,0.81)-0.405);
584  if(d_rocedge<=0.0625) passedFiducial=false;
585  if(!( (IntSubDetID==PixelSubdetector::PixelBarrel &&
586  ((!isHalfModule && fabs(lx)<0.6) ||
587  (isHalfModule && lx>-0.3 && lx<0.2))) ||
588  (IntSubDetID==PixelSubdetector::PixelEndcap &&
589  ((panel==1 &&
590  ((module==1 && fabs(lx)<0.2) ||
591  (module==2 &&
592  ((fabs(lx)<0.55 && abs(disk)==1) ||
593  (lx>-0.5 && lx<0.2 && disk==-2) ||
594  (lx>-0.5 && lx<0.0 && disk==2))) ||
595  (module==3 && lx>-0.6 && lx<0.5) ||
596  (module==4 && lx>-0.3 && lx<0.15))) ||
597  (panel==2 &&
598  ((module==1 && fabs(lx)<0.6) ||
599  (module==2 &&
600  ((fabs(lx)<0.55 && abs(disk)==1) ||
601  (lx>-0.6 && lx<0.5 && abs(disk)==2))) ||
602  (module==3 && fabs(lx)<0.5))))))) passedFiducial=false;
603  if(((IntSubDetID==PixelSubdetector::PixelBarrel && !isHalfModule) ||
604  (IntSubDetID==PixelSubdetector::PixelEndcap && !(panel==1 && (module==1 || module==4)))) &&
605  fabs(lx)<0.06) passedFiducial=false;
606 
607 
608  //*************** find closest clusters ********************
609  float dx_cl[2]; float dy_cl[2]; dx_cl[0]=dx_cl[1]=dy_cl[0]=dy_cl[1]=-9999.;
611  iSetup.get<TkPixelCPERecord>().get("PixelCPEGeneric", cpEstimator);
612  if(cpEstimator.isValid()){
613  const PixelClusterParameterEstimator &cpe(*cpEstimator);
615  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
616  if(tracker.isValid()){
617  const TrackerGeometry *tkgeom=&(*tracker);
618  edm::Handle<edmNew::DetSetVector<SiPixelCluster> > clusterCollectionHandle;
619  iEvent.getByToken( clusterCollectionToken_, clusterCollectionHandle );
620  if(clusterCollectionHandle.isValid()){
621  const edmNew::DetSetVector<SiPixelCluster>& clusterCollection=*clusterCollectionHandle;
622  edmNew::DetSetVector<SiPixelCluster>::const_iterator itClusterSet=clusterCollection.begin();
623  float minD[2]; minD[0]=minD[1]=10000.;
624  for( ; itClusterSet!=clusterCollection.end(); itClusterSet++){
625  DetId detId(itClusterSet->id());
626  if(detId.rawId()!=hit->geographicalId().rawId()) continue;
627  //unsigned int sdId=detId.subdetId();
628  const PixelGeomDetUnit *pixdet=(const PixelGeomDetUnit*) tkgeom->idToDetUnit(detId);
629  edmNew::DetSet<SiPixelCluster>::const_iterator itCluster=itClusterSet->begin();
630  for( ; itCluster!=itClusterSet->end(); ++itCluster){
631  LocalPoint lp(itCluster->x(), itCluster->y(), 0.);
632  PixelClusterParameterEstimator::ReturnType params=cpe.getParameters(*itCluster,*pixdet);
633  lp=std::get<0>(params);
634  float D = sqrt((lp.x()-lx)*(lp.x()-lx)+(lp.y()-ly)*(lp.y()-ly));
635  if(D<minD[0]){
636  minD[1]=minD[0];
637  dx_cl[1]=dx_cl[0];
638  dy_cl[1]=dy_cl[0];
639  minD[0]=D;
640  dx_cl[0]=lp.x();
641  dy_cl[0]=lp.y();
642  }else if(D<minD[1]){
643  minD[1]=D;
644  dx_cl[1]=lp.x();
645  dy_cl[1]=lp.y();
646  }
647  } // loop on clusterSets
648  } // loop on clusterCollection
649  for(size_t i=0; i<2; i++){
650  if(minD[i]<9999.){
651  dx_cl[i]=fabs(dx_cl[i]-lx);
652  dy_cl[i]=fabs(dy_cl[i]-ly);
653  }
654  }
655  } // valid clusterCollectionHandle
656  } // valid tracker
657  } // valid cpEstimator
658  // distance of hit from closest cluster!
659  float d_cl[2]; d_cl[0]=d_cl[1]=-9999.;
660  if(dx_cl[0]!=-9999. && dy_cl[0]!=-9999.) d_cl[0]=sqrt(dx_cl[0]*dx_cl[0]+dy_cl[0]*dy_cl[0]);
661  if(dx_cl[1]!=-9999. && dy_cl[1]!=-9999.) d_cl[1]=sqrt(dx_cl[1]*dx_cl[1]+dy_cl[1]*dy_cl[1]);
662  if(isHitMissing && (d_cl[0]<0.05 || d_cl[1]<0.05)){ isHitMissing=0; isHitValid=1; }
663 
664 
665  if(debug_){
666  std::cout << "Ready to add hit in histogram:\n";
667  //std::cout << "detid: "<<hit_detId<<std::endl;
668  std::cout << "isHitValid: "<<isHitValid<<std::endl;
669  std::cout << "isHitMissing: "<<isHitMissing<<std::endl;
670  //std::cout << "passedEdgeCut: "<<passedFiducial<<std::endl;
671  }
672 
673 
674  if(pxd!=theSiPixelStructure.end() && isHitValid && passedFiducial)
675  ++nvalid;
676  if(pxd!=theSiPixelStructure.end() && isHitMissing && passedFiducial)
677  ++nmissing;
678 
679  if (pxd!=theSiPixelStructure.end() && passedFiducial && (isHitValid || isHitMissing))
680  (*pxd).second->fill(ltp, isHitValid, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);
681 
682  //}//end if (persistent hit exists and is pixel hit)
683 
684  }//end of else
685 
686 
687  }//end for (all traj measurements of pixeltrack)
688  }//end if (is pixeltrack)
689  else
690  if(debug_) std::cout << "no pixeltrack:\n";
691 
692  }//end loop on map entries
693 }
694 
695 
696 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
int i
Definition: DBlmapReader.cc:9
virtual void setPropagationDirection(PropagationDirection dir)
Definition: Propagator.h:144
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const_iterator end(bool update=false) 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:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void analyze(const edm::Event &, const edm::EventSetup &)
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > clusterCollectionToken_
std::map< uint32_t, SiPixelHitEfficiencyModule * > theSiPixelStructure
T y() const
Definition: PV3DBase.h:63
GlobalPoint globalPosition() const
bool isHalfModule() const
full or half module
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
unsigned int ladder() const
ladder id
Definition: PXBDetId.h:39
data_type const * const_iterator
Definition: DetSetNew.h:30
id_type id(size_t cell) const
int plaquetteName() const
plaquetteId (in pannel)
float float float z
virtual void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
edm::EDGetTokenT< reco::VertexCollection > vertexCollectionToken_
virtual ReturnType getParameters(const SiPixelCluster &cl, const GeomDetUnit &det) const =0
int iEvent
Definition: GenABIO.cc:230
bool isHalfModule() const
full or half module
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
T sqrt(T t)
Definition: SSEVec.h:48
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
unsigned int module() const
det id
Definition: PXBDetId.h:43
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
bool isValid() const
Definition: HandleBase.h:76
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
int diskName() const
disk id
Definition: DetId.h:18
size_type size() const
map size
const T & get() const
Definition: EventSetup.h:55
key_type key() const
Accessor for product key.
Definition: Ref.h:266
int layerName() const
layer id
T const * product() const
Definition: ESHandle.h:62
T const * product() const
Definition: Handle.h:81
virtual const GeomDetUnit * idToDetUnit(DetId) const
Return the pointer to the GeomDetUnit corresponding to a given DetId.
virtual void dqmBeginRun(const edm::Run &r, edm::EventSetup const &iSetup)
int pannelName() const
pannel id
tuple cout
Definition: gather_cfg.py:121
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:6
const_iterator begin() const
first iterator over the map (read only)
volatile std::atomic< bool > shutdown_flag false
std::tuple< LocalPoint, LocalError, SiPixelRecHitQuality::QualWordType > ReturnType
Definition: DDAxes.h:10
bool isValid() const
Definition: ESHandle.h:37
int pannelName() const
pannel id
T x() const
Definition: PV3DBase.h:62
Definition: vlib.h:208
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:150
int layerName() const
layer id
const_iterator begin(bool update=false) const
Definition: Run.h:41