CMS 3D CMS Logo

CMSTMagFieldEquation.h
Go to the documentation of this file.
1 //
2 // copied from G4TMagFieldEquation
3 //
4 // Class description:
5 //
6 // Templated version of equation of motion of a particle in a pure magnetic field.
7 // Enables use of inlined code for field, equation, stepper, driver,
8 // avoiding all virtual calls.
9 //
10 // Adapted from G4Mag_UsualEqRhs.hh
11 // --------------------------------------------------------------------
12 // Created: Josh Xie (Google Summer of Code 2014 )
13 // Adapted from G4Mag_UsualEqRhs
14 //
15 // Modified by Vincenzo innocente 7/2022 to adapt to specific CMS field
16 //
17 #ifndef CMSTMAGFIELDEQUATION_H
18 #define CMSTMAGFIELDEQUATION_H
19 
20 #include "G4Mag_UsualEqRhs.hh"
21 #include <cassert>
22 
23 template <class T_Field>
24 class CMSTMagFieldEquation final : public G4Mag_UsualEqRhs {
25 public:
26  CMSTMagFieldEquation(T_Field* f) : G4Mag_UsualEqRhs(f) {
27  assert(f);
28  itsField = f;
29  }
30 
31  ~CMSTMagFieldEquation() override { ; }
32 
33  inline void GetFieldValueCMS(const G4double Point[], G4double Field[]) const {
34  itsField->GetFieldValue(Point, Field);
35  }
36 
37  inline void TEvaluateRhsGivenB(const G4double y[],
38  G4double inv_momentum_magnitude,
39  const G4double B[3],
40  G4double dydx[]) const {
41  G4double cof = FCof() * inv_momentum_magnitude;
42 
43  dydx[0] = y[3] * inv_momentum_magnitude; // (d/ds)x = Vx/V
44  dydx[1] = y[4] * inv_momentum_magnitude; // (d/ds)y = Vy/V
45  dydx[2] = y[5] * inv_momentum_magnitude; // (d/ds)z = Vz/V
46 
47  dydx[3] = cof * (y[4] * B[2] - y[5] * B[1]); // Ax = a*(Vy*Bz - Vz*By)
48  dydx[4] = cof * (y[5] * B[0] - y[3] * B[2]); // Ay = a*(Vz*Bx - Vx*Bz)
49  dydx[5] = cof * (y[3] * B[1] - y[4] * B[0]); // Az = a*(Vx*By - Vy*Bx)
50 
51  return;
52  }
53 
54  __attribute__((always_inline)) void TRightHandSide(const G4double y[],
56  G4double dydx[]) const {
57  // CMS field is three dimentional
58  G4double Field[3];
59  GetFieldValueCMS(y, Field);
61  }
62 
63 private:
64  // Dependent objects
65  T_Field* itsField;
66 };
67 
68 #endif
Definition: APVGainStruct.h:7
assert(be >=bs)
double f[11][100]
Structure Point Contains parameters of Gaussian fits to DMRs.
void TEvaluateRhsGivenB(const G4double y[], G4double inv_momentum_magnitude, const G4double B[3], G4double dydx[]) const
__attribute__((always_inline)) void TRightHandSide(const G4double y[]
void GetFieldValueCMS(const G4double Point[], G4double Field[]) const