CMS 3D CMS Logo

TrackQuality.cc
Go to the documentation of this file.
1 /*
2  * TrackQuality.cc
3  *
4  * Created by Christophe Saout on 9/25/08.
5  * 2007 __MyCompanyName__.
6  *
7  */
8 
9 #include <algorithm>
10 #include <vector>
11 
13 
16 
26 
31 
33 
35 
36 // #define DEBUG_TRACK_QUALITY
37 
38 namespace {
39  const uint32_t NonMatchedTrackId = (uint32_t)-1;
40 
41  struct MatchedHit {
42  DetId detId;
43  uint32_t simTrackId;
44  EncodedEventId collision;
45  int recHitId;
47 
48  bool operator<(const MatchedHit &other) const {
49  if (detId < other.detId)
50  return true;
51  else if (detId > other.detId)
52  return false;
53  else if (collision < other.collision)
54  return true;
55  else if (other.collision < collision)
56  return false;
57  else
58  return simTrackId < other.simTrackId;
59  }
60 
61  bool operator==(const MatchedHit &other) const {
62  return detId == other.detId && collision == other.collision && simTrackId == other.simTrackId;
63  }
64  };
65  /*
66 static bool operator < (const MatchedHit &hit, DetId detId)
67 {
68  return hit.detId < detId;
69 }
70 static bool operator < (DetId detId, const MatchedHit &hit)
71 {
72  return detId < hit.detId;
73 }
74 */
75 } // namespace
76 
77 typedef std::pair<TrackQuality::Layer::SubDet, short int> DetLayer;
78 
79 // in case multiple hits were found, figure out the highest priority
80 static const int statePriorities[] = {
81  /* Unknown */ 3,
82  /* Good */ 5,
83  /* Missed */ 0,
84  /* Noise */ 7,
85  /* Bad */ 2,
86  /* Dead */ 4,
87  /* Shared */ 6,
88  /* Misassoc */ 1};
89 
90 DetLayer getDetLayer(DetId detId, const TrackerTopology *tTopo) {
92  short int layer = 0;
93 
94  switch (detId.det()) {
95  case DetId::Tracker:
96  layer = tTopo->layer(detId);
97  break;
98 
99  case DetId::Muon:
100  switch (detId.subdetId()) {
101  case MuonSubdetId::DT:
103  layer = DTLayerId(detId).layer();
104  break;
105 
106  case MuonSubdetId::CSC:
108  layer = CSCDetId(detId).layer();
109  break;
110 
111  case MuonSubdetId::RPC:
112  if (RPCDetId(detId).region())
114  else
116  layer = RPCDetId(detId).layer();
117  break;
118 
119  default:
120  /* should not get here */
121  ;
122  }
123  break;
124 
125  default:
126  /* should not get here */
127  ;
128  }
129 
130  return DetLayer(det, layer);
131 }
132 
134  : trackerHitAssociatorConfig_(config.getParameter<edm::ParameterSet>("hitAssociator"), std::move(iC)) {}
135 
138 }
139 
141  std::vector<MatchedHit> matchedHits;
142 
143  // iterate over reconstructed hits
144  for (trackingRecHit_iterator hit = tr->recHitsBegin(); hit != tr->recHitsEnd(); ++hit) {
145  // on which module the hit lies
146  DetId detId = (*hit)->geographicalId();
147 
148  // FIXME: check for double-sided modules?
149 
150  // didn't find a hit on that module
151  if (!(*hit)->isValid()) {
152  MatchedHit matchedHit;
153  matchedHit.detId = detId;
154  matchedHit.simTrackId = NonMatchedTrackId;
155  // check why hit wasn't valid and propagate information
156  switch ((*hit)->getType()) {
158  matchedHit.state = Layer::Dead;
159  break;
160 
161  case TrackingRecHit::bad:
162  matchedHit.state = Layer::Bad;
163  break;
164 
165  default:
166  matchedHit.state = Layer::Missed;
167  }
168  matchedHit.recHitId = hit - tr->recHitsBegin();
169  matchedHits.push_back(matchedHit);
170  continue;
171  }
172 
173  // find simulated tracks causing hit that was reconstructed
174  std::vector<SimHitIdpr> simIds = associator_->associateHitId(**hit);
175 
176  // must be noise or so
177  if (simIds.empty()) {
178  MatchedHit matchedHit;
179  matchedHit.detId = detId;
180  matchedHit.simTrackId = NonMatchedTrackId;
181  matchedHit.state = Layer::Noise;
182  matchedHit.recHitId = hit - tr->recHitsBegin();
183  matchedHits.push_back(matchedHit);
184  continue;
185  }
186 
187  // register all simulated tracks contributing
188  for (std::vector<SimHitIdpr>::const_iterator i = simIds.begin(); i != simIds.end(); ++i) {
189  MatchedHit matchedHit;
190  matchedHit.detId = detId;
191  matchedHit.simTrackId = i->first;
192  matchedHit.collision = i->second;
193  // RecHit <-> SimHit matcher currently doesn't support muon system
194  if (detId.det() == DetId::Muon)
195  matchedHit.state = Layer::Unknown;
196  else
197  // assume hit was mismatched (until possible confirmation)
198  matchedHit.state = Layer::Misassoc;
199  matchedHit.recHitId = hit - tr->recHitsBegin();
200  matchedHits.push_back(matchedHit);
201  }
202  }
203 
204  // sort hits found so far by module id
205  std::stable_sort(matchedHits.begin(), matchedHits.end());
206 
207  // in case we added missed modules, re-sort
208  std::stable_sort(matchedHits.begin(), matchedHits.end());
209 
210  // prepare for ordering results by layer enum and layer/disk number
211  typedef std::multimap<DetLayer, const MatchedHit *> LayerHitMap;
212  LayerHitMap layerHitMap;
213 
214  // iterate over all simulated/reconstructed hits again
215  for (std::vector<MatchedHit>::const_iterator hit = matchedHits.begin(); hit != matchedHits.end();) {
216  // we can have multiple reco-to-sim matches per module, find best one
217  const MatchedHit *best = nullptr;
218 
219  // this loop iterates over all subsequent hits in the same module
220  do {
221  // update our best hit pointer
222  if (!best || statePriorities[hit->state] > statePriorities[best->state] ||
223  best->simTrackId == NonMatchedTrackId) {
224  best = &*hit;
225  }
226  ++hit;
227  } while (hit != matchedHits.end() && hit->detId == best->detId);
228 
229  // ignore hit in case track reco was looking at the wrong module
230  if (best->simTrackId != NonMatchedTrackId || best->state != Layer::Missed) {
231  layerHitMap.insert(std::make_pair(getDetLayer(best->detId, tTopo), best));
232  }
233  }
234 
235  layers_.clear();
236 
237 #ifdef DEBUG_TRACK_QUALITY
238  std::cout << "---------------------" << std::endl;
239 #endif
240  // now prepare final collection
241  for (LayerHitMap::const_iterator hit = layerHitMap.begin(); hit != layerHitMap.end(); ++hit) {
242 #ifdef DEBUG_TRACK_QUALITY
243  std::cout << "detLayer (" << hit->first.first << ", " << hit->first.second << ")"
244  << " [" << (uint32_t)hit->second->detId << "] sim(" << (int)hit->second->simTrackId << ")"
245  << " hit(" << hit->second->recHitId << ") -> " << hit->second->state << std::endl;
246 #endif
247 
248  // find out if we need to start a new layer
249  Layer *layer = layers_.empty() ? nullptr : &layers_.back();
250  if (!layer || hit->first.first != layer->subDet || hit->first.second != layer->layer) {
251  Layer newLayer;
252  newLayer.subDet = hit->first.first;
253  newLayer.layer = hit->first.second;
254  layers_.push_back(newLayer);
255  layer = &layers_.back();
256  }
257 
258  // create hit and add it to layer
259  Layer::Hit newHit;
260  newHit.recHitId = hit->second->recHitId;
261  newHit.state = hit->second->state;
262 
263  layer->hits.push_back(newHit);
264  }
265 }
TrackQuality::Layer::hits
std::vector< Hit > hits
Definition: TrackQuality.h:56
statePriorities
static const int statePriorities[]
Definition: TrackQuality.cc:80
MuonSubdetId::CSC
static constexpr int CSC
Definition: MuonSubdetId.h:12
mps_fire.i
i
Definition: mps_fire.py:355
PixelSubdetector.h
reco::Track::recHitsBegin
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:88
DetLayer
Definition: DetLayer.h:21
TrackQuality::layers_
std::vector< Layer > layers_
Definition: TrackQuality.h:83
DTLayerId.h
edm
HLT enums.
Definition: AlignableModifier.h:19
TrackerTopology
Definition: TrackerTopology.h:16
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
RPCDetId
Definition: RPCDetId.h:16
gather_cfg.cout
cout
Definition: gather_cfg.py:144
PSimHitContainer.h
DetLayer
std::pair< TrackQuality::Layer::SubDet, short int > DetLayer
Definition: TrackQuality.cc:77
TrackerTopology::layer
unsigned int layer(const DetId &id) const
Definition: TrackerTopology.cc:47
TrackingRecHitFwd.h
TrackerHitAssociator.h
TrackQuality::Layer::Hit
Definition: TrackQuality.h:49
TrackQuality::Layer::Hit::recHitId
short int recHitId
Definition: TrackQuality.h:50
TrackQuality::associator_
std::unique_ptr< TrackerHitAssociator > associator_
Definition: TrackQuality.h:81
CSCDetId.h
TrackQuality::layer
const Layer & layer(unsigned int index) const
Return information about the given layer by index.
Definition: TrackQuality.h:77
EncodedEventId
Definition: EncodedEventId.h:11
config
Definition: config.py:1
DetId
Definition: DetId.h:17
TrackerTopology.h
TrackingRecHit.h
Track.h
TrackFwd.h
TrackQuality::Layer::Unknown
Definition: TrackQuality.h:47
reco::Track::recHitsEnd
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:91
CSCDetId::layer
int layer() const
Definition: CSCDetId.h:56
TrackQuality.h
trackingPlots.other
other
Definition: trackingPlots.py:1465
MuonSubdetId::DT
static constexpr int DT
Definition: MuonSubdetId.h:11
DTLayerId
Definition: DTLayerId.h:12
TrackQuality::Layer::MuonCSC
Definition: TrackQuality.h:42
edm::OwnVector::const_iterator
Definition: OwnVector.h:41
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
TrackQuality::Layer::Hit::state
State state
Definition: TrackQuality.h:51
TrackingRecHit::bad
Definition: TrackingRecHit.h:49
RPCDetId.h
TrackQuality::Layer::Noise
Definition: TrackQuality.h:47
operator==
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
Definition: QGLikelihoodObject.h:49
TrackQuality::SimParticleTrail
std::vector< TrackingParticleRef > SimParticleTrail
Definition: TrackQuality.h:30
edm::ParameterSet
Definition: ParameterSet.h:36
DetId::Tracker
Definition: DetId.h:25
ParameterSet
Definition: Functions.h:16
CSCDetId
Definition: CSCDetId.h:26
TrackQuality::Layer::Bad
Definition: TrackQuality.h:47
TrackQuality::Layer::MuonRPCEndcap
Definition: TrackQuality.h:44
TrackQuality::Layer::Missed
Definition: TrackQuality.h:47
IdealGeometryRecord.h
edm::EventSetup
Definition: EventSetup.h:57
TrackQuality::newEvent
void newEvent(const edm::Event &, const edm::EventSetup &)
Pre-process event information (for accessing reconstruction information)
Definition: TrackQuality.cc:136
TrackQuality::evaluate
void evaluate(SimParticleTrail const &, reco::TrackBaseRef const &, const TrackerTopology *tTopo)
Compute information about the track reconstruction quality.
Definition: TrackQuality.cc:140
MuonSubdetId.h
getDetLayer
DetLayer getDetLayer(DetId detId, const TrackerTopology *tTopo)
Definition: TrackQuality.cc:90
TrackQuality::Layer::Invalid
Definition: TrackQuality.h:34
TrackQuality::TrackQuality
TrackQuality(const edm::ParameterSet &, edm::ConsumesCollector &iC)
Constructor by pset.
Definition: TrackQuality.cc:133
TrackQuality::trackerHitAssociatorConfig_
TrackerHitAssociator::Config trackerHitAssociatorConfig_
Definition: TrackQuality.h:80
TrackerHitAssociator
Definition: TrackerHitAssociator.h:55
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
DetId.h
TrackingParticleFwd.h
MuonSubdetId::RPC
static constexpr int RPC
Definition: MuonSubdetId.h:13
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
TrackQuality::Layer::layer
short int layer
Definition: TrackQuality.h:55
HLT_2018_cff.region
region
Definition: HLT_2018_cff.py:81479
edm::RefToBase< reco::Track >
TrackingRecHit::inactive
Definition: TrackingRecHit.h:48
DetId::Muon
Definition: DetId.h:26
TrackQuality::Layer::MuonRPCBarrel
Definition: TrackQuality.h:43
operator<
bool operator<(DTCELinkId const &lhs, DTCELinkId const &rhs)
Definition: DTCELinkId.h:70
ParameterSet.h
TrackQuality::Layer::subDet
SubDet subDet
Definition: TrackQuality.h:54
TrackQuality::Layer::SubDet
SubDet
Definition: TrackQuality.h:33
edm::Event
Definition: Event.h:73
RPCDetId::layer
int layer() const
Definition: RPCDetId.h:85
TrackQuality::Layer
Definition: TrackQuality.h:32
DTLayerId::layer
int layer() const
Return the layer number.
Definition: DTLayerId.h:42
TrackQuality::Layer::Dead
Definition: TrackQuality.h:47
StripSubdetector.h
TrackQuality::Layer::Misassoc
Definition: TrackQuality.h:47
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
hit
Definition: SiStripHitEffFromCalibTree.cc:88
TrackQuality::Layer::State
State
Definition: TrackQuality.h:47
TrackQuality::Layer::MuonDT
Definition: TrackQuality.h:41