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