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