ACTARSim
ACTAR TPC Simulation Reference Guide
ActarSimUniformEMField.cc
Go to the documentation of this file.
1 // - AUTHOR: Hector Alvarez-Pol 05/2005
2 /******************************************************************
3  * Copyright (C) 2005-2016, Hector Alvarez-Pol *
4  * All rights reserved. *
5  * *
6  * License according to GNU LESSER GPL (see lgpl-3.0.txt). *
7  * For the list of contributors see CREDITS. *
8  ******************************************************************/
9 //////////////////////////////////////////////////////////////////
10 /// \class ActarSimUniformEMField
11 /// Uniform electric and magnetic fields definition
12 /////////////////////////////////////////////////////////////////
13 
15 #include "G4FieldManager.hh"
16 #include "G4MagneticField.hh"
17 #include "G4MagIntegratorStepper.hh"
18 #include "G4EqMagElectricField.hh"
19 #include "G4ClassicalRK4.hh"
20 #include "G4ChordFinder.hh"
21 #include "G4TransportationManager.hh"
22 
23 #include "G4PhysicalConstants.hh"
24 #include "G4SystemOfUnits.hh"
25 
26 //////////////////////////////////////////////////////////////////
27 /// Default zero field constructor
31 
32  equation = new G4EqMagElectricField(this);
33  stepper = new G4ClassicalRK4(equation);
34  GetGlobalFieldManager()->SetDetectorField(this);
35  theChordFinder = new G4ChordFinder((G4MagneticField*)this, 1.0e-2 * mm, stepper);
36  GetGlobalFieldManager()->SetChordFinder(theChordFinder);
37  //DefineUnits();
38 }
39 
40 //////////////////////////////////////////////////////////////////
41 /// Constructor with initial values for the electric an magnetic fields
42 ActarSimUniformEMField::ActarSimUniformEMField(const G4ThreeVector magFieldVector,
43  const G4ThreeVector elecFieldVector) {
44  equation = new G4EqMagElectricField(this);
45  stepper = new G4ClassicalRK4(equation);
46  GetGlobalFieldManager()->SetDetectorField(this);
47  theChordFinder = new G4ChordFinder((G4MagneticField*)this, 1.0e-2 * mm, stepper);
48  GetGlobalFieldManager()->SetChordFinder(theChordFinder);
49 
50  SetFieldValue(magFieldVector, elecFieldVector);
51  //DefineUnits();
52 }
53 
54 //////////////////////////////////////////////////////////////////
55 /// Copy constructor
57  : G4ElectroMagneticField(p) {
58  for(G4int i=0;i<6;i++)
60 
61  equation = new G4EqMagElectricField(this);
62  stepper = new G4ClassicalRK4(equation);
63  GetGlobalFieldManager()->SetDetectorField(this);
64  theChordFinder = new G4ChordFinder((G4MagneticField*)this, 1.0e-2 * mm, stepper);
65  GetGlobalFieldManager()->SetChordFinder(theChordFinder);
66 }
67 
68 //////////////////////////////////////////////////////////////////
69 /// Operator =
71  if (&p == this) return *this;
72  for (G4int i=0; i<6; i++)
74  return *this;
75 }
76 
77 //////////////////////////////////////////////////////////////////
78 /// Destructor
80  GetGlobalFieldManager()->SetDetectorField(0);
81 }
82 
83 //////////////////////////////////////////////////////////////////
84 /// Set the value of the Global Field to fieldVector along Y
85 void ActarSimUniformEMField::SetFieldValue(const G4ThreeVector magFieldVector,
86  const G4ThreeVector elecFieldVector) {
87  if(elecFieldVector!=G4ThreeVector(0.,0.,0.) ||
88  magFieldVector!=G4ThreeVector(0.,0.,0.) ) {
89  fieldComponents[0] = magFieldVector.x();
90  fieldComponents[1] = magFieldVector.y();
91  fieldComponents[2] = magFieldVector.z();
92  fieldComponents[3] = elecFieldVector.x();
93  fieldComponents[4] = elecFieldVector.y();
94  fieldComponents[5] = elecFieldVector.z();
95  }
96  else {
97  // If the new field's value is Zero, then it is best to
98  // insure that it is not used for propagation.
99  GetGlobalFieldManager()->SetDetectorField(0);
100  }
101 }
102 
103 //////////////////////////////////////////////////////////////////
104 /// Set the value of the Electric Field to fieldVector
105 void ActarSimUniformEMField::SetPureElectricFieldValue(G4ThreeVector fieldVector) {
106  if(fieldVector!=G4ThreeVector(0.,0.,0.) ) {
107  fieldComponents[0] = 0.;
108  fieldComponents[1] = 0.;
109  fieldComponents[2] = 0.;
110  fieldComponents[3] = fieldVector.x();
111  fieldComponents[4] = fieldVector.y();
112  fieldComponents[5] = fieldVector.z();
113  }
114  else {
115  // If the new field's value is Zero, then it is best to
116  // insure that it is not used for propagation.
117  GetGlobalFieldManager()->SetDetectorField(0);
118  }
119 }
120 
121 //////////////////////////////////////////////////////////////////
122 /// Set the value of the Magnetic Field to fieldVector
123 void ActarSimUniformEMField::SetPureMagneticFieldValue(G4ThreeVector fieldVector) {
124  if(fieldVector!=G4ThreeVector(0.,0.,0.) ) {
125  fieldComponents[0] = fieldVector.x();
126  fieldComponents[1] = fieldVector.y();
127  fieldComponents[2] = fieldVector.z();
128  fieldComponents[3] = 0.;
129  fieldComponents[4] = 0.;
130  fieldComponents[5] = 0.;
131  }
132  else {
133  // If the new field's value is Zero, then it is best to
134  // insure that it is not used for propagation.
135  GetGlobalFieldManager()->SetDetectorField(0);
136  }
137 }
138 
139 //////////////////////////////////////////////////////////////////
140 /// This is a virtual function in G4ElectroMagneticField to be instanciated here:
141 /// Return as Bfield[0], [1], [2] the magnetic field x, y & z components
142 /// and as Bfield[3], [4], [5] G4the electric field x, y & z components
143 void ActarSimUniformEMField::GetFieldValue(const G4double thePoint[4],
144  G4double* theField) const {
145  if(thePoint) {;} //avoid the warning message
146 
147  theField[0] = fieldComponents[0];
148  theField[1] = fieldComponents[1];
149  theField[2] = fieldComponents[2];
150  theField[3] = fieldComponents[3];
151  theField[4] = fieldComponents[4];
152  theField[5] = fieldComponents[5];
153  /*
154  G4cout << " GGGGGGGGG "
155  << thePoint[0] << " " << thePoint[1] << " "<< thePoint[2] << " " << thePoint[3] << " "
156  << theField[0] << " "<< theField[1] << " "<< theField[2] << " "<< theField[3] << " "
157  << theField[4] << " "<< theField[5] << G4endl;
158  */
159 }
160 
161 //////////////////////////////////////////////////////////////////
162 /// Returns the uniform magnetic field value
164  return G4ThreeVector(fieldComponents[0], fieldComponents[1], fieldComponents[2]);
165 }
166 
167 //////////////////////////////////////////////////////////////////
168 /// Returns the uniform electric field value
170  return G4ThreeVector(fieldComponents[3],
171  fieldComponents[4],
172  fieldComponents[5]);
173 }
174 
175 /*
176 G4bool DoesFieldChangeEnergy(){
177  //
178  // Returns true if any electric field component is present;
179  // otherwise false
180  //
181 
182  if(fieldComponents[3] != 0. ||
183  fieldComponents[4] != 0. ||
184  fieldComponents[5] != 0. )
185  return true;
186  else
187  return false;
188 }
189 */
190 
191 //////////////////////////////////////////////////////////////////
192 /// Getting a local pointer to the global field manager
194  return G4TransportationManager::GetTransportationManager()->GetFieldManager();
195 }
196 
197 /*
198 #include "G4UnitsTable.hh"
199 void ActarSimUniformEMField::DefineUnits() {
200  //
201  // Defining units for the electric field...why G4 has not the Electric field
202  // units defined?
203  //
204 
205  //G4UnitDefinition(const G4String& name, const G4String& symbol,
206  // const G4String& category, G4double value);
207 
208  G4UnitDefinition("volt/meter","V/m","Electric Field",volt/meter);
209  G4UnitDefinition("kilovolt/meter","kV/m","Electric Field",kilovolt/meter);
210  G4UnitDefinition("kilovolt/centimeter","kV/cm","Electric Field",kilovolt/centimeter);
211 
212  }
213 */
ActarSimUniformEMField operator=(const ActarSimUniformEMField &p)
Operator =.
G4FieldManager * GetGlobalFieldManager()
Find the global Field Manager.
void SetPureElectricFieldValue(G4ThreeVector fieldVector)
Set the value of the Electric Field to fieldVector.
G4ThreeVector GetMagneticFieldValue()
Returns the uniform magnetic field value.
void SetPureMagneticFieldValue(G4ThreeVector fieldVector)
Set the value of the Magnetic Field to fieldVector.
G4double fieldComponents[6]
The EM field: follows the G4ElectroMagneticField convention.
G4ThreeVector GetElectricFieldValue()
Returns the uniform electric field value.
G4EqMagElectricField * equation
Equation.
ActarSimUniformEMField()
Default zero field constructor.
void GetFieldValue(const G4double thePoint[4], G4double *theField) const
G4ChordFinder * theChordFinder
Chord parameter.
G4MagIntegratorStepper * stepper
Integrator stepper.
void SetFieldValue(const G4ThreeVector magFieldVector, const G4ThreeVector elecFieldVector)
Set the value of the Global Field to fieldVector along Y.