Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
errprop.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 //
28 //
29 // ------------------------------------------------------------
30 // GEANT 4 example main
31 // ------------------------------------------------------------
32 //
33 // History:
34 // - Created: P. Arce May 2007
35 //
36 
38 #include "G4SteppingVerbose.hh"
39 
40 #include "G4ErrorPropagator.hh"
41 #include "G4ErrorPropagatorData.hh"
47 #include "G4ErrorFreeTrajState.hh"
48 
49 #include "G4UImanager.hh"
50 #include "G4SystemOfUnits.hh"
51 
52 void Initialize();
53 G4ErrorTarget* BuildTarget( G4int iTarget );
54 void ProcessEvent( G4int iProp, size_t nEv );
55 void Finalize();
56 
59 
60 //-------------------------------------------------------------
61 int main()
62 {
63 
64  Initialize();
65 
66  //----- Choose propagation mode
67  // 0: propagate until target, all steps in one go
68  // 1: propagate until target, returning control to the user at each step
69  G4int iProp = 0;
70  char* prop = getenv("G4ERROR_PROP");
71  if( prop ) {
72  if( G4String(prop) == G4String("UNTIL_TARGET") ){
73  iProp = 0;
74  } else if ( G4String(prop) == G4String("STEP_BY_STEP") ) {
75  iProp = 1;
76  } else {
77  G4Exception("exG4eReco","Fatal error in Argument",FatalErrorInArgument,G4String("Variable G4ERROR_PROP = " + G4String(prop) + " It must be: UNTIL_TARGET or STEP_BY_STEP").c_str());
78  }
79  } else {
80  G4Exception("exG4eReco","Fatal error in Argument",JustWarning,"Variable G4ERROR_PROP not defined, taking it = UNTIL_TARGET");
81  }
82 
83  size_t nEvents = 3;
84  for( size_t ii = 0; ii < nEvents; ii++ ){
85  ProcessEvent( iProp, ii );
86  }
87 
88  Finalize();
89 
90 }
91 
92 
93 //-------------------------------------------------------------
94 void Initialize()
95 {
97 
98  // Initialize the GEANT4e manager
101 
103 
104  G4UImanager::GetUIpointer()->ApplyCommand("/exerror/setField -10. kilogauss");
105 
106  g4emgr->InitGeant4e();
107 
108  G4UImanager::GetUIpointer()->ApplyCommand("/control/verbose 1");
109  G4UImanager::GetUIpointer()->ApplyCommand("/tracking/verbose 1");
110  G4UImanager::GetUIpointer()->ApplyCommand("/geant4e/limits/stepLength 100 mm");
111 
112  //----- Choose target type:
113  // 1: PlaneSurfaceTarget
114  // 2: CylSurfaceTarget
115  // 3: GeomVolumeTarget
116  // 4: TrackLengthTarget
117  G4int iTarget = 1;
118  char* target = getenv("G4ERROR_TARGET");
119  if( target ) {
120  if( G4String(target) == G4String("PLANE_SURFACE") ) {
121  iTarget = 1;
122  }else if( G4String(target) == G4String("CYL_SURFACE") ) {
123  iTarget = 2;
124  }else if( G4String(target) == G4String("VOLUME") ) {
125  iTarget = 3;
126  }else if( G4String(target) == G4String("TRKLEN") ) {
127  iTarget = 4;
128  }else {
129  G4Exception("exG4eReco","Fatal error in Argument",FatalErrorInArgument,G4String("Variable G4ERROR_TARGET = " + G4String(target) + " It must be: PLANE_SURFACE, CYL_SURFACE, VOLUME, TRKLEN").c_str());
130  }
131  } else {
132  G4Exception("exG4eReco","Fatal error in Argument",JustWarning,"Variable G4ERROR_TARGET not defined, taking it = PLANE_SURFACE");
133  }
134 
135  theTarget = BuildTarget( iTarget );
136  g4edata->SetTarget( theTarget );
137 
139  char* mode = getenv("G4ERROR_MODE");
140  if( mode ) {
141  if( G4String(mode) == G4String("FORWARDS") ) {
143  } else if( G4String(mode) == G4String("BACKWARDS") ) {
145  } else {
146  G4Exception("exG4eReco","Fatal error in Argument",FatalErrorInArgument,G4String("Variable G4ERROR_MODE = " + G4String(mode) + " It must be: FORWARDS or BACKWARDS").c_str());
147  }
148  } else {
149  G4Exception("exG4eReco","Fatal error in Argument",JustWarning,"Variable G4ERROR_MODE not defined, taking it = BACKWARDS");
150  }
151 
152 }
153 
154 
155 void ProcessEvent( G4int iProp, size_t )
156 {
157 
158 // Set the starting trajectory.
159  G4ThreeVector xv3( 0, 0, 0 );
160  G4ThreeVector pv3( 20.0*GeV, 0.0, 0.0 );
161  G4ErrorTrajErr error( 5, 0 );
162  G4ErrorFreeTrajState* g4ErrorTrajState = new G4ErrorFreeTrajState( "mu-", xv3, pv3, error );
163 
165 
166  //int ierr = 0;
167 
168  G4Point3D surfPos(224.*cm,0.,0.);
169  G4Normal3D surfNorm(1.,0.,0.);
170  //- G4ErrorTarget* theG4ErrorTarget = new G4ErrorPlaneSurfaceTarget(surfNorm, surfPos );
171 
172  if( iProp == 0){
173  // Propagate until G4ErrorTarget is found all in one go
174  //ierr =
175  g4emgr->Propagate( g4ErrorTrajState, theTarget, theG4ErrorMode );
176  } else if( iProp == 1){
177 
178  // Propagate until G4ErrorTarget is reached step by step
179 
180  g4emgr->InitTrackPropagation();
181 
182  // G4Track* aTrack = G4EventManager::GetEventManager()->GetTrackingManager()->GetTrack();
183  bool moreEvt = TRUE;
184  while( moreEvt ){
185 
186  //ierr =
187  g4emgr->PropagateOneStep( g4ErrorTrajState, theG4ErrorMode );
188 
189  //---- Check if target is reached
190  if( g4emgr->GetPropagator()->CheckIfLastStep( g4ErrorTrajState->GetG4Track() )) {
191  g4emgr->GetPropagator()->InvokePostUserTrackingAction( g4ErrorTrajState->GetG4Track() );
192  moreEvt = 0;
193  G4cout << "STEP_BY_STEP propagation: Last Step " << G4endl;
194  }
195  }
196  }
197 
198  G4cout << " $$$ PROPAGATION ENDED " << G4endl;
199  // extract current state info
200  G4Point3D posEnd = g4ErrorTrajState->GetPosition();
201  G4Normal3D momEnd = g4ErrorTrajState->GetMomentum();
202  G4ErrorTrajErr errorEnd = g4ErrorTrajState->GetError();
203 
204  G4cout << " Position: " << posEnd << G4endl
205  << " Momentum: " << momEnd << G4endl
206  << " Error: " << errorEnd << G4endl;
207 }
208 
209 
210 //-------------------------------------------------------------
212 {
213 
214  G4ErrorTarget* target = 0;
215  if( iTarget == 1 ) {
216  G4Point3D surfPos(221.*cm,0.,0.);
217  G4Normal3D surfNorm(1.,0.,0.);
218  target = new G4ErrorPlaneSurfaceTarget(surfNorm, surfPos );
219  }else if( iTarget == 2 ) {
220  G4double radius = 222*cm;
221  target = new G4ErrorCylSurfaceTarget(radius);
222  }else if( iTarget == 3 ) {
223  target = new G4ErrorGeomVolumeTarget("MUON");
224  }else if( iTarget == 4 ) {
225  target = new G4ErrorTrackLengthTarget(223.*cm);
226  }else {
227  G4Exception("exG4eReco","Fatal error in Argument",FatalErrorInArgument,"Target type has to be between 1 and 4");
228  }
229  return target;
230 }
231 
232 
233 //-------------------------------------------------------------
234 void Finalize()
235 {
237 
238 }