test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 namespace {
83  inline double checked_asin(double x, const char *expr, const char *file, int line) {
84  if (fabs(x) >= 1.0) throw cms::Exception("CorruptData") << "asin(x) called with x = " << expr << " = " << x << "\n\tat " << file << ":" << line << "\n";
85  return asin(x);
86  }
87 }
88 
89 //#define asin(X) checked_asin(X, #X, __FILE__, __LINE__)
90 
91 InnerDeltaPhi:: InnerDeltaPhi( const DetLayer& outlayer, const DetLayer& layer,
92  const TrackingRegion & region,
93  const edm::EventSetup& iSetup,
94  bool precise, float extraTolerance) :
95  innerIsBarrel(layer.isBarrel()),
96  outerIsBarrel(outlayer.isBarrel()),
97  thePrecise(precise),
98  ol( outlayer.seqNum()),
99  theROrigin(region.originRBound()),
100  theRLayer(0),
101  theThickness(0),
102  theExtraTolerance(extraTolerance),
103  theA(0),
104  theB(0),
105  theVtxZ(region.origin().z()),
106  thePtMin(region.ptMin()),
107  theVtx(region.origin().x(),region.origin().y()),
108  sigma(&layer,iSetup)
109 
110 {
111  float zMinOrigin = theVtxZ-region.originZBound();
112  float zMaxOrigin = theVtxZ+region.originZBound();
114 
115 
116  if (innerIsBarrel) initBarrelLayer( layer);
117  else initForwardLayer( layer, zMinOrigin, zMaxOrigin);
118 
119  if(outerIsBarrel) initBarrelMS(outlayer);
120  else initForwardMS(outlayer);
121 
122 }
123 
124 
125 void InnerDeltaPhi::initBarrelMS(const DetLayer& outLayer) {
126  const BarrelDetLayer& bl = static_cast<const BarrelDetLayer&>(outLayer);
127  float rLayer = bl.specificSurface().radius();
128  auto zmax = 0.5f*outLayer.surface().bounds().length();
129  PixelRecoPointRZ zero(0., 0.);
130  PixelRecoPointRZ point1(rLayer, 0.);
131  PixelRecoPointRZ point2(rLayer, zmax);
132  auto scatt1 = 3.f*sigma(thePtMin,zero, point1, ol);
133  auto scatt2 = 3.f*sigma(thePtMin,zero, point2, ol);
134  theDeltaScatt = (scatt2-scatt1)/zmax;
135  theScatt0 = scatt1;
136 }
137 
138 void InnerDeltaPhi::initForwardMS(const DetLayer& outLayer) {
139  const ForwardDetLayer &fl = static_cast<const ForwardDetLayer&>(outLayer);
140  auto minR = fl.specificSurface().innerRadius();
141  auto maxR = fl.specificSurface().outerRadius();
142  auto layerZ = outLayer.position().z();
143  // compute min and max multiple scattering correction
144  PixelRecoPointRZ zero(0., theVtxZ);
145  PixelRecoPointRZ point1(minR, layerZ);
146  PixelRecoPointRZ point2(maxR, layerZ);
147  auto scatt1 = 3.f*sigma(thePtMin,zero, point1, ol);
148  auto scatt2 = 3.f*sigma(thePtMin,zero, point2, ol);
149  theDeltaScatt = (scatt2-scatt1)/(maxR-minR);
150  theScatt0 = scatt1 - theDeltaScatt*minR;
151 }
152 
153 
154 
156 {
157  const BarrelDetLayer& bl = static_cast<const BarrelDetLayer&>(layer);
158  float rLayer = bl.specificSurface().radius();
159 
160  // the maximal delta phi will be for the innermost hits
161  theThickness = layer.surface().bounds().thickness();
162  theRLayer = rLayer - 0.5f*theThickness;
163 }
164 
166  float zMinOrigin, float zMaxOrigin)
167 {
168  const ForwardDetLayer &fl = static_cast<const ForwardDetLayer&>(layer);
169  theRLayer = fl.specificSurface().innerRadius();
170  float layerZ = layer.position().z();
171  theThickness = layer.surface().bounds().thickness();
172  float layerZmin = layerZ > 0 ? layerZ-0.5f*theThickness: layerZ+0.5f*theThickness;
173  theB = layerZ > 0 ? zMaxOrigin : zMinOrigin;
174  theA = layerZmin - theB;
175 }
176 
177 
178 
179 PixelRecoRange<float> InnerDeltaPhi::phiRange(const Point2D& hitXY,float hitZ,float errRPhi) const
180 {
181  float rLayer = theRLayer;
182  Point2D crossing;
183 
184  Point2D dHit = hitXY-theVtx;
185  auto dHitmag = dHit.mag();
186  float dLayer = 0.;
187  float dL = 0.;
188 
189  // track is crossing layer with angle such as:
190  // this factor should be taken in computation of eror projection
191  float cosCross = 0;
192 
193 
194  //
195  // compute crossing of stright track with inner layer
196  //
197  if (!innerIsBarrel) {
198  auto t = theA/(hitZ-theB); auto dt = std::abs(theThickness/(hitZ-theB));
199  crossing = theVtx + t*dHit;
200  rLayer = crossing.mag();
201  dLayer = t*dHitmag; dL = dt * dHitmag;
202  cosCross = std::abs( dHit.unit().dot(crossing.unit()));
203  } else {
204 
205  //
206  // compute crossing of track with layer
207  // dHit - from VTX to outer hit
208  // rLayer - layer radius
209  // dLayer - distance from VTX to inner layer in direction of dHit
210  // vect(rLayer) = vect(rVTX) + vect(dHit).unit * dLayer
211  // rLayer^2 = (vect(rVTX) + vect(dHit).unit * dLayer)^2 and we have square eqation for dLayer
212  //
213  // barrel case
214  //
215  auto vtxmag2 = theVtx.mag2();
216  if (vtxmag2 < 1.e-10f) {
217  dLayer = rLayer;
218  }
219  else {
220  // there are cancellation here....
221  double var_c = vtxmag2-sqr(rLayer);
222  double var_b = theVtx.dot(dHit.unit());
223  double var_delta = sqr(var_b)-var_c;
224  if (var_delta <=0.) var_delta = 0;
225  dLayer = -var_b + std::sqrt(var_delta); //only the value along vector is OK.
226  }
227  crossing = theVtx+ dHit.unit() * dLayer;
228  cosCross = std::abs( dHit.unit().dot(crossing.unit()));
229  dL = theThickness/cosCross;
230  }
231 
232 #ifdef USE_VECTORS_HERE
233  float32x4_t num{dHitmag,dLayer,theROrigin * (dHitmag-dLayer),1.f};
234  float32x4_t den{2*theRCurvature,2*theRCurvature,dHitmag*dLayer,1.f};
235  auto phis = f_asin07f(num/den);
236  phis = phis*dLayer/(rLayer*cosCross);
237  auto deltaPhi = std::abs(phis[0]-phis[1]);
238  auto deltaPhiOrig = phis[2];
239 #else
240 #warning no vector!
241  auto alphaHit = cropped_asin( dHitmag/(2*theRCurvature));
242  auto OdeltaPhi = std::abs( alphaHit - cropped_asin( dLayer/(2*theRCurvature)));
243  OdeltaPhi *= dLayer/(rLayer*cosCross);
244  // compute additional delta phi due to origin radius
245  auto OdeltaPhiOrig = cropped_asin( theROrigin * (dHitmag-dLayer) / (dHitmag*dLayer));
246  OdeltaPhiOrig *= dLayer/(rLayer*cosCross);
247  // std::cout << "dphi " << OdeltaPhi<<'/'<<OdeltaPhiOrig << ' ' << deltaPhi<<'/'<<deltaPhiOrig << std::endl;
248 
249  auto deltaPhi = OdeltaPhi;
250  auto deltaPhiOrig = OdeltaPhiOrig;
251 #endif
252 
253  // additinal angle due to not perpendicular stright line crossing (for displaced beam)
254  // double dPhiCrossing = (cosCross > 0.9999) ? 0 : dL * sqrt(1-sqr(cosCross))/ rLayer;
255  Point2D crossing2 = theVtx + dHit.unit()* (dLayer+dL);
256  auto phicross2 = f_phi(crossing2);
257  auto phicross1 = f_phi(crossing);
258  auto dphicross = phicross2-phicross1;
259  if (dphicross < -float(M_PI)) dphicross += float(2*M_PI);
260  if (dphicross > float(M_PI)) dphicross -= float(2*M_PI);
261  if (dphicross > float(M_PI/2)) dphicross = 0.; // something wrong?
262  phicross2 = phicross1 + dphicross;
263 
264 
265 
266  // inner hit error taken as constant
267  auto deltaPhiHit = theExtraTolerance / rLayer;
268 
269  // outer hit error
270  // double deltaPhiHitOuter = errRPhi/rLayer;
271  auto deltaPhiHitOuter = errRPhi/hitXY.mag();
272 
273  auto margin = deltaPhi+deltaPhiOrig+deltaPhiHit+deltaPhiHitOuter ;
274 
275  if (thePrecise) {
276  // add multiple scattering correction
277 
278  /*
279  PixelRecoPointRZ zero(0., theVtxZ);
280  PixelRecoPointRZ point(hitXY.mag(), hitZ);
281  auto scatt = 3.f*sigma(thePtMin,zero, point, ol);
282  */
283 
284  auto w = outerIsBarrel ? std::abs(hitZ) : hitXY.mag();
285  auto nscatt = theScatt0 + theDeltaScatt*w;
286 
287  // std::cout << "scatt " << (outerIsBarrel ? "B" : "F") << (innerIsBarrel ? "B " : "F ")
288  // << scatt << ' ' << nscatt << ' ' << nscatt/scatt << std::endl;
289 
290  margin += nscatt/ rLayer ;
291  }
292 
293  return PixelRecoRange<float>( std::min(phicross1,phicross2)-margin,
294  std::max(phicross1,phicross2)+margin);
295 }
296 
297 
298 
299 
float dt
Definition: AMPTWrapper.h:126
virtual const BoundSurface & surface() const =0
The surface of the GeometricSearchDet.
tuple ret
prodAgent to be discontinued
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 &quot;dot&quot; 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
PixelRecoRange< float > phiRange(const Point2D &hitXY, float zHit, float errRPhi) const
Point2D theVtx
Definition: InnerDeltaPhi.h:61
Basic2DVector unit() const
virtual float thickness() const =0
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
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
void initForwardMS(const DetLayer &outLayer)
float theThickness
Definition: InnerDeltaPhi.h:49
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)
virtual const BoundCylinder & specificSurface() const final
Extension of the interface.
T bendingRadius(T pt, const edm::EventSetup &iSetup)
Square< F >::type sqr(const F &f)
Definition: Square.h:13
virtual const BoundDisk & specificSurface() const final
InnerDeltaPhi(const DetLayer &outlayer, const DetLayer &layer, const TrackingRegion &region, const edm::EventSetup &iSetup, bool precise=true, float extraTolerance=0.f)
tuple cout
Definition: gather_cfg.py:145
float theExtraTolerance
Definition: InnerDeltaPhi.h:54
long double T
MultipleScatteringParametrisation sigma
Definition: InnerDeltaPhi.h:64