Geant4 11.1.1
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// 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"
48
49// --------------------------------------------------------------------
51{
52 theRayShooter = new G4RayShooter();
53 theMessenger = new G4MatScanMessenger(this);
54 theEventManager = G4EventManager::GetEventManager();
55
56 eyePosition = G4ThreeVector(0., 0., 0.);
57 thetaSpan = 90. * deg;
58 phiSpan = 360. * deg;
59}
60
61// --------------------------------------------------------------------
63{
64 delete theRayShooter;
65 delete theMatScannerSteppingAction;
66 delete theMessenger;
67}
68
69// --------------------------------------------------------------------
71{
73 G4ApplicationState currentState = theStateMan->GetCurrentState();
74 if(currentState != G4State_Idle)
75 {
76 G4cerr << "Illegal application state - Scan() ignored." << G4endl;
77 return;
78 }
79
80 if(theMatScannerSteppingAction == nullptr)
81 {
82 theMatScannerSteppingAction = new G4MSSteppingAction();
83 }
84 StoreUserActions();
85 DoScan();
86 RestoreUserActions();
87}
88
89// --------------------------------------------------------------------
90void G4MaterialScanner::StoreUserActions()
91{
92 theUserEventAction = theEventManager->GetUserEventAction();
93 theUserStackingAction = theEventManager->GetUserStackingAction();
94 theUserTrackingAction = theEventManager->GetUserTrackingAction();
95 theUserSteppingAction = theEventManager->GetUserSteppingAction();
96
97 theEventManager->SetUserAction(theMatScannerEventAction);
98 theEventManager->SetUserAction(theMatScannerStackingAction);
99 theEventManager->SetUserAction(theMatScannerTrackingAction);
100 theEventManager->SetUserAction(theMatScannerSteppingAction);
101
103 if(theSDMan != nullptr)
104 {
105 theSDMan->Activate("/", false);
106 }
107
109 theGeomMan->OpenGeometry();
110 theGeomMan->CloseGeometry(true);
111}
112
113// --------------------------------------------------------------------
114void G4MaterialScanner::RestoreUserActions()
115{
116 theEventManager->SetUserAction(theUserEventAction);
117 theEventManager->SetUserAction(theUserStackingAction);
118 theEventManager->SetUserAction(theUserTrackingAction);
119 theEventManager->SetUserAction(theUserSteppingAction);
120
122 if(theSDMan != nullptr)
123 {
124 theSDMan->Activate("/", true);
125 }
126}
127
128// --------------------------------------------------------------------
129void G4MaterialScanner::DoScan()
130{
131 // Confirm material table is updated
133
134 ///// // Make sure Geantino has been initialized
135 ///// G4ProcessVector* pVector
136 ///// =
137 /// G4Geantino::GeantinoDefinition()->GetProcessManager()->GetProcessList();
138 ///// for (G4int j=0; j < pVector->size(); ++j) {
139 ///// (*pVector)[j]->BuildPhysicsTable(*(G4Geantino::GeantinoDefinition()));
140 ///// }
141
142 // Close geometry and set the application state
144 geomManager->OpenGeometry();
145 geomManager->CloseGeometry(1, 0);
146
147 G4ThreeVector center(0, 0, 0);
150 navigator->LocateGlobalPointAndSetup(center, 0, false);
151
153 theStateMan->SetNewState(G4State_GeomClosed);
154
155 // Event loop
156 G4int iEvent = 0;
157 for(G4int iTheta = 0; iTheta < nTheta; ++iTheta)
158 {
159 G4double theta = thetaMin;
160 if(iTheta > 0)
161 theta += G4double(iTheta) * thetaSpan / G4double(nTheta - 1);
162 G4double aveLength = 0.;
163 G4double aveX0 = 0.;
164 G4double aveLambda = 0.;
165 G4cout << G4endl;
166 G4cout
167 << " Theta(deg) Phi(deg) Length(mm) x0 lambda0"
168 << G4endl;
169 G4cout << G4endl;
170 for(G4int iPhi = 0; iPhi < nPhi; ++iPhi)
171 {
172 G4Event* anEvent = new G4Event(iEvent++);
173 G4double phi = phiMin;
174 if(iPhi > 0)
175 phi += G4double(iPhi) * phiSpan / G4double(nPhi - 1);
176 eyeDirection =
177 G4ThreeVector(std::cos(theta) * std::cos(phi),
178 std::cos(theta) * std::sin(phi), std::sin(theta));
179 theRayShooter->Shoot(anEvent, eyePosition, eyeDirection);
180 theMatScannerSteppingAction->Initialize(regionSensitive, theRegion);
181 theEventManager->ProcessOneEvent(anEvent);
182 G4double length = theMatScannerSteppingAction->GetTotalStepLength();
183 G4double x0 = theMatScannerSteppingAction->GetX0();
184 G4double lambda = theMatScannerSteppingAction->GetLambda0();
185
186 G4cout << " " << std::setw(11) << theta / deg << " "
187 << std::setw(11) << phi / deg << " " << std::setw(11)
188 << length / mm << " " << std::setw(11) << x0 << " "
189 << std::setw(11) << lambda << G4endl;
190 aveLength += length / mm;
191 aveX0 += x0;
192 aveLambda += lambda;
193 }
194 if(nPhi > 1)
195 {
196 G4cout << G4endl;
197 G4cout << " ave. for theta = " << std::setw(11) << theta / deg << " : "
198 << std::setw(11) << aveLength / nPhi << " " << std::setw(11)
199 << aveX0 / nPhi << " " << std::setw(11) << aveLambda / nPhi
200 << G4endl;
201 }
202 }
203
204 theStateMan->SetNewState(G4State_Idle);
205 return;
206}
207
208// --------------------------------------------------------------------
210{
212 if(aRegion != nullptr)
213 {
214 theRegion = aRegion;
215 regionName = val;
216 return true;
217 }
218 else
219 {
220 G4cerr << "Region <" << val << "> not found. Command ignored." << G4endl;
221 G4cerr << "Defined regions are : " << G4endl;
222 for(std::size_t i = 0; i < G4RegionStore::GetInstance()->size(); ++i)
223 {
224 G4cerr << " " << (*(G4RegionStore::GetInstance()))[i]->GetName();
225 }
226 G4cerr << G4endl;
227 return false;
228 }
229}
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:132
void Shoot(G4Event *evt, G4ThreeVector vtx, G4ThreeVector direc)
Definition: G4RayShooter.cc:39
static G4RegionStore * GetInstance()
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
static G4RunManagerKernel * GetRunManagerKernel()
void Activate(G4String dName, G4bool activeFlag)
Definition: G4SDManager.cc:125
static G4SDManager * GetSDMpointerIfExist()
Definition: G4SDManager.cc:47
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
G4bool SetNewState(const G4ApplicationState &requestedState)
static G4TransportationManager * GetTransportationManager()
G4Navigator * GetNavigatorForTracking() const