CMS 3D CMS Logo

HelixArbitraryPlaneCrossing.cc
Go to the documentation of this file.
4 
5 #include <cmath>
6 #include <vdt/vdtMath.h>
7 #include <iostream>
9 
10 #ifdef VI_DEBUG
11 #include <atomic>
12 struct MaxIter {
13  MaxIter() {}
14  ~MaxIter() { std::cout << "maxiter " << v << std::endl; }
15  void operator()(int i) const {
16  int old = v;
17  int t = std::min(old, i);
18  while (not v.compare_exchange_weak(old, t)) {
19  t = std::min(old, i);
20  }
21  }
22  mutable std::atomic<int> v{100};
23 };
24 #else
25 struct MaxIter {
26  MaxIter() {}
27  void operator()(int) const {}
28 };
29 #endif
30 static const MaxIter maxiter;
31 
33  const DirectionType& direction,
34  const float curvature,
35  const PropagationDirection propDir)
36  : theQuadraticCrossingFromStart(point, direction, curvature, propDir),
37  theX0(point.x()),
38  theY0(point.y()),
39  theZ0(point.z()),
40  theRho(curvature),
41  thePropDir(propDir),
42  theCachedS(0),
43  theCachedDPhi(0.),
44  theCachedSDPhi(0.),
45  theCachedCDPhi(1.) {
46  //
47  // Components of direction vector (with correct normalisation)
48  //
49  double px = direction.x();
50  double py = direction.y();
51  double pz = direction.z();
52  double pt2 = px * px + py * py;
53  double p2 = pt2 + pz * pz;
54  double pI = 1. / sqrt(p2);
55  double ptI = 1. / sqrt(pt2);
56  theCosPhi0 = px * ptI;
57  theSinPhi0 = py * ptI;
58  theCosTheta = pz * pI;
59  theSinTheta = pt2 * ptI * pI;
60 }
61 //
62 // Propagation status and path length to intersection
63 //
64 std::pair<bool, double> HelixArbitraryPlaneCrossing::pathLength(const Plane& plane) {
65  //
66  // Constants used for control of convergence
67  //
68  constexpr int maxIterations = 20;
69  //
70  // maximum distance to plane (taking into account numerical precision)
71  //
72  float maxNumDz = theNumericalPrecision * plane.position().mag();
73  float safeMaxDist = (theMaxDistToPlane > maxNumDz ? theMaxDistToPlane : maxNumDz);
74  //
75  // Prepare internal value of the propagation direction and position / direction vectors for iteration
76  //
77 
78  float dz = plane.localZ(Surface::GlobalPoint(theX0, theY0, theZ0));
79  if (std::abs(dz) < safeMaxDist)
80  return std::make_pair(true, 0.);
81 
82  bool notFail;
83  double dSTotal;
84  // Use existing 2nd order object at first pass
85  std::tie(notFail, dSTotal) = theQuadraticCrossingFromStart.pathLength(plane);
86  if
87  UNLIKELY(!notFail) return std::make_pair(notFail, dSTotal);
88  auto xnew = positionInDouble(dSTotal);
89 
90  auto propDir = thePropDir;
91  auto newDir = dSTotal >= 0 ? alongMomentum : oppositeToMomentum;
92  if (propDir == anyDirection) {
93  propDir = newDir;
94  } else {
95  if
96  UNLIKELY(newDir != propDir) return std::pair<bool, double>(false, 0);
97  }
98 
99  //
100  // Prepare iterations: count and total pathlength
101  //
102  auto iteration = maxIterations;
103  while (notAtSurface(plane, xnew, safeMaxDist)) {
104  //
105  // return empty solution vector if no convergence after maxIterations iterations
106  //
107  if
108  UNLIKELY(--iteration == 0) {
109  LogDebug("HelixArbitraryPlaneCrossing") << "pathLength : no convergence";
110  return std::pair<bool, double>(false, 0);
111  }
112 
113  //
114  // create temporary object for subsequent passes.
115  auto pnew = directionInDouble(dSTotal);
116  HelixArbitraryPlaneCrossing2Order quadraticCrossing(
117  xnew.x(), xnew.y(), xnew.z(), pnew.x(), pnew.y(), theCosTheta, theSinTheta, theRho, anyDirection);
118 
119  auto deltaS2 = quadraticCrossing.pathLength(plane);
120 
121  if
122  UNLIKELY(!deltaS2.first) return deltaS2;
123  //
124  // Calculate and sort total pathlength (max. 2 solutions)
125  //
126  dSTotal += deltaS2.second;
127  auto newDir = dSTotal >= 0 ? alongMomentum : oppositeToMomentum;
128  if (propDir == anyDirection) {
129  propDir = newDir;
130  } else {
131  if
132  UNLIKELY(newDir != propDir) return std::pair<bool, double>(false, 0);
133  }
134  //
135  // Step forward by dSTotal.
136  //
137  xnew = positionInDouble(dSTotal);
138  }
139  //
140  // Return result
141  //
143 
144  return std::make_pair(true, dSTotal);
145 }
146 //
147 // Position on helix after a step of path length s.
148 //
150  // use result in double precision
152  return PositionType(pos.x(), pos.y(), pos.z());
153 }
154 //
155 // Position on helix after a step of path length s in double precision.
156 //
158  //
159  // Calculate delta phi (if not already available)
160  //
161  if
162  UNLIKELY(s != theCachedS) {
163  theCachedS = s;
165  vdt::fast_sincos(theCachedDPhi, theCachedSDPhi, theCachedCDPhi);
166  }
167  //
168  // Calculate with appropriate formulation of full helix formula or with
169  // 2nd order approximation.
170  //
171  // if ( fabs(theCachedDPhi)>1.e-1 ) {
172  if (std::abs(theCachedDPhi) > 1.e-4) {
173  // "standard" helix formula
174  double o = 1. / theRho;
178  }
179  // else if ( fabs(theCachedDPhi)>theNumericalPrecision ) {
180  // // full helix formula, but avoiding (1-cos(deltaPhi)) for small angles
181  // return PositionTypeDouble(theX0+(-theSinPhi0*theCachedSDPhi*theCachedSDPhi/(1.+theCachedCDPhi)+
182  // theCosPhi0*theCachedSDPhi)/theRho,
183  // theY0+(theCosPhi0*theCachedSDPhi*theCachedSDPhi/(1.+theCachedCDPhi)+
184  // theSinPhi0*theCachedSDPhi)/theRho,
185  // theZ0+theCachedS*theCosTheta);
186  // }
187  else {
188  // Use 2nd order.
190  }
191 }
192 //
193 // Direction vector on helix after a step of path length s.
194 //
196  // use result in double precision
198  return DirectionType(dir.x(), dir.y(), dir.z());
199 }
200 //
201 // Direction vector on helix after a step of path length s in double precision.
202 //
204  //
205  // Calculate delta phi (if not already available)
206  //
207  if
208  UNLIKELY(s != theCachedS) { // very very unlikely!
209  theCachedS = s;
211  vdt::fast_sincos(theCachedDPhi, theCachedSDPhi, theCachedCDPhi);
212  }
213 
214  if (std::abs(theCachedDPhi) > 1.e-4) {
215  // full helix formula
219  } else {
220  // 2nd order
222  }
223 }
224 // Iteration control: continue if distance to plane > theMaxDistToPlane. Includes
225 // protection for numerical precision (Surfaces work with single precision).
227  const PositionTypeDouble& point,
228  const float maxDist) const {
229  float dz = plane.localZ(Surface::GlobalPoint(point.x(), point.y(), point.z()));
230  return std::abs(dz) > maxDist;
231 }
232 
Likely.h
anyDirection
Definition: PropagationDirection.h:4
mps_fire.i
i
Definition: mps_fire.py:428
HelixArbitraryPlaneCrossing::PositionTypeDouble
Basic3DVector< double > PositionTypeDouble
Definition: HelixArbitraryPlaneCrossing.h:37
MessageLogger.h
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
detailsBasic3DVector::z
float float float z
Definition: extBasic3DVector.h:14
min
T min(T a, T b)
Definition: MathUtil.h:58
MaxIter::operator()
void operator()(int) const
Definition: HelixArbitraryPlaneCrossing.cc:27
multPhiCorr_741_25nsDY_cfi.py
py
Definition: multPhiCorr_741_25nsDY_cfi.py:12
HelixPlaneCrossing::DirectionType
Basic3DVector< float > DirectionType
Definition: HelixPlaneCrossing.h:23
HelixArbitraryPlaneCrossing::theCachedSDPhi
double theCachedSDPhi
Definition: HelixArbitraryPlaneCrossing.h:65
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
oppositeToMomentum
Definition: PropagationDirection.h:4
HelixArbitraryPlaneCrossing::directionInDouble
DirectionTypeDouble directionInDouble(double s) const
Definition: HelixArbitraryPlaneCrossing.cc:203
findQualityFiles.v
v
Definition: findQualityFiles.py:179
PixelRecoUtilities::curvature
T curvature(T InversePt, const edm::EventSetup &iSetup)
Definition: PixelRecoUtilities.h:42
Basic3DVector::mag
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Definition: extBasic3DVector.h:116
HelixArbitraryPlaneCrossing::pathLength
std::pair< bool, double > pathLength(const Plane &plane) override
Definition: HelixArbitraryPlaneCrossing.cc:64
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:42
HelixArbitraryPlaneCrossing::theNumericalPrecision
static const float theNumericalPrecision
Definition: HelixArbitraryPlaneCrossing.h:68
HelixArbitraryPlaneCrossing::DirectionTypeDouble
Basic3DVector< double > DirectionTypeDouble
Definition: HelixArbitraryPlaneCrossing.h:38
Plane.h
UNLIKELY
#define UNLIKELY(x)
Definition: Likely.h:21
alignCSCRings.s
s
Definition: alignCSCRings.py:92
HelixArbitraryPlaneCrossing2Order::directionInDouble
DirectionTypeDouble directionInDouble(double s) const
Definition: HelixArbitraryPlaneCrossing2Order.cc:124
Basic3DVector::y
T y() const
Cartesian y coordinate.
Definition: extBasic3DVector.h:97
HelixArbitraryPlaneCrossing::theRho
const double theRho
Definition: HelixArbitraryPlaneCrossing.h:59
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
p2
double p2[4]
Definition: TauolaWrapper.h:90
Point3DBase< float, GlobalTag >
HelixArbitraryPlaneCrossing::theY0
const double theY0
Definition: HelixArbitraryPlaneCrossing.h:56
HelixArbitraryPlaneCrossing::position
PositionType position(double s) const override
Definition: HelixArbitraryPlaneCrossing.cc:149
HelixArbitraryPlaneCrossing::theCosTheta
double theCosTheta
Definition: HelixArbitraryPlaneCrossing.h:58
MaxIter::MaxIter
MaxIter()
Definition: HelixArbitraryPlaneCrossing.cc:26
HelixArbitraryPlaneCrossing::theMaxDistToPlane
static const float theMaxDistToPlane
Definition: HelixArbitraryPlaneCrossing.h:69
HelixArbitraryPlaneCrossing::HelixArbitraryPlaneCrossing
HelixArbitraryPlaneCrossing(const PositionType &point, const DirectionType &direction, const float curvature, const PropagationDirection propDir=alongMomentum)
Definition: HelixArbitraryPlaneCrossing.cc:32
HelixArbitraryPlaneCrossing::direction
DirectionType direction(double s) const override
Definition: HelixArbitraryPlaneCrossing.cc:195
HelixArbitraryPlaneCrossing::positionInDouble
PositionTypeDouble positionInDouble(double s) const
Definition: HelixArbitraryPlaneCrossing.cc:157
HelixArbitraryPlaneCrossing.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
HLT_FULL_cff.maxIterations
maxIterations
Definition: HLT_FULL_cff.py:13241
HelixArbitraryPlaneCrossing::theCachedCDPhi
double theCachedCDPhi
Definition: HelixArbitraryPlaneCrossing.h:66
HelixArbitraryPlaneCrossing::notAtSurface
bool notAtSurface(const Plane &, const PositionTypeDouble &, const float) const
Definition: HelixArbitraryPlaneCrossing.cc:226
Plane::localZ
float localZ(const GlobalPoint &gp) const
Definition: Plane.h:45
HelixArbitraryPlaneCrossing2Order::pathLength
std::pair< bool, double > pathLength(const Plane &) override
Definition: HelixArbitraryPlaneCrossing2Order.cc:35
HelixArbitraryPlaneCrossing::theX0
const double theX0
Definition: HelixArbitraryPlaneCrossing.h:56
maxiter
static const MaxIter maxiter
Definition: HelixArbitraryPlaneCrossing.cc:30
HelixArbitraryPlaneCrossing2Order::positionInDouble
PositionTypeDouble positionInDouble(double s) const
Definition: HelixArbitraryPlaneCrossing2Order.cc:105
HelixArbitraryPlaneCrossing::theCachedDPhi
double theCachedDPhi
Definition: HelixArbitraryPlaneCrossing.h:64
HLT_FULL_cff.pt2
pt2
Definition: HLT_FULL_cff.py:9872
HelixArbitraryPlaneCrossing::theSinPhi0
double theSinPhi0
Definition: HelixArbitraryPlaneCrossing.h:57
TtFullHadJetPartonMatch_cfi.maxDist
maxDist
Definition: TtFullHadJetPartonMatch_cfi.py:35
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
GloballyPositioned::position
const PositionType & position() const
Definition: GloballyPositioned.h:36
HelixArbitraryPlaneCrossing::theQuadraticCrossingFromStart
HelixArbitraryPlaneCrossing2Order theQuadraticCrossingFromStart
Definition: HelixArbitraryPlaneCrossing.h:54
PVValHelper::dz
Definition: PVValidationHelpers.h:51
HelixArbitraryPlaneCrossing::theCachedS
double theCachedS
Definition: HelixArbitraryPlaneCrossing.h:63
PropagationDirection
PropagationDirection
Definition: PropagationDirection.h:4
genVertex_cff.x
x
Definition: genVertex_cff.py:12
Plane
Definition: Plane.h:16
HelixArbitraryPlaneCrossing::theSinTheta
double theSinTheta
Definition: HelixArbitraryPlaneCrossing.h:58
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
Basic3DVector::x
T x() const
Cartesian x coordinate.
Definition: extBasic3DVector.h:94
HelixArbitraryPlaneCrossing::theCosPhi0
double theCosPhi0
Definition: HelixArbitraryPlaneCrossing.h:57
HelixArbitraryPlaneCrossing::theZ0
const double theZ0
Definition: HelixArbitraryPlaneCrossing.h:56
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HelixArbitraryPlaneCrossing::thePropDir
const PropagationDirection thePropDir
Definition: HelixArbitraryPlaneCrossing.h:61
point
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
MaxIter
Definition: HelixArbitraryPlaneCrossing.cc:25
align_cfg.iteration
iteration
Definition: align_cfg.py:5
Basic3DVector::z
T z() const
Cartesian z coordinate.
Definition: extBasic3DVector.h:100
HelixArbitraryPlaneCrossing2Order
Definition: HelixArbitraryPlaneCrossing2Order.h:10
alongMomentum
Definition: PropagationDirection.h:4
Basic3DVector< float >
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
HelixPlaneCrossing::PositionType
Basic3DVector< float > PositionType
the helix is passed to the constructor and does not appear in the interface
Definition: HelixPlaneCrossing.h:22