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