source: trunk/examples/extended/errorpropagation/errprop.cc@ 1244

Last change on this file since 1244 was 1230, checked in by garnier, 16 years ago

update to geant4.9.3

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