CMS 3D CMS Logo

StraightTrajectory.cc
Go to the documentation of this file.
3 
7 
9 {
10  //
11  // solve the equation
12  // (x^2 + y^2 = R^2), (1)
13  // x = x_0 + v_x*t, (2)
14  // y = y_0 + v_y*t (3)
15  // for t
16  //
17  // subsitute (2) and (3) in (1):
18  // => t^2*(v_x^2 + v_y^2) + t*( 2*x_0*v_x + 2*y_0*v_y ) + x_0^2 + y_0^2 - R^2 = 0
19  // => t = (-b +/- sqrt(b^2 - ac) ) / a see https://en.wikipedia.org/wiki/Quadratic_formula, divide equation by 2
20  // with a = v_x^2 + v_y^2;
21  // with b = x_0*v_x + y_0*v_y
22  // with c = x_0^2 + y_0^2 - R^2
23  //
24  // substitute: v_x = p_x / E * c ( note: extra * c absorbed in p_x units)
25  // substitute: v_y = p_y / E * c ( note: extra * c absorbed in p_y units)
26  // => t*c = (-b +/- sqrt(b^2 - ac) ) / a * E
27  // with a = p_x^2 + p_y^2
28  // with b = p_x*x_0 + p_y*y_0
29  // with c = x_0^2 + y_0^2 - R^2
30  double a = momentum_.Perp2();
31  double b = (position_.X()*momentum_.X() + position_.Y()*momentum_.Y() );
32  double c = position_.Perp2() - layer.getRadius()*layer.getRadius();
33 
34  double delta = b*b - a*c;
35  if(delta < 0)
36  {
37  return -1;
38  }
39  double sqrtDelta = sqrt(delta);
40 
41  //
42  // return the earliest solution > 0,
43  // return -1 if no positive solution exists
44  // note: 'a' always positive, sqrtDelta always positive
45  //
46  double tc1 = (-b - sqrtDelta)/a*momentum_.E();
47  double tc2 = (-b + sqrtDelta)/a*momentum_.E();
48 
49  if(onLayer && tc2 > 0)
50  {
51  bool particleMovesInwards = momentum_.X()*position_.X() + momentum_.Y()*position_.Y() < 0;
52 
53  double posX2 = position_.X() + momentum_.X()/momentum_.E()*tc2;
54  double posY2 = position_.Y() + momentum_.Y()/momentum_.E()*tc2;
55  bool particleMovesInwards2 = momentum_.X()*posX2 + momentum_.Y()*posY2 < 0;
56 
57  if(particleMovesInwards != particleMovesInwards2)
58  {
59  return tc2;
60  }
61 
62  return -1;
63 
64  }
65 
66  if(tc1 > 0)
67  {
68  return tc1;
69  }
70  else if(tc2 > 0)
71  {
72  return tc2;
73  }
74 
75  return -1.;
76 
77 
78 
79 }
80 
81 void fastsim::StraightTrajectory::move(double deltaTimeC)
82 {
83  position_.SetXYZT(
84  position_.X() + momentum_.X()/momentum_.E()*deltaTimeC,
85  position_.Y() + momentum_.Y()/momentum_.E()*deltaTimeC,
86  position_.Z() + momentum_.Z()/momentum_.E()*deltaTimeC,
87  position_.T() + deltaTimeC / fastsim::Constants::speedOfLight);
88 }
dbl * delta
Definition: mlp_gen.cc:36
Implementation of a barrel detector layer (cylindrical).
static double constexpr speedOfLight
Speed of light [cm / ns].
Definition: Constants.h:16
math::XYZTLorentzVector position_
position of the particle that was used to create trajectory
Definition: Trajectory.h:95
T sqrt(T t)
Definition: SSEVec.h:18
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
double nextCrossingTimeC(const BarrelSimplifiedGeometry &layer, bool onLayer=false) const override
Return delta time (t*c) of the next intersection of trajectory and barrel layer.
const double getRadius() const
Return radius of the barrel layer.
math::XYZTLorentzVector momentum_
momentum of the particle that was used to create trajectory
Definition: Trajectory.h:96
void move(double deltaTimeC) override
Move the particle along the helix trajectory for a given time.