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
G4ErrorPropagatorManager.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file G4ErrorPropagatorManager.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
//
26
//
27
// ------------------------------------------------------------
28
// GEANT 4 class implementation file
29
// ------------------------------------------------------------
30
//
31
32
#include "
G4ErrorPropagatorManager.hh
"
33
34
#include "
G4SystemOfUnits.hh
"
35
#include "
G4MagIntegratorStepper.hh
"
36
#include "
G4Mag_UsualEqRhs.hh
"
37
#include "
G4Mag_EqRhs.hh
"
38
#include "
G4MagIntegratorDriver.hh
"
39
40
#include "
G4ClassicalRK4.hh
"
41
#include "
G4ExactHelixStepper.hh
"
42
#include "
G4HelixExplicitEuler.hh
"
43
44
#include "
G4EventManager.hh
"
45
#include "
G4ErrorRunManagerHelper.hh
"
46
#include "
G4ErrorPropagator.hh
"
47
#include "
G4ErrorMag_UsualEqRhs.hh
"
48
49
#include "
G4VParticleChange.hh
"
50
#include "
G4ParticleChangeForMSC.hh
"
51
#include "
G4ParticleChange.hh
"
52
#include "
G4Track.hh
"
53
#include "
G4TransportationManager.hh
"
54
#include "
G4ErrorPropagationNavigator.hh
"
55
#include "
G4GeometryManager.hh
"
56
#include "
G4StateManager.hh
"
57
#include "
G4ChordFinder.hh
"
58
#include "
G4EquationOfMotion.hh
"
59
#include "
G4FieldManager.hh
"
60
#include "
G4PropagatorInField.hh
"
61
#include "
G4RunManager.hh
"
62
#include "
G4VParticleChange.hh
"
63
64
G4ThreadLocal
G4ErrorPropagatorManager
*
65
G4ErrorPropagatorManager::theG4ErrorPropagatorManager
= 0;
66
67
//-----------------------------------------------------------------------
68
G4ErrorPropagatorManager
*
G4ErrorPropagatorManager::GetErrorPropagatorManager
()
69
{
70
if
(
theG4ErrorPropagatorManager
== NULL ) {
71
theG4ErrorPropagatorManager
=
new
G4ErrorPropagatorManager
;
72
}
73
74
return
theG4ErrorPropagatorManager
;
75
}
76
77
78
//-----------------------------------------------------------------------
79
G4ErrorPropagatorManager::G4ErrorPropagatorManager
()
80
{
81
//----- Initialize a few things
82
//o theG4ErrorPropagatorManager = this;
83
84
char
* g4emverb = std::getenv(
"G4EVERBOSE"
);
85
if
( !g4emverb ) {
86
G4ErrorPropagatorData::GetErrorPropagatorData
()->
SetVerbose
( 0 );
87
}
else
{
88
G4ErrorPropagatorData::GetErrorPropagatorData
()->
SetVerbose
( atoi( g4emverb ) );
89
}
90
91
thePropagator
= 0;
92
93
theEquationOfMotion
= 0;
94
95
StartG4ErrorRunManagerHelper
();
96
97
G4ErrorPropagatorData::GetErrorPropagatorData
()->
SetState
(
G4ErrorState_PreInit
);
98
99
theG4ErrorPropagationNavigator
= 0;
100
101
StartNavigator
();
//navigator has to be initialized at the beggining !?!?!
102
103
104
}
105
106
107
//-----------------------------------------------------------------------
108
G4ErrorPropagatorManager::~G4ErrorPropagatorManager
()
109
{
110
delete
theEquationOfMotion
;
111
delete
theG4ErrorPropagationNavigator
;
112
delete
thePropagator
;
113
delete
theG4ErrorRunManagerHelper
;
114
delete
theG4ErrorPropagatorManager
;
115
}
116
117
118
//-----------------------------------------------------------------------
119
void
G4ErrorPropagatorManager::StartG4ErrorRunManagerHelper
()
120
{
121
//----- Initialize G4ErrorRunManagerHelper
122
theG4ErrorRunManagerHelper
=
G4ErrorRunManagerHelper::GetRunManagerKernel
();
123
124
if
(
theG4ErrorRunManagerHelper
== 0 ) {
125
theG4ErrorRunManagerHelper
=
new
G4ErrorRunManagerHelper
();
126
}
127
128
//----- User Initialization classes
129
//--- GEANT4e PhysicsList
130
if
(
G4ErrorPropagatorData::verbose
() >= 4 )
G4cout
<<
" G4ErrorPropagatorManager::StartG4eRunManager() done "
<<
theG4ErrorRunManagerHelper
<<
G4endl
;
131
//- theG4eRunManager->SetUserInitialization(new G4ErrorPhysicsList);
132
133
}
134
135
136
//-----------------------------------------------------------------------
137
void
G4ErrorPropagatorManager::StartNavigator
()
138
{
139
if
(
theG4ErrorPropagationNavigator
== 0 ) {
140
G4TransportationManager
*transportationManager =
G4TransportationManager::GetTransportationManager
();
141
142
G4Navigator
* g4navi = transportationManager->
GetNavigatorForTracking
();
143
144
G4VPhysicalVolume
*
world
= g4navi->
GetWorldVolume
();
145
G4int
verb = g4navi->
GetVerboseLevel
();
146
delete
g4navi;
147
148
theG4ErrorPropagationNavigator
=
new
G4ErrorPropagationNavigator
();
149
150
if
( world != 0 ) {
151
theG4ErrorPropagationNavigator
->
SetWorldVolume
( world );
152
}
153
theG4ErrorPropagationNavigator
->
SetVerboseLevel
( verb );
154
155
transportationManager->
SetNavigatorForTracking
(
theG4ErrorPropagationNavigator
);
156
transportationManager->
GetPropagatorInField
()->
GetIntersectionLocator
()
157
->
SetNavigatorFor
(
theG4ErrorPropagationNavigator
);
158
G4EventManager::GetEventManager
()->
GetTrackingManager
()->
GetSteppingManager
()
159
->
SetNavigator
(
theG4ErrorPropagationNavigator
);
160
// G4ThreeVector center(0,0,0);
161
// theG4ErrorPropagationNavigator->LocateGlobalPointAndSetup(center,0,false);
162
163
}
164
165
if
(
G4ErrorPropagatorData::verbose
() >= 2 )
G4cout
<<
" theState at StartNavigator "
<<
PrintG4ErrorState
() <<
G4endl
;
166
167
}
168
169
170
//-----------------------------------------------------------------------
171
void
G4ErrorPropagatorManager::InitGeant4e
()
172
{
173
if
(
G4ErrorPropagatorData::verbose
() >= 1 )
G4cout
<<
"InitGeant4e GEANT4e State= "
<<
PrintG4ErrorState
() <<
" GEANT4 State= "
<<
PrintG4State
() <<
G4endl
;
174
G4ApplicationState
currentState =
G4StateManager::GetStateManager
()->
GetCurrentState
();
175
//----- Initialize run
176
// if( G4StateManager::GetStateManager()->GetCurrentState() == G4State_PreInit) {
177
178
if
(
G4ErrorPropagatorData::GetErrorPropagatorData
()->GetState() ==
G4ErrorState_PreInit
) {
179
if
( currentState ==
G4State_PreInit
|| currentState ==
G4State_Idle
) {
180
// G4eRunManager::GetRunManager()->Initialize();
181
theG4ErrorRunManagerHelper
->
InitializeGeometry
();
182
theG4ErrorRunManagerHelper
->
InitializePhysics
();
183
}
184
185
InitFieldForBackwards
();
186
187
//- G4StateManager::GetStateManager()->SetNewState(G4State_Idle);
188
189
if
(
G4ErrorPropagatorData::verbose
() >= 4 )
G4cout
<<
" bef theG4ErrorPropagatorManager->RunInitialization() "
<<
G4StateManager::GetStateManager
()->
GetCurrentState
() <<
G4endl
;
190
theG4ErrorRunManagerHelper
->
RunInitialization
();
191
if
(
G4ErrorPropagatorData::verbose
() >= 4 )
G4cout
<<
" aft theG4ErrorPropagatorManager->RunInitialization() "
<<
G4StateManager::GetStateManager
()->
GetCurrentState
() <<
G4endl
;
192
193
if
( !
thePropagator
)
thePropagator
=
new
G4ErrorPropagator
();
// currently the only propagator possible
194
195
InitTrackPropagation
();
196
}
else
{
197
std::ostringstream
message
;
198
message <<
"Illegal GEANT4e State= "
<<
PrintG4ErrorState
();
199
G4Exception
(
"G4ErrorPropagatorManager::InitGeant4e()"
,
200
"IllegalState"
,
JustWarning
, message);
201
}
202
203
//----- Set the tracking geometry for this propagation
204
//t SetTrackingGeometry();
205
//----- Set the physics list for this propagation
206
//t SetPhysicsList();
207
//----- Set the field propagation parameters for this propagation
208
//t SetFieldPropagationParameters();
209
G4ErrorPropagatorData::GetErrorPropagatorData
()->
SetState
(
G4ErrorState_Init
);
210
211
if
(
G4ErrorPropagatorData::verbose
() >= 2 )
G4cout
<<
"End InitGeant4e GEANT4e State= "
<<
PrintG4ErrorState
() <<
" GEANT4 State= "
<<
PrintG4State
() <<
G4endl
;
212
213
214
}
215
216
217
//-----------------------------------------------------------------------
218
void
G4ErrorPropagatorManager::InitTrackPropagation
()
219
{
220
thePropagator
->
SetStepN
( 0 );
221
222
G4ErrorPropagatorData::GetErrorPropagatorData
()->
SetState
(
G4ErrorState_Propagating
);
223
224
}
225
226
227
//-----------------------------------------------------------------------
228
G4bool
G4ErrorPropagatorManager::InitFieldForBackwards
()
229
{
230
231
if
(
G4ErrorPropagatorData::verbose
() >= 4 )
G4cout
<<
" G4ErrorPropagatorManager::InitFieldForBackwards() "
<<
G4endl
;
232
//----- Gets the current equation of motion
233
G4FieldManager
* fieldMgr=
G4TransportationManager::GetTransportationManager
()->
GetFieldManager
();
234
// G4cout << " fieldMgr " << fieldMgr << G4endl;
235
if
( !fieldMgr )
return
0;
236
237
// G4Field* myfield = fieldMgr->GetDetectorField();
238
G4ChordFinder
* cf = fieldMgr ->
GetChordFinder
();
239
if
( !cf )
return
0;
240
auto
driver = cf->
GetIntegrationDriver
();
241
if
( !driver )
return
0;
242
auto
equation = driver->
GetEquationOfMotion
();
243
244
//----- Replaces the equation by a G4ErrorMag_UsualEqRhs to handle backwards tracking
245
if
( !dynamic_cast<G4ErrorMag_UsualEqRhs*>(equation) ) {
246
247
G4MagneticField
* myfield = (
G4MagneticField
*)fieldMgr->
GetDetectorField
();
248
249
// G4Mag_UsualEqRhs* fEquation_usual = dynamic_cast<G4Mag_UsualEqRhs*>(equation);
250
if
(
theEquationOfMotion
== 0 )
theEquationOfMotion
=
new
G4ErrorMag_UsualEqRhs
(myfield);
251
252
//---- Pass the equation of motion to the G4MagIntegratorStepper
253
driver->SetEquationOfMotion(
theEquationOfMotion
);
254
255
//--- change stepper for speed tests
256
G4MagIntegratorStepper
* g4eStepper =
new
G4ClassicalRK4
(
theEquationOfMotion
);
257
// G4MagIntegratorStepper* g4eStepper = new G4ExactHelixStepper(theEquationOfMotion);
258
259
//----
260
G4MagneticField
* field =
static_cast<
G4MagneticField
*
>
(
const_cast<
G4Field
*
>
(fieldMgr->
GetDetectorField
()));
261
G4ChordFinder
* pChordFinder =
new
G4ChordFinder
(field, 1.0
e
-2*
mm
, g4eStepper);
262
263
fieldMgr->
SetChordFinder
(pChordFinder);
264
265
}
266
267
return
1;
268
}
269
270
271
//-----------------------------------------------------------------------
272
G4int
G4ErrorPropagatorManager::Propagate
(
G4ErrorTrajState
* currentTS,
const
G4ErrorTarget
*
target
,
G4ErrorMode
mode )
273
{
274
G4ErrorPropagatorData::GetErrorPropagatorData
()->
SetMode
( mode );
275
if
( !
thePropagator
)
thePropagator
=
new
G4ErrorPropagator
();
// currently the only propagator possible
276
277
SetSteppingManagerVerboseLevel
();
278
InitTrackPropagation
();
279
280
G4int
ierr =
thePropagator
->
Propagate
( currentTS, target, mode );
281
282
EventTermination
();
283
284
return
ierr;
285
}
286
287
288
//-----------------------------------------------------------------------
289
G4int
G4ErrorPropagatorManager::PropagateOneStep
(
G4ErrorTrajState
* currentTS,
G4ErrorMode
mode )
290
{
291
G4ErrorPropagatorData::GetErrorPropagatorData
()->
SetMode
( mode );
292
293
if
( !
thePropagator
)
thePropagator
=
new
G4ErrorPropagator
();
// currently the only propagator possible
294
295
SetSteppingManagerVerboseLevel
();
296
297
return
thePropagator
->
PropagateOneStep
( currentTS );
298
}
299
300
301
//-----------------------------------------------------------------------
302
G4bool
G4ErrorPropagatorManager::CloseGeometry
()
303
{
304
G4GeometryManager
* geomManager =
G4GeometryManager::GetInstance
();
305
geomManager->
OpenGeometry
();
306
if
(
G4StateManager::GetStateManager
()->GetCurrentState() !=
G4State_GeomClosed
) {
307
G4StateManager::GetStateManager
()->
SetNewState
(
G4State_Quit
);
308
}
309
310
return
TRUE
;
311
}
312
313
314
//---------------------------------------------------------------------------
315
void
G4ErrorPropagatorManager::SetUserInitialization
(
G4VUserDetectorConstruction
* userInit)
316
{
317
theG4ErrorRunManagerHelper
->
SetUserInitialization
( userInit);
318
}
319
320
321
//---------------------------------------------------------------------------
322
void
G4ErrorPropagatorManager::SetUserInitialization
(
G4VPhysicalVolume
* userInit)
323
{
324
theG4ErrorRunManagerHelper
->
SetUserInitialization
( userInit);
325
}
326
327
328
//---------------------------------------------------------------------------
329
void
G4ErrorPropagatorManager::SetUserInitialization
(
G4VUserPhysicsList
* userInit)
330
{
331
theG4ErrorRunManagerHelper
->
SetUserInitialization
( userInit);
332
}
333
334
335
//---------------------------------------------------------------------------
336
void
G4ErrorPropagatorManager::SetUserAction
(
G4UserTrackingAction
* userAction)
337
{
338
G4EventManager::GetEventManager
()->
SetUserAction
( userAction );
339
}
340
341
342
//---------------------------------------------------------------------------
343
void
G4ErrorPropagatorManager::SetUserAction
(
G4UserSteppingAction
* userAction)
344
{
345
G4EventManager::GetEventManager
()->
SetUserAction
( userAction );
346
}
347
348
349
//---------------------------------------------------------------------------
350
void
G4ErrorPropagatorManager::SetSteppingManagerVerboseLevel
()
351
{
352
G4TrackingManager
* trkmgr =
G4EventManager::GetEventManager
()->
GetTrackingManager
();
353
trkmgr->
GetSteppingManager
()->
SetVerboseLevel
( trkmgr->
GetVerboseLevel
() );
354
}
355
356
357
//---------------------------------------------------------------------------
358
void
G4ErrorPropagatorManager::EventTermination
()
359
{
360
G4ErrorPropagatorData::GetErrorPropagatorData
()->
SetState
(
G4ErrorState_Init
);
361
}
362
363
364
//---------------------------------------------------------------------------
365
void
G4ErrorPropagatorManager::RunTermination
()
366
{
367
G4ErrorPropagatorData::GetErrorPropagatorData
()->
SetState
(
G4ErrorState_PreInit
);
368
theG4ErrorRunManagerHelper
->
RunTermination
();
369
}
370
371
372
//---------------------------------------------------------------------------
373
G4String
G4ErrorPropagatorManager::PrintG4ErrorState
()
374
{
375
return
PrintG4ErrorState
(
G4ErrorPropagatorData::GetErrorPropagatorData
()->GetState() );
376
}
377
378
379
//---------------------------------------------------------------------------
380
G4String
G4ErrorPropagatorManager::PrintG4ErrorState
(
G4ErrorState
state )
381
{
382
G4String
nam =
""
;
383
switch
(state){
384
case
G4ErrorState_PreInit
:
385
nam =
"G4ErrorState_PreInit"
;
386
break
;
387
case
G4ErrorState_Init
:
388
nam =
"G4ErrorState_Init"
;
389
break
;
390
case
G4ErrorState_Propagating
:
391
nam =
"G4ErrorState_Propagating"
;
392
break
;
393
case
G4ErrorState_TargetCloserThanBoundary
:
394
nam =
"G4ErrorState_TargetCloserThanBoundary"
;
395
break
;
396
case
G4ErrorState_StoppedAtTarget
:
397
nam =
"G4ErrorState_StoppedAtTarget"
;
398
break
;
399
}
400
401
return
nam;
402
}
403
404
405
//---------------------------------------------------------------------------
406
G4String
G4ErrorPropagatorManager::PrintG4State
()
407
{
408
return
PrintG4State
(
G4StateManager::GetStateManager
()->GetCurrentState());
409
}
410
411
412
//---------------------------------------------------------------------------
413
G4String
G4ErrorPropagatorManager::PrintG4State
(
G4ApplicationState
state )
414
{
415
G4String
nam =
""
;
416
switch
( state ){
417
case
G4State_PreInit
:
418
nam =
"G4State_PreInit"
;
419
break
;
420
case
G4State_Init
:
421
nam =
"G4State_Init"
;
422
break
;
423
case
G4State_Idle
:
424
nam =
"G4State_Idle"
;
425
break
;
426
case
G4State_GeomClosed
:
427
nam =
"G4State_GeomClosed"
;
428
break
;
429
case
G4State_EventProc
:
430
nam =
"G4State_EventProc"
;
431
break
;
432
case
G4State_Quit
:
433
nam =
"G4State_Quit"
;
434
break
;
435
case
G4State_Abort
:
436
nam =
"G4State_Abort"
;
437
break
;
438
}
439
440
return
nam;
441
442
}
geant4
tree
geant4-10.6-release
source
error_propagation
src
G4ErrorPropagatorManager.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:25:13
using
1.8.2 with
ECCE GitHub integration