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