source: trunk/source/error_propagation/src/G4ErrorPropagatorManager.cc@ 1227

Last change on this file since 1227 was 1058, checked in by garnier, 17 years ago

file release beta

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