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  //tracksrc_ = pSet_.getParameter<edm::InputTag>("trajectoryInput");
87  applyEdgeCut_ = pSet_.getUntrackedParameter<bool>("applyEdgeCut");
88  nSigma_EdgeCut_ = pSet_.getUntrackedParameter<double>("nSigma_EdgeCut");
90  vertexCollectionToken_ = consumes<reco::VertexCollection>(std::string("offlinePrimaryVertices"));
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  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 
115  LogInfo("PixelDQM") << "SiPixelHitEfficiencySource beginJob()" << endl;
116  firstRun = true;
117 }
118 
120  LogInfo("PixelDQM") << "SiPixelHitEfficiencySource beginRun()" << endl;
121 
122  if(firstRun){
123  // retrieve TrackerGeometry for pixel dets
125  iSetup.get<TrackerDigiGeometryRecord>().get(TG);
126  if (debug_) LogVerbatim("PixelDQM") << "TrackerGeometry "<< &(*TG) <<" size is "<< TG->dets().size() << endl;
127 
128  // build theSiPixelStructure with the pixel barrel and endcap dets from TrackerGeometry
129  for (TrackerGeometry::DetContainer::const_iterator pxb = TG->detsPXB().begin();
130  pxb!=TG->detsPXB().end(); pxb++) {
131  if (dynamic_cast<PixelGeomDetUnit const *>((*pxb))!=0) {
132  SiPixelHitEfficiencyModule* module = new SiPixelHitEfficiencyModule((*pxb)->geographicalId().rawId());
133  theSiPixelStructure.insert(pair<uint32_t, SiPixelHitEfficiencyModule*>((*pxb)->geographicalId().rawId(), module));
134  }
135  }
136  for (TrackerGeometry::DetContainer::const_iterator pxf = TG->detsPXF().begin();
137  pxf!=TG->detsPXF().end(); pxf++) {
138  if (dynamic_cast<PixelGeomDetUnit const *>((*pxf))!=0) {
139  SiPixelHitEfficiencyModule* module = new SiPixelHitEfficiencyModule((*pxf)->geographicalId().rawId());
140  theSiPixelStructure.insert(pair<uint32_t, SiPixelHitEfficiencyModule*>((*pxf)->geographicalId().rawId(), module));
141  }
142  }
143  LogInfo("PixelDQM") << "SiPixelStructure size is " << theSiPixelStructure.size() << endl;
144 
145  // book residual histograms in theSiPixelFolder - one (x,y) pair of histograms per det
146  SiPixelFolderOrganizer theSiPixelFolder;
147  for (std::map<uint32_t, SiPixelHitEfficiencyModule*>::iterator pxd = theSiPixelStructure.begin();
148  pxd!=theSiPixelStructure.end(); pxd++) {
149 
150  if(modOn){
151  if (theSiPixelFolder.setModuleFolder((*pxd).first,0,isUpgrade)) (*pxd).second->book(pSet_,0,isUpgrade);
152  else throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource Folder Creation Failed! ";
153  }
154  if(ladOn){
155  if (theSiPixelFolder.setModuleFolder((*pxd).first,1,isUpgrade)) (*pxd).second->book(pSet_,1,isUpgrade);
156  else throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource ladder Folder Creation Failed! ";
157  }
158  if(layOn){
159  if (theSiPixelFolder.setModuleFolder((*pxd).first,2,isUpgrade)) (*pxd).second->book(pSet_,2,isUpgrade);
160  else throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource layer Folder Creation Failed! ";
161  }
162  if(phiOn){
163  if (theSiPixelFolder.setModuleFolder((*pxd).first,3,isUpgrade)) (*pxd).second->book(pSet_,3,isUpgrade);
164  else throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource phi Folder Creation Failed! ";
165  }
166  if(bladeOn){
167  if (theSiPixelFolder.setModuleFolder((*pxd).first,4,isUpgrade)) (*pxd).second->book(pSet_,4,isUpgrade);
168  else throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource Blade Folder Creation Failed! ";
169  }
170  if(diskOn){
171  if (theSiPixelFolder.setModuleFolder((*pxd).first,5,isUpgrade)) (*pxd).second->book(pSet_,5,isUpgrade);
172  else throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource Disk Folder Creation Failed! ";
173  }
174  if(ringOn){
175  if (theSiPixelFolder.setModuleFolder((*pxd).first,6,isUpgrade)) (*pxd).second->book(pSet_,6,isUpgrade);
176  else throw cms::Exception("LogicError") << "SiPixelHitEfficiencySource Ring Folder Creation Failed! ";
177  }
178  }
179 
180  nvalid=0;
181  nmissing=0;
182 
183  firstRun = false;
184  }
185 }
186 
187 
189  LogInfo("PixelDQM") << "SiPixelHitEfficiencySource endJob()";
190 
191  // save the residual histograms to an output root file
192  bool saveFile = pSet_.getUntrackedParameter<bool>("saveFile", true);
193  if (saveFile) {
195  LogInfo("PixelDQM") << " - saving histograms to "<< outputFile.data();
196  dbe_->save(outputFile);
197  }
198  LogInfo("PixelDQM") << endl; // dbe_->showDirStructure();
199 
200  //std::cout<< "********** SUMMARY **********"<<std::endl;
201  //std::cout<< "number of valid hits: "<<nvalid<<std::endl;
202  //std::cout<< "number of missing hits: "<<nmissing<<std::endl;
203 }
204 
205 
207 
208  edm::Handle<reco::VertexCollection> vertexCollectionHandle;
209  iEvent.getByToken( vertexCollectionToken_, vertexCollectionHandle );
210  if(!vertexCollectionHandle.isValid()) return;
211  nvtx_=0;
212  vtxntrk_=-9999;
213  vtxD0_=-9999.; vtxX_=-9999.; vtxY_=-9999.; vtxZ_=-9999.; vtxndof_=-9999.; vtxchi2_=-9999.;
214  const reco::VertexCollection & vertices = *vertexCollectionHandle.product();
215  reco::VertexCollection::const_iterator bestVtx=vertices.end();
216  for(reco::VertexCollection::const_iterator it=vertices.begin(); it!=vertices.end(); ++it){
217  if(!it->isValid()) continue;
218  if(vtxntrk_==-9999 ||
219  vtxntrk_<int(it->tracksSize()) ||
220  (vtxntrk_==int(it->tracksSize()) && fabs(vtxZ_)>fabs(it->z()))){
221  vtxntrk_=it->tracksSize();
222  vtxD0_=it->position().rho();
223  vtxX_=it->x();
224  vtxY_=it->y();
225  vtxZ_=it->z();
226  vtxndof_=it->ndof();
227  vtxchi2_=it->chi2();
228  bestVtx=it;
229  }
230  if(fabs(it->z())<=20. && fabs(it->position().rho())<=2. && it->ndof()>4) nvtx_++;
231  }
232  if(nvtx_<1) return;
233 
234  //Get the geometry
236  iSetup.get<TrackerDigiGeometryRecord>().get(TG);
237  const TrackerGeometry* theTrackerGeometry = TG.product();
238 
239  //get the map
241  iEvent.getByToken( tracksrc_, match );
242  const TrajTrackAssociationCollection ttac = *(match.product());
243 
244  if(debug_){
245  //std::cout << "Trajectories\t : " << trajColl.size() << std::endl;
246  //std::cout << "recoTracks \t : " << trackColl.size() << std::endl;
247  std::cout << "+++ NEW EVENT +++"<< std::endl;
248  std::cout << "Map entries \t : " << ttac.size() << std::endl;
249  }
250 
251  std::set<SiPixelCluster> clusterSet;
252  // TrajectoryStateCombiner tsoscomb;
253  //define variables for extrapolation
254  int extrapolateFrom_ = 2;
255  int extrapolateTo_ = 1;
256  float maxlxmatch_=0.2;
257  float maxlymatch_=0.2;
258  bool keepOriginalMissingHit_=true;
259  ESHandle<MeasurementTracker> measurementTrackerHandle;
260 
261  iSetup.get<CkfComponentsRecord>().get(measurementTrackerHandle);
262 
264  iSetup.get<TrackingComponentsRecord>().get("Chi2",est);
265  edm::Handle<MeasurementTrackerEvent> measurementTrackerEventHandle;
266  iEvent.getByToken(measurementTrackerEventToken_, measurementTrackerEventHandle);
268  iSetup.get<TrackingComponentsRecord>().get("PropagatorWithMaterial",prop);
269  Propagator* thePropagator = prop.product()->clone();
270  //determines direction of the propagator => inward
271  if (extrapolateFrom_>=extrapolateTo_) {
273  }
274  TrajectoryStateCombiner trajStateComb;
275  bool debug_ = false;
276 
277  //Loop over track collection
278  for(TrajTrackAssociationCollection::const_iterator it = ttac.begin();it != ttac.end(); ++it){
279  //define vector to save extrapolated tracks
280  std::vector<TrajectoryMeasurement> expTrajMeasurements;
281 
282  const edm::Ref<std::vector<Trajectory> > traj_iterator = it->key;
283  // Trajectory Map, extract Trajectory for this track
284  reco::TrackRef trackref = it->val;
285  //tracks++;
286 
287  bool isBpixtrack = false, isFpixtrack = false;
288  int nStripHits=0; int L1hits=0; int L2hits=0; int L3hits=0; int L4hits=0; int D1hits=0; int D2hits=0; int D3hits=0;
289  std::vector<TrajectoryMeasurement> tmeasColl =traj_iterator->measurements();
290  std::vector<TrajectoryMeasurement>::const_iterator tmeasIt;
291  //loop on measurements to find out what kind of hits there are
292  for(tmeasIt = tmeasColl.begin();tmeasIt!=tmeasColl.end();tmeasIt++){
293  //if(! tmeasIt->updatedState().isValid()) continue; NOT NECESSARY (I HOPE)
294  TransientTrackingRecHit::ConstRecHitPointer testhit = tmeasIt->recHit();
295  if(testhit->geographicalId().det() != DetId::Tracker) continue;
296  uint testSubDetID = (testhit->geographicalId().subdetId());
297  const DetId & hit_detId = testhit->geographicalId();
298  int hit_layer = 0;
299  int hit_ladder = 0;
300  int hit_mod = 0;
301  int hit_disk = 0;
302 
303  if(testSubDetID==PixelSubdetector::PixelBarrel){
304  isBpixtrack = true;
305  if (!isUpgrade) {
306  hit_layer = PixelBarrelName(hit_detId).layerName();
307  } else if (isUpgrade) {
308  hit_layer = PixelBarrelNameUpgrade(hit_detId).layerName();
309  }
310 
311  hit_ladder = PXBDetId(hit_detId).ladder();
312  hit_mod = PXBDetId(hit_detId).module();
313 
314  if(hit_layer==1) L1hits++;
315  if(hit_layer==2) L2hits++;
316  if(hit_layer==3) L3hits++;
317  if(isUpgrade && hit_layer==4) L4hits++;
318  }
319  if(testSubDetID==PixelSubdetector::PixelEndcap){
320  isFpixtrack = true;
321  if (!isUpgrade) { hit_disk = PixelEndcapName(hit_detId).diskName(); }
322  else if (isUpgrade) { hit_disk = PixelEndcapNameUpgrade(hit_detId).diskName(); }
323 
324  if(hit_disk==1) D1hits++;
325  if(hit_disk==2) D2hits++;
326  if(isUpgrade && hit_disk==3) D3hits++;
327  }
328  if(testSubDetID==StripSubdetector::TIB) nStripHits++;
329  if(testSubDetID==StripSubdetector::TOB) nStripHits++;
330  if(testSubDetID==StripSubdetector::TID) nStripHits++;
331  if(testSubDetID==StripSubdetector::TEC) nStripHits++;
332  //check if last valid hit is in Layer 2 or Disk 1
333 
334  bool lastValidL2 = false;
335  if ((testSubDetID == PixelSubdetector::PixelBarrel && hit_layer == extrapolateFrom_)
336  || (testSubDetID == PixelSubdetector::PixelEndcap && hit_disk == 1)) {
337  if (testhit->isValid()) {
338  if (tmeasIt == tmeasColl.end()-1) {
339  lastValidL2=true;
340  } else {
341  tmeasIt++;
342  TransientTrackingRecHit::ConstRecHitPointer nextRecHit = tmeasIt->recHit();
343  uint nextSubDetID = (nextRecHit->geographicalId().subdetId());
344  int nextlayer = PixelBarrelName(nextRecHit->geographicalId()).layerName();
345  if (nextSubDetID == PixelSubdetector::PixelBarrel && nextlayer==extrapolateTo_ ) {
346  lastValidL2=true; //&& !nextRecHit->isValid()) lastValidL2=true;
347  }
348  tmeasIt--;
349  }
350  }
351  }//end check last valid layer
352  if (lastValidL2) {
353  std::vector< const BarrelDetLayer*> pxbLayers = measurementTrackerHandle->geometricSearchTracker()->pixelBarrelLayers();
354  const DetLayer* pxb1 = pxbLayers[extrapolateTo_-1];
355  const MeasurementEstimator* estimator = est.product();
356  const LayerMeasurements* theLayerMeasurements = new LayerMeasurements(*measurementTrackerHandle, *measurementTrackerEventHandle);
357  const TrajectoryStateOnSurface tsosPXB2 = tmeasIt->updatedState();
358  expTrajMeasurements = theLayerMeasurements->measurements(*pxb1, tsosPXB2, *thePropagator, *estimator);
359  delete theLayerMeasurements;
360  if ( !expTrajMeasurements.empty()) {
361  for(uint p=0; p<expTrajMeasurements.size();p++){
362  TrajectoryMeasurement pxb1TM(expTrajMeasurements[p]);
363  auto pxb1Hit = pxb1TM.recHit();
364  //remove hits with rawID == 0
365  if(pxb1Hit->geographicalId().rawId()==0){
366  expTrajMeasurements.erase(expTrajMeasurements.begin()+p);
367  continue;
368  }
369  }
370  }
371  //
372  }
373  //check if extrapolated hit to layer 1 one matches the original hit
374  TrajectoryStateOnSurface chkPredTrajState=trajStateComb(tmeasIt->forwardPredictedState(), tmeasIt->backwardPredictedState());
375  float chkx=chkPredTrajState.globalPosition().x();
376  float chky=chkPredTrajState.globalPosition().y();
377  float chkz=chkPredTrajState.globalPosition().z();
378  LocalPoint chklp=chkPredTrajState.localPosition();
379  if (testSubDetID == PixelSubdetector::PixelBarrel && hit_layer == extrapolateTo_) {
380  // Here we will drop the extrapolated hits if there is a hit and use that hit
381  vector<int > imatches;
382  size_t imatch=0;
383  float glmatch=9999.;
384  for (size_t iexp=0; iexp<expTrajMeasurements.size(); iexp++) {
385  const DetId & exphit_detId = expTrajMeasurements[iexp].recHit()->geographicalId();
386  int exphit_ladder = PXBDetId(exphit_detId).ladder();
387  int exphit_mod = PXBDetId(exphit_detId).module();
388  int dladder = abs( exphit_ladder - hit_ladder );
389  if (dladder > 10) dladder = 20 - dladder;
390  int dmodule = abs( exphit_mod - hit_mod);
391  if (dladder != 0 || dmodule != 0) {
392  continue;
393  }
394 
395  TrajectoryStateOnSurface predTrajState=expTrajMeasurements[iexp].updatedState();
396  float x=predTrajState.globalPosition().x();
397 float y=predTrajState.globalPosition().y();
398  float z=predTrajState.globalPosition().z();
399  float dxyz=sqrt((chkx-x)*(chkx-x)+(chky-y)*(chky-y)+(chkz-z)*(chkz-z));
400 
401  if (dxyz<=glmatch) {
402  glmatch=dxyz;
403  imatch=iexp;
404  imatches.push_back(int(imatch));
405  }
406 
407  } // found the propagated traj best matching the hit in data
408 
409  float lxmatch = 9999.0;
410  float lymatch = 9999.0;
411  if(!expTrajMeasurements.empty()){
412  if (glmatch<9999.) { // if there is any propagated trajectory for this hit
413  const DetId & matchhit_detId = expTrajMeasurements[imatch].recHit()->geographicalId();
414 
415  int matchhit_ladder = PXBDetId(matchhit_detId).ladder();
416  int dladder = abs(matchhit_ladder-hit_ladder);
417  if (dladder > 10) dladder = 20 - dladder;
418  LocalPoint lp = expTrajMeasurements[imatch].updatedState().localPosition();
419  lxmatch=fabs(lp.x() - chklp.x());
420  lymatch=fabs(lp.y() - chklp.y());
421  }
422  if (lxmatch < maxlxmatch_ && lymatch < maxlymatch_) {
423 
424  if (testhit->getType()!=TrackingRecHit::missing || keepOriginalMissingHit_) {
425  expTrajMeasurements.erase(expTrajMeasurements.begin()+imatch);
426  }
427 
428  }
429 
430  } //expected trajectory measurment not empty
431  }
432  }//loop on trajectory measurments tmeasColl
433 
434  //if an extrapolated hit was found but not matched to an exisitng L1 hit then push the hit back into the collection
435  //now keep the first one that is left
436  if(!expTrajMeasurements.empty()){
437  for (size_t f=0; f<expTrajMeasurements.size(); f++) {
438  TrajectoryMeasurement AddHit=expTrajMeasurements[f];
439  if (AddHit.recHit()->getType()==TrackingRecHit::missing){
440  tmeasColl.push_back(AddHit);
441  isBpixtrack = true;
442 
443  }
444 
445  }
446 
447 
448 
449  }
450  if(isBpixtrack || isFpixtrack){
451  if(trackref->pt()<0.6 ||
452  nStripHits<11 ||
453  fabs(trackref->dxy(bestVtx->position()))>0.05 ||
454  fabs(trackref->dz(bestVtx->position()))>0.5) continue;
455 
456  if(debug_){
457  std::cout << "isBpixtrack : " << isBpixtrack << std::endl;
458  std::cout << "isFpixtrack : " << isFpixtrack << std::endl;
459  }
460  //std::cout<<"This tracks has so many hits: "<<tmeasColl.size()<<std::endl;
461  for(std::vector<TrajectoryMeasurement>::const_iterator tmeasIt = tmeasColl.begin(); tmeasIt!=tmeasColl.end(); tmeasIt++){
462  //if(! tmeasIt->updatedState().isValid()) continue;
463  TrajectoryStateOnSurface tsos = tmeasIt->updatedState();
464 
466  if(hit->geographicalId().det() != DetId::Tracker )
467  continue;
468  else {
469 
470 // //residual
471  const DetId & hit_detId = hit->geographicalId();
472  //uint IntRawDetID = (hit_detId.rawId());
473  uint IntSubDetID = (hit_detId.subdetId());
474 
475  if(IntSubDetID == 0 ){
476  if(debug_) std::cout << "NO IntSubDetID\n";
477  continue;
478  }
479  if(IntSubDetID!=PixelSubdetector::PixelBarrel && IntSubDetID!=PixelSubdetector::PixelEndcap)
480  continue;
481 
482  int disk=0; int layer=0; int panel=0; int module=0; bool isHalfModule=false;
483  if(IntSubDetID==PixelSubdetector::PixelBarrel){ // it's a BPIX hit
484  if (!isUpgrade) {
485  layer = PixelBarrelName(hit_detId).layerName();
486  isHalfModule = PixelBarrelName(hit_detId).isHalfModule();
487  } else if (isUpgrade) {
488  layer = PixelBarrelNameUpgrade(hit_detId).layerName();
489  isHalfModule = PixelBarrelNameUpgrade(hit_detId).isHalfModule();
490  }
491  }else if(IntSubDetID==PixelSubdetector::PixelEndcap){ // it's an FPIX hit
492  if (!isUpgrade) {
493  disk = PixelEndcapName(hit_detId).diskName();
494  panel = PixelEndcapName(hit_detId).pannelName();
495  module = PixelEndcapName(hit_detId).plaquetteName();
496  } else if (isUpgrade) {
497  disk = PixelEndcapNameUpgrade(hit_detId).diskName();
498  panel = PixelEndcapNameUpgrade(hit_detId).pannelName();
499  module = PixelEndcapNameUpgrade(hit_detId).plaquetteName();
500  }
501  }
502 
503  if (!isUpgrade) {
504  if(layer==1){
505  if(fabs(trackref->dxy(bestVtx->position()))>0.01 ||
506  fabs(trackref->dz(bestVtx->position()))>0.1) continue;
507  if(!(L2hits>0&&L3hits>0) && !(L2hits>0&&D1hits>0) && !(D1hits>0&&D2hits>0)) continue;
508  }else if(layer==2){
509  if(fabs(trackref->dxy(bestVtx->position()))>0.02 ||
510  fabs(trackref->dz(bestVtx->position()))>0.1) continue;
511  if(!(L1hits>0&&L3hits>0) && !(L1hits>0&&D1hits>0)) continue;
512  }else if(layer==3){
513  if(fabs(trackref->dxy(bestVtx->position()))>0.02 ||
514  fabs(trackref->dz(bestVtx->position()))>0.1) continue;
515  if(!(L1hits>0&&L2hits>0)) continue;
516  }else if(disk==1){
517  if(fabs(trackref->dxy(bestVtx->position()))>0.05 ||
518  fabs(trackref->dz(bestVtx->position()))>0.5) continue;
519  if(!(L1hits>0&&D2hits>0) && !(L2hits>0&&D2hits>0)) continue;
520  }else if(disk==2){
521  if(fabs(trackref->dxy(bestVtx->position()))>0.05 ||
522  fabs(trackref->dz(bestVtx->position()))>0.5) continue;
523  if(!(L1hits>0&&D1hits>0)) continue;
524  }
525  } else if (isUpgrade) {
526  if(layer==1){
527  if(fabs(trackref->dxy(bestVtx->position()))>0.01 ||
528  fabs(trackref->dz(bestVtx->position()))>0.1) continue;
529  if(!(L2hits>0&&L3hits>0&&L4hits>0) && !(L2hits>0&&D1hits>0&&D2hits) && !(D1hits>0&&D2hits>0&&D3hits>0)) continue;
530  }else if(layer==2){
531  if(fabs(trackref->dxy(bestVtx->position()))>0.02 ||
532  fabs(trackref->dz(bestVtx->position()))>0.1) continue;
533  if(!(L1hits>0&&L3hits>0&&L4hits>0) && !(L1hits>0&&L3hits>0&&D1hits>0) && !(L1hits>0&&D1hits>0&&D2hits>0)) continue;
534  }else if(layer==3){
535  if(fabs(trackref->dxy(bestVtx->position()))>0.02 ||
536  fabs(trackref->dz(bestVtx->position()))>0.1) continue;
537  if(!(L1hits>0&&L2hits>0&&L4hits>0) && !(L1hits>0&&L2hits>0&&D1hits>0)) continue;
538  }else if(isUpgrade && layer==4){
539  if(fabs(trackref->dxy(bestVtx->position()))>0.02 ||
540  fabs(trackref->dz(bestVtx->position()))>0.1) continue;
541  if(!(L1hits>0&&L2hits>0&&L3hits>0)) continue;
542  }else if(disk==1){
543  if(fabs(trackref->dxy(bestVtx->position()))>0.05 ||
544  fabs(trackref->dz(bestVtx->position()))>0.5) continue;
545  if(!(L1hits>0&&L2hits>0&&D2hits>0) && !(L1hits>0&&D2hits>0&&D3hits>0) && !(L2hits>0&&D2hits>0&&D3hits>0)) continue;
546  }else if(disk==2){
547  if(fabs(trackref->dxy(bestVtx->position()))>0.05 ||
548  fabs(trackref->dz(bestVtx->position()))>0.5) continue;
549  if(!(L1hits>0&&L2hits>0&&D1hits>0) && !(L1hits>0&&D1hits>0&&D3hits>0) && !(L2hits>0&&D1hits>0&&D3hits>0)) continue;
550  }else if(disk==3){
551  if(fabs(trackref->dxy(bestVtx->position()))>0.05 ||
552  fabs(trackref->dz(bestVtx->position()))>0.5) continue;
553  if(!(L1hits>0&&D1hits>0&&D2hits>0) && !(L2hits>0&&D1hits>0&&D2hits>0)) continue;
554  }
555  }//endif(isUpgrade)
556 
557  //check wether hit is valid or missing using track algo flag
558  bool isHitValid =hit->hit()->getType()==TrackingRecHit::valid;
559  bool isHitMissing =hit->hit()->getType()==TrackingRecHit::missing;
560  //std::cout<<"------ New Hit"<<std::endl;
561  //std::cout<<(hit->hit()->getType()==TrackingRecHit::missing)<<std::endl;
562 
563  // get the enclosed persistent hit
564  //const TrackingRecHit *persistentHit = hit->hit();
565  // check if it's not null, and if it's a valid pixel hit
566  //if ((persistentHit != 0) && (typeid(*persistentHit) == typeid(SiPixelRecHit))) {
567 
568  if(debug_) std::cout << "the hit is persistent\n";
569 
570  // tell the C++ compiler that the hit is a pixel hit
571  //const SiPixelRecHit* pixhit = dynamic_cast<const SiPixelRecHit*>( hit->hit() );
572 
573  //define tracker and pixel geometry and topology
574  const TrackerGeometry& theTracker(*theTrackerGeometry);
575  const PixelGeomDetUnit* theGeomDet = dynamic_cast<const PixelGeomDetUnit*> (theTracker.idToDet(hit_detId) );
576  //test if PixelGeomDetUnit exists
577  if(theGeomDet == 0) {
578  if(debug_) std::cout << "NO THEGEOMDET\n";
579  continue;
580  }
581 
582  //const RectangularPixelTopology * topol = dynamic_cast<const RectangularPixelTopology*>(&(theGeomDet->specificTopology()));
583 
584  std::map<uint32_t, SiPixelHitEfficiencyModule*>::iterator pxd = theSiPixelStructure.find((*hit).geographicalId().rawId());
585 
586  // calculate alpha and beta from cluster position
588  //LocalVector localDir = ltp.momentum()/ltp.momentum().mag();
589 
590  //float clust_alpha = atan2(localDir.z(), localDir.x());
591  //float clust_beta = atan2(localDir.z(), localDir.y());
592 
593 
594 
595  // THE CUTS
596  //int nrows = theGeomDet->specificTopology().nrows();
597  //int ncols = theGeomDet->specificTopology().ncolumns();
598  //
599  //std::pair<float,float> pitchTest = theGeomDet->specificTopology().pitch();
600  //RectangularPixelTopology rectTopolTest = RectangularPixelTopology(nrows, ncols, pitch.first, pitch.second);
601  //std::pair<float,float> pixelTest = rectTopol.pixel(tsos.localPosition());
602  //
603 
604 
605  //*************** Edge cut ********************
606  //double glx=tsos.globalPosition().x();
607  //double gly=tsos.globalPosition().y();
608  //double glz=tsos.globalPosition().z();
609  double lx=tsos.localPosition().x();
610  double ly=tsos.localPosition().y();
611  //double lz=tsos.localPosition().z();
612  //double lx_err=tsos.localError().positionError().xx();
613  //double ly_err=tsos.localError().positionError().yy();
614  //int telescope=0; int telescope_valid=0;
615  if(fabs(lx)>0.55 || fabs(ly)>3.0) continue;
616  //LocalTrajectoryParameters predTrajParam=tsos.localParameters();
617  //LocalVector dir=predTrajParam.momentum()/predTrajParam.momentum().mag();
618  //double alpha=atan2(dir.z(), dir.x());
619  //double beta=atan2(dir.z(), dir.y());
620  bool passedFiducial=true;
621  // Module fiducials:
622  if(IntSubDetID==PixelSubdetector::PixelBarrel && fabs(ly)>=3.1) passedFiducial=false;
623  if(IntSubDetID==PixelSubdetector::PixelEndcap &&
624  !((panel==1 &&
625  ((module==1 && fabs(ly)<0.7) ||
626  ((module==2 && fabs(ly)<1.1) &&
627  !(disk==-1 && ly>0.8 && lx>0.2) &&
628  !(disk==1 && ly<-0.7 && lx>0.2) &&
629  !(disk==2 && ly<-0.8)) ||
630  ((module==3 && fabs(ly)<1.5) &&
631  !(disk==-2 && lx>0.1 && ly>1.0) &&
632  !(disk==2 && lx>0.1 && ly<-1.0)) ||
633  ((module==4 && fabs(ly)<1.9) &&
634  !(disk==-2 && ly>1.5) &&
635  !(disk==2 && ly<-1.5)))) ||
636  (panel==2 &&
637  ((module==1 && fabs(ly)<0.7) ||
638  (module==2 && fabs(ly)<1.2 &&
639  !(disk>0 && ly>1.1) &&
640  !(disk<0 && ly<-1.1)) ||
641  (module==3 && fabs(ly)<1.6 &&
642  !(disk>0 && ly>1.5) &&
643  !(disk<0 && ly<-1.5)))))) passedFiducial=false;
644  if(IntSubDetID==PixelSubdetector::PixelEndcap &&
645  ((panel==1 && (module==1 || (module>=3 && abs(disk)==1))) ||
646  (panel==2 && ((module==1 && abs(disk)==2) ||
647  (module==3 && abs(disk)==1))))) passedFiducial=false;
648  // ROC fiducials:
649  double ly_mod = fabs(ly);
650  if(IntSubDetID==PixelSubdetector::PixelEndcap && (panel+module)%2==1) ly_mod=ly_mod+0.405;
651  float d_rocedge = fabs(fmod(ly_mod,0.81)-0.405);
652  if(d_rocedge<=0.0625) passedFiducial=false;
653  if(!( (IntSubDetID==PixelSubdetector::PixelBarrel &&
654  ((!isHalfModule && fabs(lx)<0.6) ||
655  (isHalfModule && lx>-0.3 && lx<0.2))) ||
656  (IntSubDetID==PixelSubdetector::PixelEndcap &&
657  ((panel==1 &&
658  ((module==1 && fabs(lx)<0.2) ||
659  (module==2 &&
660  ((fabs(lx)<0.55 && abs(disk)==1) ||
661  (lx>-0.5 && lx<0.2 && disk==-2) ||
662  (lx>-0.5 && lx<0.0 && disk==2))) ||
663  (module==3 && lx>-0.6 && lx<0.5) ||
664  (module==4 && lx>-0.3 && lx<0.15))) ||
665  (panel==2 &&
666  ((module==1 && fabs(lx)<0.6) ||
667  (module==2 &&
668  ((fabs(lx)<0.55 && abs(disk)==1) ||
669  (lx>-0.6 && lx<0.5 && abs(disk)==2))) ||
670  (module==3 && fabs(lx)<0.5))))))) passedFiducial=false;
671  if(((IntSubDetID==PixelSubdetector::PixelBarrel && !isHalfModule) ||
672  (IntSubDetID==PixelSubdetector::PixelEndcap && !(panel==1 && (module==1 || module==4)))) &&
673  fabs(lx)<0.06) passedFiducial=false;
674 
675 
676  //*************** find closest clusters ********************
677  float dx_cl[2]; float dy_cl[2]; dx_cl[0]=dx_cl[1]=dy_cl[0]=dy_cl[1]=-9999.;
679  iSetup.get<TkPixelCPERecord>().get("PixelCPEGeneric", cpEstimator);
680  if(cpEstimator.isValid()){
681  const PixelClusterParameterEstimator &cpe(*cpEstimator);
683  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
684  if(tracker.isValid()){
685  const TrackerGeometry *tkgeom=&(*tracker);
686  edm::Handle<edmNew::DetSetVector<SiPixelCluster> > clusterCollectionHandle;
687  iEvent.getByToken( clusterCollectionToken_, clusterCollectionHandle );
688  if(clusterCollectionHandle.isValid()){
689  const edmNew::DetSetVector<SiPixelCluster>& clusterCollection=*clusterCollectionHandle;
690  edmNew::DetSetVector<SiPixelCluster>::const_iterator itClusterSet=clusterCollection.begin();
691  float minD[2]; minD[0]=minD[1]=10000.;
692  for( ; itClusterSet!=clusterCollection.end(); itClusterSet++){
693  DetId detId(itClusterSet->id());
694  if(detId.rawId()!=hit->geographicalId().rawId()) continue;
695  //unsigned int sdId=detId.subdetId();
696  const PixelGeomDetUnit *pixdet=(const PixelGeomDetUnit*) tkgeom->idToDetUnit(detId);
697  edmNew::DetSet<SiPixelCluster>::const_iterator itCluster=itClusterSet->begin();
698  for( ; itCluster!=itClusterSet->end(); ++itCluster){
699  LocalPoint lp(itCluster->x(), itCluster->y(), 0.);
700  PixelClusterParameterEstimator::ReturnType params=cpe.getParameters(*itCluster,*pixdet);
701  lp=std::get<0>(params);
702  float D = sqrt((lp.x()-lx)*(lp.x()-lx)+(lp.y()-ly)*(lp.y()-ly));
703  if(D<minD[0]){
704  minD[1]=minD[0];
705  dx_cl[1]=dx_cl[0];
706  dy_cl[1]=dy_cl[0];
707  minD[0]=D;
708  dx_cl[0]=lp.x();
709  dy_cl[0]=lp.y();
710  }else if(D<minD[1]){
711  minD[1]=D;
712  dx_cl[1]=lp.x();
713  dy_cl[1]=lp.y();
714  }
715  } // loop on clusterSets
716  } // loop on clusterCollection
717  for(size_t i=0; i<2; i++){
718  if(minD[i]<9999.){
719  dx_cl[i]=fabs(dx_cl[i]-lx);
720  dy_cl[i]=fabs(dy_cl[i]-ly);
721  }
722  }
723  } // valid clusterCollectionHandle
724  } // valid tracker
725  } // valid cpEstimator
726  // distance of hit from closest cluster!
727  float d_cl[2]; d_cl[0]=d_cl[1]=-9999.;
728  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]);
729  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]);
730  if(isHitMissing && (d_cl[0]<0.05 || d_cl[1]<0.05)){ isHitMissing=0; isHitValid=1; }
731 
732 
733  if(debug_){
734  std::cout << "Ready to add hit in histogram:\n";
735  //std::cout << "detid: "<<hit_detId<<std::endl;
736  std::cout << "isHitValid: "<<isHitValid<<std::endl;
737  std::cout << "isHitMissing: "<<isHitMissing<<std::endl;
738  //std::cout << "passedEdgeCut: "<<passedFiducial<<std::endl;
739  }
740 
741 
742  if(pxd!=theSiPixelStructure.end() && isHitValid && passedFiducial)
743  ++nvalid;
744  if(pxd!=theSiPixelStructure.end() && isHitMissing && passedFiducial)
745  ++nmissing;
746 
747  if (pxd!=theSiPixelStructure.end() && passedFiducial && (isHitValid || isHitMissing))
748  (*pxd).second->fill(ltp, isHitValid, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);
749 
750  //}//end if (persistent hit exists and is pixel hit)
751 
752  }//end of else
753 
754 
755  }//end for (all traj measurements of pixeltrack)
756  }//end if (is pixeltrack)
757  else
758  if(debug_) std::cout << "no pixeltrack:\n";
759 
760  }//end loop on map entries
761 }
762 
763 
764 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
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
virtual void beginRun(const edm::Run &r, edm::EventSetup const &iSetup)
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]
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2424
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
virtual const GeomDet * idToDet(DetId) const
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.
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