Geant4
9.6.p02
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
geant4_9_6_p02
examples
extended
field
field01
src
F01FieldSetup.cc
Go to the documentation of this file.
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
// $Id$
31
//
32
// User Field setup class implementation.
33
//
34
35
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
36
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
37
38
#include "
F01FieldSetup.hh
"
39
#include "
F01FieldMessenger.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
// #include "G4SIunits.hh"
64
65
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
66
67
// Constructors:
68
69
F01FieldSetup::F01FieldSetup
(
G4ThreeVector
fieldVector)
70
: fFieldManager(0),
71
fChordFinder(0),
72
fEquation(0),
73
fMagneticField(new
G4UniformMagField
(fieldVector)),
74
// G4ThreeVector(3.3*tesla, 0.0, 0.0 ));
75
fStepper(0),
76
fStepperType(0),
77
fMinStep(0.),
78
fFieldMessenger(0)
79
{
80
G4cout
<<
" F01FieldSetup: magnetic field set to Uniform( "
81
<< fieldVector <<
" ) "
<<
G4endl
;
82
InitialiseAll
();
83
}
84
85
F01FieldSetup::F01FieldSetup
()
86
: fFieldManager(0),
87
fChordFinder(0),
88
fEquation(0),
89
fMagneticField(new
G4UniformMagField
(
G4ThreeVector
())),
90
// G4ThreeVector(0.0, 0.0, 0.0 ));
91
fStepper(0),
92
fStepperType(0),
93
fMinStep(0.),
94
fFieldMessenger(0)
95
{
96
G4cout
<<
" F01FieldSetup: magnetic field set to Uniform( 0.0, 0, 0 ) "
97
<<
G4endl
;
98
InitialiseAll
();
99
}
100
101
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
102
103
void
F01FieldSetup::InitialiseAll
()
104
{
105
fFieldMessenger
=
new
F01FieldMessenger
(
this
) ;
106
107
fEquation
=
new
G4Mag_UsualEqRhs
(
fMagneticField
);
108
109
fMinStep
= 1.0*
mm
;
// minimal step of 1 mm is default
110
111
fStepperType
= 4 ;
// ClassicalRK4 is default stepper
112
113
fFieldManager
=
G4TransportationManager::GetTransportationManager
()
114
->
GetFieldManager
();
115
CreateStepperAndChordFinder
();
116
}
117
118
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
119
120
F01FieldSetup::~F01FieldSetup
()
121
{
122
// GetGlobalFieldManager()->SetDetectorField(0);
123
124
if
(
fMagneticField
)
delete
fMagneticField
;
125
if
(
fChordFinder
)
delete
fChordFinder
;
126
if
(
fStepper
)
delete
fStepper
;
127
}
128
129
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
130
131
void
F01FieldSetup::CreateStepperAndChordFinder
()
132
{
133
// Update field
134
135
SetStepper
();
136
G4cout
<<
"The minimal step is equal to "
<<
fMinStep
/
mm
<<
" mm"
<<
G4endl
;
137
138
fFieldManager
->
SetDetectorField
(
fMagneticField
);
139
140
if
(
fChordFinder
)
delete
fChordFinder
;
141
142
fChordFinder
=
new
G4ChordFinder
(
fMagneticField
,
fMinStep
,
fStepper
);
143
144
fFieldManager
->
SetChordFinder
(
fChordFinder
);
145
146
return
;
147
}
148
149
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
150
151
void
F01FieldSetup::SetStepper
()
152
{
153
// Set stepper according to the stepper type
154
155
if
(
fStepper
)
delete
fStepper
;
156
157
switch
(
fStepperType
)
158
{
159
case
0:
160
fStepper
=
new
G4ExplicitEuler
(
fEquation
);
161
G4cout
<<
"G4ExplicitEuler is calledS"
<<
G4endl
;
162
break
;
163
case
1:
164
fStepper
=
new
G4ImplicitEuler
(
fEquation
);
165
G4cout
<<
"G4ImplicitEuler is called"
<<
G4endl
;
166
break
;
167
case
2:
168
fStepper
=
new
G4SimpleRunge
(
fEquation
);
169
G4cout
<<
"G4SimpleRunge is called"
<<
G4endl
;
170
break
;
171
case
3:
172
fStepper
=
new
G4SimpleHeum
(
fEquation
);
173
G4cout
<<
"G4SimpleHeum is called"
<<
G4endl
;
174
break
;
175
case
4:
176
fStepper
=
new
G4ClassicalRK4
(
fEquation
);
177
G4cout
<<
"G4ClassicalRK4 (default) is called"
<<
G4endl
;
178
break
;
179
case
5:
180
fStepper
=
new
G4HelixExplicitEuler
(
fEquation
);
181
G4cout
<<
"G4HelixExplicitEuler is called"
<<
G4endl
;
182
break
;
183
case
6:
184
fStepper
=
new
G4HelixImplicitEuler
(
fEquation
);
185
G4cout
<<
"G4HelixImplicitEuler is called"
<<
G4endl
;
186
break
;
187
case
7:
188
fStepper
=
new
G4HelixSimpleRunge
(
fEquation
);
189
G4cout
<<
"G4HelixSimpleRunge is called"
<<
G4endl
;
190
break
;
191
case
8:
192
fStepper
=
new
G4CashKarpRKF45
(
fEquation
);
193
G4cout
<<
"G4CashKarpRKF45 is called"
<<
G4endl
;
194
break
;
195
case
9:
196
fStepper
=
new
G4RKG3_Stepper
(
fEquation
);
197
G4cout
<<
"G4RKG3_Stepper is called"
<<
G4endl
;
198
break
;
199
default
:
fStepper
= 0;
200
}
201
return
;
202
}
203
204
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
205
206
void
F01FieldSetup::SetFieldValue
(
G4double
fieldStrength)
207
{
208
// Set the value of the Global Field to fieldValue along Z
209
210
#ifdef G4VERBOSE
211
G4cout
<<
"Setting Field strength to "
212
<< fieldStrength /
gauss
<<
" Gauss."
;
// << G4endl;
213
#endif
214
215
G4ThreeVector
fieldSetVec(0.0, 0.0, fieldStrength);
216
this->
SetFieldValue
( fieldSetVec );
217
// *************
218
219
#ifdef G4VERBOSE
220
G4double
fieldValue[6],
position
[4];
221
position[0] = position[1] = position[2] = position[3] = 0.0;
222
if
( fieldStrength != 0.0 ) {
223
fMagneticField
->
GetFieldValue
( position, fieldValue);
224
G4ThreeVector
fieldVec(fieldValue[0], fieldValue[1], fieldValue[2]);
225
// G4cout << " fMagneticField is now " << fMagneticField
226
G4cout
<<
" Magnetic field vector is "
227
<< fieldVec /
gauss
<<
" G "
<<
G4endl
;
228
}
else
{
229
if
(
fMagneticField
== 0 )
230
G4cout
<<
" Magnetic field pointer is null."
<<
G4endl
;
231
else
232
G4Exception
(
"F01FieldSetup::SetFieldValue(double)"
,
233
"IncorrectForZeroField"
,
234
FatalException
,
235
"fMagneticField ptr should be set to 0 for no field."
);
236
}
237
#endif
238
}
239
240
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
241
242
void
F01FieldSetup::SetFieldValue
(
G4ThreeVector
fieldVector)
243
{
244
// Set the value of the Global Field
245
246
if
(
fMagneticField
)
delete
fMagneticField
;
247
248
if
(fieldVector !=
G4ThreeVector
(0.,0.,0.))
249
{
250
fMagneticField
=
new
G4UniformMagField
(fieldVector);
251
// CreateStepperAndChordFinder();
252
}
253
else
254
{
255
// If the new field's value is Zero, signal it as below
256
// so that it is not used for propagation.
257
fMagneticField
= 0;
258
}
259
260
// Set this as the field of the global Field Manager
261
GetGlobalFieldManager
()->
SetDetectorField
(
fMagneticField
);
262
263
// Now notify equation of new field
264
fEquation
->
SetFieldObj
(
fMagneticField
);
265
266
}
267
268
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
269
270
G4FieldManager
*
F01FieldSetup::GetGlobalFieldManager
()
271
{
272
// Utility method
273
274
return
G4TransportationManager::GetTransportationManager
()
275
->
GetFieldManager
();
276
}
277
278
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
279
Generated on Sat May 25 2013 14:32:25 for Geant4 by
1.8.4