Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions | Variables
errprop.cc File Reference

Main program of the errorpropagation example. More...

#include "ExErrorDetectorConstruction.hh"
#include "G4SteppingVerbose.hh"
#include "G4ErrorPropagator.hh"
#include "G4ErrorPropagatorData.hh"
#include "G4ErrorPropagatorManager.hh"
#include "G4ErrorPlaneSurfaceTarget.hh"
#include "G4ErrorCylSurfaceTarget.hh"
#include "G4ErrorGeomVolumeTarget.hh"
#include "G4ErrorTrackLengthTarget.hh"
#include "G4ErrorFreeTrajState.hh"
#include "G4UImanager.hh"
#include "G4SystemOfUnits.hh"

Go to the source code of this file.

Functions

void Initialize ()
 
G4ErrorTargetBuildTarget (G4int iTarget)
 
void ProcessEvent (G4int iProp, size_t nEv)
 
void Finalize ()
 
int main ()
 

Variables

G4ErrorTargettheTarget
 
G4ErrorMode theG4ErrorMode
 

Detailed Description

Main program of the errorpropagation example.

Definition in file errprop.cc.

Function Documentation

G4ErrorTarget * BuildTarget ( G4int  iTarget)

Definition at line 213 of file errprop.cc.

References python.hepunit::cm, FatalErrorInArgument, and G4Exception().

Referenced by Initialize().

214 {
215 
216  G4ErrorTarget* target = 0;
217  if( iTarget == 1 ) {
218  G4Point3D surfPos(221.*cm,0.,0.);
219  G4Normal3D surfNorm(1.,0.,0.);
220  target = new G4ErrorPlaneSurfaceTarget(surfNorm, surfPos );
221  }else if( iTarget == 2 ) {
222  G4double radius = 222*cm;
223  target = new G4ErrorCylSurfaceTarget(radius);
224  }else if( iTarget == 3 ) {
225  target = new G4ErrorGeomVolumeTarget("MUON");
226  }else if( iTarget == 4 ) {
227  target = new G4ErrorTrackLengthTarget(223.*cm);
228  }else {
229  G4Exception("exG4eReco","Fatal error in Argument",FatalErrorInArgument,"Target type has to be between 1 and 4");
230  }
231  return target;
232 }
const XML_Char * target
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double G4double
Definition: G4Types.hh:76
void Finalize ( )
void Initialize ( )

Definition at line 96 of file errprop.cc.

References G4UImanager::ApplyCommand(), BuildTarget(), FatalErrorInArgument, G4ErrorMode_PropBackwards, G4ErrorMode_PropForwards, G4Exception(), G4ErrorPropagatorData::GetErrorPropagatorData(), G4ErrorPropagatorManager::GetErrorPropagatorManager(), G4UImanager::GetUIpointer(), G4ErrorPropagatorManager::InitGeant4e(), JustWarning, G4VSteppingVerbose::SetInstance(), G4ErrorPropagatorData::SetTarget(), G4ErrorPropagatorManager::SetUserInitialization(), and theG4ErrorMode.

Referenced by G4GDMLParser::G4GDMLParser(), G4MPImanager::G4MPImanager(), main(), HepMCG4AsciiReaderMessenger::SetNewValue(), and HadrontherapyDetectorConstruction::UpdateGeometry().

97 {
99 
100  // Initialize the GEANT4e manager
103 
105 
106  G4UImanager::GetUIpointer()->ApplyCommand("/exerror/setField -10. kilogauss");
107 
108  g4emgr->InitGeant4e();
109 
110  G4UImanager::GetUIpointer()->ApplyCommand("/control/verbose 1");
111  G4UImanager::GetUIpointer()->ApplyCommand("/tracking/verbose 1");
112  G4UImanager::GetUIpointer()->ApplyCommand("/geant4e/limits/stepLength 100 mm");
113 
114  //----- Choose target type:
115  // 1: PlaneSurfaceTarget
116  // 2: CylSurfaceTarget
117  // 3: GeomVolumeTarget
118  // 4: TrackLengthTarget
119  G4int iTarget = 1;
120  char* target = getenv("G4ERROR_TARGET");
121  if( target ) {
122  if( G4String(target) == G4String("PLANE_SURFACE") ) {
123  iTarget = 1;
124  }else if( G4String(target) == G4String("CYL_SURFACE") ) {
125  iTarget = 2;
126  }else if( G4String(target) == G4String("VOLUME") ) {
127  iTarget = 3;
128  }else if( G4String(target) == G4String("TRKLEN") ) {
129  iTarget = 4;
130  }else {
131  G4Exception("exG4eReco","Fatal error in Argument",FatalErrorInArgument,G4String("Variable G4ERROR_TARGET = " + G4String(target) + " It must be: PLANE_SURFACE, CYL_SURFACE, VOLUME, TRKLEN").c_str());
132  }
133  } else {
134  G4Exception("exG4eReco","Fatal error in Argument",JustWarning,"Variable G4ERROR_TARGET not defined, taking it = PLANE_SURFACE");
135  }
136 
137  theTarget = BuildTarget( iTarget );
138  g4edata->SetTarget( theTarget );
139 
141  char* mode = getenv("G4ERROR_MODE");
142  if( mode ) {
143  if( G4String(mode) == G4String("FORWARDS") ) {
145  } else if( G4String(mode) == G4String("BACKWARDS") ) {
147  } else {
148  G4Exception("exG4eReco","Fatal error in Argument",FatalErrorInArgument,G4String("Variable G4ERROR_MODE = " + G4String(mode) + " It must be: FORWARDS or BACKWARDS").c_str());
149  }
150  } else {
151  G4Exception("exG4eReco","Fatal error in Argument",JustWarning,"Variable G4ERROR_MODE not defined, taking it = BACKWARDS");
152  }
153 
154 }
const XML_Char * target
static G4ErrorPropagatorManager * GetErrorPropagatorManager()
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4ErrorMode theG4ErrorMode
Definition: errprop.cc:60
void SetUserInitialization(G4VUserDetectorConstruction *userInit)
G4ErrorTarget * theTarget
Definition: errprop.cc:59
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void SetTarget(const G4ErrorTarget *target)
static void SetInstance(G4VSteppingVerbose *Instance)
G4ErrorTarget * BuildTarget(G4int iTarget)
Definition: errprop.cc:213
static G4ErrorPropagatorData * GetErrorPropagatorData()
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:419
int main ( )

Definition at line 63 of file errprop.cc.

References FatalErrorInArgument, Finalize(), G4Exception(), Initialize(), JustWarning, and ProcessEvent().

64 {
65 
66  Initialize();
67 
68  //----- Choose propagation mode
69  // 0: propagate until target, all steps in one go
70  // 1: propagate until target, returning control to the user at each step
71  G4int iProp = 0;
72  char* prop = getenv("G4ERROR_PROP");
73  if( prop ) {
74  if( G4String(prop) == G4String("UNTIL_TARGET") ){
75  iProp = 0;
76  } else if ( G4String(prop) == G4String("STEP_BY_STEP") ) {
77  iProp = 1;
78  } else {
79  G4Exception("exG4eReco","Fatal error in Argument",FatalErrorInArgument,G4String("Variable G4ERROR_PROP = " + G4String(prop) + " It must be: UNTIL_TARGET or STEP_BY_STEP").c_str());
80  }
81  } else {
82  G4Exception("exG4eReco","Fatal error in Argument",JustWarning,"Variable G4ERROR_PROP not defined, taking it = UNTIL_TARGET");
83  }
84 
85  size_t nEvents = 3;
86  for( size_t ii = 0; ii < nEvents; ii++ ){
87  ProcessEvent( iProp, ii );
88  }
89 
90  Finalize();
91 
92 }
void Initialize()
Definition: errprop.cc:96
void ProcessEvent(G4int iProp, size_t nEv)
Definition: errprop.cc:157
int G4int
Definition: G4Types.hh:78
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void Finalize()
Definition: errprop.cc:236
void ProcessEvent ( G4int  iProp,
size_t  nEv 
)

Definition at line 157 of file errprop.cc.

References G4ErrorPropagator::CheckIfLastStep(), python.hepunit::cm, G4cout, G4endl, G4ErrorTrajState::GetError(), G4ErrorPropagatorManager::GetErrorPropagatorManager(), G4ErrorTrajState::GetG4Track(), G4ErrorTrajState::GetMomentum(), G4ErrorTrajState::GetPosition(), G4ErrorPropagatorManager::GetPropagator(), python.hepunit::GeV, G4ErrorPropagatorManager::InitTrackPropagation(), G4ErrorPropagator::InvokePostUserTrackingAction(), G4ErrorPropagatorManager::Propagate(), G4ErrorPropagatorManager::PropagateOneStep(), theG4ErrorMode, and TRUE.

Referenced by main().

158 {
159 
160 // Set the starting trajectory.
161  G4ThreeVector xv3( 0, 0, 0 );
162  G4ThreeVector pv3( 20.0*GeV, 0.0, 0.0 );
163  G4ErrorTrajErr error( 5, 0 );
164  G4ErrorFreeTrajState* g4ErrorTrajState = new G4ErrorFreeTrajState( "mu-", xv3, pv3, error );
165 
167 
168  //int ierr = 0;
169 
170  G4Point3D surfPos(224.*cm,0.,0.);
171  G4Normal3D surfNorm(1.,0.,0.);
172  //- G4ErrorTarget* theG4ErrorTarget = new G4ErrorPlaneSurfaceTarget(surfNorm, surfPos );
173 
174  if( iProp == 0){
175  // Propagate until G4ErrorTarget is found all in one go
176  //ierr =
177  g4emgr->Propagate( g4ErrorTrajState, theTarget, theG4ErrorMode );
178  } else if( iProp == 1){
179 
180  // Propagate until G4ErrorTarget is reached step by step
181 
182  g4emgr->InitTrackPropagation();
183 
184  // G4Track* aTrack = G4EventManager::GetEventManager()->GetTrackingManager()->GetTrack();
185  bool moreEvt = TRUE;
186  while( moreEvt ){
187 
188  //ierr =
189  g4emgr->PropagateOneStep( g4ErrorTrajState, theG4ErrorMode );
190 
191  //---- Check if target is reached
192  if( g4emgr->GetPropagator()->CheckIfLastStep( g4ErrorTrajState->GetG4Track() )) {
193  g4emgr->GetPropagator()->InvokePostUserTrackingAction( g4ErrorTrajState->GetG4Track() );
194  moreEvt = 0;
195  G4cout << "STEP_BY_STEP propagation: Last Step " << G4endl;
196  }
197  }
198  }
199 
200  G4cout << " $$$ PROPAGATION ENDED " << G4endl;
201  // extract current state info
202  G4Point3D posEnd = g4ErrorTrajState->GetPosition();
203  G4Normal3D momEnd = g4ErrorTrajState->GetMomentum();
204  G4ErrorTrajErr errorEnd = g4ErrorTrajState->GetError();
205 
206  G4cout << " Position: " << posEnd << G4endl
207  << " Momentum: " << momEnd << G4endl
208  << " Error: " << errorEnd << G4endl;
209 }
G4int PropagateOneStep(G4ErrorTrajState *currentTS, G4ErrorMode mode=G4ErrorMode_PropForwards)
void InvokePostUserTrackingAction(G4Track *fpTrack)
G4Point3D GetPosition() const
static G4ErrorPropagatorManager * GetErrorPropagatorManager()
G4ErrorMode theG4ErrorMode
Definition: errprop.cc:60
G4GLOB_DLL std::ostream G4cout
G4ErrorPropagator * GetPropagator() const
G4Vector3D GetMomentum() const
G4ErrorTarget * theTarget
Definition: errprop.cc:59
#define TRUE
Definition: globals.hh:55
G4Track * GetG4Track() const
G4bool CheckIfLastStep(G4Track *aTrack)
G4int Propagate(G4ErrorTrajState *currentTS, const G4ErrorTarget *target, G4ErrorMode mode=G4ErrorMode_PropForwards)
#define G4endl
Definition: G4ios.hh:61
G4ErrorTrajErr GetError() const

Variable Documentation

G4ErrorMode theG4ErrorMode

Definition at line 60 of file errprop.cc.

Referenced by Initialize(), and ProcessEvent().

G4ErrorTarget* theTarget