Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4ErrorPropagatorManager.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//
26//
27// ------------------------------------------------------------
28// GEANT 4 class implementation file
29// ------------------------------------------------------------
30//
31
33
34#include "G4SystemOfUnits.hh"
36#include "G4Mag_UsualEqRhs.hh"
37#include "G4Mag_EqRhs.hh"
39
40#include "G4ClassicalRK4.hh"
43
44#include "G4EventManager.hh"
46#include "G4ErrorPropagator.hh"
48
49#include "G4VParticleChange.hh"
51#include "G4ParticleChange.hh"
52#include "G4Track.hh"
55#include "G4GeometryManager.hh"
56#include "G4StateManager.hh"
57#include "G4ChordFinder.hh"
58#include "G4EquationOfMotion.hh"
59#include "G4FieldManager.hh"
61#include "G4RunManager.hh"
62#include "G4VParticleChange.hh"
63
65 G4ErrorPropagatorManager::theG4ErrorPropagatorManager = 0;
66
67//-----------------------------------------------------------------------
69{
70 if(theG4ErrorPropagatorManager == NULL)
71 {
72 theG4ErrorPropagatorManager = new G4ErrorPropagatorManager;
73 }
74
75 return theG4ErrorPropagatorManager;
76}
77
78//-----------------------------------------------------------------------
80{
81 //----- Initialize a few things
82 // o theG4ErrorPropagatorManager = this;
83
84 char* g4emverb = std::getenv("G4EVERBOSE");
85 if(!g4emverb)
86 {
88 }
89 else
90 {
92 }
93
94 thePropagator = 0;
95
96 theEquationOfMotion = 0;
97
98 StartG4ErrorRunManagerHelper();
99
102
103 theG4ErrorPropagationNavigator = 0;
104
105 StartNavigator(); // navigator has to be initialized at the beggining !?!?!
106}
107
108//-----------------------------------------------------------------------
110{
111 delete theEquationOfMotion;
112 delete theG4ErrorPropagationNavigator;
113 delete thePropagator;
114 delete theG4ErrorRunManagerHelper;
115 delete theG4ErrorPropagatorManager;
116}
117
118//-----------------------------------------------------------------------
119void G4ErrorPropagatorManager::StartG4ErrorRunManagerHelper()
120{
121 //----- Initialize G4ErrorRunManagerHelper
122 theG4ErrorRunManagerHelper = G4ErrorRunManagerHelper::GetRunManagerKernel();
123
124 if(theG4ErrorRunManagerHelper == 0)
125 {
126 theG4ErrorRunManagerHelper = new G4ErrorRunManagerHelper();
127 }
128
129 //----- User Initialization classes
130 //--- GEANT4e PhysicsList
132 G4cout << " G4ErrorPropagatorManager::StartG4eRunManager() done "
133 << theG4ErrorRunManagerHelper << G4endl;
134 //- theG4eRunManager->SetUserInitialization(new G4ErrorPhysicsList);
135}
136
137//-----------------------------------------------------------------------
138void G4ErrorPropagatorManager::StartNavigator()
139{
140 if(theG4ErrorPropagationNavigator == 0)
141 {
142 G4TransportationManager* transportationManager =
144
145 G4Navigator* g4navi = transportationManager->GetNavigatorForTracking();
146
147 G4VPhysicalVolume* world = g4navi->GetWorldVolume();
148 G4int verb = g4navi->GetVerboseLevel();
149 delete g4navi;
150
151 theG4ErrorPropagationNavigator = new G4ErrorPropagationNavigator();
152
153 if(world != 0)
154 {
155 theG4ErrorPropagationNavigator->SetWorldVolume(world);
156 }
157 theG4ErrorPropagationNavigator->SetVerboseLevel(verb);
158
159 transportationManager->SetNavigatorForTracking(
160 theG4ErrorPropagationNavigator);
161 transportationManager->GetPropagatorInField()
163 ->SetNavigatorFor(theG4ErrorPropagationNavigator);
167 ->SetNavigator(theG4ErrorPropagationNavigator);
168 // G4ThreeVector center(0,0,0);
169 // theG4ErrorPropagationNavigator->LocateGlobalPointAndSetup(center,0,false);
170 }
171
173 G4cout << " theState at StartNavigator " << PrintG4ErrorState() << G4endl;
174}
175
176//-----------------------------------------------------------------------
178{
180 G4cout << "InitGeant4e GEANT4e State= " << PrintG4ErrorState()
181 << " GEANT4 State= " << PrintG4State() << G4endl;
182 G4ApplicationState currentState =
184 //----- Initialize run
185 // if( G4StateManager::GetStateManager()->GetCurrentState() ==
186 // G4State_PreInit) {
187
190 {
191 if(currentState == G4State_PreInit || currentState == G4State_Idle)
192 {
193 // G4eRunManager::GetRunManager()->Initialize();
194 theG4ErrorRunManagerHelper->InitializeGeometry();
195 theG4ErrorRunManagerHelper->InitializePhysics();
196 }
197
199
200 //- G4StateManager::GetStateManager()->SetNewState(G4State_Idle);
201
203 G4cout << " bef theG4ErrorPropagatorManager->RunInitialization() "
205 theG4ErrorRunManagerHelper->RunInitialization();
207 G4cout << " aft theG4ErrorPropagatorManager->RunInitialization() "
209
210 if(!thePropagator)
211 thePropagator =
212 new G4ErrorPropagator(); // currently the only propagator possible
213
215 }
216 else
217 {
218 std::ostringstream message;
219 message << "Illegal GEANT4e State= " << PrintG4ErrorState();
220 G4Exception("G4ErrorPropagatorManager::InitGeant4e()", "IllegalState",
221 JustWarning, message);
222 }
223
224 //----- Set the tracking geometry for this propagation
225 // t SetTrackingGeometry();
226 //----- Set the physics list for this propagation
227 // t SetPhysicsList();
228 //----- Set the field propagation parameters for this propagation
229 // t SetFieldPropagationParameters();
231
233 G4cout << "End InitGeant4e GEANT4e State= " << PrintG4ErrorState()
234 << " GEANT4 State= " << PrintG4State() << G4endl;
235}
236
237//-----------------------------------------------------------------------
239{
240 thePropagator->SetStepN(0);
241
244}
245
246//-----------------------------------------------------------------------
248{
250 G4cout << " G4ErrorPropagatorManager::InitFieldForBackwards() " << G4endl;
251 //----- Gets the current equation of motion
252 G4FieldManager* fieldMgr =
254 // G4cout << " fieldMgr " << fieldMgr << G4endl;
255 if(!fieldMgr)
256 return 0;
257
258 // G4Field* myfield = fieldMgr->GetDetectorField();
259 G4ChordFinder* cf = fieldMgr->GetChordFinder();
260 if(!cf)
261 return 0;
262 auto driver = cf->GetIntegrationDriver();
263 if(!driver)
264 return 0;
265 auto equation = driver->GetEquationOfMotion();
266
267 //----- Replaces the equation by a G4ErrorMag_UsualEqRhs to handle backwards
268 //tracking
269 if(!dynamic_cast<G4ErrorMag_UsualEqRhs*>(equation))
270 {
271 G4MagneticField* myfield = (G4MagneticField*) fieldMgr->GetDetectorField();
272
273 // G4Mag_UsualEqRhs* fEquation_usual =
274 // dynamic_cast<G4Mag_UsualEqRhs*>(equation);
275 if(theEquationOfMotion == 0)
276 theEquationOfMotion = new G4ErrorMag_UsualEqRhs(myfield);
277
278 //---- Pass the equation of motion to the G4MagIntegratorStepper
279 driver->SetEquationOfMotion(theEquationOfMotion);
280
281 //--- change stepper for speed tests
282 G4MagIntegratorStepper* g4eStepper =
283 new G4ClassicalRK4(theEquationOfMotion);
284 // G4MagIntegratorStepper* g4eStepper = new
285 // G4ExactHelixStepper(theEquationOfMotion);
286
287 //----
288 G4MagneticField* field = static_cast<G4MagneticField*>(
289 const_cast<G4Field*>(fieldMgr->GetDetectorField()));
290 G4ChordFinder* pChordFinder =
291 new G4ChordFinder(field, 1.0e-2 * mm, g4eStepper);
292
293 fieldMgr->SetChordFinder(pChordFinder);
294 }
295
296 return 1;
297}
298
299//-----------------------------------------------------------------------
301 const G4ErrorTarget* target,
302 G4ErrorMode mode)
303{
305 if(!thePropagator)
306 thePropagator =
307 new G4ErrorPropagator(); // currently the only propagator possible
308
311
312 G4int ierr = thePropagator->Propagate(currentTS, target, mode);
313
315
316 return ierr;
317}
318
319//-----------------------------------------------------------------------
321 G4ErrorMode mode)
322{
324
325 if(!thePropagator)
326 thePropagator =
327 new G4ErrorPropagator(); // currently the only propagator possible
328
330
331 return thePropagator->PropagateOneStep(currentTS);
332}
333
334//-----------------------------------------------------------------------
336{
338 geomManager->OpenGeometry();
339 if(G4StateManager::GetStateManager()->GetCurrentState() != G4State_GeomClosed)
340 {
342 }
343
344 return TRUE;
345}
346
347//---------------------------------------------------------------------------
350{
351 theG4ErrorRunManagerHelper->SetUserInitialization(userInit);
352}
353
354//---------------------------------------------------------------------------
356 G4VPhysicalVolume* userInit)
357{
358 theG4ErrorRunManagerHelper->SetUserInitialization(userInit);
359}
360
361//---------------------------------------------------------------------------
363 G4VUserPhysicsList* userInit)
364{
365 theG4ErrorRunManagerHelper->SetUserInitialization(userInit);
366}
367
368//---------------------------------------------------------------------------
370{
372}
373
374//---------------------------------------------------------------------------
376{
378}
379
380//---------------------------------------------------------------------------
382{
383 G4TrackingManager* trkmgr =
386}
387
388//---------------------------------------------------------------------------
390{
392}
393
394//---------------------------------------------------------------------------
396{
399 theG4ErrorRunManagerHelper->RunTermination();
400}
401
402//---------------------------------------------------------------------------
404{
405 return PrintG4ErrorState(
407}
408
409//---------------------------------------------------------------------------
411{
412 G4String nam = "";
413 switch(state)
414 {
416 nam = "G4ErrorState_PreInit";
417 break;
419 nam = "G4ErrorState_Init";
420 break;
422 nam = "G4ErrorState_Propagating";
423 break;
425 nam = "G4ErrorState_TargetCloserThanBoundary";
426 break;
428 nam = "G4ErrorState_StoppedAtTarget";
429 break;
430 }
431
432 return nam;
433}
434
435//---------------------------------------------------------------------------
437{
438 return PrintG4State(G4StateManager::GetStateManager()->GetCurrentState());
439}
440
441//---------------------------------------------------------------------------
443{
444 G4String nam = "";
445 switch(state)
446 {
447 case G4State_PreInit:
448 nam = "G4State_PreInit";
449 break;
450 case G4State_Init:
451 nam = "G4State_Init";
452 break;
453 case G4State_Idle:
454 nam = "G4State_Idle";
455 break;
457 nam = "G4State_GeomClosed";
458 break;
460 nam = "G4State_EventProc";
461 break;
462 case G4State_Quit:
463 nam = "G4State_Quit";
464 break;
465 case G4State_Abort:
466 nam = "G4State_Abort";
467 break;
468 }
469
470 return nam;
471}
G4ApplicationState
@ G4State_EventProc
@ G4State_Init
@ G4State_Idle
@ G4State_Quit
@ G4State_Abort
@ G4State_GeomClosed
@ G4State_PreInit
@ G4ErrorState_TargetCloserThanBoundary
@ G4ErrorState_Propagating
@ G4ErrorState_Init
@ G4ErrorState_PreInit
@ G4ErrorState_StoppedAtTarget
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4VIntegrationDriver * GetIntegrationDriver()
static void SetVerbose(G4int ver)
static G4ErrorPropagatorData * GetErrorPropagatorData()
void SetMode(G4ErrorMode mode)
void SetState(G4ErrorState sta)
void SetUserInitialization(G4VUserDetectorConstruction *userInit)
G4int Propagate(G4ErrorTrajState *currentTS, const G4ErrorTarget *target, G4ErrorMode mode=G4ErrorMode_PropForwards)
void SetUserAction(G4UserTrackingAction *userAction)
G4int PropagateOneStep(G4ErrorTrajState *currentTS, G4ErrorMode mode=G4ErrorMode_PropForwards)
static G4ErrorPropagatorManager * GetErrorPropagatorManager()
G4int PropagateOneStep(G4ErrorTrajState *currentTS)
void SetStepN(const G4int sn)
G4int Propagate(G4ErrorTrajState *currentTS, const G4ErrorTarget *target, G4ErrorMode mode=G4ErrorMode_PropForwards)
static G4ErrorRunManagerHelper * GetRunManagerKernel()
void SetUserInitialization(G4VUserDetectorConstruction *userInit)
void SetUserAction(G4UserEventAction *userAction)
static G4EventManager * GetEventManager()
G4TrackingManager * GetTrackingManager() const
void SetChordFinder(G4ChordFinder *aChordFinder)
const G4Field * GetDetectorField() const
G4ChordFinder * GetChordFinder()
static G4GeometryManager * GetInstance()
void OpenGeometry(G4VPhysicalVolume *vol=nullptr)
void SetVerboseLevel(G4int level)
G4int GetVerboseLevel() const
void SetWorldVolume(G4VPhysicalVolume *pWorld)
G4VPhysicalVolume * GetWorldVolume() const
G4VIntersectionLocator * GetIntersectionLocator()
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
G4bool SetNewState(const G4ApplicationState &requestedState)
void SetNavigator(G4Navigator *value)
void SetVerboseLevel(G4int vLevel)
G4int GetVerboseLevel() const
G4SteppingManager * GetSteppingManager() const
static G4TransportationManager * GetTransportationManager()
G4PropagatorInField * GetPropagatorInField() const
G4Navigator * GetNavigatorForTracking() const
G4FieldManager * GetFieldManager() const
void SetNavigatorForTracking(G4Navigator *newNavigator)
virtual G4EquationOfMotion * GetEquationOfMotion()=0
void SetNavigatorFor(G4Navigator *fNavigator)
#define TRUE
Definition: globals.hh:41
#define G4ThreadLocal
Definition: tls.hh:77