CMS 3D CMS Logo

SiPixelPhase1TrackEfficiency.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelPhase1TrackEfficiency
4 // Class: SiPixelPhase1TrackEfficiency
5 //
6 
7 // Original Author: Marcel Schneider
8 
11 
23 
25  SiPixelPhase1Base(iConfig)
26 {
27  tracksToken_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"));
28  vtxToken_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("primaryvertices"));
29  applyVertexCut_=iConfig.getUntrackedParameter<bool>("VertexCut",true);
30 
31 }
32 
34 
35  // get geometry
37  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
38  assert(tracker.isValid());
39 
40  // get primary vertex
42  iEvent.getByToken( vtxToken_, vertices);
43 
44  if (!vertices.isValid()) return;
45 
46  histo[VERTICES].fill(vertices->size(),DetId(0),&iEvent);
47 
48  if (applyVertexCut_ && vertices->empty()) return;
49 
50  // should be used for weird cuts
51  //const auto primaryVertex = vertices->at(0);
52 
53  // get the map
55  iEvent.getByToken( tracksToken_, tracks);
56  if (!tracks.isValid()) return;
57 
58  for (auto const & track : *tracks) {
59 
60  //this cut is needed to be consisten with residuals calculation
61  if (applyVertexCut_ && (track.pt() < 0.75 || std::abs( track.dxy(vertices->at(0).position()) ) > 5*track.dxyError())) continue;
62 
63  bool isBpixtrack = false, isFpixtrack = false;
64  int nStripHits = 0;
65 
66  // first, look at the full track to see whether it is good
67  // auto const & trajParams = track.extra()->trajParams();
68  auto hb = track.recHitsBegin();
69  for(unsigned int h=0;h<track.recHitsSize();h++){
70 
71  auto hit = *(hb+h);
72  if(!hit->isValid()) continue;
73 
74  DetId id = hit->geographicalId();
75  uint32_t subdetid = (id.subdetId());
76 
77  // count strip hits
78  if(subdetid==StripSubdetector::TIB) nStripHits++;
79  if(subdetid==StripSubdetector::TOB) nStripHits++;
80  if(subdetid==StripSubdetector::TID) nStripHits++;
81  if(subdetid==StripSubdetector::TEC) nStripHits++;
82 
83  // check that we are in the pixel
84  if (subdetid == PixelSubdetector::PixelBarrel) isBpixtrack = true;
85  if (subdetid == PixelSubdetector::PixelEndcap) isFpixtrack = true;
86  }
87 
88  if (!isBpixtrack && !isFpixtrack) continue;
89 
90  // then, look at each hit
91  for(unsigned int h=0;h<track.recHitsSize();h++){
92  auto hit = *(hb+h);
93 
94  DetId id = hit->geographicalId();
95  uint32_t subdetid = (id.subdetId());
96  if ( subdetid != PixelSubdetector::PixelBarrel
97  && subdetid != PixelSubdetector::PixelEndcap) continue;
98 
99  bool isHitValid = hit->getType()==TrackingRecHit::valid;
100  bool isHitMissing = hit->getType()==TrackingRecHit::missing;
101  bool isHitInactive = hit->getType()==TrackingRecHit::inactive;
102 
103  /*
104  const SiPixelRecHit* pixhit = dynamic_cast<const SiPixelRecHit*>(hit);
105  const PixelGeomDetUnit* geomdetunit = dynamic_cast<const PixelGeomDetUnit*> ( tracker->idToDet(id) );
106  const PixelTopology& topol = geomdetunit->specificTopology();
107 
108  // this commented part is useful if one wants ROC level maps of hits, however the local position may fall out of a ROC and the ROC maps will look very strange (with no white cross)
109  LocalPoint lp;
110 
111  if (pixhit) {
112  lp = pixhit->localPosition();
113  } else {
114  lp = trajParams[h].position();
115  }
116 
117  MeasurementPoint mp = topol.measurementPosition(lp);
118  int row = (int) mp.x();
119  int col = (int) mp.y();
120  */
121 
122  if (isHitValid) {
123  histo[VALID].fill(id, &iEvent);
124  histo[EFFICIENCY].fill(1, id, &iEvent);
125  }
126  if (isHitMissing) {
127  histo[MISSING].fill(id, &iEvent);
128  histo[EFFICIENCY].fill(0, id, &iEvent);
129  }
130  if (isHitInactive) {
131  histo[INACTIVE].fill(id, &iEvent);
132  }
133  }
134  }
135  histo[VALID ].executePerEventHarvesting(&iEvent);
136  histo[MISSING ].executePerEventHarvesting(&iEvent);
137  histo[INACTIVE].executePerEventHarvesting(&iEvent);
138 }
139 
141 
edm::EDGetTokenT< reco::TrackCollection > tracksToken_
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void analyze(const edm::Event &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int iEvent
Definition: GenABIO.cc:230
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isValid() const
Definition: HandleBase.h:74
Definition: DetId.h:18
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
const T & get() const
Definition: EventSetup.h:55
std::vector< HistogramManager > histo
bool isValid() const
Definition: ESHandle.h:47
SiPixelPhase1TrackEfficiency(const edm::ParameterSet &conf)