CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
StraightTrajectory.cc
Go to the documentation of this file.
3 
7 
9  bool onLayer) const {
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  return -1;
37  }
38  double sqrtDelta = sqrt(delta);
39 
40  //
41  // return the earliest solution > 0,
42  // return -1 if no positive solution exists
43  // note: 'a' always positive, sqrtDelta always positive
44  //
45  double tc1 = (-b - sqrtDelta) / a * momentum_.E();
46  double tc2 = (-b + sqrtDelta) / a * momentum_.E();
47 
48  if (onLayer && tc2 > 0) {
49  bool particleMovesInwards = momentum_.X() * position_.X() + momentum_.Y() * position_.Y() < 0;
50 
51  double posX2 = position_.X() + momentum_.X() / momentum_.E() * tc2;
52  double posY2 = position_.Y() + momentum_.Y() / momentum_.E() * tc2;
53  bool particleMovesInwards2 = momentum_.X() * posX2 + momentum_.Y() * posY2 < 0;
54 
55  if (particleMovesInwards != particleMovesInwards2) {
56  return tc2;
57  }
58 
59  return -1;
60  }
61 
62  if (tc1 > 0) {
63  return tc1;
64  } else if (tc2 > 0) {
65  return tc2;
66  }
67 
68  return -1.;
69 }
70 
71 void fastsim::StraightTrajectory::move(double deltaTimeC) {
72  position_.SetXYZT(position_.X() + momentum_.X() / momentum_.E() * deltaTimeC,
73  position_.Y() + momentum_.Y() / momentum_.E() * deltaTimeC,
74  position_.Z() + momentum_.Z() / momentum_.E() * deltaTimeC,
75  position_.T() + deltaTimeC / fastsim::Constants::speedOfLight);
76 }
const edm::EventSetup & c
Implementation of a barrel detector layer (cylindrical).
static double constexpr speedOfLight
Speed of light [cm / ns].
Definition: Constants.h:12
constexpr std::array< uint8_t, layerIndexSize > layer
math::XYZTLorentzVector position_
position of the particle that was used to create trajectory
Definition: Trajectory.h:91
T sqrt(T t)
Definition: SSEVec.h:19
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119
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:92
void move(double deltaTimeC) override
Move the particle along the helix trajectory for a given time.