File indexing completed on 2024-04-06 12:04:14
0001 #ifndef Geom_GloballyPositioned_H
0002 #define Geom_GloballyPositioned_H
0003
0004 #include "DataFormats/GeometryVector/interface/Point3DBase.h"
0005 #include "DataFormats/GeometryVector/interface/Vector3DBase.h"
0006 #include "DataFormats/GeometryVector/interface/LocalTag.h"
0007 #include "DataFormats/GeometryVector/interface/GlobalTag.h"
0008 #include "DataFormats/GeometrySurface/interface/TkRotation.h"
0009
0010
0011
0012
0013
0014
0015
0016
0017 template <class T>
0018 class GloballyPositioned {
0019 public:
0020 typedef T Scalar;
0021 typedef Point3DBase<T, GlobalTag> PositionType;
0022 typedef TkRotation<T> RotationType;
0023 typedef Point3DBase<T, GlobalTag> GlobalPoint;
0024 typedef Point3DBase<T, LocalTag> LocalPoint;
0025 typedef Vector3DBase<T, GlobalTag> GlobalVector;
0026 typedef Vector3DBase<T, LocalTag> LocalVector;
0027
0028 static T iniPhi() { return 999.9978; }
0029 static T iniEta() { return 999.9978; }
0030
0031 GloballyPositioned() { setCache(); }
0032 GloballyPositioned(const PositionType& pos, const RotationType& rot) : thePos(pos), theRot(rot) { setCache(); }
0033
0034 virtual ~GloballyPositioned() {}
0035
0036 const PositionType& position() const { return thePos; }
0037
0038 const RotationType& rotation() const { return theRot; }
0039
0040 T phi() const { return thePhi; }
0041 T eta() const { return theEta; }
0042
0043
0044 class ToLocal {
0045 public:
0046 ToLocal(GloballyPositioned const& frame) : thePos(frame.position()), theRot(frame.rotation().transposed()) {}
0047
0048 LocalPoint operator()(const GlobalPoint& gp) const { return toLocal(gp); }
0049
0050 LocalVector operator()(const GlobalVector& gv) const { return toLocal(gv); }
0051
0052 LocalPoint toLocal(const GlobalPoint& gp) const {
0053 return LocalPoint(theRot.multiplyInverse(gp.basicVector() - thePos.basicVector()));
0054 }
0055
0056 LocalVector toLocal(const GlobalVector& gv) const { return LocalVector(theRot.multiplyInverse(gv.basicVector())); }
0057
0058
0059 PositionType thePos;
0060 RotationType theRot;
0061 };
0062
0063
0064
0065
0066 GlobalPoint toGlobal(const LocalPoint& lp) const {
0067 return GlobalPoint(rotation().multiplyInverse(lp.basicVector()) + position().basicVector());
0068 }
0069
0070
0071
0072
0073
0074 template <class U>
0075 Point3DBase<U, GlobalTag> toGlobal(const Point3DBase<U, LocalTag>& lp) const {
0076 return Point3DBase<U, GlobalTag>(rotation().multiplyInverse(lp.basicVector()) + position().basicVector());
0077 }
0078
0079
0080
0081
0082 GlobalVector toGlobal(const LocalVector& lv) const {
0083 return GlobalVector(rotation().multiplyInverse(lv.basicVector()));
0084 }
0085
0086
0087
0088
0089
0090 template <class U>
0091 Vector3DBase<U, GlobalTag> toGlobal(const Vector3DBase<U, LocalTag>& lv) const {
0092 return Vector3DBase<U, GlobalTag>(rotation().multiplyInverse(lv.basicVector()));
0093 }
0094
0095
0096
0097
0098 LocalPoint toLocal(const GlobalPoint& gp) const {
0099 return LocalPoint(rotation() * (gp.basicVector() - position().basicVector()));
0100 }
0101
0102
0103
0104
0105
0106 template <class U>
0107 Point3DBase<U, LocalTag> toLocal(const Point3DBase<U, GlobalTag>& gp) const {
0108 return Point3DBase<U, LocalTag>(rotation() * (gp.basicVector() - position().basicVector()));
0109 }
0110
0111
0112
0113
0114 LocalVector toLocal(const GlobalVector& gv) const { return LocalVector(rotation() * gv.basicVector()); }
0115
0116
0117
0118
0119
0120 template <class U>
0121 Vector3DBase<U, LocalTag> toLocal(const Vector3DBase<U, GlobalTag>& gv) const {
0122 return Vector3DBase<U, LocalTag>(rotation() * gv.basicVector());
0123 }
0124
0125
0126
0127
0128 void move(const GlobalVector& displacement) {
0129 thePos += displacement;
0130 setCache();
0131 }
0132
0133
0134
0135
0136 void rotate(const RotationType& rotation) {
0137 theRot *= rotation;
0138 setCache();
0139 }
0140
0141 private:
0142 PositionType thePos;
0143 RotationType theRot;
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156 void setCache() {
0157 if ((thePos.x() == 0.) && (thePos.y() == 0.)) {
0158 thePhi = theEta = 0.;
0159 } else {
0160 thePhi = thePos.barePhi();
0161 theEta = thePos.eta();
0162 }
0163 }
0164
0165 T thePhi;
0166 T theEta;
0167 };
0168
0169 #endif