Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:51:30

0001 #ifndef BaseTrackerRecHit_H
0002 #define BaseTrackerRecHit_H
0003 
0004 #include "DataFormats/TrackerRecHit2D/interface/trackerHitRTTI.h"
0005 #include "DataFormats/TrackingRecHit/interface/TrackingRecHitGlobalState.h"
0006 #include "DataFormats/GeometryCommonDetAlgo/interface/ErrorFrameTransformer.h"
0007 #include "Geometry/CommonDetUnit/interface/TrackerGeomDet.h"
0008 #include "DataFormats/GeometrySurface/interface/Surface.h"
0009 
0010 //#define DO_INTERNAL_CHECKS_BTR
0011 //#define VI_DEBUG
0012 
0013 class OmniClusterRef;
0014 
0015 class BaseTrackerRecHit : public TrackingRecHit {
0016 public:
0017   BaseTrackerRecHit() : qualWord_(0) {}
0018 
0019   // fake TTRH interface
0020   BaseTrackerRecHit const* hit() const final { return this; }
0021 
0022   ~BaseTrackerRecHit() override {}
0023 
0024   // no position (as in persistent)
0025   BaseTrackerRecHit(DetId id, trackerHitRTTI::RTTI rt) : TrackingRecHit(id, (unsigned int)(rt)), qualWord_(0) {}
0026   BaseTrackerRecHit(const GeomDet& idet, trackerHitRTTI::RTTI rt)
0027       : TrackingRecHit(idet, (unsigned int)(rt)), qualWord_(0) {}
0028 
0029   BaseTrackerRecHit(const LocalPoint& p, const LocalError& e, GeomDet const& idet, trackerHitRTTI::RTTI rt)
0030       : TrackingRecHit(idet, (unsigned int)(rt)), pos_(p), err_(e), qualWord_(0) {
0031     auto trackerDet = static_cast<TrackerGeomDet const*>(det());
0032     LocalError lape = trackerDet->localAlignmentError();
0033     if (lape.valid())
0034       err_ = LocalError(err_.xx() + lape.xx(), err_.xy() + lape.xy(), err_.yy() + lape.yy());
0035   }
0036 
0037   trackerHitRTTI::RTTI rtti() const { return trackerHitRTTI::rtti(*this); }
0038   bool isSingle() const { return trackerHitRTTI::isSingle(*this); }
0039   bool isMatched() const { return trackerHitRTTI::isMatched(*this); }
0040   bool isProjected() const { return trackerHitRTTI::isProjected(*this); }
0041   bool isProjMono() const { return trackerHitRTTI::isProjMono(*this); }
0042   bool isProjStereo() const { return trackerHitRTTI::isProjStereo(*this); }
0043   bool isMulti() const { return trackerHitRTTI::isMulti(*this); }
0044 
0045   virtual bool isPixel() const { return false; }
0046   virtual bool isPhase2() const { return false; }
0047 
0048   // used by trackMerger (to be improved)
0049   virtual OmniClusterRef const& firstClusterRef() const = 0;
0050 
0051   // verify that hits can share clusters...
0052   inline bool sameDetModule(TrackingRecHit const& hit) const;
0053 
0054   bool hasPositionAndError() const override;
0055 
0056   LocalPoint localPosition() const override {
0057     check();
0058     return pos_;
0059   }
0060 
0061   LocalError localPositionError() const override {
0062     check();
0063     return err_;
0064   }
0065   const LocalPoint& localPositionFast() const {
0066     check();
0067     return pos_;
0068   }
0069   const LocalError& localPositionErrorFast() const {
0070     check();
0071     return err_;
0072   }
0073 
0074   // to be specialized for 1D and 2D
0075   void getKfComponents(KfComponentsHolder& holder) const override = 0;
0076   int dimension() const override = 0;
0077 
0078   void getKfComponents1D(KfComponentsHolder& holder) const;
0079   void getKfComponents2D(KfComponentsHolder& holder) const;
0080 
0081   // global coordinates
0082   // Extension of the TrackingRecHit interface
0083   const Surface* surface() const final { return &(det()->surface()); }
0084 
0085   GlobalPoint globalPosition() const final { return surface()->toGlobal(localPosition()); }
0086 
0087   GlobalError globalPositionError() const final {
0088     return ErrorFrameTransformer().transform(localPositionError(), *surface());
0089   }
0090   float errorGlobalR() const final { return std::sqrt(globalPositionError().rerr(globalPosition())); }
0091   float errorGlobalZ() const final { return std::sqrt(globalPositionError().czz()); }
0092   float errorGlobalRPhi() const final {
0093     return globalPosition().perp() * sqrt(globalPositionError().phierr(globalPosition()));
0094   }
0095 
0096   // once cache removed will obsolete the above
0097   TrackingRecHitGlobalState globalState() const {
0098     GlobalError globalError = ErrorFrameTransformer::transform(localPositionError(), *surface());
0099     GlobalPoint gp = globalPosition();
0100     float r = gp.perp();
0101     float errorRPhi = r * std::sqrt(float(globalError.phierr(gp)));
0102     float errorR = std::sqrt(float(globalError.rerr(gp)));
0103     float errorZ = std::sqrt(float(globalError.czz()));
0104     return (TrackingRecHitGlobalState){gp.basicVector(), r, gp.barePhi(), errorR, errorZ, errorRPhi};
0105   }
0106 
0107   /// cluster probability, overloaded by pixel rechits.
0108   virtual float clusterProbability() const { return 1.f; }
0109 
0110 public:
0111   // obsolete (for what tracker is concerned...) interface
0112   AlgebraicVector parameters() const override;
0113   AlgebraicSymMatrix parametersError() const override;
0114   AlgebraicMatrix projectionMatrix() const override;
0115 
0116 private:
0117 #ifdef VI_DEBUG
0118   void check() const { assert(det()); }
0119 #elif defined(DO_INTERNAL_CHECKS_BTR)
0120   void check() const;
0121 #else
0122   static void check() {}
0123 #endif
0124 
0125 protected:
0126   LocalPoint pos_;
0127   LocalError err_;
0128 
0129 protected:
0130   //this comes for free (padding)
0131   unsigned int qualWord_;
0132 };
0133 
0134 bool BaseTrackerRecHit::sameDetModule(TrackingRecHit const& hit) const {
0135   unsigned int myid = geographicalId().rawId();
0136   unsigned int mysubd = myid >> (DetId::kSubdetOffset);
0137 
0138   unsigned int id = hit.geographicalId().rawId();
0139   unsigned int subd = id >> (DetId::kSubdetOffset);
0140 
0141   if (mysubd != subd)
0142     return false;
0143 
0144   //Protection against invalid hits
0145   if (!hit.isValid())
0146     return false;
0147 
0148   const unsigned int limdet = 10;  // TIB=11
0149 
0150   if (mysubd > limdet) {  // strip
0151     // mask glue and stereo
0152     myid |= 3;
0153     id |= 3;
0154   }
0155   return id == myid;
0156 }
0157 
0158 // Comparison operators
0159 inline bool operator<(const BaseTrackerRecHit& one, const BaseTrackerRecHit& other) {
0160   return (one.geographicalId() < other.geographicalId());
0161 }
0162 #endif  // BaseTrackerRecHit_H