source: trunk/source/run/src/G4MaterialScanner.cc@ 1149

Last change on this file since 1149 was 1058, checked in by garnier, 17 years ago

file release beta

File size: 7.8 KB
Line 
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,v 1.3 2006/06/29 21:13:46 gunter Exp $
28// GEANT4 tag $Name: geant4-09-02-ref-02 $
29//
30//
31//
32
33
34#include "G4MaterialScanner.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"
42#include "G4TransportationManager.hh"
43#include "G4RunManagerKernel.hh"
44#include "G4Region.hh"
45#include "G4RegionStore.hh"
46#include "G4ProcessManager.hh"
47#include "G4ProcessVector.hh"
48/////#include "G4Geantino.hh"
49#include "G4SDManager.hh"
50
51
52G4MaterialScanner::G4MaterialScanner()
53{
54 theRayShooter = new G4RayShooter();
55 theMessenger = new G4MatScanMessenger(this);
56 theEventManager = G4EventManager::GetEventManager();
57
58 theUserEventAction = 0;
59 theUserStackingAction = 0;
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;
79}
80
81G4MaterialScanner::~G4MaterialScanner()
82{
83 delete theRayShooter;
84 delete theMatScannerSteppingAction;
85 delete theMessenger;
86}
87
88void G4MaterialScanner::Scan()
89{
90 G4StateManager* theStateMan = G4StateManager::GetStateManager();
91 G4ApplicationState currentState = theStateMan->GetCurrentState();
92 if(currentState!=G4State_Idle)
93 {
94 G4cerr << "Illegal application state - Scan() ignored." << G4endl;
95 return;
96 }
97
98 if(!theMatScannerSteppingAction)
99 { theMatScannerSteppingAction = new G4MSSteppingAction(); }
100 StoreUserActions();
101 DoScan();
102 RestoreUserActions();
103}
104
105void G4MaterialScanner::StoreUserActions()
106{
107 theUserEventAction = theEventManager->GetUserEventAction();
108 theUserStackingAction = theEventManager->GetUserStackingAction();
109 theUserTrackingAction = theEventManager->GetUserTrackingAction();
110 theUserSteppingAction = theEventManager->GetUserSteppingAction();
111
112 theEventManager->SetUserAction(theMatScannerEventAction);
113 theEventManager->SetUserAction(theMatScannerStackingAction);
114 theEventManager->SetUserAction(theMatScannerTrackingAction);
115 theEventManager->SetUserAction(theMatScannerSteppingAction);
116
117 G4SDManager* theSDMan = G4SDManager::GetSDMpointerIfExist();
118 if(theSDMan)
119 { theSDMan->Activate("/",false); }
120
121 G4GeometryManager* theGeomMan = G4GeometryManager::GetInstance();
122 theGeomMan->OpenGeometry();
123 theGeomMan->CloseGeometry(true);
124}
125
126void G4MaterialScanner::RestoreUserActions()
127{
128 theEventManager->SetUserAction(theUserEventAction);
129 theEventManager->SetUserAction(theUserStackingAction);
130 theEventManager->SetUserAction(theUserTrackingAction);
131 theEventManager->SetUserAction(theUserSteppingAction);
132
133 G4SDManager* theSDMan = G4SDManager::GetSDMpointerIfExist();
134 if(theSDMan)
135 { theSDMan->Activate("/",true); }
136}
137
138void G4MaterialScanner::DoScan()
139{
140// Confirm material table is updated
141 G4RunManagerKernel::GetRunManagerKernel()->UpdateRegion();
142
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
151 G4GeometryManager* geomManager = G4GeometryManager::GetInstance();
152 geomManager->OpenGeometry();
153 geomManager->CloseGeometry(1,0);
154
155 G4ThreeVector center(0,0,0);
156 G4Navigator* navigator =
157 G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
158 navigator->LocateGlobalPointAndSetup(center,0,false);
159
160 G4StateManager* theStateMan = G4StateManager::GetStateManager();
161 theStateMan->SetNewState(G4State_GeomClosed);
162
163// Event loop
164 G4int iEvent = 0;
165 for(G4int iTheta=0;iTheta<nTheta;iTheta++)
166 {
167 G4double theta = thetaMin;
168 if(iTheta>0) theta += G4double(iTheta)*thetaSpan/G4double(nTheta-1);
169 G4double aveLength = 0.;
170 G4double aveX0 = 0.;
171 G4double aveLambda = 0.;
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 {
202 G4cout << G4endl;
203 G4cout << " ave. for theta = " << std::setw(11) << theta/deg << " : "
204 << std::setw(11) << aveLength/nPhi << " "
205 << std::setw(11) << aveX0/nPhi << " "
206 << std::setw(11) << aveLambda/nPhi << G4endl;
207 }
208 }
209
210 theStateMan->SetNewState(G4State_Idle);
211 return;
212}
213
214G4bool G4MaterialScanner::SetRegionName(const G4String& val)
215{
216 G4Region* aRegion = G4RegionStore::GetInstance()->GetRegion(val);
217 if(aRegion)
218 {
219 theRegion = aRegion;
220 regionName = val;
221 return true;
222 }
223 else
224 {
225 G4cerr << "Region <" << val << "> not found. Command ignored." << G4endl;
226 G4cerr << "Defined regions are : " << G4endl;
227 for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
228 { G4cerr << " " << (*(G4RegionStore::GetInstance()))[i]->GetName(); }
229 G4cerr << G4endl;
230 return false;
231 }
232}
Note: See TracBrowser for help on using the repository browser.