CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Attributes
TrackQuality Class Reference

This class analyses the reconstruction quality for a given track. More...

#include <TrackQuality.h>

Classes

struct  Layer
 

Public Types

typedef std::vector< TrackingParticleRefSimParticleTrail
 

Public Member Functions

void evaluate (SimParticleTrail const &, reco::TrackBaseRef const &, const TrackerTopology *tTopo)
 Compute information about the track reconstruction quality. More...
 
const Layerlayer (unsigned int index) const
 Return information about the given layer by index. More...
 
void newEvent (const edm::Event &, const edm::EventSetup &)
 Pre-process event information (for accessing reconstruction information) More...
 
unsigned int numberOfLayers () const
 Return the number of layers with simulated and/or reconstructed hits. More...
 
 TrackQuality (const edm::ParameterSet &, edm::ConsumesCollector &iC)
 Constructor by pset. More...
 

Private Attributes

std::unique_ptr< TrackerHitAssociatorassociator_
 
std::vector< Layerlayers_
 
TrackerHitAssociator::Config trackerHitAssociatorConfig_
 

Detailed Description

This class analyses the reconstruction quality for a given track.

Definition at line 28 of file TrackQuality.h.

Member Typedef Documentation

◆ SimParticleTrail

Definition at line 30 of file TrackQuality.h.

Constructor & Destructor Documentation

◆ TrackQuality()

TrackQuality::TrackQuality ( const edm::ParameterSet config,
edm::ConsumesCollector iC 
)

Constructor by pset.

Definition at line 135 of file TrackQuality.cc.

136  : trackerHitAssociatorConfig_(config.getParameter<edm::ParameterSet>("hitAssociator"), std::move(iC)) {}

Member Function Documentation

◆ evaluate()

void TrackQuality::evaluate ( SimParticleTrail const &  spt,
reco::TrackBaseRef const &  tr,
const TrackerTopology tTopo 
)

Compute information about the track reconstruction quality.

Definition at line 142 of file TrackQuality.cc.

142  {
143  std::vector<MatchedHit> matchedHits;
144 
145  // iterate over reconstructed hits
146  for (trackingRecHit_iterator hit = tr->recHitsBegin(); hit != tr->recHitsEnd(); ++hit) {
147  // on which module the hit lies
148  DetId detId = (*hit)->geographicalId();
149 
150  // FIXME: check for double-sided modules?
151 
152  // didn't find a hit on that module
153  if (!(*hit)->isValid()) {
154  MatchedHit matchedHit;
155  matchedHit.detId = detId;
156  matchedHit.simTrackId = NonMatchedTrackId;
157  // check why hit wasn't valid and propagate information
158  switch ((*hit)->getType()) {
160  matchedHit.state = Layer::Dead;
161  break;
162 
163  case TrackingRecHit::bad:
164  matchedHit.state = Layer::Bad;
165  break;
166 
167  default:
168  matchedHit.state = Layer::Missed;
169  }
170  matchedHit.recHitId = hit - tr->recHitsBegin();
171  matchedHits.push_back(matchedHit);
172  continue;
173  }
174 
175  // find simulated tracks causing hit that was reconstructed
176  std::vector<SimHitIdpr> simIds = associator_->associateHitId(**hit);
177 
178  // must be noise or so
179  if (simIds.empty()) {
180  MatchedHit matchedHit;
181  matchedHit.detId = detId;
182  matchedHit.simTrackId = NonMatchedTrackId;
183  matchedHit.state = Layer::Noise;
184  matchedHit.recHitId = hit - tr->recHitsBegin();
185  matchedHits.push_back(matchedHit);
186  continue;
187  }
188 
189  // register all simulated tracks contributing
190  for (std::vector<SimHitIdpr>::const_iterator i = simIds.begin(); i != simIds.end(); ++i) {
191  MatchedHit matchedHit;
192  matchedHit.detId = detId;
193  matchedHit.simTrackId = i->first;
194  matchedHit.collision = i->second;
195  // RecHit <-> SimHit matcher currently doesn't support muon system
196  if (detId.det() == DetId::Muon)
197  matchedHit.state = Layer::Unknown;
198  else
199  // assume hit was mismatched (until possible confirmation)
200  matchedHit.state = Layer::Misassoc;
201  matchedHit.recHitId = hit - tr->recHitsBegin();
202  matchedHits.push_back(matchedHit);
203  }
204  }
205 
206  // sort hits found so far by module id
207  std::stable_sort(matchedHits.begin(), matchedHits.end());
208 
209  // in case we added missed modules, re-sort
210  std::stable_sort(matchedHits.begin(), matchedHits.end());
211 
212  // prepare for ordering results by layer enum and layer/disk number
213  typedef std::multimap<DetLayer, const MatchedHit *> LayerHitMap;
214  LayerHitMap layerHitMap;
215 
216  // iterate over all simulated/reconstructed hits again
217  for (std::vector<MatchedHit>::const_iterator hit = matchedHits.begin(); hit != matchedHits.end();) {
218  // we can have multiple reco-to-sim matches per module, find best one
219  const MatchedHit *best = nullptr;
220 
221  // this loop iterates over all subsequent hits in the same module
222  do {
223  // update our best hit pointer
224  if (!best || statePriorities[hit->state] > statePriorities[best->state] ||
225  best->simTrackId == NonMatchedTrackId) {
226  best = &*hit;
227  }
228  ++hit;
229  } while (hit != matchedHits.end() && hit->detId == best->detId);
230 
231  // ignore hit in case track reco was looking at the wrong module
232  if (best->simTrackId != NonMatchedTrackId || best->state != Layer::Missed) {
233  layerHitMap.insert(std::make_pair(getDetLayer(best->detId, tTopo), best));
234  }
235  }
236 
237  layers_.clear();
238 
239 #ifdef DEBUG_TRACK_QUALITY
240  std::cout << "---------------------" << std::endl;
241 #endif
242  // now prepare final collection
243  for (LayerHitMap::const_iterator hit = layerHitMap.begin(); hit != layerHitMap.end(); ++hit) {
244 #ifdef DEBUG_TRACK_QUALITY
245  std::cout << "detLayer (" << hit->first.first << ", " << hit->first.second << ")"
246  << " [" << (uint32_t)hit->second->detId << "] sim(" << (int)hit->second->simTrackId << ")"
247  << " hit(" << hit->second->recHitId << ") -> " << hit->second->state << std::endl;
248 #endif
249 
250  // find out if we need to start a new layer
251  Layer *layer = layers_.empty() ? nullptr : &layers_.back();
252  if (!layer || hit->first.first != layer->subDet || hit->first.second != layer->layer) {
253  Layer newLayer;
254  newLayer.subDet = hit->first.first;
255  newLayer.layer = hit->first.second;
256  layers_.push_back(newLayer);
257  layer = &layers_.back();
258  }
259 
260  // create hit and add it to layer
261  Layer::Hit newHit;
262  newHit.recHitId = hit->second->recHitId;
263  newHit.state = hit->second->state;
264 
265  layer->hits.push_back(newHit);
266  }
267 }

References associator_, TrackQuality::Layer::Bad, TrackingRecHit::bad, gather_cfg::cout, TrackQuality::Layer::Dead, DetId::det(), getDetLayer(), TrackQuality::Layer::hits, mps_fire::i, TrackingRecHit::inactive, TrackQuality::Layer::layer, layer(), layers_, TrackQuality::Layer::Misassoc, TrackQuality::Layer::Missed, DetId::Muon, TrackQuality::Layer::Noise, TrackQuality::Layer::Hit::recHitId, reco::Track::recHitsBegin(), reco::Track::recHitsEnd(), TrackQuality::Layer::Hit::state, statePriorities, TrackQuality::Layer::subDet, and TrackQuality::Layer::Unknown.

Referenced by TrackClassifier::qualityInformation().

◆ layer()

const Layer& TrackQuality::layer ( unsigned int  index) const
inline

Return information about the given layer by index.

Definition at line 77 of file TrackQuality.h.

77 { return layers_[index]; }

References layers_.

Referenced by evaluate(), geometryXMLparser.DTAlignable::index(), geometryXMLparser.CSCAlignable::index(), and TrackClassifier::qualityInformation().

◆ newEvent()

void TrackQuality::newEvent ( const edm::Event ev,
const edm::EventSetup es 
)

Pre-process event information (for accessing reconstruction information)

Definition at line 138 of file TrackQuality.cc.

138  {
139  associator_ = std::make_unique<TrackerHitAssociator>(ev, trackerHitAssociatorConfig_);
140 }

References associator_, ev, and trackerHitAssociatorConfig_.

Referenced by TrackClassifier::newEvent().

◆ numberOfLayers()

unsigned int TrackQuality::numberOfLayers ( ) const
inline

Return the number of layers with simulated and/or reconstructed hits.

Definition at line 74 of file TrackQuality.h.

74 { return layers_.size(); }

References layers_.

Referenced by TrackClassifier::qualityInformation().

Member Data Documentation

◆ associator_

std::unique_ptr<TrackerHitAssociator> TrackQuality::associator_
private

Definition at line 81 of file TrackQuality.h.

Referenced by evaluate(), and newEvent().

◆ layers_

std::vector<Layer> TrackQuality::layers_
private

Definition at line 83 of file TrackQuality.h.

Referenced by evaluate(), layer(), and numberOfLayers().

◆ trackerHitAssociatorConfig_

TrackerHitAssociator::Config TrackQuality::trackerHitAssociatorConfig_
private

Definition at line 80 of file TrackQuality.h.

Referenced by newEvent().

TrackQuality::Layer::hits
std::vector< Hit > hits
Definition: TrackQuality.h:56
statePriorities
static const int statePriorities[]
Definition: TrackQuality.cc:82
mps_fire.i
i
Definition: mps_fire.py:428
TrackQuality::layers_
std::vector< Layer > layers_
Definition: TrackQuality.h:83
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
gather_cfg.cout
cout
Definition: gather_cfg.py:144
TrackQuality::associator_
std::unique_ptr< TrackerHitAssociator > associator_
Definition: TrackQuality.h:81
TrackQuality::layer
const Layer & layer(unsigned int index) const
Return information about the given layer by index.
Definition: TrackQuality.h:77
LayerTriplets::Layer
SeedingLayerSetsHits::SeedingLayer Layer
Definition: LayerTriplets.h:14
config
Definition: config.py:1
DetId
Definition: DetId.h:17
TrackQuality::Layer::Unknown
Definition: TrackQuality.h:47
edm::OwnVector::const_iterator
Definition: OwnVector.h:41
TrackingRecHit::bad
Definition: TrackingRecHit.h:49
TrackQuality::Layer::Noise
Definition: TrackQuality.h:47
edm::ParameterSet
Definition: ParameterSet.h:47
TrackQuality::Layer::Bad
Definition: TrackQuality.h:47
TrackQuality::Layer::Missed
Definition: TrackQuality.h:47
getDetLayer
DetLayer getDetLayer(DetId detId, const TrackerTopology *tTopo)
Definition: TrackQuality.cc:92
TrackQuality::trackerHitAssociatorConfig_
TrackerHitAssociator::Config trackerHitAssociatorConfig_
Definition: TrackQuality.h:80
eostools.move
def move(src, dest)
Definition: eostools.py:511
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
TrackQuality::Layer::layer
short int layer
Definition: TrackQuality.h:55
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
TrackingRecHit::inactive
Definition: TrackingRecHit.h:48
DetId::Muon
Definition: DetId.h:26
TrackQuality::Layer::subDet
SubDet subDet
Definition: TrackQuality.h:54
TrackQuality::Layer::Dead
Definition: TrackQuality.h:47
TrackQuality::Layer::Misassoc
Definition: TrackQuality.h:47
hit
Definition: SiStripHitEffFromCalibTree.cc:88
Hit
SeedingHitSet::ConstRecHitPointer Hit
Definition: SeedGeneratorFromProtoTracksEDProducer.cc:34