Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:49

0001 /**
0002  * base class for FastSim tracker RecHit containers
0003  * it inherits from BaseTrackerRecHit
0004  * and adds all the special FastSim features required to 
0005  * - perform truth matching,
0006  * - duplicate track removal
0007  * - fast tracking emulation
0008  */
0009 
0010 #ifndef FastTrackerRecHit_H
0011 #define FastTrackerRecHit_H
0012 
0013 #include "DataFormats/TrackerRecHit2D/interface/BaseTrackerRecHit.h"
0014 
0015 namespace fastTrackerRecHitType {
0016   enum HitType {
0017     siPixel = 0,
0018     siStrip1D = 1,
0019     siStrip2D = 2,
0020     siStripMatched2D = 3,
0021     siStripProjectedMono2D = 4,
0022     siStripProjectedStereo2D = 5,
0023   };
0024   inline trackerHitRTTI::RTTI rtti(HitType hitType) {
0025     if (hitType >= siPixel && hitType <= siStrip2D)
0026       return trackerHitRTTI::fastSingle;
0027     else if (hitType == siStripMatched2D)
0028       return trackerHitRTTI::fastMatch;
0029     else if (hitType == siStripProjectedMono2D)
0030       return trackerHitRTTI::fastProjMono;
0031     else if (hitType == siStripProjectedStereo2D)
0032       return trackerHitRTTI::fastProjStereo;
0033     else
0034       return trackerHitRTTI::undef;
0035   }
0036   inline bool is2D(HitType hitType) { return hitType != siStrip1D; }
0037   inline bool isPixel(HitType hitType) { return hitType == siPixel; }
0038 }  // namespace fastTrackerRecHitType
0039 
0040 class FastTrackerRecHit : public BaseTrackerRecHit {
0041 public:
0042   /// default constructor
0043   ///
0044   FastTrackerRecHit() : BaseTrackerRecHit(), isPixel_(false), is2D_(true), recHitCombinationIndex_(-1) {}
0045 
0046   /// destructor
0047   ///
0048   ~FastTrackerRecHit() override {}
0049 
0050   /// constructor
0051   /// requires a position with error in local detector coordinates,
0052   /// the detector id, and type information (rt)
0053   FastTrackerRecHit(const LocalPoint& p,
0054                     const LocalError& e,
0055                     GeomDet const& idet,
0056                     fastTrackerRecHitType::HitType hitType)
0057       : BaseTrackerRecHit(p, e, idet, fastTrackerRecHitType::rtti(hitType)),
0058         isPixel_(fastTrackerRecHitType::isPixel(hitType)),
0059         is2D_(fastTrackerRecHitType::is2D(hitType)),
0060         recHitCombinationIndex_(-1),
0061         energyLoss_(0.0)  //holy golden seal
0062   {
0063     store();
0064   }
0065 
0066   FastTrackerRecHit* clone() const override {
0067     FastTrackerRecHit* p = new FastTrackerRecHit(*this);
0068     p->load();
0069     return p;
0070   }
0071 
0072   /// Steers behaviour of hit in track fit.
0073   /// Hit is interpreted as 1D or 2D depending on value of is2D_
0074 
0075   float energyLoss() const { return energyLoss_; }  // holy golden seal
0076   void setEnergyLoss(float e) { energyLoss_ = e; }  //   holy golden seal was a virtual void...
0077   void getKfComponents(KfComponentsHolder& holder) const override {
0078     if (is2D_)
0079       getKfComponents2D(holder);
0080     else
0081       getKfComponents1D(holder);
0082   }
0083 
0084   /// Steers behaviour of hit in track fit.
0085   /// Hit is interpreted as 1D or 2D depending on value of is2D_
0086   int dimension() const override { return is2D_ ? 2 : 1; }  ///< get the dimensions right
0087 
0088   /// Steers behaviour of hit in track fit.
0089   /// FastSim hit smearing assumes
0090   bool canImproveWithTrack() const override { return false; }
0091 
0092   /* getters */
0093 
0094   virtual size_t nIds() const { return 0; }
0095   virtual int32_t id(size_t i = 0) const { return -1; }
0096   virtual int32_t eventId(size_t i = 0) const { return -1; }
0097 
0098   virtual size_t nSimTrackIds() const { return 0; }
0099   virtual int32_t simTrackId(size_t i) const { return -1; }
0100   virtual int32_t simTrackEventId(size_t i) const { return -1; }
0101 
0102   virtual int32_t recHitCombinationIndex() const { return recHitCombinationIndex_; }
0103 
0104   bool isPixel() const override { return isPixel_; }  ///< pixel or strip?
0105 
0106   /* setters */
0107 
0108   virtual void setEventId(int32_t eventId){};
0109 
0110   void set2D(bool is2D = true) { is2D_ = is2D; }
0111 
0112   virtual void setRecHitCombinationIndex(int32_t recHitCombinationIndex) {
0113     recHitCombinationIndex_ = recHitCombinationIndex;
0114   }
0115 
0116   /// bogus function :
0117   /// implement purely virtual function of TrackingRecHit
0118   std::vector<const TrackingRecHit*> recHits() const override { return std::vector<TrackingRecHit const*>(); }
0119 
0120   /// bogus function :
0121   /// implement purely virtual function of TrackingRecHit
0122   std::vector<TrackingRecHit*> recHits() override { return std::vector<TrackingRecHit*>(); }
0123 
0124   /// bogus function :
0125   /// implement purely virutal function of BaseTrackerRecHit
0126   OmniClusterRef const& firstClusterRef() const override;
0127 
0128   /// fastsim's way to check whether 2 single hits share sim-information or not
0129   /// hits are considered to share sim-information if
0130   /// - they have the same hit id number
0131   /// - they have the same event id number
0132   // used by functions
0133   // - FastTrackerSingleRecHit::sharesInput
0134   // - FastSiStripMatchedRecHit::sharesInput
0135   // - FastProjectedSiStripRecHit2D::sharesInput
0136   inline bool sameId(const FastTrackerRecHit* other, size_t i = 0, size_t j = 0) const {
0137     return id(i) == other->id(j) && eventId(i) == other->eventId(j);
0138   }
0139   inline bool sharesInput(const TrackingRecHit* other, SharedInputType what) const override {
0140     // cast other hit
0141     if (!trackerHitRTTI::isFast(*other))
0142       return false;
0143     const FastTrackerRecHit* otherCast = static_cast<const FastTrackerRecHit*>(other);
0144 
0145     // checks
0146     if (this->nIds() == 1) {         // this hit is single/projected
0147       if (otherCast->nIds() == 1) {  // other hit is single/projected
0148         return this->sameId(otherCast, 0, 0);
0149       } else {  // other hit is matched
0150         if (what == all) {
0151           return false;
0152         } else {
0153           return (this->sameId(otherCast, 0, 0) || this->sameId(otherCast, 0, 1));
0154         }
0155       }
0156     } else {                         // this hit is matched
0157       if (otherCast->nIds() == 1) {  // other hit is single/projected
0158         if (what == all) {
0159           return false;
0160         } else {
0161           return (this->sameId(otherCast, 0, 0) || this->sameId(otherCast, 1, 0));
0162         }
0163       } else {  // other hit is matched
0164         if (what == all) {
0165           return (this->sameId(otherCast, 0, 0) && this->sameId(otherCast, 1, 1));
0166         } else {
0167           return (this->sameId(otherCast, 0, 0) || this->sameId(otherCast, 1, 1));
0168         }
0169       }
0170     }
0171   }
0172 
0173 protected:
0174   const bool isPixel_;  ///< hit is either on pixel modul (isPixel_ = true) or strip module (isPixel_ = false)
0175   bool is2D_;           ///< hit is either one dimensional (is2D_ = false) or two dimensions (is2D_ = true)
0176 
0177   LocalPoint myPos_;  ///< helps making the hit postion and error persistent
0178   LocalError myErr_;  ///< helps making the hit postion and error persistent
0179 
0180   void store() {
0181     myPos_ = pos_;
0182     myErr_ = err_;
0183   }  ///< helps making the hit postion and error persistent
0184   void load() {
0185     pos_ = myPos_;
0186     err_ = myErr_;
0187   }  ///< helps making the hit postion and error persistent
0188 
0189   uint32_t recHitCombinationIndex_;
0190   float energyLoss_;  //holy golden seal
0191 
0192 protected:
0193   FastTrackerRecHit* clone_(TkCloner const& cloner, TrajectoryStateOnSurface const& tsos) const override {
0194     return this->clone();
0195   }
0196 };
0197 
0198 /// Comparison operator
0199 ///
0200 inline bool operator<(const FastTrackerRecHit& one, const FastTrackerRecHit& other) {
0201   return (one.geographicalId() < other.geographicalId());
0202 }
0203 
0204 #endif