File indexing completed on 2024-04-06 12:05:19
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
0011
0012
0013 class OmniClusterRef;
0014
0015 class BaseTrackerRecHit : public TrackingRecHit {
0016 public:
0017 BaseTrackerRecHit() : qualWord_(0) {}
0018
0019
0020 BaseTrackerRecHit const* hit() const final { return this; }
0021
0022 ~BaseTrackerRecHit() override {}
0023
0024
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
0049 virtual OmniClusterRef const& firstClusterRef() const = 0;
0050
0051
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
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
0082
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
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
0108 virtual float clusterProbability() const { return 1.f; }
0109
0110 public:
0111
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
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
0145 if (!hit.isValid())
0146 return false;
0147
0148 const unsigned int limdet = 10;
0149
0150 if (mysubd > limdet) {
0151
0152 myid |= 3;
0153 id |= 3;
0154 }
0155 return id == myid;
0156 }
0157
0158
0159 inline bool operator<(const BaseTrackerRecHit& one, const BaseTrackerRecHit& other) {
0160 return (one.geographicalId() < other.geographicalId());
0161 }
0162 #endif