File indexing completed on 2024-04-06 12:28:51
0001 #ifndef PixelRecoLineRZ_H
0002 #define PixelRecoLineRZ_H
0003
0004
0005
0006
0007 #include <cmath>
0008
0009 #include "RecoTracker/TkMSParametrization/interface/PixelRecoPointRZ.h"
0010 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0011
0012 class PixelRecoLineRZ {
0013 public:
0014 typedef PixelRecoPointRZ LineOrigin;
0015
0016 PixelRecoLineRZ() {}
0017
0018 PixelRecoLineRZ(const GlobalPoint& p1, const GlobalPoint& p2)
0019 : theTIP2(initTIP2(p1.x(), p1.y(), p2.x(), p2.y())),
0020 theOrigin(LineOrigin(subTIP(p1.perp()), p1.z())),
0021 theCotLine(initCot(p2.z() - theOrigin.z(), subTIP(p2.perp()) - theOrigin.r())) {}
0022
0023 PixelRecoLineRZ(const LineOrigin& aOrigin, float aCotLine, float transverseIP = 0.f)
0024 : theTIP2(transverseIP * transverseIP), theOrigin(subTIP(aOrigin.r()), aOrigin.z()), theCotLine(aCotLine) {}
0025
0026 PixelRecoLineRZ(const LineOrigin& aOrigin, const PixelRecoPointRZ& aPoint, float transverseIP = 0.f)
0027 : theTIP2(transverseIP * transverseIP),
0028 theOrigin(subTIP(aOrigin.r()), aOrigin.z()),
0029 theCotLine(initCot(aPoint.z() - theOrigin.z(), subTIP(aPoint.r()) - theOrigin.r())) {}
0030
0031 float cotLine() const { return theCotLine; }
0032 float transverseIP() const { return std::sqrt(theTIP2); }
0033 float transverseIP2() const { return theTIP2; }
0034 LineOrigin origin() const { return LineOrigin(addTIP(theOrigin.r()), theOrigin.z()); }
0035
0036 float zAtR(float r) const { return theOrigin.z() + (subTIP(r) - theOrigin.r()) * theCotLine; }
0037 float rAtZ(float z) const {
0038 return (std::abs(theCotLine) > 1.e-4f) ? addTIP(theOrigin.r() + (z - theOrigin.z()) / theCotLine) : 99999.f;
0039 }
0040
0041 private:
0042 static float initCot(float dz, float dr) { return (std::abs(dr) > 1.e-4f) ? dz / dr : 99999.f; }
0043 static float initTIP2(float x1, float y1, float x2, float y2) {
0044 double l = y1 * (x2 - x1) - x1 * (y2 - y1);
0045 return l * l / ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
0046 }
0047
0048 inline float addTIP(float val) const { return theTIP2 ? std::sqrt(val * val + theTIP2) : val; }
0049 inline float subTIP(float val) const {
0050 if (!theTIP2)
0051 return val;
0052 float val2 = val * val;
0053 return val2 > theTIP2 ? std::sqrt(val2 - theTIP2) : 0.;
0054 }
0055
0056 private:
0057 float theTIP2;
0058 LineOrigin theOrigin;
0059 float theCotLine;
0060 };
0061
0062
0063 class SimpleLineRZ {
0064 public:
0065 typedef PixelRecoPointRZ Point;
0066
0067 SimpleLineRZ() {}
0068
0069 SimpleLineRZ(const Point& aOrigin, float aCotLine) : theOrigin(aOrigin), theCotLine(aCotLine) {}
0070
0071 SimpleLineRZ(const Point& aOrigin, const Point& aPoint)
0072 : theOrigin(aOrigin), theCotLine((aPoint.z() - theOrigin.z()) / (aPoint.r() - theOrigin.r())) {}
0073
0074 float cotLine() const { return theCotLine; }
0075 Point const& origin() const { return theOrigin; }
0076
0077 float zAtR(float r) const { return theOrigin.z() + (r - theOrigin.r()) * theCotLine; }
0078 float rAtZ(float z) const { return theOrigin.r() + (z - theOrigin.z()) / theCotLine; }
0079
0080 private:
0081 Point theOrigin;
0082 float theCotLine = 0;
0083 };
0084
0085 #endif