Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef TrackingRecHit_h
0002 #define TrackingRecHit_h
0003 
0004 #include "DataFormats/CLHEP/interface/AlgebraicObjects.h"
0005 #include "DataFormats/DetId/interface/DetId.h"
0006 #include "DataFormats/GeometrySurface/interface/LocalError.h"
0007 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0008 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0009 #include "DataFormats/GeometryCommonDetAlgo/interface/GlobalError.h"
0010 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0011 #include "DataFormats/GeometrySurface/interface/Surface.h"
0012 
0013 #include <vector>
0014 #include <memory>
0015 #include <cassert>
0016 
0017 class TkCloner;
0018 class TrajectoryStateOnSurface;
0019 class KfComponentsHolder;
0020 
0021 class TrackingRecHit {
0022 public:
0023 #ifndef __GCCXML__
0024   using RecHitPointer = std::shared_ptr<TrackingRecHit const>;  // requires to much editing
0025   using ConstRecHitPointer = std::shared_ptr<TrackingRecHit const>;
0026 #else
0027   typedef TrackingRecHit const* RecHitPointer;
0028   typedef TrackingRecHit const* ConstRecHitPointer;
0029 #endif
0030 
0031   typedef std::vector<ConstRecHitPointer> RecHitContainer;
0032   typedef std::vector<ConstRecHitPointer> ConstRecHitContainer;
0033 
0034   friend class MuonTransientTrackingRecHit;
0035 
0036   typedef unsigned int id_type;
0037 
0038   /** Type of hits:
0039    *   valid    = valid hit
0040    *   mwissing  = detector is good, but no rec hit found
0041    *   inactive = detector is off, so there was no hope
0042    *   bad      = there were many bad strips within the ellipse (in Tracker)
0043    *            = hit is compatible with the trajectory, but chi2 is too large (in Muon System)
0044    */
0045   enum Type {
0046     valid = 0,
0047     missing = 1,
0048     inactive = 2,
0049     bad = 3,
0050     missing_inner = 4,
0051     missing_outer = 5,
0052     inactive_inner = 6,
0053     inactive_outer = 7
0054   };
0055   static const int typeMask = 0xf;  // mask for the above
0056   static const int rttiShift = 24;  // shift amount to get the rtti
0057 
0058   /// definition of equality via shared input
0059   enum SharedInputType { all, some };
0060 
0061   explicit TrackingRecHit(DetId id, Type type = valid) : m_id(id), m_status(type), m_det(nullptr) {}
0062   explicit TrackingRecHit(id_type id = 0, Type type = valid) : m_id(id), m_status(type), m_det(nullptr) {}
0063   TrackingRecHit(DetId id, unsigned int rt, Type type = valid)
0064       : m_id(id), m_status((rt << rttiShift) | int(type)), m_det(nullptr) {}
0065 
0066   explicit TrackingRecHit(const GeomDet& idet, Type type = valid)
0067       : m_id(idet.geographicalId()), m_status(type), m_det(&idet) {}
0068   TrackingRecHit(const GeomDet& idet, unsigned int rt, Type type = valid)
0069       : m_id(idet.geographicalId()), m_status((rt << rttiShift) | int(type)), m_det(&idet) {}
0070   TrackingRecHit(const GeomDet& idet, TrackingRecHit const& rh) : m_id(rh.m_id), m_status(rh.m_status), m_det(&idet) {}
0071 
0072   virtual ~TrackingRecHit() {}
0073 
0074   // fake TTRH interface
0075   virtual TrackingRecHit const* hit() const { return this; }
0076   virtual TrackingRecHit* cloneHit() const { return clone(); }
0077 
0078   virtual TrackingRecHit* clone() const = 0;
0079 #ifndef __GCCXML__
0080   virtual RecHitPointer cloneSH() const { return RecHitPointer(clone()); }
0081   // clone and add the geom (ready for refit)
0082   RecHitPointer cloneForFit(const GeomDet& idet) const {
0083     auto cl = cloneSH();
0084     const_cast<TrackingRecHit&>(*cl).setDet(idet);  // const_cast (can be fixed editing some 100 files)
0085     return cl;
0086   }
0087 #endif
0088   virtual void setDet(const GeomDet& idet) { m_det = &idet; }
0089 
0090   virtual AlgebraicVector parameters() const = 0;
0091 
0092   virtual AlgebraicSymMatrix parametersError() const = 0;
0093 
0094   virtual AlgebraicMatrix projectionMatrix() const = 0;
0095 
0096   virtual void getKfComponents(KfComponentsHolder& holder) const;
0097 
0098   virtual int dimension() const = 0;
0099 
0100   /// Access to component RecHits (if any)
0101   virtual std::vector<const TrackingRecHit*> recHits() const = 0;
0102   virtual void recHitsV(std::vector<const TrackingRecHit*>&) const;
0103 
0104   /// Non-const access to component RecHits (if any)
0105   virtual std::vector<TrackingRecHit*> recHits() = 0;
0106   virtual void recHitsV(std::vector<TrackingRecHit*>&);
0107 
0108 #ifndef __GCCXML__
0109   virtual ConstRecHitContainer transientHits() const {
0110     ConstRecHitContainer result;
0111     std::vector<const TrackingRecHit*> hits;
0112     recHitsV(hits);
0113     for (auto h : hits)
0114       result.push_back(h->cloneSH());
0115     return result;
0116   }
0117 #endif
0118 
0119   id_type rawId() const { return m_id; }
0120   DetId geographicalId() const { return m_id; }
0121 
0122   const GeomDet* det() const { return m_det; }
0123   virtual const Surface* surface() const { return &(det()->surface()); }
0124 
0125   /// CAUTION: the GeomDetUnit* is zero for composite hits
0126   /// (matched hits in the tracker, segments in the muon).
0127   /// Always check this pointer before using it!
0128   virtual const GeomDetUnit* detUnit() const;
0129 
0130   virtual LocalPoint localPosition() const = 0;
0131 
0132   virtual LocalError localPositionError() const = 0;
0133 
0134   /// to be redefined by daughter class
0135   virtual bool hasPositionAndError() const { return true; };
0136 
0137   virtual float weight() const { return 1.; }
0138 
0139   Type type() const { return Type(typeMask & m_status); }
0140   Type getType() const { return Type(typeMask & m_status); }
0141   bool isValid() const { return getType() == valid; }
0142 
0143   unsigned int getRTTI() const { return m_status >> rttiShift; }
0144 
0145   /** Returns true if the two TrackingRecHits are using the same input information 
0146    * (like Digis, Clusters, etc), false otherwise. The second argument specifies 
0147    * how much sharing is needed in order to return true: the value "all" 
0148    * means that all inputs of the two hits must be identical; the value "some" means
0149    * that at least one of the inputs is in common. */
0150   virtual bool sharesInput(const TrackingRecHit* other, SharedInputType what) const;
0151 
0152   //  global coordinates
0153 
0154   virtual GlobalPoint globalPosition() const;
0155   virtual GlobalError globalPositionError() const;
0156 
0157   virtual float errorGlobalR() const;
0158   virtual float errorGlobalZ() const;
0159   virtual float errorGlobalRPhi() const;
0160 
0161   /// Returns true if the clone( const TrajectoryStateOnSurface&) method returns an
0162   /// improved hit, false if it returns an identical copy.
0163   /// In order to avoid redundent copies one should call canImproveWithTrack() before
0164   /// calling clone( const TrajectoryStateOnSurface&).
0165   ///this will be done inside the TkCloner itself
0166   virtual bool canImproveWithTrack() const { return false; }
0167 
0168 private:
0169   friend class TkCloner;
0170   // double dispatch
0171   virtual TrackingRecHit* clone_(TkCloner const&, TrajectoryStateOnSurface const&) const {
0172     assert("clone" == nullptr);
0173     return clone();  // default
0174   }
0175 #ifndef __GCCXML__
0176   virtual RecHitPointer cloneSH_(TkCloner const&, TrajectoryStateOnSurface const&) const {
0177     assert("cloneSH" == nullptr);
0178     return cloneSH();  // default
0179   }
0180 #endif
0181 
0182 protected:
0183   // used by muon...
0184   void setId(id_type iid) { m_id = iid; }
0185   void setType(Type ttype) { m_status = ttype; }
0186 
0187   void setRTTI(unsigned int rt) { m_status &= (rt << rttiShift); }  // can be done only once...
0188 
0189 private:
0190   id_type m_id;
0191 
0192   unsigned int m_status;  // bit assigned (type 0-8) (rtti 24-31)
0193 
0194   const GeomDet* m_det;
0195 };
0196 
0197 #endif