Geant4  10.02.p01
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: G4MaterialScanner.cc 66892 2013-01-17 10:57:59Z gunter $
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 {
54  theMessenger = new G4MatScanMessenger(this);
56 
61 
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;
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 
100  DoScan();
102 }
103 
105 {
110 
115 
117  if(theSDMan)
118  { theSDMan->Activate("/",false); }
119 
121  theGeomMan->OpenGeometry();
122  theGeomMan->CloseGeometry(true);
123 }
124 
126 {
131 
133  if(theSDMan)
134  { theSDMan->Activate("/",true); }
135 }
136 
138 {
139 // Confirm material table is updated
141 
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));
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 {
215  G4Region* aRegion = G4RegionStore::GetInstance()->GetRegion(val);
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 }
G4UserEventAction * theMatScannerEventAction
G4double GetX0() const
G4ThreeVector eyeDirection
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
G4UserStackingAction * theUserStackingAction
CLHEP::Hep3Vector G4ThreeVector
G4UserTrackingAction * theMatScannerTrackingAction
G4bool SetRegionName(const G4String &val)
G4Navigator * GetNavigatorForTracking() const
void Initialize(G4bool rSens, G4Region *reg)
int G4int
Definition: G4Types.hh:78
static G4RunManagerKernel * GetRunManagerKernel()
G4UserEventAction * GetUserEventAction()
static G4RegionStore * GetInstance()
G4UserSteppingAction * theUserSteppingAction
static G4StateManager * GetStateManager()
G4GLOB_DLL std::ostream G4cout
G4bool SetNewState(G4ApplicationState requestedState)
static const double deg
Definition: G4SIunits.hh:151
void Activate(G4String dName, G4bool activeFlag)
Definition: G4SDManager.cc:117
bool G4bool
Definition: G4Types.hh:79
G4UserSteppingAction * GetUserSteppingAction()
G4ApplicationState GetCurrentState() const
static G4GeometryManager * GetInstance()
G4double GetTotalStepLength() const
static G4TransportationManager * GetTransportationManager()
G4UserEventAction * theUserEventAction
G4EventManager * theEventManager
G4double GetLambda0() const
void Shoot(G4Event *evt, G4ThreeVector vtx, G4ThreeVector direc)
Definition: G4RayShooter.cc:59
void SetUserAction(G4UserEventAction *userAction)
G4UserTrackingAction * GetUserTrackingAction()
static G4EventManager * GetEventManager()
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=0, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
Definition: G4Navigator.cc:122
G4MSSteppingAction * theMatScannerSteppingAction
#define G4endl
Definition: G4ios.hh:61
void OpenGeometry(G4VPhysicalVolume *vol=0)
void ProcessOneEvent(G4Event *anEvent)
G4MatScanMessenger * theMessenger
G4UserTrackingAction * theUserTrackingAction
double G4double
Definition: G4Types.hh:76
G4UserStackingAction * theMatScannerStackingAction
static const double mm
Definition: G4SIunits.hh:114
G4ThreeVector eyePosition
G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=0)
G4ApplicationState
G4UserStackingAction * GetUserStackingAction()
G4GLOB_DLL std::ostream G4cerr
G4RayShooter * theRayShooter
static G4SDManager * GetSDMpointerIfExist()
Definition: G4SDManager.cc:49