Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:22

0001 
0002 #ifndef FASTSIMULATION_TRACKING_FASTTRACKINGHELPER_H
0003 #define FASTSIMULATION_TRACKING_FASTTRACKINGHELPER_H
0004 
0005 #include "DataFormats/TrackerRecHit2D/interface/FastTrackerRecHitCollection.h"
0006 #include "DataFormats/TrackerRecHit2D/interface/FastTrackerRecHit.h"
0007 
0008 namespace fastTrackingUtilities {
0009 
0010   template <class T>
0011   inline void setRecHitCombinationIndex(edm::OwnVector<T> &recHits, int32_t icomb) {
0012     for (auto &recHit : recHits) {
0013       if (!trackerHitRTTI::isFast(recHit)) {
0014         throw cms::Exception("fastTrackingHelpers::setRecHitCombinationIndex: one of hits in OwnVector is non-fastsim");
0015       }
0016       static_cast<FastTrackerRecHit &>(recHit).setRecHitCombinationIndex(icomb);
0017     }
0018   }
0019 
0020   // get recHitCombination for TrackCandidate and TrajectorySeed
0021   template <class T>
0022   int32_t getRecHitCombinationIndex(const T &object) {
0023     // seed must have at least one hit
0024     if (object.recHits().empty()) {
0025       throw cms::Exception("fastTrackingHelpers::getRecHitCombinationIndex")
0026           << "  given object has 0 hits" << std::endl;
0027     }
0028 
0029     const TrackingRecHit &recHit = *object.recHits().begin();
0030     if (!trackerHitRTTI::isFast(recHit)) {
0031       throw cms::Exception("fastTrackingHelpers::setRecHitCombinationIndex")
0032           << "  one of hits in OwnVector is non-fastsim" << std::endl;
0033     }
0034     // cast and return combination index
0035     return static_cast<const FastTrackerRecHit &>(recHit).recHitCombinationIndex();
0036     // return combination index of first hit
0037   }
0038 
0039   inline bool hitIsMasked(const FastTrackerRecHit *hit, const std::vector<bool> &hitMasks) {
0040     for (unsigned int i = 0; i < hit->nIds(); i++) {
0041       if (!(hitMasks)[hit->id(i)]) {
0042         return false;
0043       }
0044     }
0045     return true;
0046   }
0047 
0048   inline double hitLocalError(const TrackingRecHit *hit) {
0049     double xx = hit->localPositionError().xx();
0050     double yy = hit->localPositionError().yy();
0051     double xy = hit->localPositionError().xy();
0052     double delta = std::sqrt((xx - yy) * (xx - yy) + 4. * xy * xy);
0053     return 0.5 * (xx + yy - delta);
0054   }
0055 }  // namespace fastTrackingUtilities
0056 
0057 #endif