ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Run.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Run.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 //
28 
29 #include "Run.hh"
30 #include "DetectorConstruction.hh"
31 
32 #include "HistoManager.hh"
33 #include "PrimaryGeneratorAction.hh"
34 
35 #include "G4Material.hh"
36 #include "G4SystemOfUnits.hh"
37 #include "G4UnitsTable.hh"
38 
39 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
40 
41 Run::Run(const DetectorConstruction* detector)
42 : G4Run(),
43  fDetector(detector),
44  fParticle(0), fEkin(0.),
45  fEdeposit(0.), fEdeposit2(0.),
46  fTrackLen(0.), fTrackLen2(0.),
47  fProjRange(0.), fProjRange2(0.),
48  fPenetration(0.), fPenetration2(0.),
49  fNbOfSteps(0), fNbOfSteps2(0),
50  fStepSize(0.), fStepSize2(0.)
51 {}
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54 
55 Run::~Run()
56 {}
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
61 {
63  fEkin = energy;
64 }
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 
68 void Run::AddEdep (G4double e)
69 {
70  fEdeposit += e;
71  fEdeposit2 += e*e;
72 }
73 
74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
75 
77 {
78  fTrackLen += t;
79  fTrackLen2 += t*t;
80 }
81 
82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
83 
85 {
86  fProjRange += x;
87  fProjRange2 += x*x;
88 }
89 
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
91 
93 {
94  fPenetration += x;
95  fPenetration2 += x*x;
96 }
97 
98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
99 
100 void Run::AddStepSize (G4int nb, G4double st)
101 {
102  fNbOfSteps += nb;
103  fNbOfSteps2 += nb*nb;
104  fStepSize += st ;
105  fStepSize2 += st*st;
106 }
107 
108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
109 
110 void Run::Merge(const G4Run* run)
111 {
112  const Run* localRun = static_cast<const Run*>(run);
113 
114  // pass information about primary particle
115  fParticle = localRun->fParticle;
116  fEkin = localRun->fEkin;
117 
118  // accumulate sums
119  fEdeposit += localRun->fEdeposit;
120  fEdeposit2 += localRun->fEdeposit2;
121  fTrackLen += localRun->fTrackLen;
122  fTrackLen2 += localRun->fTrackLen2;
123  fProjRange += localRun->fProjRange;
124  fProjRange2 += localRun->fProjRange2;
125  fPenetration += localRun->fPenetration;
126  fPenetration2 += localRun->fPenetration2;
127  fNbOfSteps += localRun->fNbOfSteps ;
128  fNbOfSteps2 += localRun->fNbOfSteps2;
129  fStepSize += localRun->fStepSize;
130  fStepSize2 += localRun->fStepSize2;
131 
132  G4Run::Merge(run);
133 }
134 
135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
136 
137 void Run::EndOfRun()
138 {
139  std::ios::fmtflags mode = G4cout.flags();
140  G4cout.setf(std::ios::fixed,std::ios::floatfield);
141  G4int prec = G4cout.precision(2);
142 
143  //run conditions
144  //
146  G4double density = material->GetDensity();
147  G4String partName = fParticle->GetParticleName();
148 
149  G4cout << "\n ======================= run summary ====================\n";
150  G4cout
151  << "\n The run is " << numberOfEvent << " "<< partName << " of "
152  << G4BestUnit(fEkin,"Energy") << " through a sphere of radius "
153  << G4BestUnit(fDetector->GetAbsorRadius(),"Length") << "of "
154  << material->GetName() << " (density: "
155  << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
156 
157  if (numberOfEvent == 0) {
158  G4cout.setf(mode,std::ios::floatfield);
159  G4cout.precision(prec);
160  return;
161  }
162 
163  //compute track length of primary track
164  //
166  G4double rmsTrack = fTrackLen2 - fTrackLen*fTrackLen;
167 
168  if (rmsTrack>0.) rmsTrack = std::sqrt(rmsTrack); else rmsTrack = 0.;
169 
170  G4cout.precision(3);
171  G4cout
172  << "\n Track length of primary track = " << G4BestUnit(fTrackLen,"Length")
173  << " +- "
174  << G4BestUnit( rmsTrack,"Length");
175 
176  //compute projected range of primary track
177  //
180  if (rmsProj>0.) rmsProj = std::sqrt(rmsProj); else rmsProj = 0.;
181 
182  G4cout
183  << "\n Projected range = "
184  << G4BestUnit(fProjRange,"Length")
185  << " +- " << G4BestUnit( rmsProj,"Length");
186 
187  //compute penetration of primary track
188  //
191  if (rmsPene>0.) rmsPene = std::sqrt(rmsPene); else rmsPene = 0.;
192 
193  G4cout
194  << "\n Penetration = "
195  << G4BestUnit(fPenetration,"Length")
196  << " +- " << G4BestUnit( rmsPene,"Length")
197  << G4endl;
198 
199  //
200 
201  //output file
202  FILE *myFile;
203  myFile = fopen ("range.txt","a");
204  fprintf (myFile, "%e %e %e %e %e %e %e\n",
205  fEkin/eV,
206  fTrackLen/nm,
207  rmsTrack/nm,
208  fProjRange/nm,
209  rmsProj/nm,
210  fPenetration/nm,
211  rmsPene/nm
212  );
213  fclose (myFile);
214 
215  // reset default formats
216  G4cout.setf(mode,std::ios::floatfield);
217  G4cout.precision(prec);
218 
219 }
220