Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4MaterialScanner.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27//
28//
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"
48
50{
51 theRayShooter = new G4RayShooter();
52 theMessenger = new G4MatScanMessenger(this);
53 theEventManager = G4EventManager::GetEventManager();
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
65 eyePosition = G4ThreeVector(0., 0., 0.);
66 nTheta = 91;
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;
76}
77
79{
80 delete theRayShooter;
81 delete theMatScannerSteppingAction;
82 delete theMessenger;
83}
84
86{
88 G4ApplicationState currentState = theStateMan->GetCurrentState();
89 if(currentState != G4State_Idle)
90 {
91 G4cerr << "Illegal application state - Scan() ignored." << G4endl;
92 return;
93 }
94
95 if(!theMatScannerSteppingAction)
96 {
97 theMatScannerSteppingAction = new G4MSSteppingAction();
98 }
99 StoreUserActions();
100 DoScan();
101 RestoreUserActions();
102}
103
104void G4MaterialScanner::StoreUserActions()
105{
106 theUserEventAction = theEventManager->GetUserEventAction();
107 theUserStackingAction = theEventManager->GetUserStackingAction();
108 theUserTrackingAction = theEventManager->GetUserTrackingAction();
109 theUserSteppingAction = theEventManager->GetUserSteppingAction();
110
111 theEventManager->SetUserAction(theMatScannerEventAction);
112 theEventManager->SetUserAction(theMatScannerStackingAction);
113 theEventManager->SetUserAction(theMatScannerTrackingAction);
114 theEventManager->SetUserAction(theMatScannerSteppingAction);
115
117 if(theSDMan)
118 {
119 theSDMan->Activate("/", false);
120 }
121
123 theGeomMan->OpenGeometry();
124 theGeomMan->CloseGeometry(true);
125}
126
127void G4MaterialScanner::RestoreUserActions()
128{
129 theEventManager->SetUserAction(theUserEventAction);
130 theEventManager->SetUserAction(theUserStackingAction);
131 theEventManager->SetUserAction(theUserTrackingAction);
132 theEventManager->SetUserAction(theUserSteppingAction);
133
135 if(theSDMan)
136 {
137 theSDMan->Activate("/", true);
138 }
139}
140
141void G4MaterialScanner::DoScan()
142{
143 // Confirm material table is updated
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
154 // Close geometry and set the application state
156 geomManager->OpenGeometry();
157 geomManager->CloseGeometry(1, 0);
158
159 G4ThreeVector center(0, 0, 0);
162 navigator->LocateGlobalPointAndSetup(center, 0, false);
163
165 theStateMan->SetNewState(G4State_GeomClosed);
166
167 // Event loop
168 G4int iEvent = 0;
169 for(G4int iTheta = 0; iTheta < nTheta; iTheta++)
170 {
171 G4double theta = thetaMin;
172 if(iTheta > 0)
173 theta += G4double(iTheta) * thetaSpan / G4double(nTheta - 1);
174 G4double aveLength = 0.;
175 G4double aveX0 = 0.;
176 G4double aveLambda = 0.;
177 G4cout << G4endl;
178 G4cout
179 << " Theta(deg) Phi(deg) Length(mm) x0 lambda0"
180 << G4endl;
181 G4cout << G4endl;
182 for(G4int iPhi = 0; iPhi < nPhi; iPhi++)
183 {
184 G4Event* anEvent = new G4Event(iEvent++);
185 G4double phi = phiMin;
186 if(iPhi > 0)
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));
191 theRayShooter->Shoot(anEvent, eyePosition, eyeDirection);
192 theMatScannerSteppingAction->Initialize(regionSensitive, theRegion);
193 theEventManager->ProcessOneEvent(anEvent);
194 G4double length = theMatScannerSteppingAction->GetTotalStepLength();
195 G4double x0 = theMatScannerSteppingAction->GetX0();
196 G4double lambda = theMatScannerSteppingAction->GetLambda0();
197
198 G4cout << " " << std::setw(11) << theta / deg << " "
199 << std::setw(11) << phi / deg << " " << std::setw(11)
200 << length / mm << " " << std::setw(11) << x0 << " "
201 << std::setw(11) << lambda << G4endl;
202 aveLength += length / mm;
203 aveX0 += x0;
204 aveLambda += lambda;
205 }
206 if(nPhi > 1)
207 {
208 G4cout << G4endl;
209 G4cout << " ave. for theta = " << std::setw(11) << theta / deg << " : "
210 << std::setw(11) << aveLength / nPhi << " " << std::setw(11)
211 << aveX0 / nPhi << " " << std::setw(11) << aveLambda / nPhi
212 << G4endl;
213 }
214 }
215
216 theStateMan->SetNewState(G4State_Idle);
217 return;
218}
219
221{
223 if(aRegion)
224 {
225 theRegion = aRegion;
226 regionName = val;
227 return true;
228 }
229 else
230 {
231 G4cerr << "Region <" << val << "> not found. Command ignored." << G4endl;
232 G4cerr << "Defined regions are : " << G4endl;
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;
239 }
240}
G4ApplicationState
@ G4State_Idle
@ G4State_GeomClosed
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4UserTrackingAction * GetUserTrackingAction()
void SetUserAction(G4UserEventAction *userAction)
G4UserSteppingAction * GetUserSteppingAction()
G4UserStackingAction * GetUserStackingAction()
G4UserEventAction * GetUserEventAction()
static G4EventManager * GetEventManager()
void ProcessOneEvent(G4Event *anEvent)
static G4GeometryManager * GetInstance()
G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=nullptr)
void OpenGeometry(G4VPhysicalVolume *vol=nullptr)
G4double GetLambda0() const
G4double GetX0() const
G4double GetTotalStepLength() const
void Initialize(G4bool rSens, G4Region *reg)
G4bool SetRegionName(const G4String &val)
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=nullptr, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
Definition: G4Navigator.cc:126
void Shoot(G4Event *evt, G4ThreeVector vtx, G4ThreeVector direc)
Definition: G4RayShooter.cc:57
static G4RegionStore * GetInstance()
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
static G4RunManagerKernel * GetRunManagerKernel()
void Activate(G4String dName, G4bool activeFlag)
Definition: G4SDManager.cc:121
static G4SDManager * GetSDMpointerIfExist()
Definition: G4SDManager.cc:48
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
G4bool SetNewState(const G4ApplicationState &requestedState)
static G4TransportationManager * GetTransportationManager()
G4Navigator * GetNavigatorForTracking() const