ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4MaterialScanner.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4MaterialScanner.cc
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 "G4SystemOfUnits.hh"
34 #include "G4EventManager.hh"
35 #include "G4MatScanMessenger.hh"
36 #include "G4RayShooter.hh"
37 #include "G4MSSteppingAction.hh"
38 #include "G4GeometryManager.hh"
39 #include "G4StateManager.hh"
40 #include "G4Event.hh"
42 #include "G4RunManagerKernel.hh"
43 #include "G4Region.hh"
44 #include "G4RegionStore.hh"
45 #include "G4ProcessManager.hh"
46 #include "G4ProcessVector.hh"
47 #include "G4SDManager.hh"
48 
49 
51 {
53  theMessenger = new G4MatScanMessenger(this);
55 
60 
65 
66  eyePosition = G4ThreeVector(0.,0.,0.);
67  nTheta = 91;
68  thetaMin = 0.*deg;
69  thetaSpan = 90.*deg;
70  nPhi = 37;
71  phiMin = 0.*deg;
72  phiSpan = 360.*deg;
73 
74  regionSensitive = false;
75  regionName = "notDefined";
76  theRegion = 0;
77 }
78 
80 {
81  delete theRayShooter;
83  delete theMessenger;
84 }
85 
87 {
89  G4ApplicationState currentState = theStateMan->GetCurrentState();
90  if(currentState!=G4State_Idle)
91  {
92  G4cerr << "Illegal application state - Scan() ignored." << G4endl;
93  return;
94  }
95 
99  DoScan();
101 }
102 
104 {
109 
114 
116  if(theSDMan)
117  { theSDMan->Activate("/",false); }
118 
120  theGeomMan->OpenGeometry();
121  theGeomMan->CloseGeometry(true);
122 }
123 
125 {
130 
132  if(theSDMan)
133  { theSDMan->Activate("/",true); }
134 }
135 
137 {
138 // Confirm material table is updated
140 
147 
148 // Close geometry and set the application state
150  geomManager->OpenGeometry();
151  geomManager->CloseGeometry(1,0);
152 
153  G4ThreeVector center(0,0,0);
156  navigator->LocateGlobalPointAndSetup(center,0,false);
157 
159  theStateMan->SetNewState(G4State_GeomClosed);
160 
161 // Event loop
162  G4int iEvent = 0;
163  for(G4int iTheta=0;iTheta<nTheta;iTheta++)
164  {
166  if(iTheta>0) theta += G4double(iTheta)*thetaSpan/G4double(nTheta-1);
167  G4double aveLength = 0.;
168  G4double aveX0 = 0.;
169  G4double aveLambda = 0.;
170  G4cout << G4endl;
171  G4cout << " Theta(deg) Phi(deg) Length(mm) x0 lambda0" << G4endl;
172  G4cout << G4endl;
173  for(G4int iPhi=0;iPhi<nPhi;iPhi++)
174  {
175  G4Event* anEvent = new G4Event(iEvent++);
176  G4double phi = phiMin;
177  if(iPhi>0) phi += G4double(iPhi)*phiSpan/G4double(nPhi-1);
178  eyeDirection = G4ThreeVector(std::cos(theta)*std::cos(phi),
179  std::cos(theta)*std::sin(phi),
180  std::sin(theta));
187 
188  G4cout << " "
189  << std::setw(11) << theta/deg << " "
190  << std::setw(11) << phi/deg << " "
191  << std::setw(11) << length/mm << " "
192  << std::setw(11) << x0 << " "
193  << std::setw(11) << lambda << G4endl;
194  aveLength += length/mm;
195  aveX0 += x0;
196  aveLambda += lambda;
197  }
198  if(nPhi>1)
199  {
200  G4cout << G4endl;
201  G4cout << " ave. for theta = " << std::setw(11) << theta/deg << " : "
202  << std::setw(11) << aveLength/nPhi << " "
203  << std::setw(11) << aveX0/nPhi << " "
204  << std::setw(11) << aveLambda/nPhi << G4endl;
205  }
206  }
207 
208  theStateMan->SetNewState(G4State_Idle);
209  return;
210 }
211 
213 {
214  G4Region* aRegion = G4RegionStore::GetInstance()->GetRegion(val);
215  if(aRegion)
216  {
217  theRegion = aRegion;
218  regionName = val;
219  return true;
220  }
221  else
222  {
223  G4cerr << "Region <" << val << "> not found. Command ignored." << G4endl;
224  G4cerr << "Defined regions are : " << G4endl;
225  for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
226  { G4cerr << " " << (*(G4RegionStore::GetInstance()))[i]->GetName(); }
227  G4cerr << G4endl;
228  return false;
229  }
230 }