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 // G4MaterialScanner implementation 27 // 28 // Author: M.Asai, May 2006 29 // ------------------------------------------- 30 31 #include "G4MaterialScanner.hh" 32 33 #include "G4Event.hh" 34 #include "G4EventManager.hh" 35 #include "G4GeometryManager.hh" 36 #include "G4MSSteppingAction.hh" 37 #include "G4MatScanMessenger.hh" 38 #include "G4ProcessManager.hh" 39 #include "G4ProcessVector.hh" 40 #include "G4RayShooter.hh" 41 #include "G4Region.hh" 42 #include "G4RegionStore.hh" 43 #include "G4RunManagerKernel.hh" 44 #include "G4SDManager.hh" 45 #include "G4StateManager.hh" 46 #include "G4SystemOfUnits.hh" 47 #include "G4TransportationManager.hh" 48 49 // ------------------------------------------- 50 G4MaterialScanner::G4MaterialScanner() 51 { 52 theRayShooter = new G4RayShooter(); 53 theMessenger = new G4MatScanMessenger(this); 54 theEventManager = G4EventManager::GetEventMa 55 56 eyePosition = G4ThreeVector(0., 0., 0.); 57 thetaSpan = 90. * deg; 58 phiSpan = 360. * deg; 59 } 60 61 // ------------------------------------------- 62 G4MaterialScanner::~G4MaterialScanner() 63 { 64 delete theRayShooter; 65 delete theMatScannerSteppingAction; 66 delete theMessenger; 67 } 68 69 // ------------------------------------------- 70 void G4MaterialScanner::Scan() 71 { 72 G4StateManager* theStateMan = G4StateManager 73 G4ApplicationState currentState = theStateMa 74 if (currentState != G4State_Idle) { 75 G4cerr << "Illegal application state - Sca 76 return; 77 } 78 79 if (theMatScannerSteppingAction == nullptr) 80 theMatScannerSteppingAction = new G4MSStep 81 } 82 StoreUserActions(); 83 DoScan(); 84 RestoreUserActions(); 85 } 86 87 // ------------------------------------------- 88 void G4MaterialScanner::StoreUserActions() 89 { 90 theUserEventAction = theEventManager->GetUse 91 theUserStackingAction = theEventManager->Get 92 theUserTrackingAction = theEventManager->Get 93 theUserSteppingAction = theEventManager->Get 94 95 theEventManager->SetUserAction(theMatScanner 96 theEventManager->SetUserAction(theMatScanner 97 theEventManager->SetUserAction(theMatScanner 98 theEventManager->SetUserAction(theMatScanner 99 100 G4SDManager* theSDMan = G4SDManager::GetSDMp 101 if (theSDMan != nullptr) { 102 theSDMan->Activate("/", false); 103 } 104 105 G4GeometryManager* theGeomMan = G4GeometryMa 106 theGeomMan->OpenGeometry(); 107 theGeomMan->CloseGeometry(true); 108 } 109 110 // ------------------------------------------- 111 void G4MaterialScanner::RestoreUserActions() 112 { 113 theEventManager->SetUserAction(theUserEventA 114 theEventManager->SetUserAction(theUserStacki 115 theEventManager->SetUserAction(theUserTracki 116 theEventManager->SetUserAction(theUserSteppi 117 118 G4SDManager* theSDMan = G4SDManager::GetSDMp 119 if (theSDMan != nullptr) { 120 theSDMan->Activate("/", true); 121 } 122 } 123 124 // ------------------------------------------- 125 void G4MaterialScanner::DoScan() 126 { 127 // Confirm material table is updated 128 G4RunManagerKernel::GetRunManagerKernel()->U 129 130 // Close geometry and set the application st 131 G4GeometryManager* geomManager = G4GeometryM 132 geomManager->OpenGeometry(); 133 geomManager->CloseGeometry(true, false); 134 135 G4ThreeVector center(0, 0, 0); 136 G4Navigator* navigator = 137 G4TransportationManager::GetTransportation 138 navigator->LocateGlobalPointAndSetup(center, 139 140 G4StateManager* theStateMan = G4StateManager 141 theStateMan->SetNewState(G4State_GeomClosed) 142 143 // Event loop 144 G4int iEvent = 0; 145 for (G4int iTheta = 0; iTheta < nTheta; ++iT 146 G4double theta = thetaMin; 147 if (iTheta > 0) theta += G4double(iTheta) 148 G4double aveLength = 0.; 149 G4double aveX0 = 0.; 150 G4double aveLambda = 0.; 151 G4cout << G4endl; 152 G4cout << " Theta(deg) Phi(deg) 153 G4cout << G4endl; 154 for (G4int iPhi = 0; iPhi < nPhi; ++iPhi) 155 auto anEvent = new G4Event(iEvent++); 156 G4double phi = phiMin; 157 if (iPhi > 0) phi += G4double(iPhi) * ph 158 eyeDirection = G4ThreeVector(std::cos(th 159 std::sin(th 160 theRayShooter->Shoot(anEvent, eyePositio 161 theMatScannerSteppingAction->Initialize( 162 theEventManager->ProcessOneEvent(anEvent 163 G4double length = theMatScannerSteppingA 164 G4double x0 = theMatScannerSteppingActio 165 G4double lambda = theMatScannerSteppingA 166 167 G4cout << " " << std::setw(11) << 168 << " " << std::setw(11) << length 169 << std::setw(11) << lambda; 170 if(1 == verbosity) 171 { 172 theMatScannerSteppingAction->PrintInte 173 } 174 else if(2 == verbosity) 175 { 176 theMatScannerSteppingAction->PrintEach 177 } 178 G4cout << G4endl; 179 aveLength += length / mm; 180 aveX0 += x0; 181 aveLambda += lambda; 182 } 183 if (nPhi > 1) { 184 G4cout << G4endl; 185 G4cout << " ave. for theta = " << std::s 186 << aveLength / nPhi << " " << std 187 << aveLambda / nPhi << G4endl; 188 } 189 } 190 191 theStateMan->SetNewState(G4State_Idle); 192 return; 193 } 194 195 // ------------------------------------------- 196 G4bool G4MaterialScanner::SetRegionName(const 197 { 198 G4Region* aRegion = G4RegionStore::GetInstan 199 if (aRegion != nullptr) { 200 theRegion = aRegion; 201 regionName = val; 202 return true; 203 } 204 205 G4cerr << "Region <" << val << "> not found. 206 G4cerr << "Defined regions are : " << G4endl 207 for (const auto& i : *G4RegionStore::GetInst 208 G4cerr << " " << i->GetName(); 209 } 210 G4cerr << G4endl; 211 return false; 212 } 213