ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
F03FieldSetup.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file F03FieldSetup.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
28 //
29 //
30 //
31 //
32 // Field Setup class implementation.
33 //
34 //
35 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
36 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
37 
38 #include "F03FieldSetup.hh"
39 #include "F03FieldMessenger.hh"
40 
41 #include "G4MagneticField.hh"
42 #include "G4UniformMagField.hh"
43 #include "G4FieldManager.hh"
45 #include "G4Mag_UsualEqRhs.hh"
47 #include "G4ChordFinder.hh"
48 
49 #include "G4ExplicitEuler.hh"
50 #include "G4ImplicitEuler.hh"
51 #include "G4SimpleRunge.hh"
52 #include "G4SimpleHeum.hh"
53 #include "G4ClassicalRK4.hh"
54 #include "G4HelixExplicitEuler.hh"
55 #include "G4HelixImplicitEuler.hh"
56 #include "G4HelixSimpleRunge.hh"
57 #include "G4CashKarpRKF45.hh"
58 #include "G4RKG3_Stepper.hh"
59 
60 #include "G4PhysicalConstants.hh"
61 #include "G4SystemOfUnits.hh"
62 
63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64 
66  : fFieldManager(0),
67  fLocalFieldManager(0),
68  fChordFinder(0),
69  fLocalChordFinder(0),
70  fEquation(0),
71  fLocalEquation(0),
72  fMagneticField(0),
73  fLocalMagneticField(0),
74  fStepper(0),
75  fLocalStepper(0),
76  fFieldMessenger(0)
77 {
79  0.0, // 0.5*tesla,
80  0.0));
82  0.0, // 0.5*tesla,
83  0.0));
84 
86 
89 
90  fMinStep = 0.25*mm ; // minimal step of 1 mm is default
91  fStepperType = 4 ; // ClassicalRK4 is default stepper
92 
95 
96  UpdateField();
97 }
98 
99 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
100 
102 {
103  delete fMagneticField;
104  delete fChordFinder;
105  delete fStepper;
106  delete fFieldMessenger;
107 }
108 
109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
110 
112 {
113  // It must be possible to call 'again' - e.g. to choose an alternative stepper
114  // has been chosen, or in case other changes have been made.
115 
116  // 1. First clean up previous state.
117  delete fChordFinder;
118  fChordFinder= nullptr;
119  delete fLocalChordFinder;
120  fLocalChordFinder= nullptr;
121 
122  G4cout<<"F03FieldSetup::UpdateField> The minimal step is equal to "
123  << fMinStep/mm <<" mm"<<G4endl;
124  G4cout<<" Stepper Type chosen = " << fStepperType
125  << G4endl;
126 
127  // 2. Create the steppers ( Note: this also deletes the previous ones. )
128  CreateSteppers();
129 
130 
131  // 3. Create the chord finder(s)
135 
138 
139  // 4. Ensure that the field is updated (in Field manager & equation)
142 }
143 
144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
145 
147 {
148  delete fStepper;
149  fStepper= nullptr;
150 
151  delete fLocalStepper;
152  fLocalStepper= nullptr;
153 
154  switch ( fStepperType )
155  {
156  case 0:
159  G4cout<<"G4ExplicitEuler is called"<<G4endl;
160  break;
161  case 1:
164  G4cout<<"G4ImplicitEuler is called"<<G4endl;
165  break;
166  case 2:
169  G4cout<<"G4SimpleRunge is called"<<G4endl;
170  break;
171  case 3:
174  G4cout<<"G4SimpleHeum is called"<<G4endl;
175  break;
176  case 4:
179  G4cout<<"G4ClassicalRK4 (default) is called"<<G4endl;
180  break;
181  case 5:
184  G4cout<<"G4HelixExplicitEuler is called"<<G4endl;
185  break;
186  case 6:
189  G4cout<<"G4HelixImplicitEuler is called"<<G4endl;
190  break;
191  case 7:
194  G4cout<<"G4HelixSimpleRunge is called"<<G4endl;
195  break;
196  case 8:
199  G4cout<<"G4CashKarpRKF45 is called"<<G4endl;
200  break;
201  case 9:
204  G4cout<<"G4RKG3_Stepper is called"<<G4endl;
205  break;
206  default: fStepper = 0;
207  }
208 }
209 
210 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
211 
213 {
214  G4ThreeVector fieldSetVec(0.0, 0.0, fieldStrength);
215  SetFieldValue( fieldSetVec );
216 }
217 
218 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
219 
221 {
222  if(fMagneticField) delete fMagneticField;
223 
224  if(fieldVector != G4ThreeVector(0.,0.,0.))
225  {
226  fMagneticField = new G4UniformMagField(fieldVector);
227  }
228  else
229  {
230  // If the new field's value is Zero, then
231  // setting the pointer to zero ensures
232  // that it is not used for propagation.
233  fMagneticField = 0;
234  }
235 
236  // Either
237  // - UpdateField() to reset all (ChordFinder, Equation);
238  // UpdateField();
239  // or simply update the field manager & equation of motion
240  // with pointer to new field
243 
244 }
245 
246 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
247 
249 {
251 
252  if(fieldVector != G4ThreeVector(0.,0.,0.))
253  {
254  fLocalMagneticField = new G4UniformMagField(fieldVector);
255  }
256  else
257  {
258  // If the new field's value is Zero, then
259  // setting the pointer to zero ensures
260  // that it is not used for propagation.
262  }
263 
264  // Either
265  // - UpdateField() to reset all (ChordFinder, Equation);
266  // UpdateField();
267  // or simply update the field manager & equation of motion
268  // with pointer to new field
271 }
272 
273 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
274 
276 {
278  ->GetFieldManager();
279 }
280 
281 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
282 
284 {
285  if ( ! magneticField ) return G4ThreeVector();
286 
287  static G4double fieldValue[6], position[4];
288  position[0] = position[1] = position[2] = position[3] = 0.0;
289 
290  magneticField->GetFieldValue( position, fieldValue);
291  G4ThreeVector fieldVec(fieldValue[0], fieldValue[1], fieldValue[2]);
292 
293  return fieldVec;
294 }
295 
296 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......