ECCE @ EIC Software
Reference for
ECCE @ EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
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
"
44
#include "
G4TransportationManager.hh
"
45
#include "
G4Mag_UsualEqRhs.hh
"
46
#include "
G4MagIntegratorStepper.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
65
F03FieldSetup::F03FieldSetup
()
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
{
78
fMagneticField
=
new
G4UniformMagField
(
G4ThreeVector
(3.3*
tesla
,
79
0.0,
// 0.5*tesla,
80
0.0));
81
fLocalMagneticField
=
new
G4UniformMagField
(
G4ThreeVector
(3.3*
tesla
,
82
0.0,
// 0.5*tesla,
83
0.0));
84
85
fFieldMessenger
=
new
F03FieldMessenger
(
this
);
86
87
fEquation
=
new
G4Mag_UsualEqRhs
(
fMagneticField
);
88
fLocalEquation
=
new
G4Mag_UsualEqRhs
(
fLocalMagneticField
);
89
90
fMinStep
= 0.25*
mm
;
// minimal step of 1 mm is default
91
fStepperType
= 4 ;
// ClassicalRK4 is default stepper
92
93
fFieldManager
=
GetGlobalFieldManager
();
94
fLocalFieldManager
=
new
G4FieldManager
();
95
96
UpdateField
();
97
}
98
99
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
100
101
F03FieldSetup::~F03FieldSetup
()
102
{
103
delete
fMagneticField
;
104
delete
fChordFinder
;
105
delete
fStepper
;
106
delete
fFieldMessenger
;
107
}
108
109
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
110
111
void
F03FieldSetup::UpdateField
()
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)
132
fChordFinder
=
new
G4ChordFinder
(
fMagneticField
,
fMinStep
,
fStepper
);
133
fLocalChordFinder
=
new
G4ChordFinder
(
fLocalMagneticField
,
134
fMinStep
,
fLocalStepper
);
135
136
fFieldManager
->
SetChordFinder
(
fChordFinder
);
137
fLocalFieldManager
->
SetChordFinder
(
fLocalChordFinder
);
138
139
// 4. Ensure that the field is updated (in Field manager & equation)
140
fFieldManager
->
SetDetectorField
(
fMagneticField
);
141
fLocalFieldManager
->
SetDetectorField
(
fLocalMagneticField
);
142
}
143
144
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
145
146
void
F03FieldSetup::CreateSteppers
()
147
{
148
delete
fStepper
;
149
fStepper
=
nullptr
;
150
151
delete
fLocalStepper
;
152
fLocalStepper
=
nullptr
;
153
154
switch
(
fStepperType
)
155
{
156
case
0:
157
fStepper
=
new
G4ExplicitEuler
(
fEquation
);
158
fLocalStepper
=
new
G4ExplicitEuler
(
fLocalEquation
);
159
G4cout
<<
"G4ExplicitEuler is called"
<<
G4endl
;
160
break
;
161
case
1:
162
fStepper
=
new
G4ImplicitEuler
(
fEquation
);
163
fLocalStepper
=
new
G4ImplicitEuler
(
fLocalEquation
);
164
G4cout
<<
"G4ImplicitEuler is called"
<<
G4endl
;
165
break
;
166
case
2:
167
fStepper
=
new
G4SimpleRunge
(
fEquation
);
168
fLocalStepper
=
new
G4SimpleRunge
(
fLocalEquation
);
169
G4cout
<<
"G4SimpleRunge is called"
<<
G4endl
;
170
break
;
171
case
3:
172
fStepper
=
new
G4SimpleHeum
(
fEquation
);
173
fLocalStepper
=
new
G4SimpleHeum
(
fLocalEquation
);
174
G4cout
<<
"G4SimpleHeum is called"
<<
G4endl
;
175
break
;
176
case
4:
177
fStepper
=
new
G4ClassicalRK4
(
fEquation
);
178
fLocalStepper
=
new
G4ClassicalRK4
(
fLocalEquation
);
179
G4cout
<<
"G4ClassicalRK4 (default) is called"
<<
G4endl
;
180
break
;
181
case
5:
182
fStepper
=
new
G4HelixExplicitEuler
(
fEquation
);
183
fLocalStepper
=
new
G4HelixExplicitEuler
(
fLocalEquation
);
184
G4cout
<<
"G4HelixExplicitEuler is called"
<<
G4endl
;
185
break
;
186
case
6:
187
fStepper
=
new
G4HelixImplicitEuler
(
fEquation
);
188
fLocalStepper
=
new
G4HelixImplicitEuler
(
fLocalEquation
);
189
G4cout
<<
"G4HelixImplicitEuler is called"
<<
G4endl
;
190
break
;
191
case
7:
192
fStepper
=
new
G4HelixSimpleRunge
(
fEquation
);
193
fLocalStepper
=
new
G4HelixSimpleRunge
(
fLocalEquation
);
194
G4cout
<<
"G4HelixSimpleRunge is called"
<<
G4endl
;
195
break
;
196
case
8:
197
fStepper
=
new
G4CashKarpRKF45
(
fEquation
);
198
fLocalStepper
=
new
G4CashKarpRKF45
(
fLocalEquation
);
199
G4cout
<<
"G4CashKarpRKF45 is called"
<<
G4endl
;
200
break
;
201
case
9:
202
fStepper
=
new
G4RKG3_Stepper
(
fEquation
);
203
fLocalStepper
=
new
G4RKG3_Stepper
(
fLocalEquation
);
204
G4cout
<<
"G4RKG3_Stepper is called"
<<
G4endl
;
205
break
;
206
default
:
fStepper
= 0;
207
}
208
}
209
210
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
211
212
void
F03FieldSetup::SetFieldZValue
(
G4double
fieldStrength)
213
{
214
G4ThreeVector
fieldSetVec(0.0, 0.0, fieldStrength);
215
SetFieldValue
( fieldSetVec );
216
}
217
218
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
219
220
void
F03FieldSetup::SetFieldValue
(
G4ThreeVector
fieldVector)
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
241
GetGlobalFieldManager
()->
SetDetectorField
(
fMagneticField
);
242
fEquation
->
SetFieldObj
(
fMagneticField
);
243
244
}
245
246
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
247
248
void
F03FieldSetup::SetLocalFieldValue
(
G4ThreeVector
fieldVector)
249
{
250
if
(
fLocalMagneticField
)
delete
fLocalMagneticField
;
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.
261
fLocalMagneticField
= 0;
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
269
GetLocalFieldManager
()->
SetDetectorField
(
fLocalMagneticField
);
270
fEquation
->
SetFieldObj
(
fLocalMagneticField
);
271
}
272
273
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
274
275
G4FieldManager
*
F03FieldSetup::GetGlobalFieldManager
()
276
{
277
return
G4TransportationManager::GetTransportationManager
()
278
->
GetFieldManager
();
279
}
280
281
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
282
283
G4ThreeVector
F03FieldSetup::GetConstantFieldValue
(
G4MagneticField
* magneticField)
const
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......
geant4
tree
geant4-10.6-release
examples
extended
field
field03
src
F03FieldSetup.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:25:05
using
1.8.2 with
ECCE GitHub integration