ATLAS Offline Software
G4mplEqMagElectricField.cxx
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * DISCLAIMER *
4 // * *
5 // * The following disclaimer summarizes all the specific disclaimers *
6 // * of contributors to this software. The specific disclaimers,which *
7 // * govern, are listed with their locations in: *
8 // * http://cern.ch/geant4/license *
9 // * *
10 // * Neither the authors of this software system, nor their employing *
11 // * institutes,nor the agencies providing financial support for this *
12 // * work make any representation or warranty, express or implied, *
13 // * regarding this software system or assume any liability for its *
14 // * use. *
15 // * *
16 // * This code implementation is the intellectual property of the *
17 // * GEANT4 collaboration. *
18 // * By copying, distributing or modifying the Program (or any work *
19 // * based on the Program) you indicate your acceptance of this *
20 // * statement, and all its terms. *
21 // ********************************************************************
22 //
23 //
24 // This is the (right-hand side for) equation of motion in a combined
25 // magnetic and electric field for ordinary charged partilces
26 // and magnetic monopoles (with magnetic charge.)
27 //
28 // Was based on G4EqMagElectricField.hh (by V.Grichine)
29 //
30 // 30.04.10 S.Burdin (modified to use for the monopole trajectories).
31 //
32 // -------------------------------------------------------------------
33 
34 // class header
35 #include "G4mplEqMagElectricField.hh"
36 
37 // STL headers
38 #include <iomanip>
39 
40 // CLHEP headers
41 #include "CLHEP/Units/PhysicalConstants.h"
42 
43 // Geant4 headers
44 #include "globals.hh"
45 #include "G4Version.hh"
46 
47 G4mplEqMagElectricField::G4mplEqMagElectricField(G4MagneticField *emField )
48  : G4Mag_EqRhs( emField )
49  , fMassCof(100000. )
50  , fElCharge( 0 )
51  , fMagCharge( 0 )
52  , init( false ) {
53 
54 }
55 
56 void
57 G4mplEqMagElectricField::SetChargeMomentumMass(G4ChargeState particleCharge,
58  G4double MomentumXc,
59  G4double particleMass)
60 {
61  init = true;
62 
63  fElCharge =CLHEP::eplus* particleCharge.GetCharge()*CLHEP::c_light;
64  fMagCharge = (particleMass < 0.0) ? CLHEP::eplus*particleCharge.MagneticCharge()*CLHEP::c_light : 0.0; // protection against ordinary particles
65 
66  fMassCof = particleMass*particleMass ;
67 
68  G4Mag_EqRhs::SetChargeMomentumMass(particleCharge, MomentumXc, particleMass); // allows electrically charged particles to use the AtlasRK4 and NystromRK4 propagators (still don't work with magnetic charges)
69 
70 }
71 
72 void
73 G4mplEqMagElectricField::EvaluateRhsGivenB(const G4double y[],
74  const G4double Field[],
75  G4double dydx[] ) const
76 {
77  // Components of y:
78  // 0-2 dr/ds,
79  // 3-5 dp/ds - momentum derivatives
80 
81  if (!init)G4Exception("G4mplEqMagElectricField::EvaluateRhsGivenB","NotInitialized",FatalException,"SetChargeMomentumMass has not been called");
82 
83  const G4double pSquared = y[3]*y[3] + y[4]*y[4] + y[5]*y[5] ;
84 
85  const G4double Energy = std::sqrt( pSquared + fMassCof );
86 
87  // const G4double pModuleInverse = (pSquared <= 0.0) ? 0.0 : 1.0/std::sqrt(pSquared);
88  const G4double pModuleInverse = 1.0/std::sqrt(pSquared);
89 
90  const G4double inverse_velocity = Energy * pModuleInverse / CLHEP::c_light;
91 
92  const G4double cofEl = fElCharge * pModuleInverse ;
93  const G4double cofMag = fMagCharge * Energy * pModuleInverse;
94 
95 
96  dydx[0] = y[3]*pModuleInverse ;
97  dydx[1] = y[4]*pModuleInverse ;
98  dydx[2] = y[5]*pModuleInverse ;
99 
100  // dp/ds = dp/dt * dt/ds = dp/dt / v = Force / velocity
101 
102  dydx[3] = cofMag * Field[0] + cofEl * (y[4]*Field[2] - y[5]*Field[1]);
103  dydx[4] = cofMag * Field[1] + cofEl * (y[5]*Field[0] - y[3]*Field[2]);
104  dydx[5] = cofMag * Field[2] + cofEl * (y[3]*Field[1] - y[4]*Field[0]);
105 
106  dydx[6] = 0.;//not used
107 
109 
110  // Lab Time of flight
111  dydx[7] = inverse_velocity;
112 
113  return ;
114 }
Energy
std::vector< double > Energy
Definition: CalibHitToCaloCell.h:23
python.PhysicalConstants.c_light
float c_light
Definition: PhysicalConstants.py:63
python.PyKernel.init
def init(v_theApp, v_rootStream=None)
Definition: PyKernel.py:45
y
#define y
python.SystemOfUnits.eplus
int eplus
Definition: SystemOfUnits.py:137