Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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// $Id$
27//
28// ------------------------------------------------------------
29// GEANT 4 class implementation file
30// ------------------------------------------------------------
31//
32
34
35#include "G4SystemOfUnits.hh"
37#include "G4Mag_UsualEqRhs.hh"
38#include "G4Mag_EqRhs.hh"
40
41#include "G4ClassicalRK4.hh"
44
45#include "G4EventManager.hh"
47#include "G4ErrorPropagator.hh"
49
50#include "G4VParticleChange.hh"
52#include "G4ParticleChange.hh"
53#include "G4Track.hh"
56#include "G4GeometryManager.hh"
57#include "G4StateManager.hh"
58#include "G4ChordFinder.hh"
59#include "G4EquationOfMotion.hh"
60#include "G4FieldManager.hh"
62#include "G4RunManager.hh"
63#include "G4VParticleChange.hh"
64
66G4ErrorPropagatorManager::theG4ErrorPropagatorManager = 0;
67
68//-----------------------------------------------------------------------
70{
71 if( theG4ErrorPropagatorManager == NULL ) {
72 theG4ErrorPropagatorManager = new G4ErrorPropagatorManager;
73 }
74
75 return theG4ErrorPropagatorManager;
76}
77
78
79//-----------------------------------------------------------------------
81{
82 //----- Initialize a few things
83 //o theG4ErrorPropagatorManager = this;
84
85 char* g4emverb = getenv("G4EVERBOSE");
86 if( !g4emverb ) {
88 } else {
90 }
91
92 thePropagator = 0;
93
94 theEquationOfMotion = 0;
95
96 StartG4ErrorRunManagerHelper();
97
99
100 theG4ErrorPropagationNavigator = 0;
101
102 StartNavigator(); //navigator has to be initialized at the beggining !?!?!
103
104
105}
106
107
108//-----------------------------------------------------------------------
110{
111 delete theEquationOfMotion;
112 delete theG4ErrorPropagationNavigator;
113 delete thePropagator;
114 delete theG4ErrorRunManagerHelper;
115 delete theG4ErrorPropagatorManager;
116}
117
118
119//-----------------------------------------------------------------------
120void G4ErrorPropagatorManager::StartG4ErrorRunManagerHelper()
121{
122 //----- Initialize G4ErrorRunManagerHelper
123 theG4ErrorRunManagerHelper = G4ErrorRunManagerHelper::GetRunManagerKernel();
124
125 if( theG4ErrorRunManagerHelper == 0 ) {
126 theG4ErrorRunManagerHelper = new G4ErrorRunManagerHelper();
127 }
128
129 //----- User Initialization classes
130 //--- GEANT4e PhysicsList
131 if( G4ErrorPropagatorData::verbose() >= 4 ) G4cout << " G4ErrorPropagatorManager::StartG4eRunManager() done " << theG4ErrorRunManagerHelper << G4endl;
132 //- theG4eRunManager->SetUserInitialization(new G4ErrorPhysicsList);
133
134}
135
136
137//-----------------------------------------------------------------------
138void G4ErrorPropagatorManager::StartNavigator()
139{
140 if( theG4ErrorPropagationNavigator == 0 ) {
142
143 G4Navigator* g4navi = transportationManager->GetNavigatorForTracking();
144
145 G4VPhysicalVolume* world = g4navi->GetWorldVolume();
146 G4int verb = g4navi->GetVerboseLevel();
147 delete g4navi;
148
149 theG4ErrorPropagationNavigator = new G4ErrorPropagationNavigator();
150
151 if( world != 0 ) {
152 theG4ErrorPropagationNavigator->SetWorldVolume( world );
153 }
154 theG4ErrorPropagationNavigator->SetVerboseLevel( verb );
155
156 transportationManager->SetNavigatorForTracking(theG4ErrorPropagationNavigator);
157 transportationManager->GetPropagatorInField()->GetIntersectionLocator()
158 ->SetNavigatorFor(theG4ErrorPropagationNavigator);
160 ->SetNavigator(theG4ErrorPropagationNavigator);
161 // G4ThreeVector center(0,0,0);
162 // theG4ErrorPropagationNavigator->LocateGlobalPointAndSetup(center,0,false);
163
164 }
165
166 if( G4ErrorPropagatorData::verbose() >= 2 ) G4cout << " theState at StartNavigator " << PrintG4ErrorState() << G4endl;
167
168}
169
170
171//-----------------------------------------------------------------------
173{
174 if( G4ErrorPropagatorData::verbose() >= 1 ) G4cout << "InitGeant4e GEANT4e State= " << PrintG4ErrorState() << " GEANT4 State= " << PrintG4State() << G4endl;
176 //----- Initialize run
177 // if( G4StateManager::GetStateManager()->GetCurrentState() == G4State_PreInit) {
178
180 if ( currentState == G4State_PreInit || currentState == G4State_Idle) {
181 // G4eRunManager::GetRunManager()->Initialize();
182 theG4ErrorRunManagerHelper->InitializeGeometry();
183 theG4ErrorRunManagerHelper->InitializePhysics();
184 }
185
187
188 //- G4StateManager::GetStateManager()->SetNewState(G4State_Idle);
189
190 if( G4ErrorPropagatorData::verbose() >= 4 ) G4cout << " bef theG4ErrorPropagatorManager->RunInitialization() " << G4StateManager::GetStateManager()->GetCurrentState() << G4endl;
191 theG4ErrorRunManagerHelper->RunInitialization();
192 if( G4ErrorPropagatorData::verbose() >= 4 ) G4cout << " aft theG4ErrorPropagatorManager->RunInitialization() " << G4StateManager::GetStateManager()->GetCurrentState() << G4endl;
193
194 if( !thePropagator ) thePropagator = new G4ErrorPropagator(); // currently the only propagator possible
195
197 } else {
198 G4cerr << "G4ErrorPropagatorManager::InitGeant4e: Illegal application state - "
199 << "G4ErrorPropagatorManager::InitGeant4e() ignored." << G4endl;
200 G4cerr << " GEANT4e State= " << PrintG4ErrorState()
201 //<< " GEANT4 State= " << PrintG4State()
202 << G4endl;
203 }
204
205 //----- Set the tracking geometry for this propagation
206 //t SetTrackingGeometry();
207 //----- Set the physics list for this propagation
208 //t SetPhysicsList();
209 //----- Set the field propagation parameters for this propagation
210 //t SetFieldPropagationParameters();
212
213 if( G4ErrorPropagatorData::verbose() >= 2 ) G4cout << "End InitGeant4e GEANT4e State= " << PrintG4ErrorState() << " GEANT4 State= " << PrintG4State() << G4endl;
214
215
216}
217
218
219//-----------------------------------------------------------------------
221{
222 thePropagator->SetStepN( 0 );
223
225
226}
227
228
229//-----------------------------------------------------------------------
231{
232
233 if( G4ErrorPropagatorData::verbose() >= 4 ) G4cout << " G4ErrorPropagatorManager::InitFieldForBackwards() " << G4endl;
234 //----- Gets the current equation of motion
236 // G4cout << " fieldMgr " << fieldMgr << G4endl;
237 if( !fieldMgr ) return 0;
238
239 // G4Field* myfield = fieldMgr->GetDetectorField();
240 G4ChordFinder* cf = fieldMgr ->GetChordFinder();
241 if( !cf ) return 0;
243 if( !mid ) return 0;
244 G4MagIntegratorStepper* stepper = const_cast<G4MagIntegratorStepper*>(mid->GetStepper());
245 if( !stepper ) return 0;
246 G4EquationOfMotion* equation = stepper->GetEquationOfMotion();
247
248 //----- Replaces the equation by a G4ErrorMag_UsualEqRhs to handle backwards tracking
249 if ( !dynamic_cast<G4ErrorMag_UsualEqRhs*>(equation) ) {
250
251 G4MagneticField* myfield = (G4MagneticField*)fieldMgr->GetDetectorField();
252
253 // G4Mag_UsualEqRhs* fEquation_usual = dynamic_cast<G4Mag_UsualEqRhs*>(equation);
254 if( theEquationOfMotion == 0 ) theEquationOfMotion = new G4ErrorMag_UsualEqRhs(myfield);
255
256 //---- Pass the equation of motion to the G4MagIntegratorStepper
257 stepper->SetEquationOfMotion( theEquationOfMotion );
258
259 //--- change stepper for speed tests
260 G4MagIntegratorStepper* g4eStepper = new G4ClassicalRK4(theEquationOfMotion);
261 // G4MagIntegratorStepper* g4eStepper = new G4ExactHelixStepper(theEquationOfMotion);
262
263 //----
264 G4MagneticField* field = static_cast<G4MagneticField*>(const_cast<G4Field*>(fieldMgr->GetDetectorField()));
265 G4ChordFinder* pChordFinder = new G4ChordFinder(field, 1.0e-2*mm, g4eStepper);
266
267 fieldMgr->SetChordFinder(pChordFinder);
268
269 }
270
271 return 1;
272}
273
274
275//-----------------------------------------------------------------------
277{
279 if( !thePropagator ) thePropagator = new G4ErrorPropagator(); // currently the only propagator possible
280
283
284 G4int ierr = thePropagator->Propagate( currentTS, target, mode );
285
287
288 return ierr;
289}
290
291
292//-----------------------------------------------------------------------
294{
296
297 if( !thePropagator ) thePropagator = new G4ErrorPropagator(); // currently the only propagator possible
298
300
301 return thePropagator->PropagateOneStep( currentTS );
302}
303
304
305//-----------------------------------------------------------------------
307{
309 geomManager->OpenGeometry();
310 if( G4StateManager::GetStateManager()->GetCurrentState() != G4State_GeomClosed) {
312 }
313
314 return TRUE;
315}
316
317
318//---------------------------------------------------------------------------
320{
321 theG4ErrorRunManagerHelper->SetUserInitialization( userInit);
322}
323
324
325//---------------------------------------------------------------------------
327{
328 theG4ErrorRunManagerHelper->SetUserInitialization( userInit);
329}
330
331
332//---------------------------------------------------------------------------
334{
335 theG4ErrorRunManagerHelper->SetUserInitialization( userInit);
336}
337
338
339//---------------------------------------------------------------------------
341{
343}
344
345
346//---------------------------------------------------------------------------
348{
350}
351
352
353//---------------------------------------------------------------------------
355{
357 trkmgr->GetSteppingManager()->SetVerboseLevel( trkmgr->GetVerboseLevel() );
358}
359
360
361//---------------------------------------------------------------------------
363{
365}
366
367
368//---------------------------------------------------------------------------
370{
372 theG4ErrorRunManagerHelper->RunTermination();
373}
374
375
376//---------------------------------------------------------------------------
378{
380}
381
382
383//---------------------------------------------------------------------------
385{
386 G4String nam = "";
387 switch (state){
389 nam = "G4ErrorState_PreInit";
390 break;
391 case G4ErrorState_Init:
392 nam = "G4ErrorState_Init";
393 break;
395 nam = "G4ErrorState_Propagating";
396 break;
398 nam = "G4ErrorState_TargetCloserThanBoundary";
399 break;
401 nam = "G4ErrorState_StoppedAtTarget";
402 break;
403 }
404
405 return nam;
406}
407
408
409//---------------------------------------------------------------------------
411{
412 return PrintG4State(G4StateManager::GetStateManager()->GetCurrentState());
413}
414
415
416//---------------------------------------------------------------------------
418{
419 G4String nam = "";
420 switch ( state ){
421 case G4State_PreInit:
422 nam = "G4State_PreInit";
423 break;
424 case G4State_Init:
425 nam = "G4State_Init";
426 break;
427 case G4State_Idle:
428 nam = "G4State_Idle";
429 break;
431 nam = "G4State_GeomClosed";
432 break;
434 nam = "G4State_EventProc";
435 break;
436 case G4State_Quit:
437 nam = "G4State_Quit";
438 break;
439 case G4State_Abort:
440 nam = "G4State_Abort";
441 break;
442 }
443
444 return nam;
445
446}
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
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cerr
G4DLLIMPORT std::ostream G4cout
G4MagInt_Driver * 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()
void OpenGeometry(G4VPhysicalVolume *vol=0)
static G4GeometryManager * GetInstance()
const G4MagIntegratorStepper * GetStepper() const
G4EquationOfMotion * GetEquationOfMotion()
void SetEquationOfMotion(G4EquationOfMotion *newEquation)
void SetVerboseLevel(G4int level)
G4int GetVerboseLevel() const
void SetWorldVolume(G4VPhysicalVolume *pWorld)
G4VPhysicalVolume * GetWorldVolume() const
G4VIntersectionLocator * GetIntersectionLocator()
G4ApplicationState GetCurrentState() const
static G4StateManager * GetStateManager()
G4bool SetNewState(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)
void SetNavigatorFor(G4Navigator *fNavigator)
#define TRUE
Definition: globals.hh:55