CMS 3D CMS Logo

TkRadialStripTopology.cc
Go to the documentation of this file.
3 
4 #include <iostream>
5 #include <cmath>
6 #include <algorithm>
7 #include <cassert>
8 
9 #include <vdt/vdtMath.h>
10 
11 #ifdef MATH_STS
12 #include <iostream>
13 #endif
14 namespace {
15 
16 #ifdef MATH_STS
17  struct Stat {
18  Stat(const char* in) : name(in){};
19  ~Stat() {
20  std::cout << name << ": atan0 calls tot/large/over1: " << natan << "/" << nlarge << "/" << over1 << std::endl;
21  }
22 
23  void add(float t) {
24  auto at = std::abs(t);
25  ++natan;
26  if (at > 0.40f)
27  ++nlarge;
28  if (at > 1.0)
29  ++over1;
30  }
31  const char* name;
32  long long natan = 0;
33  long long nlarge = 0;
34  long long over1 = 0;
35  };
36 
37  Stat statM("mpos");
38  Stat statS("span");
39 #endif
40 
41  // valid for |x| < 0.15 (better then 10^-9
42  template <typename T>
43  inline T tan15(T x) {
44  return x * (T(1) + (x * x) * (T(0.33331906795501708984375) + (x * x) * T(0.135160386562347412109375)));
45  }
46 
47  // valid for z < pi/8
48  // x * (1 + x*x * (-0.33322894573211669921875 + x*x * (0.1967026889324188232421875 + x*x * (-0.11053790152072906494140625)))) // .1e-7 by Sollya
49  inline float atan0(float t) {
50  auto z = t;
51  // if( t > 0.4142135623730950f ) // * tan pi/8
52  // z = (t-1.0f)/(t+1.0f);
53  float z2 = z * z;
54  float ret =
55  (((8.05374449538e-2f * z2 - 1.38776856032E-1f) * z2 + 1.99777106478E-1f) * z2 - 3.33329491539E-1f) * z2 * z + z;
56  // if( t > 0.4142135623730950f ) ret +=0.7853981633974483096f;
57  return ret;
58  }
59 
60  inline float atanClip(float t) {
61  constexpr float tanPi8 = 0.4142135623730950;
62  constexpr float pio8 = 3.141592653589793238 / 8;
63  float at = std::abs(t);
64  return std::copysign((at < tanPi8) ? atan0(at) : pio8, t);
65  }
66 
67 } // namespace
68 
69 TkRadialStripTopology::TkRadialStripTopology(int ns, float aw, float dh, float r, int yAx, float yMid)
70  : theNumberOfStrips(ns),
71  theAngularWidth(aw),
72  theAWidthInverse(1.f / aw),
73  theTanAW(std::tan(aw)),
74  theDetHeight(dh),
75  theCentreToIntersection(r),
76  theYAxisOrientation(yAx),
77  yCentre(yMid),
78  theRadialSigma(std::pow(dh, 2.f) * (1.f / 12.f)) {
79  // Angular offset of extreme edge of detector, so that angle is
80  // zero for a strip lying along local y axis = long symmetry axis of plane of strips
81  thePhiOfOneEdge = -(0.5 * theNumberOfStrips) * theAngularWidth; // always negative!
83  assert(std::abs(thePhiOfOneEdge) < 0.15); //
84 
85  LogTrace("TkRadialStripTopology") << "TkRadialStripTopology: constructed with"
86  << " strips = " << ns << " width = " << aw << " rad "
87  << " det_height = " << dh << " ctoi = " << r << " phi_edge = " << thePhiOfOneEdge
88  << " rad "
89  << " y_ax_ori = " << theYAxisOrientation << " y_det_centre = " << yCentre << "\n";
90 }
91 
93  return std::min(int(strip(lp)), theNumberOfStrips - 1);
94 }
95 
97  return std::min(nstrips(), static_cast<int>(std::max(float(0), strip(lp))) + 1);
98 }
99 
101  return yAxisOrientation() * y + originToIntersection();
102 }
103 
105  return detHeight() * std::sqrt(1.f + std::pow(lp.x() / yDistanceToIntersection(lp.y()), 2.f));
106 }
107 
108 float TkRadialStripTopology::xOfStrip(int strip, float y) const {
109  return yAxisOrientation() * yDistanceToIntersection(y) * std::tan(stripAngle(static_cast<float>(strip) - 0.5f));
110 }
111 
112 float TkRadialStripTopology::strip(const LocalPoint& lp) const {
113  // phi is measured from y axis --> sign of angle is sign of x * yAxisOrientation --> use atan2(x,y), not atan2(y,x)
114  const float phi = atanClip(lp.x() / yDistanceToIntersection(lp.y()));
115  const float aStrip = (phi - phiOfOneEdge()) * theAWidthInverse;
116  return std::max(float(0), std::min((float)nstrips(), aStrip));
117 }
118 
119 float TkRadialStripTopology::coveredStrips(const LocalPoint& lp1, const LocalPoint& lp2) const {
120  // http://en.wikipedia.org/wiki/List_of_trigonometric_identities#Angle_sum_and_difference_identities
121  // atan(a)-atan(b) = atan( (a-b)/(1+a*b) )
122  // avoid divisions
123  // float t1 = lp1.x()/yDistanceToIntersection( lp1.y() );
124  // float t2 = lp2.x()/yDistanceToIntersection( lp2.y() );
125  // float t = (t1-t2)/(1.+t1*t2);
126  auto y1 = yDistanceToIntersection(lp1.y());
127  auto y2 = yDistanceToIntersection(lp2.y());
128  auto x1 = lp1.x();
129  auto x2 = lp2.x();
130 
131  auto t = (y2 * x1 - y1 * x2) / (y1 * y2 + x1 * x2);
132 
133 #ifdef MATH_STS
134  statS.add(t);
135 #endif
136  // std::cout << "atans " << atanClip(t)
137  // <<" "<< std::atan2(lp1.x(),yDistanceToIntersection(lp1.y()) )
138  // -std::atan2(lp2.x(),yDistanceToIntersection(lp2.y()) ) << std::endl;
139  // clip???
140  return atanClip(t) * theAWidthInverse;
141  // return (measurementPosition(lp1)-measurementPosition(lp2)).x();
142 }
143 
146 }
147 
149  const float // y = (L/cos(phi))*mp.y()*cos(phi)
150  y(mp.y() * detHeight() + yCentreOfStripPlane()),
152  return LocalPoint(x, y);
153 }
154 
156  // phi is [pi/2 - conventional local phi], use atan2(x,y) rather than atan2(y,x)
157  // clip ( at pi/8 or detedge+tollerance?)
158  float t = lp.x() / yDistanceToIntersection(lp.y());
159 #ifdef MATH_STS
160  statM.add(t);
161 #endif
162  const float phi = atanClip(t);
164 }
165 
166 LocalError TkRadialStripTopology::localError(float strip, float stripErr2) const {
167  double phi = stripAngle(strip);
168 
169  const double t1(tan15(phi)), // std::tan(phif)), // (vdt::fast_tanf(phif)),
170  t2(t1 * t1),
171  // s1(std::sin(phi)), c1(std::cos(phi)),
172  // cs(s1*c1), s2(s1*s1), c2(1-s2), // rotation matrix
173 
174  tt(stripErr2 * std::pow(centreToIntersection() * angularWidth(), 2.f)), // tangential sigma^2 *c2
175  rr(theRadialSigma), // radial sigma^2( uniform prob density along strip) *c2
176 
177  xx(tt + t2 * rr), yy(t2 * tt + rr), xy(t1 * (rr - tt));
178 
179  return LocalError(xx, xy, yy);
180 }
181 
183  const double phi(stripAngle(mp.x())), s1(std::sin(phi)), c1(std::cos(phi)), cs(s1 * c1), s2(s1 * s1),
184  c2(1 - s2), // rotation matrix
185 
187  c1), // tangential measurement unit (local pitch)
188  R(detHeight() / c1), // radial measurement unit (strip length)
189  tt(me.uu() * T * T), // tangential sigma^2
190  rr(me.vv() * R * R), // radial sigma^2
191  tr(me.uv() * T * R),
192 
193  xx(c2 * tt + 2 * cs * tr + s2 * rr), yy(s2 * tt - 2 * cs * tr + c2 * rr), xy(cs * (rr - tt) + tr * (c2 - s2));
194 
195  return LocalError(xx, xy, yy);
196 }
197 
199  const double yHitToInter(yDistanceToIntersection(p.y())),
200  t(yAxisOrientation() * p.x() / yHitToInter), // tan(strip angle)
201  cs(t / (1 + t * t)), s2(t * cs), c2(1 - s2), // rotation matrix
202 
203  T2(1. / (std::pow(angularWidth(), 2.f) *
204  (std::pow(p.x(), 2.f) + std::pow(yHitToInter, 2)))), // 1./tangential measurement unit (local pitch) ^2
205  R2(c2 / std::pow(detHeight(), 2.f)), // 1./ radial measurement unit (strip length) ^2
206 
207  uu((c2 * e.xx() - 2 * cs * e.xy() + s2 * e.yy()) * T2), vv((s2 * e.xx() + 2 * cs * e.xy() + c2 * e.yy()) * R2),
208  uv((cs * (e.xx() - e.yy()) + e.xy() * (c2 - s2)) * std::sqrt(T2 * R2));
209 
210  return MeasurementError(uu, uv, vv);
211 }
212 
213 // The local pitch is the local x width of the strip at the local (x,y)
215  // this should be ~ y*(tan(phi+aw)-tan(phi)) = -x + y*(tan(aw)+tan(phi))/(1.f-tan(aw)*tan(phi)) tan(phi)=x/y
216  float y = yDistanceToIntersection(lp.y());
217  float x = std::abs(lp.x());
218  return y * (y * theTanAW + x) / (y - theTanAW * x) - x;
219 }
220 
221 /* old version
222 float TkRadialStripTopology::localPitch(const LocalPoint& lp) const {
223  // this should be ~ y*(tan(phi+aw)-tan(phi)) = -tan(phi) + (tan(aw)+tan(phi))/(1.f-tan(aw)*tan(phi))
224  const int istrip = std::min(nstrips(), static_cast<int>(strip(lp)) + 1); // which strip number
225  float fangle = stripAngle(static_cast<float>(istrip) - 0.5); // angle of strip centre
226  float p =
227  yDistanceToIntersection( lp.y() ) * std::sin(angularWidth()) /
228  std::pow( std::cos(fangle-0.5f*angularWidth()), 2.f);
229 
230  float theTanAW = std::tan(theAngularWidth);
231  float y = yDistanceToIntersection( lp.y() );
232  float x = std::abs(lp.x());
233  float myP = y*(y*theTanAW+x)/(y-theTanAW*x)-x; // (y*theTanAW+x)/(1.f-theTanAW*x/y)-x;
234  std::cout << "localPitch " << p << " " << myP << std::endl;
235 
236  return p;
237 
238 }
239 */
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:542
Point2DBase
Definition: Point2DBase.h:9
RandomServiceHelper.t2
t2
Definition: RandomServiceHelper.py:257
DDAxes::y
TkRadialStripTopology::theNumberOfStrips
int theNumberOfStrips
Definition: TkRadialStripTopology.h:236
TkRadialStripTopology::localError
LocalError localError(float strip, float stripErr2) const override
Definition: TkRadialStripTopology.cc:166
MessageLogger.h
TkRadialStripTopology::localPitch
float localPitch(const LocalPoint &) const override
Definition: TkRadialStripTopology.cc:214
TkRadialStripTopology::measurementError
MeasurementError measurementError(const LocalPoint &, const LocalError &) const override
Definition: TkRadialStripTopology.cc:198
groupFilesInBlocks.tt
int tt
Definition: groupFilesInBlocks.py:144
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
detailsBasic3DVector::z
float float float z
Definition: extBasic3DVector.h:14
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
fwrapper::cs
unique_ptr< ClusterSequence > cs
Definition: fastjetfortran_madfks.cc:47
TkRadialStripTopology::coveredStrips
float coveredStrips(const LocalPoint &lp1, const LocalPoint &lp2) const override
Definition: TkRadialStripTopology.cc:119
min
T min(T a, T b)
Definition: MathUtil.h:58
findQualityFiles.rr
string rr
Definition: findQualityFiles.py:185
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
TkRadialStripTopology::yCentreOfStripPlane
float yCentreOfStripPlane() const override
Definition: TkRadialStripTopology.h:228
cms::cuda::assert
assert(be >=bs)
TkRadialStripTopology::thePhiOfOneEdge
float thePhiOfOneEdge
Definition: TkRadialStripTopology.h:242
DDAxes::x
indexGen.s2
s2
Definition: indexGen.py:107
TkRadialStripTopology::detHeight
float detHeight() const override
Definition: TkRadialStripTopology.h:174
align::LocalPoint
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
testProducerWithPsetDescEmpty_cfi.z2
z2
Definition: testProducerWithPsetDescEmpty_cfi.py:41
TkRadialStripTopology::nearestStrip
int nearestStrip(const LocalPoint &) const override
Definition: TkRadialStripTopology.cc:96
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
testProducerWithPsetDescEmpty_cfi.y1
y1
Definition: testProducerWithPsetDescEmpty_cfi.py:29
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
TkRadialStripTopology::centreToIntersection
float centreToIntersection() const override
Definition: TkRadialStripTopology.h:186
TkRadialStripTopology::theTanOfOneEdge
float theTanOfOneEdge
Definition: TkRadialStripTopology.h:243
TkRadialStripTopology::localStripLength
float localStripLength(const LocalPoint &) const override
Definition: TkRadialStripTopology.cc:104
MeasurementError
Definition: MeasurementError.h:8
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
TkRadialStripTopology::theAWidthInverse
float theAWidthInverse
Definition: TkRadialStripTopology.h:238
Point3DBase< float, LocalTag >
TkRadialStripTopology::measurementPosition
MeasurementPoint measurementPosition(const LocalPoint &) const override
Definition: TkRadialStripTopology.cc:155
geometryCSVtoXML.xy
xy
Definition: geometryCSVtoXML.py:19
testProducerWithPsetDescEmpty_cfi.y2
y2
Definition: testProducerWithPsetDescEmpty_cfi.py:30
MeasurementPoint
Measurement2DPoint MeasurementPoint
Measurement points are two-dimensional by default.
Definition: MeasurementPoint.h:12
TkRadialStripTopology::theYAxisOrientation
float theYAxisOrientation
Definition: TkRadialStripTopology.h:244
geometryCSVtoXML.yy
yy
Definition: geometryCSVtoXML.py:19
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
TkRadialStripTopology.h
LocalError
Definition: LocalError.h:12
PV2DBase::y
T y() const
Definition: PV2DBase.h:44
PVValHelper::add
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
Definition: PVValidationHelpers.cc:12
TkRadialStripTopology::yAxisOrientation
float yAxisOrientation() const override
Definition: TkRadialStripTopology.h:223
PV2DBase::x
T x() const
Definition: PV2DBase.h:43
recoMuon::in
Definition: RecoMuonEnumerators.h:6
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
alignmentValidation.c1
c1
do drawing
Definition: alignmentValidation.py:1025
TkRadialStripTopology::yDistanceToIntersection
float yDistanceToIntersection(float y) const override
Definition: TkRadialStripTopology.cc:100
TkRadialStripTopology::stripAngle
float stripAngle(float strip) const override
Definition: TkRadialStripTopology.h:120
alignCSCRings.r
r
Definition: alignCSCRings.py:93
TkRadialStripTopology::TkRadialStripTopology
TkRadialStripTopology(int ns, float aw, float dh, float r, int yAx=1, float yMid=0.)
Definition: TkRadialStripTopology.cc:69
DDAxes::phi
std
Definition: JetResolutionObject.h:76
T
long double T
Definition: Basic3DVectorLD.h:48
TkRadialStripTopology::theTanAW
float theTanAW
Definition: TkRadialStripTopology.h:239
genVertex_cff.x
x
Definition: genVertex_cff.py:12
TkRadialStripTopology::channel
int channel(const LocalPoint &) const override
Definition: TkRadialStripTopology.cc:92
TkRadialStripTopology::phiOfOneEdge
float phiOfOneEdge() const override
Definition: TkRadialStripTopology.h:207
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
TkRadialStripTopology::nstrips
int nstrips() const override
Definition: TkRadialStripTopology.h:127
TkRadialStripTopology::xOfStrip
float xOfStrip(int strip, float y) const override
Definition: TkRadialStripTopology.cc:108
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
TkRadialStripTopology::yCentre
float yCentre
Definition: TkRadialStripTopology.h:245
TkRadialStripTopology::localPosition
LocalPoint localPosition(float strip) const override
Definition: TkRadialStripTopology.cc:144
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
TkRadialStripTopology::theAngularWidth
float theAngularWidth
Definition: TkRadialStripTopology.h:237
hlt_dqm_clientPB-live_cfg.me
me
Definition: hlt_dqm_clientPB-live_cfg.py:61
TkRadialStripTopology::angularWidth
float angularWidth() const override
Definition: TkRadialStripTopology.h:164
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
dttmaxenums::R
Definition: DTTMax.h:29
cuy.dh
dh
Definition: cuy.py:355
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
TkRadialStripTopology::theRadialSigma
double theRadialSigma
Definition: TkRadialStripTopology.h:246
TkRadialStripTopology::originToIntersection
float originToIntersection() const override
Definition: TkRadialStripTopology.h:193
TkRadialStripTopology::strip
float strip(const LocalPoint &) const override
Definition: TkRadialStripTopology.cc:112
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37