CMS 3D CMS Logo

RKPropagatorInS.cc
Go to the documentation of this file.
2 #include "RKCartesianDistance.h"
4 #include "RKLocalFieldProvider.h"
7 #include "RKAdaptiveSolver.h"
8 #include "RKOne4OrderStep.h"
9 #include "RKOneCashKarpStep.h"
10 #include "PathToPlane2Order.h"
11 #include "CartesianStateAdaptor.h"
16 #include "FrameChanger.h"
21 
24 
25 
26 std::pair<TrajectoryStateOnSurface,double>
28  const Plane& plane) const
29 {
31  if unlikely(!gp) return TsosWP(TrajectoryStateOnSurface(),0.);
32 
35  return analyticalErrorPropagation( fts, plane, side, gp.parameters(),gp.s());
36 }
37 
38 std::pair< TrajectoryStateOnSurface, double>
40 {
42  if unlikely(!gp) return TsosWP(TrajectoryStateOnSurface(),0.);
43 
46  return analyticalErrorPropagation( fts, cyl, side, gp.parameters(),gp.s());
47 
48 }
49 
52  const Plane& plane) const
53 {
54 
55  GlobalPoint gpos( ts.position());
56  GlobalVector gmom( ts.momentum());
57  double startZ = plane.localZ(gpos);
58  // (transverse) curvature
59  double rho = ts.transverseCurvature();
60  //
61  // Straight line approximation? |rho|<1.e-10 equivalent to ~ 1um
62  // difference in transversal position at 10m.
63  //
64  if unlikely( fabs(rho)<1.e-10 ) {
65  //
66  // Instantiate auxiliary object for finding intersection.
67  // Frame-independant point and vector are created explicitely to
68  // avoid confusing gcc (refuses to compile with temporary objects
69  // in the constructor).
70  //
71  LogDebug("RKPropagatorInS")<<" startZ = "<<startZ;
72 
73  if unlikely(fabs(startZ) < 1e-5){
74  LogDebug("RKPropagatorInS")<< "Propagation is not performed: state is already on final surface.";
75  GlobalTrajectoryParameters res( gpos, gmom, ts.charge(),
76  theVolume);
77  return GlobalParametersWithPath( res, 0.0);
78  }
79 
82  StraightLinePlaneCrossing planeCrossing(pos,dir, propagationDirection());
83  //
84  // get solution
85  //
86  std::pair<bool,double> propResult = planeCrossing.pathLength(plane);
87  if likely( propResult.first && theVolume !=nullptr) {
88  double s = propResult.second;
89  // point (reconverted to GlobalPoint)
90  GlobalPoint x (planeCrossing.position(s));
92  return GlobalParametersWithPath( res, s);
93  }
94  //do someting
95  LogDebug("RKPropagatorInS")<< "Straight line propgation to plane failed !!";
96  return GlobalParametersWithPath( );
97 
98  }
99 
100 
101 #ifdef EDM_ML_DEBUG
102  if (theVolume != 0) {
103  LogDebug("RKPropagatorInS") << "RKPropagatorInS: starting prop to plane in volume with pos " << theVolume->position()
104  << " Z axis " << theVolume->toGlobal( LocalVector(0,0,1)) ;
105 
106  LogDebug("RKPropagatorInS") << "The starting position is " << ts.position() << " (global) "
107  << theVolume->toLocal(ts.position()) << " (local) " ;
108 
109  FrameChanger changer;
110  auto localPlane = changer.transformPlane( plane, *theVolume);
111  LogDebug("RKPropagatorInS") << "The plane position is " << plane.position() << " (global) "
112  << localPlane.position() << " (local) " ;
113 
114  LogDebug("RKPropagatorInS") << "The initial distance to plane is " << plane.localZ( ts.position()) ;
115 
117  std::pair<bool,double> res3 = cross.pathLength(plane);
118  LogDebug("RKPropagatorInS") << "straight line distance " << res3.first << " " << res3.second ;
119  }
120 #endif
121 
123  typedef Solver::Vector RKVector;
124 
126  PathToPlane2Order pathLength( field, &field.frame());
127  CartesianLorentzForce deriv(field, ts.charge());
128 
129  RKCartesianDistance dist;
130  double eps = theTolerance;
131  Solver solver;
132  double stot = 0;
133  PropagationDirection currentDirection = propagationDirection();
134 
135  // in magVolume frame
136  RKVector start( CartesianStateAdaptor::rkstate( rkPosition(gpos), rkMomentum(gmom)));
137  int safeGuard = 0;
138  while (safeGuard++<100) {
139  CartesianStateAdaptor startState(start);
140 
141  std::pair<bool,double> path = pathLength( plane, startState.position(),
142  startState.momentum(),
143  (double) ts.charge(), currentDirection);
144  if unlikely(!path.first) {
145  LogDebug("RKPropagatorInS") << "RKPropagatorInS: Path length calculation to plane failed!"
146  << "...distance to plane " << plane.localZ( globalPosition(startState.position()))
147  << "...Local starting position in volume " << startState.position()
148  << "...Magnetic field " << field.inTesla( startState.position()) ;
149 
150 
151  return GlobalParametersWithPath();
152  }
153 
154  LogDebug("RKPropagatorInS") << "RKPropagatorInS: Path lenght to plane is " << path.second ;
155 
156 
157  double sstep = path.second;
158  if unlikely( std::abs(sstep) < eps) {
159  LogDebug("RKPropagatorInS") << "On-surface accuracy not reached, but pathLength calculation says we are there! "
160  << "path " << path.second << " distance to plane is " << startZ ;
162  return GlobalParametersWithPath( res, stot);
163  }
164 
165  LogDebug("RKPropagatorInS") << "RKPropagatorInS: Solving for " << sstep
166  << " current distance to plane is " << startZ ;
167 
168  RKVector rkresult = solver( 0, start, sstep, deriv, dist, eps);
169  stot += sstep;
170  CartesianStateAdaptor cur( rkresult);
171  double remainingZ = plane.localZ( globalPosition(cur.position()));
172 
173  if ( fabs(remainingZ) < eps) {
174  LogDebug("RKPropagatorInS") << "On-surface accuracy reached! " << remainingZ ;
176  return GlobalParametersWithPath( res, stot);
177  }
178 
179  start = rkresult;
180 
181  if (remainingZ * startZ > 0) {
182  LogDebug("RKPropagatorInS") << "Accuracy not reached yet, trying in same direction again "
183  << remainingZ ;
184  }
185  else {
186  LogDebug("RKPropagatorInS") << "Accuracy not reached yet, trying in opposite direction "
187  << remainingZ ;
188  currentDirection = invertDirection( currentDirection);
189  }
190  startZ = remainingZ;
191  }
192 
193  edm::LogError("FailedPropagation") << " too many iterations trying to reach plane ";
194  return GlobalParametersWithPath();
195 }
196 
199  const Cylinder& cyl) const {
200 
202  typedef Solver::Vector RKVector;
203 
204 
205  const GlobalPoint& sp = cyl.position();
206  if unlikely(sp.x()!=0. || sp.y()!=0.) {
207  throw PropagationException("Cannot propagate to an arbitrary cylinder");
208  }
209 
210  GlobalPoint gpos( ts.position());
211  GlobalVector gmom( ts.momentum());
212  LocalPoint pos(cyl.toLocal(gpos));
213  LocalVector mom(cyl.toLocal(gmom));
214  double startR = cyl.radius() - pos.perp();
215 
216  // LogDebug("RKPropagatorInS") << "RKPropagatorInS: starting from FTS " << ts ;
217 
218 
219  // (transverse) curvature
220  double rho = ts.transverseCurvature();
221  //
222  // Straight line approximation? |rho|<1.e-10 equivalent to ~ 1um
223  // difference in transversal position at 10m.
224  //
225  if unlikely( fabs(rho)<1.e-10 ) {
226  //
227  // Instantiate auxiliary object for finding intersection.
228  // Frame-independant point and vector are created explicitely to
229  // avoid confusing gcc (refuses to compile with temporary objects
230  // in the constructor).
231  //
232 
234 
235  //
236  // get solution
237  //
238  std::pair<bool,double> propResult = cylCrossing.pathLength(cyl);
239  if likely( propResult.first && theVolume !=nullptr) {
240  double s = propResult.second;
241  // point (reconverted to GlobalPoint)
242  GlobalPoint x (cylCrossing.position(s));
244  LogDebug("RKPropagatorInS") << "Straight line propagation to cylinder succeeded !!";
245  return GlobalParametersWithPath( res, s);
246  }
247 
248  //do someting
249  edm::LogError("RKPropagatorInS") <<"Straight line propagation to cylinder failed !!";
250  return GlobalParametersWithPath( );
251 
252  }
253 
254 
255  RKLocalFieldProvider field( fieldProvider(cyl));
256  // StraightLineCylinderCrossing pathLength( pos, mom, propagationDirection());
257  CartesianLorentzForce deriv(field, ts.charge());
258 
259  RKCartesianDistance dist;
260  double eps = theTolerance;
261  Solver solver;
262  double stot = 0;
263  PropagationDirection currentDirection = propagationDirection();
264 
265  RKVector start( CartesianStateAdaptor::rkstate( pos.basicVector(), mom.basicVector()));
266  int safeGuard = 0;
267  while (safeGuard++<100) {
268  CartesianStateAdaptor startState(start);
269  StraightLineCylinderCrossing pathLength( LocalPoint(startState.position()),
270  LocalVector(startState.momentum()),
271  currentDirection, eps);
272 
273  std::pair<bool,double> path = pathLength.pathLength( cyl);
274  if unlikely(!path.first) {
275  LogDebug("RKPropagatorInS") << "RKPropagatorInS: Path length calculation to cylinder failed!"
276  << "Radius " << cyl.radius() << " pos.perp() " << LocalPoint(startState.position()).perp() ;
277  return GlobalParametersWithPath();
278  }
279 
280  LogDebug("RKPropagatorInS") << "RKPropagatorInS: Path lenght to cylinder is " << path.second
281  << " from point (R,z) " << startState.position().perp()
282  << ", " << startState.position().z()
283  << " to R " << cyl.radius()
284  ;
285 
286 
287  double sstep = path.second;
288  if unlikely( std::abs(sstep) < eps) {
289  LogDebug("RKPropagatorInS") << "accuracy not reached, but pathLength calculation says we are there! "
290  << path.second ;
291 
293  startState.momentum(),
294  ts.charge(), cyl));
295  return GlobalParametersWithPath( res, stot);
296  }
297 
298  LogDebug("RKPropagatorInS") << "RKPropagatorInS: Solving for " << sstep
299  << " current distance to cylinder is " << startR ;
300 
301  RKVector rkresult = solver( 0, start, sstep, deriv, dist, eps);
302  stot += sstep;
303  CartesianStateAdaptor cur( rkresult);
304  double remainingR = cyl.radius() - cur.position().perp();
305 
306  if ( fabs(remainingR) < eps) {
307  LogDebug("RKPropagatorInS") << "Accuracy reached! " << remainingR ;
309  cur.momentum(),
310  ts.charge(), cyl));
311  return GlobalParametersWithPath( res, stot);
312  }
313 
314  start = rkresult;
315  if (remainingR * startR > 0) {
316  LogDebug("RKPropagatorInS") << "Accuracy not reached yet, trying in same direction again "
317  << remainingR ;
318  }
319  else {
320  LogDebug("RKPropagatorInS") << "Accuracy not reached yet, trying in opposite direction "
321  << remainingR ;
322  currentDirection = invertDirection( currentDirection);
323  }
324  startR = remainingR;
325  }
326 
327  edm::LogError("FailedPropagation") << " too many iterations trying to reach cylinder ";
328  return GlobalParametersWithPath();
329 }
330 
331 
333 {
334  return new RKPropagatorInS(*this);
335 }
336 
338  const Basic3DVector<float>& lmom,
339  TrackCharge ch, const Surface& surf) const
340 {
341  return GlobalTrajectoryParameters( surf.toGlobal( LocalPoint( lpos)),
342  surf.toGlobal( LocalVector( lmom)), ch, theVolume);
343 }
344 
346 {
348 }
349 
351 {
352  return RKLocalFieldProvider( *theVolume, cyl);
353 }
354 
356 {
357  if (dir == anyDirection) return dir;
358  return ( dir == alongMomentum ? oppositeToMomentum : alongMomentum);
359 }
360 
362 {
363  if (theVolume != nullptr) return theVolume->toLocal( pos).basicVector();
364  else return pos.basicVector();
365 }
366 
368 {
369  if (theVolume != nullptr) return theVolume->toLocal( mom).basicVector();
370  else return mom.basicVector();
371 }
372 
374 {
375  if (theVolume != nullptr) return theVolume->toGlobal( LocalPoint(pos));
376  else return GlobalPoint(pos);
377 }
378 
380 
381 {
382  if (theVolume != nullptr) return theVolume->toGlobal( LocalVector(mom));
383  else return GlobalVector(mom);
384 }
385 
388  TrackCharge charge) const
389 {
391  globalMomentum(state.momentum()),
392  charge, theVolume);
393 }
#define LogDebug(id)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:106
std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Plane &) const override
Local3DVector LocalVector
Definition: LocalVector.h:12
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:32
GlobalTrajectoryParameters gtpFromVolumeLocal(const CartesianStateAdaptor &state, TrackCharge charge) const
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:29
GlobalParametersWithPath propagateParametersOnCylinder(const FreeTrajectoryState &ts, const Cylinder &cyl) const
RKLocalFieldProvider fieldProvider() const
std::pair< bool, double > pathLength(const Cylinder &cyl) const
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
GlobalPoint globalPosition(const Basic3DVector< float > &pos) const
T y() const
Definition: PV3DBase.h:63
float localZ(const GlobalPoint &gp) const
Definition: Plane.h:45
PropagationDirection
const GlobalTrajectoryParameters & parameters() const
TrackCharge charge() const
Definition: Plane.h:17
Definition: Electron.h:4
#define unlikely(x)
#define likely(x)
int TrackCharge
Definition: TrackCharge.h:4
Basic3DVector< double > rkMomentum(const GlobalVector &mom) const
std::pair< TrajectoryStateOnSurface, double > TsosWP
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:151
Estimator of the distance between two state vectors, e.g. for convergence test.
Scalar radius() const
Radius of the cylinder.
Definition: Cylinder.h:67
T z() const
Cartesian z coordinate.
PropagationDirection invertDirection(PropagationDirection dir) const
LocalPoint toLocal(const GlobalPoint &gp) const
GlobalTrajectoryParameters gtpFromLocal(const Basic3DVector< float > &lpos, const Basic3DVector< float > &lmom, TrackCharge ch, const Surface &surf) const
Derivative calculation for the 6D cartesian case.
static RKSmallVector< double, 6 > rkstate(const Vector3D &pos, const Vector3D &mom)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const Vector3D & momentum() const
PositionType position(float s) const
const MagVolume * theVolume
T perp() const
Magnitude of transverse component.
Common base class.
GlobalVector momentum() const
std::pair< bool, double > pathLength(const Plane &plane) const
GlobalVector globalMomentum(const Basic3DVector< float > &mom) const
GlobalPoint toGlobal(const LocalPoint &lp) const
GlobalPoint position() const
const Frame & frame() const
The reference frame in which the field is defined.
static Plane transformPlane(const Plane &plane, const GloballyPositioned< T > &frame)
Definition: FrameChanger.h:15
double transverseCurvature() const
std::pair< TrajectoryStateOnSurface, double > analyticalErrorPropagation(const FreeTrajectoryState &startingState, const Surface &surface, SurfaceSideDefinition::SurfaceSide side, const GlobalTrajectoryParameters &destParameters, const double &s)
T perp() const
Magnitude of transverse component.
GlobalParametersWithPath propagateParametersOnPlane(const FreeTrajectoryState &ts, const Plane &plane) const
RKPropagatorInS(const MagVolume &vol, PropagationDirection dir=alongMomentum, double tolerance=5.e-5)
dbl *** dir
Definition: mlp_gen.cc:35
const Vector3D & position() const
std::pair< bool, double > pathLength(const Cylinder &cyl) const
T x() const
Definition: PV3DBase.h:62
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
const PositionType & position() const
Basic3DVector< double > rkPosition(const GlobalPoint &pos) const
Propagator * clone() const override
Global3DVector GlobalVector
Definition: GlobalVector.h:10
Vector inTesla(const LocalPoint &lp) const
the argument lp is in the local frame specified in the constructor
Basic3DVector cross(const Basic3DVector &v) const
Vector product, or "cross" product, with a vector of same type.