Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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// $Id$
28//
29//
30//
31
32#include "G4MaterialScanner.hh"
33
34#include "G4SystemOfUnits.hh"
35#include "G4EventManager.hh"
36#include "G4MatScanMessenger.hh"
37#include "G4RayShooter.hh"
38#include "G4MSSteppingAction.hh"
39#include "G4GeometryManager.hh"
40#include "G4StateManager.hh"
41#include "G4Event.hh"
43#include "G4RunManagerKernel.hh"
44#include "G4Region.hh"
45#include "G4RegionStore.hh"
46#include "G4ProcessManager.hh"
47#include "G4ProcessVector.hh"
48#include "G4SDManager.hh"
49
50
52{
53 theRayShooter = new G4RayShooter();
54 theMessenger = new G4MatScanMessenger(this);
55 theEventManager = G4EventManager::GetEventManager();
56
57 theUserEventAction = 0;
58 theUserStackingAction = 0;
59 theUserTrackingAction = 0;
60 theUserSteppingAction = 0;
61
62 theMatScannerEventAction = 0;
63 theMatScannerStackingAction = 0;
64 theMatScannerTrackingAction = 0;
65 theMatScannerSteppingAction = 0;
66
67 eyePosition = G4ThreeVector(0.,0.,0.);
68 nTheta = 91;
69 thetaMin = 0.*deg;
70 thetaSpan = 90.*deg;
71 nPhi = 37;
72 phiMin = 0.*deg;
73 phiSpan = 360.*deg;
74
75 regionSensitive = false;
76 regionName = "notDefined";
77 theRegion = 0;
78}
79
81{
82 delete theRayShooter;
83 delete theMatScannerSteppingAction;
84 delete theMessenger;
85}
86
88{
90 G4ApplicationState currentState = theStateMan->GetCurrentState();
91 if(currentState!=G4State_Idle)
92 {
93 G4cerr << "Illegal application state - Scan() ignored." << G4endl;
94 return;
95 }
96
97 if(!theMatScannerSteppingAction)
98 { theMatScannerSteppingAction = new G4MSSteppingAction(); }
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 { theSDMan->Activate("/",false); }
119
121 theGeomMan->OpenGeometry();
122 theGeomMan->CloseGeometry(true);
123}
124
125void G4MaterialScanner::RestoreUserActions()
126{
127 theEventManager->SetUserAction(theUserEventAction);
128 theEventManager->SetUserAction(theUserStackingAction);
129 theEventManager->SetUserAction(theUserTrackingAction);
130 theEventManager->SetUserAction(theUserSteppingAction);
131
133 if(theSDMan)
134 { theSDMan->Activate("/",true); }
135}
136
137void G4MaterialScanner::DoScan()
138{
139// Confirm material table is updated
141
142///// // Make sure Geantino has been initialized
143///// G4ProcessVector* pVector
144///// = G4Geantino::GeantinoDefinition()->GetProcessManager()->GetProcessList();
145///// for (G4int j=0; j < pVector->size(); ++j) {
146///// (*pVector)[j]->BuildPhysicsTable(*(G4Geantino::GeantinoDefinition()));
147///// }
148
149// Close geometry and set the application state
151 geomManager->OpenGeometry();
152 geomManager->CloseGeometry(1,0);
153
154 G4ThreeVector center(0,0,0);
155 G4Navigator* navigator =
157 navigator->LocateGlobalPointAndSetup(center,0,false);
158
160 theStateMan->SetNewState(G4State_GeomClosed);
161
162// Event loop
163 G4int iEvent = 0;
164 for(G4int iTheta=0;iTheta<nTheta;iTheta++)
165 {
166 G4double theta = thetaMin;
167 if(iTheta>0) theta += G4double(iTheta)*thetaSpan/G4double(nTheta-1);
168 G4double aveLength = 0.;
169 G4double aveX0 = 0.;
170 G4double aveLambda = 0.;
171 G4cout << G4endl;
172 G4cout << " Theta(deg) Phi(deg) Length(mm) x0 lambda0" << G4endl;
173 G4cout << G4endl;
174 for(G4int iPhi=0;iPhi<nPhi;iPhi++)
175 {
176 G4Event* anEvent = new G4Event(iEvent++);
177 G4double phi = phiMin;
178 if(iPhi>0) phi += G4double(iPhi)*phiSpan/G4double(nPhi-1);
179 eyeDirection = G4ThreeVector(std::cos(theta)*std::cos(phi),
180 std::cos(theta)*std::sin(phi),
181 std::sin(theta));
182 theRayShooter->Shoot(anEvent,eyePosition,eyeDirection);
183 theMatScannerSteppingAction->Initialize(regionSensitive,theRegion);
184 theEventManager->ProcessOneEvent(anEvent);
185 G4double length = theMatScannerSteppingAction->GetTotalStepLength();
186 G4double x0 = theMatScannerSteppingAction->GetX0();
187 G4double lambda = theMatScannerSteppingAction->GetLambda0();
188
189 G4cout << " "
190 << std::setw(11) << theta/deg << " "
191 << std::setw(11) << phi/deg << " "
192 << std::setw(11) << length/mm << " "
193 << std::setw(11) << x0 << " "
194 << std::setw(11) << lambda << G4endl;
195 aveLength += length/mm;
196 aveX0 += x0;
197 aveLambda += lambda;
198 }
199 if(nPhi>1)
200 {
201 G4cout << G4endl;
202 G4cout << " ave. for theta = " << std::setw(11) << theta/deg << " : "
203 << std::setw(11) << aveLength/nPhi << " "
204 << std::setw(11) << aveX0/nPhi << " "
205 << std::setw(11) << aveLambda/nPhi << G4endl;
206 }
207 }
208
209 theStateMan->SetNewState(G4State_Idle);
210 return;
211}
212
214{
216 if(aRegion)
217 {
218 theRegion = aRegion;
219 regionName = val;
220 return true;
221 }
222 else
223 {
224 G4cerr << "Region <" << val << "> not found. Command ignored." << G4endl;
225 G4cerr << "Defined regions are : " << G4endl;
226 for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
227 { G4cerr << " " << (*(G4RegionStore::GetInstance()))[i]->GetName(); }
228 G4cerr << G4endl;
229 return false;
230 }
231}
G4ApplicationState
@ G4State_Idle
@ G4State_GeomClosed
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cerr
G4DLLIMPORT std::ostream G4cout
G4UserTrackingAction * GetUserTrackingAction()
void SetUserAction(G4UserEventAction *userAction)
G4UserSteppingAction * GetUserSteppingAction()
G4UserStackingAction * GetUserStackingAction()
G4UserEventAction * GetUserEventAction()
static G4EventManager * GetEventManager()
void ProcessOneEvent(G4Event *anEvent)
G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=0)
void OpenGeometry(G4VPhysicalVolume *vol=0)
static G4GeometryManager * GetInstance()
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=0, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
Definition: G4Navigator.cc:116
void Shoot(G4Event *evt, G4ThreeVector vtx, G4ThreeVector direc)
Definition: G4RayShooter.cc:59
static G4RegionStore * GetInstance()
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
static G4RunManagerKernel * GetRunManagerKernel()
void Activate(G4String dName, G4bool activeFlag)
Definition: G4SDManager.cc:119
static G4SDManager * GetSDMpointerIfExist()
Definition: G4SDManager.cc:49
G4ApplicationState GetCurrentState() const
static G4StateManager * GetStateManager()
G4bool SetNewState(G4ApplicationState requestedState)
static G4TransportationManager * GetTransportationManager()
G4Navigator * GetNavigatorForTracking() const