Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // 27 /// \file errProp/errProp.cc 27 /// \file errProp/errProp.cc 28 /// \brief Main program of the errorpropagatio 28 /// \brief Main program of the errorpropagation example 29 // 29 // 30 // ------------------------------------------- 30 // ------------------------------------------------------------ 31 // GEANT 4 example main 31 // GEANT 4 example main 32 // ------------------------------------------- 32 // ------------------------------------------------------------ 33 // 33 // 34 // History: 34 // History: 35 // - Created: P. Arce May 2007 35 // - Created: P. Arce May 2007 36 // 36 // 37 37 38 #include "ExErrorDetectorConstruction.hh" 38 #include "ExErrorDetectorConstruction.hh" >> 39 #include "G4SteppingVerbose.hh" 39 40 40 #include "G4ErrorCylSurfaceTarget.hh" << 41 #include "G4ErrorFreeTrajState.hh" << 42 #include "G4ErrorGeomVolumeTarget.hh" << 43 #include "G4ErrorPlaneSurfaceTarget.hh" << 44 #include "G4ErrorPropagator.hh" 41 #include "G4ErrorPropagator.hh" 45 #include "G4ErrorPropagatorData.hh" 42 #include "G4ErrorPropagatorData.hh" 46 #include "G4ErrorPropagatorManager.hh" 43 #include "G4ErrorPropagatorManager.hh" >> 44 #include "G4ErrorPlaneSurfaceTarget.hh" >> 45 #include "G4ErrorCylSurfaceTarget.hh" >> 46 #include "G4ErrorGeomVolumeTarget.hh" 47 #include "G4ErrorTrackLengthTarget.hh" 47 #include "G4ErrorTrackLengthTarget.hh" 48 #include "G4SteppingVerbose.hh" << 48 #include "G4ErrorFreeTrajState.hh" 49 #include "G4SystemOfUnits.hh" << 49 50 #include "G4UImanager.hh" 50 #include "G4UImanager.hh" >> 51 #include "G4SystemOfUnits.hh" 51 52 52 void Initialize(); 53 void Initialize(); 53 G4ErrorTarget* BuildTarget(G4int iTarget); << 54 G4ErrorTarget* BuildTarget( G4int iTarget ); 54 void ProcessEvent(G4int iProp, size_t nEv); << 55 void ProcessEvent( G4int iProp, size_t nEv ); 55 void Finalize(); 56 void Finalize(); 56 57 57 G4ErrorTarget* theTarget; 58 G4ErrorTarget* theTarget; 58 G4ErrorMode theG4ErrorMode; 59 G4ErrorMode theG4ErrorMode; 59 60 60 //-------------------------------------------- 61 //------------------------------------------------------------- 61 int main() << 62 int main() 62 { 63 { >> 64 63 Initialize(); 65 Initialize(); 64 66 65 //----- Choose propagation mode 67 //----- Choose propagation mode 66 // 0: propagate until target, all steps in o 68 // 0: propagate until target, all steps in one go 67 // 1: propagate until target, returning cont 69 // 1: propagate until target, returning control to the user at each step 68 G4int iProp = 0; 70 G4int iProp = 0; 69 char* prop = std::getenv("G4ERROR_PROP"); 71 char* prop = std::getenv("G4ERROR_PROP"); 70 if (prop) { << 72 if( prop ) { 71 if (G4String(prop) == G4String("UNTIL_TARG << 73 if( G4String(prop) == G4String("UNTIL_TARGET") ){ 72 iProp = 0; 74 iProp = 0; 73 } << 75 } else if ( G4String(prop) == G4String("STEP_BY_STEP") ) { 74 else if (G4String(prop) == G4String("STEP_ << 75 iProp = 1; 76 iProp = 1; 76 } << 77 } else { 77 else { << 78 G4Exception("exG4eReco","Fatal error in Argument", 78 G4Exception("exG4eReco", "Fatal error in << 79 FatalErrorInArgument, 79 G4String("Variable G4ERROR_P << 80 G4String("Variable G4ERROR_PROP = " + G4String(prop) + 80 + " It must be: U << 81 " It must be: UNTIL_TARGET or STEP_BY_STEP").c_str()); 81 .c_str()); << 82 } 82 } << 83 } else { 83 } << 84 G4Exception("exG4eReco","Fatal error in Argument", 84 else { << 85 JustWarning, 85 G4Exception("exG4eReco", "Fatal error in A << 86 "Variable G4ERROR_PROP not defined, taking it = UNTIL_TARGET"); 86 "Variable G4ERROR_PROP not def << 87 } 87 } << 88 88 89 size_t nEvents = 3; 89 size_t nEvents = 3; 90 for (size_t ii = 0; ii < nEvents; ii++) { << 90 for( size_t ii = 0; ii < nEvents; ii++ ){ 91 ProcessEvent(iProp, ii); << 91 ProcessEvent( iProp, ii ); 92 } 92 } 93 93 94 Finalize(); 94 Finalize(); >> 95 95 } 96 } 96 97 >> 98 97 //-------------------------------------------- 99 //------------------------------------------------------------- 98 void Initialize() << 100 void Initialize() 99 { 101 { 100 G4VSteppingVerbose::SetInstance(new G4Steppi 102 G4VSteppingVerbose::SetInstance(new G4SteppingVerbose); 101 103 102 // Initialize the GEANT4e manager << 104 // Initialize the GEANT4e manager 103 G4ErrorPropagatorManager* g4emgr = G4ErrorPr << 105 G4ErrorPropagatorManager* g4emgr 104 G4ErrorPropagatorData* g4edata = G4ErrorProp << 106 = G4ErrorPropagatorManager::GetErrorPropagatorManager(); >> 107 G4ErrorPropagatorData* g4edata >> 108 = G4ErrorPropagatorData::GetErrorPropagatorData(); 105 109 106 g4emgr->SetUserInitialization(new ExErrorDet << 110 g4emgr->SetUserInitialization(new ExErrorDetectorConstruction); 107 111 108 G4UImanager::GetUIpointer()->ApplyCommand("/ 112 G4UImanager::GetUIpointer()->ApplyCommand("/exerror/setField -10. kilogauss"); 109 113 110 g4emgr->InitGeant4e(); 114 g4emgr->InitGeant4e(); 111 115 112 G4UImanager::GetUIpointer()->ApplyCommand("/ 116 G4UImanager::GetUIpointer()->ApplyCommand("/control/verbose 1"); 113 G4UImanager::GetUIpointer()->ApplyCommand("/ 117 G4UImanager::GetUIpointer()->ApplyCommand("/tracking/verbose 1"); 114 G4UImanager::GetUIpointer()->ApplyCommand("/ 118 G4UImanager::GetUIpointer()->ApplyCommand("/geant4e/limits/stepLength 100 mm"); 115 119 116 //----- Choose target type: 120 //----- Choose target type: 117 // 1: PlaneSurfaceTarget 121 // 1: PlaneSurfaceTarget 118 // 2: CylSurfaceTarget 122 // 2: CylSurfaceTarget 119 // 3: GeomVolumeTarget 123 // 3: GeomVolumeTarget 120 // 4: TrackLengthTarget 124 // 4: TrackLengthTarget 121 G4int iTarget = 1; 125 G4int iTarget = 1; 122 char* target = std::getenv("G4ERROR_TARGET") 126 char* target = std::getenv("G4ERROR_TARGET"); 123 if (target) { << 127 if( target ) { 124 if (G4String(target) == G4String("PLANE_SU << 128 if( G4String(target) == G4String("PLANE_SURFACE") ) { 125 iTarget = 1; 129 iTarget = 1; 126 } << 130 }else if( G4String(target) == G4String("CYL_SURFACE") ) { 127 else if (G4String(target) == G4String("CYL << 128 iTarget = 2; 131 iTarget = 2; 129 } << 132 }else if( G4String(target) == G4String("VOLUME") ) { 130 else if (G4String(target) == G4String("VOL << 131 iTarget = 3; 133 iTarget = 3; 132 } << 134 }else if( G4String(target) == G4String("TRKLEN") ) { 133 else if (G4String(target) == G4String("TRK << 134 iTarget = 4; 135 iTarget = 4; 135 } << 136 }else { 136 else { << 137 G4Exception("exG4eReco","Fatal error in Argument", 137 G4Exception("exG4eReco", "Fatal error in << 138 FatalErrorInArgument, 138 G4String("Variable G4ERROR_T << 139 G4String("Variable G4ERROR_TARGET = " + G4String(target) + 139 + " It must be: << 140 " It must be: PLANE_SURFACE, CYL_SURFACE, VOLUME, TRKLEN").c_str()); 140 .c_str()); << 141 } 141 } << 142 } else { 142 } << 143 G4Exception("exG4eReco","Fatal error in Argument", 143 else { << 144 JustWarning,"Variable G4ERROR_TARGET not defined, taking it = PLANE_SURFACE"); 144 G4Exception("exG4eReco", "Fatal error in A << 145 } 145 "Variable G4ERROR_TARGET not d << 146 } << 147 146 148 theTarget = BuildTarget(iTarget); << 147 theTarget = BuildTarget( iTarget ); 149 g4edata->SetTarget(theTarget); << 148 g4edata->SetTarget( theTarget ); 150 149 151 theG4ErrorMode = G4ErrorMode_PropBackwards; 150 theG4ErrorMode = G4ErrorMode_PropBackwards; 152 char* mode = std::getenv("G4ERROR_MODE"); 151 char* mode = std::getenv("G4ERROR_MODE"); 153 if (mode) { << 152 if( mode ) { 154 if (G4String(mode) == G4String("FORWARDS") << 153 if( G4String(mode) == G4String("FORWARDS") ) { 155 theG4ErrorMode = G4ErrorMode_PropForward 154 theG4ErrorMode = G4ErrorMode_PropForwards; 156 } << 155 } else if( G4String(mode) == G4String("BACKWARDS") ) { 157 else if (G4String(mode) == G4String("BACKW << 158 theG4ErrorMode = G4ErrorMode_PropBackwar 156 theG4ErrorMode = G4ErrorMode_PropBackwards; 159 } << 157 } else { 160 else { << 158 G4Exception("exG4eReco","Fatal error in Argument", 161 G4Exception("exG4eReco", "Fatal error in << 159 FatalErrorInArgument, 162 G4String("Variable G4ERROR_M << 160 G4String("Variable G4ERROR_MODE = " + G4String(mode) + 163 + " It must be: << 161 " It must be: FORWARDS or BACKWARDS").c_str()); 164 .c_str()); << 162 } 165 } << 163 } else { 166 } << 164 G4Exception("exG4eReco","Fatal error in Argument", 167 else { << 165 JustWarning,"Variable G4ERROR_MODE not defined, taking it = BACKWARDS"); 168 G4Exception("exG4eReco", "Fatal error in A << 166 } 169 "Variable G4ERROR_MODE not def << 167 170 } << 171 } 168 } 172 169 173 void ProcessEvent(G4int iProp, size_t) << 170 >> 171 void ProcessEvent( G4int iProp, size_t ) 174 { 172 { 175 // Set the starting trajectory. << 173 176 G4ThreeVector xv3(0, 0, 0); << 174 // Set the starting trajectory. 177 G4ThreeVector pv3(20.0 * GeV, 0.0, 0.0); << 175 G4ThreeVector xv3( 0, 0, 0 ); 178 G4ErrorTrajErr error(5, 0); << 176 G4ThreeVector pv3( 20.0*GeV, 0.0, 0.0 ); 179 G4ErrorFreeTrajState* g4ErrorTrajState = new << 177 G4ErrorTrajErr error( 5, 0 ); 180 << 178 G4ErrorFreeTrajState* g4ErrorTrajState 181 G4ErrorPropagatorManager* g4emgr = G4ErrorPr << 179 = new G4ErrorFreeTrajState( "mu-", xv3, pv3, error ); 182 << 180 183 // int ierr = 0; << 181 G4ErrorPropagatorManager* g4emgr 184 << 182 = G4ErrorPropagatorManager::GetErrorPropagatorManager(); 185 G4Point3D surfPos(224. * cm, 0., 0.); << 183 186 G4Normal3D surfNorm(1., 0., 0.); << 184 //int ierr = 0; 187 //- G4ErrorTarget* theG4ErrorTarget << 185 >> 186 G4Point3D surfPos(224.*cm,0.,0.); >> 187 G4Normal3D surfNorm(1.,0.,0.); >> 188 //- G4ErrorTarget* theG4ErrorTarget 188 // = new G4ErrorPlaneSurfaceTarget(surfN 189 // = new G4ErrorPlaneSurfaceTarget(surfNorm, surfPos ); 189 190 190 if (iProp == 0) { << 191 if( iProp == 0){ 191 // Propagate until G4ErrorTarget is found 192 // Propagate until G4ErrorTarget is found all in one go 192 // ierr = << 193 //ierr = 193 g4emgr->Propagate(g4ErrorTrajState, theTar << 194 g4emgr->Propagate( g4ErrorTrajState, theTarget, theG4ErrorMode ); 194 } << 195 } else if( iProp == 1){ 195 else if (iProp == 1) { << 196 // Propagate until G4ErrorTarget is reache << 197 196 >> 197 // Propagate until G4ErrorTarget is reached step by step >> 198 198 g4emgr->InitTrackPropagation(); 199 g4emgr->InitTrackPropagation(); 199 200 200 // G4Track* aTrack << 201 // G4Track* aTrack 201 // = G4EventManager::GetEventManager( 202 // = G4EventManager::GetEventManager()->GetTrackingManager()->GetTrack(); 202 bool moreEvt = TRUE; 203 bool moreEvt = TRUE; 203 while (moreEvt) { << 204 while( moreEvt ){ 204 // ierr = << 205 205 g4emgr->PropagateOneStep(g4ErrorTrajStat << 206 //ierr = 206 << 207 g4emgr->PropagateOneStep( g4ErrorTrajState, theG4ErrorMode ); >> 208 207 //---- Check if target is reached 209 //---- Check if target is reached 208 if (g4emgr->GetPropagator()->CheckIfLast << 210 if( g4emgr->GetPropagator()->CheckIfLastStep( g4ErrorTrajState->GetG4Track() )) { 209 g4emgr->GetPropagator()->InvokePostUse << 211 g4emgr->GetPropagator() >> 212 ->InvokePostUserTrackingAction( g4ErrorTrajState->GetG4Track() ); 210 moreEvt = 0; 213 moreEvt = 0; 211 G4cout << "STEP_BY_STEP propagation: L 214 G4cout << "STEP_BY_STEP propagation: Last Step " << G4endl; 212 } 215 } 213 } 216 } 214 } 217 } 215 218 216 G4cout << " $$$ PROPAGATION ENDED " << G4end 219 G4cout << " $$$ PROPAGATION ENDED " << G4endl; 217 // extract current state info 220 // extract current state info 218 G4Point3D posEnd = g4ErrorTrajState->GetPosi 221 G4Point3D posEnd = g4ErrorTrajState->GetPosition(); 219 G4Normal3D momEnd = g4ErrorTrajState->GetMom 222 G4Normal3D momEnd = g4ErrorTrajState->GetMomentum(); 220 G4ErrorTrajErr errorEnd = g4ErrorTrajState-> 223 G4ErrorTrajErr errorEnd = g4ErrorTrajState->GetError(); 221 224 222 G4cout << " Position: " << posEnd << G4endl << 225 G4cout << " Position: " << posEnd << G4endl 223 << " Error: " << errorEnd << G4endl; << 226 << " Momentum: " << momEnd << G4endl >> 227 << " Error: " << errorEnd << G4endl; 224 } 228 } 225 229 >> 230 226 //-------------------------------------------- 231 //------------------------------------------------------------- 227 G4ErrorTarget* BuildTarget(G4int iTarget) << 232 G4ErrorTarget* BuildTarget( G4int iTarget ) 228 { 233 { >> 234 229 G4ErrorTarget* target = 0; 235 G4ErrorTarget* target = 0; 230 if (iTarget == 1) { << 236 if( iTarget == 1 ) { 231 G4Point3D surfPos(221. * cm, 0., 0.); << 237 G4Point3D surfPos(221.*cm,0.,0.); 232 G4Normal3D surfNorm(1., 0., 0.); << 238 G4Normal3D surfNorm(1.,0.,0.); 233 target = new G4ErrorPlaneSurfaceTarget(sur << 239 target = new G4ErrorPlaneSurfaceTarget(surfNorm, surfPos ); 234 } << 240 }else if( iTarget == 2 ) { 235 else if (iTarget == 2) { << 241 G4double radius = 222*cm; 236 G4double radius = 222 * cm; << 237 target = new G4ErrorCylSurfaceTarget(radiu 242 target = new G4ErrorCylSurfaceTarget(radius); 238 } << 243 }else if( iTarget == 3 ) { 239 else if (iTarget == 3) { << 240 target = new G4ErrorGeomVolumeTarget("MUON 244 target = new G4ErrorGeomVolumeTarget("MUON"); 241 } << 245 }else if( iTarget == 4 ) { 242 else if (iTarget == 4) { << 246 target = new G4ErrorTrackLengthTarget(223.*cm); 243 target = new G4ErrorTrackLengthTarget(223. << 247 }else { 244 } << 248 G4Exception("exG4eReco","Fatal error in Argument", 245 else { << 249 FatalErrorInArgument,"Target type has to be between 1 and 4"); 246 G4Exception("exG4eReco", "Fatal error in A << 247 "Target type has to be between << 248 } 250 } 249 return target; 251 return target; 250 } 252 } 251 253 >> 254 252 //-------------------------------------------- 255 //------------------------------------------------------------- 253 void Finalize() 256 void Finalize() 254 { 257 { 255 G4ErrorPropagatorManager::GetErrorPropagator 258 G4ErrorPropagatorManager::GetErrorPropagatorManager()->CloseGeometry(); >> 259 256 } 260 } 257 261