CMS 3D CMS Logo

TrackQuality Class Reference

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

#include <SimTracker/TrackHistory/interface/TrackQuality.h>

List of all members.

Public Types

typedef std::vector
< TrackingParticleRef
SimParticleTrail

Public Member Functions

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

Private Attributes

std::auto_ptr
< TrackerHitAssociator
associator_
const edm::ParameterSet associatorPSet_
std::vector< Layerlayers_

Classes

struct  Layer


Detailed Description

This class analyses the reconstruction quality for a given track.

Definition at line 26 of file TrackQuality.h.


Member Typedef Documentation

typedef std::vector<TrackingParticleRef> TrackQuality::SimParticleTrail

Definition at line 29 of file TrackQuality.h.


Constructor & Destructor Documentation

TrackQuality::TrackQuality ( const edm::ParameterSet config  ) 

Constructor by pset.

Definition at line 182 of file TrackQuality.cc.

00182                                                         :
00183         associatorPSet_(config.getParameter<edm::ParameterSet>("hitAssociator"))
00184 {
00185 }


Member Function Documentation

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

Compute information about the track reconstruction quality.

Definition at line 192 of file TrackQuality.cc.

References associator_, TrackingRecHit::bad, TrackQuality::Layer::Bad, GenMuonPlsPt100GeV_cfg::cout, TrackQuality::Layer::Dead, DetId::det(), detId, lat::endl(), getDetLayer(), TrackQuality::Layer::Good, TrackQuality::Layer::hits, i, TrackingRecHit::inactive, layer(), TrackQuality::Layer::layer, layers_, TrackQuality::Layer::Misassoc, TrackQuality::Layer::Missed, DetId::Muon, TrackQuality::Layer::Noise, NonMatchedTrackId, range, TrackQuality::Layer::Hit::recHitId, TrackQuality::Layer::Shared, size, TrackQuality::Layer::Hit::state, statePriorities, TrackQuality::Layer::subDet, track, and TrackQuality::Layer::Unknown.

Referenced by TrackClassifier::qualityInformation().

00194 {
00195     std::vector<MatchedHit> matchedHits;
00196 
00197     // iterate over reconstructed hits
00198     for (trackingRecHit_iterator hit = tr->recHitsBegin();
00199             hit != tr->recHitsEnd(); ++hit)
00200     {
00201         // on which module the hit lies
00202         DetId detId = (*hit)->geographicalId();
00203 
00204         // FIXME: check for double-sided modules?
00205 
00206         // didn't find a hit on that module
00207         if (!(*hit)->isValid())
00208         {
00209             MatchedHit matchedHit;
00210             matchedHit.detId = detId;
00211             matchedHit.simTrackId = NonMatchedTrackId;
00212             // check why hit wasn't valid and propagate information
00213             switch ((*hit)->getType())
00214             {
00215             case TrackingRecHit::inactive:
00216                 matchedHit.state = Layer::Dead;
00217                 break;
00218 
00219             case TrackingRecHit::bad:
00220                 matchedHit.state = Layer::Bad;
00221                 break;
00222 
00223             default:
00224                 matchedHit.state = Layer::Missed;
00225             }
00226             matchedHit.recHitId = hit - tr->recHitsBegin();
00227             matchedHits.push_back(matchedHit);
00228             continue;
00229         }
00230 
00231         // find simulated tracks causing hit that was reconstructed
00232         std::vector<SimHitIdpr> simIds = associator_->associateHitId(**hit);
00233 
00234         // must be noise or so
00235         if (simIds.empty())
00236         {
00237             MatchedHit matchedHit;
00238             matchedHit.detId = detId;
00239             matchedHit.simTrackId = NonMatchedTrackId;
00240             matchedHit.state = Layer::Noise;
00241             matchedHit.recHitId = hit - tr->recHitsBegin();
00242             matchedHits.push_back(matchedHit);
00243             continue;
00244         }
00245 
00246         // register all simulated tracks contributing
00247         for (std::vector<SimHitIdpr>::const_iterator i = simIds.begin();
00248                 i != simIds.end(); ++i)
00249         {
00250             MatchedHit matchedHit;
00251             matchedHit.detId = detId;
00252             matchedHit.simTrackId = i->first;
00253             matchedHit.collision = i->second;
00254             // RecHit <-> SimHit matcher currently doesn't support muon system
00255             if (detId.det() == DetId::Muon)
00256                 matchedHit.state = Layer::Unknown;
00257             else
00258                 // assume hit was mismatched (until possible confirmation)
00259                 matchedHit.state = Layer::Misassoc;
00260             matchedHit.recHitId = hit - tr->recHitsBegin();
00261             matchedHits.push_back(matchedHit);
00262         }
00263     }
00264 
00265     // sort hits found so far by module id
00266     std::stable_sort(matchedHits.begin(), matchedHits.end());
00267 
00268     std::vector<MatchedHit>::size_type size = matchedHits.size();
00269 
00270     // now iterate over simulated hits and compare (tracks in chain first)
00271     for (SimParticleTrail::const_iterator track = spt.begin();
00272             track != spt.end(); ++track)
00273     {
00274         // iterate over all hits in track
00275         for (std::vector<PSimHit>::const_iterator hit =
00276                     (*track)->pSimHit_begin();
00277                 hit != (*track)->pSimHit_end(); ++hit)
00278         {
00279             MatchedHit matchedHit;
00280             matchedHit.detId = DetId(hit->detUnitId());
00281             matchedHit.simTrackId = hit->trackId();
00282             matchedHit.collision = hit->eventId();
00283 
00284             // find range of reconstructed hits belonging to this module
00285             std::pair<std::vector<MatchedHit>::iterator,
00286             std::vector<MatchedHit>::iterator>
00287             range = std::equal_range(
00288                         matchedHits.begin(),
00289                         matchedHits.begin() + size,
00290                         matchedHit.detId);
00291 
00292             // no reconstructed hit found, remember this as a missed module
00293             if (range.first == range.second)
00294             {
00295                 matchedHit.state = Layer::Missed;
00296                 matchedHit.recHitId = -1;
00297                 matchedHits.push_back(matchedHit);
00298                 continue;
00299             }
00300 
00301             // now find if the hit belongs to the correct simulated track
00302             std::vector<MatchedHit>::iterator pos =
00303                 std::lower_bound(range.first,
00304                                  range.second,
00305                                  matchedHit);
00306 
00307             // if it does, check for being a shared hit (was Misassoc before)
00308             if (pos != range.second) {
00309                 if (range.second - range.first > 1) // more than one SimHit
00310                     pos->state = Layer::Shared;
00311                 else
00312                     pos->state = Layer::Good; // only hit -> good hit
00313             }
00314         }
00315     }
00316 
00317     // in case we added missed modules, re-sort
00318     std::stable_sort(matchedHits.begin(), matchedHits.end());
00319 
00320     // prepare for ordering results by layer enum and layer/disk number
00321     typedef std::multimap<DetLayer, const MatchedHit*> LayerHitMap;
00322     LayerHitMap layerHitMap;
00323 
00324     // iterate over all simulated/reconstructed hits again
00325     for (std::vector<MatchedHit>::const_iterator hit = matchedHits.begin();
00326             hit != matchedHits.end();)
00327     {
00328         // we can have multiple reco-to-sim matches per module, find best one
00329         const MatchedHit *best = 0;
00330 
00331         // this loop iterates over all subsequent hits in the same module
00332         do
00333         {
00334             // update our best hit pointer
00335             if (!best ||
00336                     statePriorities[hit->state] > statePriorities[best->state] ||
00337                     best->simTrackId == NonMatchedTrackId)
00338             {
00339                 best = &*hit;
00340             }
00341             ++hit;
00342         }
00343         while (hit != matchedHits.end() &&
00344                 hit->detId == best->detId);
00345 
00346         // ignore hit in case track reco was looking at the wrong module
00347         if (best->simTrackId != NonMatchedTrackId ||
00348                 best->state != Layer::Missed)
00349         {
00350             layerHitMap.insert(std::make_pair(
00351                                    getDetLayer(best->detId), best));
00352         }
00353     }
00354 
00355     layers_.clear();
00356 
00357 #ifdef DEBUG_TRACK_QUALITY
00358     std::cout << "---------------------" << std::endl;
00359 #endif
00360     // now prepare final collection
00361     for (LayerHitMap::const_iterator hit = layerHitMap.begin();
00362             hit != layerHitMap.end(); ++hit)
00363     {
00364 #ifdef DEBUG_TRACK_QUALITY
00365         std::cout
00366             << "detLayer (" << hit->first.first << ", " << hit->first.second << ")"
00367             << " [" << (uint32_t)hit->second->detId << "] sim(" << (int)hit->second->simTrackId << ")"
00368             << " hit(" << hit->second->recHitId << ") -> " << hit->second->state << std::endl;
00369 #endif
00370 
00371         // find out if we need to start a new layer
00372         Layer *layer = layers_.empty() ? 0 : &layers_.back();
00373         if (!layer ||
00374                 hit->first.first != layer->subDet ||
00375                 hit->first.second != layer->layer)
00376         {
00377             Layer newLayer;
00378             newLayer.subDet = hit->first.first;
00379             newLayer.layer = hit->first.second;
00380             layers_.push_back(newLayer);
00381             layer = &layers_.back();
00382         }
00383 
00384         // create hit and add it to layer
00385         Layer::Hit newHit;
00386         newHit.recHitId = hit->second->recHitId;
00387         newHit.state = hit->second->state;
00388 
00389         layer->hits.push_back(newHit);
00390     }
00391 }

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

Return information about the given layer by index.

Definition at line 85 of file TrackQuality.h.

References layers_.

Referenced by evaluate(), and TrackClassifier::qualityInformation().

00086     {
00087         return layers_[index];
00088     }

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

Pre-process event information (for accessing reconstruction information).

Definition at line 187 of file TrackQuality.cc.

References associator_, and associatorPSet_.

Referenced by TrackClassifier::newEvent().

00188 {
00189     associator_.reset(new TrackerHitAssociator(ev, associatorPSet_));
00190 }

unsigned int TrackQuality::numberOfLayers (  )  const [inline]

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

Definition at line 79 of file TrackQuality.h.

References layers_.

Referenced by TrackClassifier::qualityInformation().

00080     {
00081         return layers_.size();
00082     }


Member Data Documentation

std::auto_ptr<TrackerHitAssociator> TrackQuality::associator_ [private]

Definition at line 92 of file TrackQuality.h.

Referenced by evaluate(), and newEvent().

const edm::ParameterSet TrackQuality::associatorPSet_ [private]

Definition at line 91 of file TrackQuality.h.

Referenced by newEvent().

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

Definition at line 94 of file TrackQuality.h.

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


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:34:18 2009 for CMSSW by  doxygen 1.5.4