CMS 3D CMS Logo

InnerDeltaPhi.cc
Go to the documentation of this file.
10 
11 #if !defined(__INTEL_COMPILER)
12 #define USE_VECTORS_HERE
13 #endif
14 
15 using namespace std;
16 
17 #ifdef VI_DEBUG
18 namespace {
19  struct Stat {
20 
21  float xmin=1.1;
22  float xmax=-1.1;
23  int nt=0;
24  int nn=0;
25  int nl=0;
26 
27  ~Stat() { std::cout << "ASIN " << xmin <<',' << xmax <<',' << nt <<','<< nn <<','<< nl << std::endl;}
28 
29  };
30 
31  Stat stat;
32 
33 }
34 
35 namespace {
36  template <class T>
37  inline T cropped_asin(T x) {
38  stat.nt++;
39  if (x<0.f) stat.nn++;
40  if (x>0.5f) stat.nl++;
41  stat.xmin = std::min(x,stat.xmin);
42  stat.xmax = std::max(x,stat.xmax);
43 
44  return std::abs(x) <= 1 ? std::asin(x) : (x > 0 ? T(M_PI/2) : -T(M_PI/2));
45  }
46 }
47 #else // for icc
48 namespace {
49  template <class T>
50  inline T cropped_asin(T x) {
51  return std::abs(x) <= 1 ? std::asin(x) : (x > 0 ? T(M_PI/2) : -T(M_PI/2));
52  }
53 }
54 #endif
55 
56 
57 namespace {
58 
59  template <class T> inline T sqr( T t) {return t*t;}
60 
61  // reasonable (5.e-4) only for |x|<0.7 then degrades..
62  template<typename T>
63  inline T f_asin07f(T x) {
64 
65  auto ret =
66  1.f + (x*x) * (0.157549798488616943359375f + (x*x)*0.125192224979400634765625f);
67 
68  return x*ret;
69  }
70 
71 }
72 
73 
75 
76 namespace {
77  inline
78  float f_atan2f(float y, float x) { return unsafe_atan2f<7>(y,x); }
79  template<typename V> inline float f_phi(V v) { return f_atan2f(v.y(),v.x());}
80 }
81 
82 InnerDeltaPhi:: InnerDeltaPhi( const DetLayer& outlayer, const DetLayer& layer,
83  const TrackingRegion & region,
84  const edm::EventSetup& iSetup,
85  bool precise, float extraTolerance) :
86  innerIsBarrel(layer.isBarrel()),
87  outerIsBarrel(outlayer.isBarrel()),
88  thePrecise(precise),
89  ol( outlayer.seqNum()),
90  theROrigin(region.originRBound()),
91  theRLayer(0),
92  theThickness(0),
93  theExtraTolerance(extraTolerance),
94  theA(0),
95  theB(0),
96  theVtxZ(region.origin().z()),
97  thePtMin(region.ptMin()),
98  theVtx(region.origin().x(),region.origin().y()),
99  sigma(&layer,iSetup)
100 
101 {
102  float zMinOrigin = theVtxZ-region.originZBound();
103  float zMaxOrigin = theVtxZ+region.originZBound();
105 
106 
107  if (innerIsBarrel) initBarrelLayer( layer);
108  else initForwardLayer( layer, zMinOrigin, zMaxOrigin);
109 
110  if(outerIsBarrel) initBarrelMS(outlayer);
111  else initForwardMS(outlayer);
112 
113 }
114 
115 
116 void InnerDeltaPhi::initBarrelMS(const DetLayer& outLayer) {
117  const BarrelDetLayer& bl = static_cast<const BarrelDetLayer&>(outLayer);
118  float rLayer = bl.specificSurface().radius();
119  auto zmax = 0.5f*outLayer.surface().bounds().length();
120  PixelRecoPointRZ zero(0., 0.);
121  PixelRecoPointRZ point1(rLayer, 0.);
122  PixelRecoPointRZ point2(rLayer, zmax);
123  auto scatt1 = 3.f*sigma(thePtMin,zero, point1, ol);
124  auto scatt2 = 3.f*sigma(thePtMin,zero, point2, ol);
125  theDeltaScatt = (scatt2-scatt1)/zmax;
126  theScatt0 = scatt1;
127 }
128 
129 void InnerDeltaPhi::initForwardMS(const DetLayer& outLayer) {
130  const ForwardDetLayer &fl = static_cast<const ForwardDetLayer&>(outLayer);
131  auto minR = fl.specificSurface().innerRadius();
132  auto maxR = fl.specificSurface().outerRadius();
133  auto layerZ = outLayer.position().z();
134  // compute min and max multiple scattering correction
135  PixelRecoPointRZ zero(0., theVtxZ);
136  PixelRecoPointRZ point1(minR, layerZ);
137  PixelRecoPointRZ point2(maxR, layerZ);
138  auto scatt1 = 3.f*sigma(thePtMin,zero, point1, ol);
139  auto scatt2 = 3.f*sigma(thePtMin,zero, point2, ol);
140  theDeltaScatt = (scatt2-scatt1)/(maxR-minR);
141  theScatt0 = scatt1 - theDeltaScatt*minR;
142 }
143 
144 
145 
147 {
148  const BarrelDetLayer& bl = static_cast<const BarrelDetLayer&>(layer);
149  float rLayer = bl.specificSurface().radius();
150 
151  // the maximal delta phi will be for the innermost hits
152  theThickness = layer.surface().bounds().thickness();
153  theRLayer = rLayer - 0.5f*theThickness;
154 }
155 
157  float zMinOrigin, float zMaxOrigin)
158 {
159  const ForwardDetLayer &fl = static_cast<const ForwardDetLayer&>(layer);
160  theRLayer = fl.specificSurface().innerRadius();
161  float layerZ = layer.position().z();
162  theThickness = layer.surface().bounds().thickness();
163  float layerZmin = layerZ > 0 ? layerZ-0.5f*theThickness: layerZ+0.5f*theThickness;
164  theB = layerZ > 0 ? zMaxOrigin : zMinOrigin;
165  theA = layerZmin - theB;
166 }
167 
168 
169 
170 PixelRecoRange<float> InnerDeltaPhi::phiRange(const Point2D& hitXY,float hitZ,float errRPhi) const
171 {
172  float rLayer = theRLayer;
173  Point2D crossing;
174 
175  Point2D dHit = hitXY-theVtx;
176  auto dHitmag = dHit.mag();
177  float dLayer = 0.;
178  float dL = 0.;
179 
180  // track is crossing layer with angle such as:
181  // this factor should be taken in computation of eror projection
182  float cosCross = 0;
183 
184 
185  //
186  // compute crossing of stright track with inner layer
187  //
188  if (!innerIsBarrel) {
189  auto t = theA/(hitZ-theB); auto dt = std::abs(theThickness/(hitZ-theB));
190  crossing = theVtx + t*dHit;
191  rLayer = crossing.mag();
192  dLayer = t*dHitmag; dL = dt * dHitmag;
193  cosCross = std::abs( dHit.unit().dot(crossing.unit()));
194  } else {
195 
196  //
197  // compute crossing of track with layer
198  // dHit - from VTX to outer hit
199  // rLayer - layer radius
200  // dLayer - distance from VTX to inner layer in direction of dHit
201  // vect(rLayer) = vect(rVTX) + vect(dHit).unit * dLayer
202  // rLayer^2 = (vect(rVTX) + vect(dHit).unit * dLayer)^2 and we have square eqation for dLayer
203  //
204  // barrel case
205  //
206  auto vtxmag2 = theVtx.mag2();
207  if (vtxmag2 < 1.e-10f) {
208  dLayer = rLayer;
209  }
210  else {
211  // there are cancellation here....
212  double var_c = vtxmag2-sqr(rLayer);
213  double var_b = theVtx.dot(dHit.unit());
214  double var_delta = sqr(var_b)-var_c;
215  if (var_delta <=0.) var_delta = 0;
216  dLayer = -var_b + std::sqrt(var_delta); //only the value along vector is OK.
217  }
218  crossing = theVtx+ dHit.unit() * dLayer;
219  cosCross = std::abs( dHit.unit().dot(crossing.unit()));
220  dL = theThickness/cosCross;
221  }
222 
223 #ifdef USE_VECTORS_HERE
224  cms_float32x4_t num{dHitmag,dLayer,theROrigin * (dHitmag-dLayer),1.f};
225  cms_float32x4_t den{2*theRCurvature,2*theRCurvature,dHitmag*dLayer,1.f};
226  auto phis = f_asin07f(num/den);
227  phis = phis*dLayer/(rLayer*cosCross);
228  auto deltaPhi = std::abs(phis[0]-phis[1]);
229  auto deltaPhiOrig = phis[2];
230 #else
231 #warning no vector!
232  auto alphaHit = cropped_asin( dHitmag/(2*theRCurvature));
233  auto OdeltaPhi = std::abs( alphaHit - cropped_asin( dLayer/(2*theRCurvature)));
234  OdeltaPhi *= dLayer/(rLayer*cosCross);
235  // compute additional delta phi due to origin radius
236  auto OdeltaPhiOrig = cropped_asin( theROrigin * (dHitmag-dLayer) / (dHitmag*dLayer));
237  OdeltaPhiOrig *= dLayer/(rLayer*cosCross);
238  // std::cout << "dphi " << OdeltaPhi<<'/'<<OdeltaPhiOrig << ' ' << deltaPhi<<'/'<<deltaPhiOrig << std::endl;
239 
240  auto deltaPhi = OdeltaPhi;
241  auto deltaPhiOrig = OdeltaPhiOrig;
242 #endif
243 
244  // additinal angle due to not perpendicular stright line crossing (for displaced beam)
245  // double dPhiCrossing = (cosCross > 0.9999) ? 0 : dL * sqrt(1-sqr(cosCross))/ rLayer;
246  Point2D crossing2 = theVtx + dHit.unit()* (dLayer+dL);
247  auto phicross2 = f_phi(crossing2);
248  auto phicross1 = f_phi(crossing);
249  auto dphicross = phicross2-phicross1;
250  if (dphicross < -float(M_PI)) dphicross += float(2*M_PI);
251  if (dphicross > float(M_PI)) dphicross -= float(2*M_PI);
252  if (dphicross > float(M_PI/2)) dphicross = 0.; // something wrong?
253  phicross2 = phicross1 + dphicross;
254 
255 
256 
257  // inner hit error taken as constant
258  auto deltaPhiHit = theExtraTolerance / rLayer;
259 
260  // outer hit error
261  // double deltaPhiHitOuter = errRPhi/rLayer;
262  auto deltaPhiHitOuter = errRPhi/hitXY.mag();
263 
264  auto margin = deltaPhi+deltaPhiOrig+deltaPhiHit+deltaPhiHitOuter ;
265 
266  if (thePrecise) {
267  // add multiple scattering correction
268 
269  /*
270  PixelRecoPointRZ zero(0., theVtxZ);
271  PixelRecoPointRZ point(hitXY.mag(), hitZ);
272  auto scatt = 3.f*sigma(thePtMin,zero, point, ol);
273  */
274 
275  auto w = outerIsBarrel ? std::abs(hitZ) : hitXY.mag();
276  auto nscatt = theScatt0 + theDeltaScatt*w;
277 
278  // std::cout << "scatt " << (outerIsBarrel ? "B" : "F") << (innerIsBarrel ? "B " : "F ")
279  // << scatt << ' ' << nscatt << ' ' << nscatt/scatt << std::endl;
280 
281  margin += nscatt/ rLayer ;
282  }
283 
284  return PixelRecoRange<float>( std::min(phicross1,phicross2)-margin,
285  std::max(phicross1,phicross2)+margin);
286 }
287 
288 
289 
290 
float dt
Definition: AMPTWrapper.h:126
virtual float length() const =0
const double w
Definition: UKUtility.cc:23
void initBarrelMS(const DetLayer &outLayer)
bool isBarrel(GeomDetEnumerators::SubDetector m)
T dot(const Basic2DVector &lh) const
Scalar product, or "dot" product, with a vector of same type.
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
const Bounds & bounds() const
Definition: Surface.h:120
virtual const BoundCylinder & specificSurface() const final
Extension of the interface.
PixelRecoRange< float > phiRange(const Point2D &hitXY, float zHit, float errRPhi) const
Point2D theVtx
Definition: InnerDeltaPhi.h:61
Basic2DVector unit() const
float theDeltaScatt
Definition: InnerDeltaPhi.h:51
T sqrt(T t)
Definition: SSEVec.h:18
T z() const
Definition: PV3DBase.h:64
Double_t margin
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual const BoundSurface & surface() const =0
The surface of the GeometricSearchDet.
double f[11][100]
T min(T a, T b)
Definition: MathUtil.h:58
float originZBound() const
bounds the particle vertex in the longitudinal plane
int nt
Definition: AMPTWrapper.h:32
#define M_PI
virtual const BoundDisk & specificSurface() const final
void initForwardMS(const DetLayer &outLayer)
float theThickness
Definition: InnerDeltaPhi.h:49
virtual float thickness() const =0
virtual const Surface::PositionType & position() const
Returns position of the surface.
void initBarrelLayer(const DetLayer &layer)
float theRCurvature
Definition: InnerDeltaPhi.h:53
void initForwardLayer(const DetLayer &layer, float zMinOrigin, float zMaxOrigin)
T bendingRadius(T pt, const edm::EventSetup &iSetup)
Square< F >::type sqr(const F &f)
Definition: Square.h:13
InnerDeltaPhi(const DetLayer &outlayer, const DetLayer &layer, const TrackingRegion &region, const edm::EventSetup &iSetup, bool precise=true, float extraTolerance=0.f)
float theExtraTolerance
Definition: InnerDeltaPhi.h:54
long double T
MultipleScatteringParametrisation sigma
Definition: InnerDeltaPhi.h:64