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