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 //
30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 
33 #include "Run.hh"
34 #include "DetectorConstruction.hh"
35 
36 #include "HistoManager.hh"
37 #include "PrimaryGeneratorAction.hh"
38 
39 #include "G4Material.hh"
40 #include "G4SystemOfUnits.hh"
41 #include "G4UnitsTable.hh"
42 
43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44 
46 : G4Run(),
47  fDetector(detector),
48  fParticle(0), fEkin(0.),
49  fEdeposit(0.), fEdeposit2(0.),
50  fTrackLen(0.), fTrackLen2(0.),
51  fProjRange(0.), fProjRange2(0.),
52  fNbOfSteps(0), fNbOfSteps2(0),
53  fStepSize(0.), fStepSize2(0.),
54  fCsdaRange(0.)
55 { }
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
59 Run::~Run()
60 { }
61 
62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
63 
65 {
67  fEkin = energy;
68 }
69 
70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
71 
72 void Run::AddEdep (G4double e)
73 {
74  fEdeposit += e;
75  fEdeposit2 += e*e;
76 }
77 
78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
79 
81 {
82  fTrackLen += t;
83  fTrackLen2 += t*t;
84 }
85 
86 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
87 
89 {
90  fProjRange += x;
91  fProjRange2 += x*x;
92 }
93 
94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
95 
96 void Run::AddStepSize (G4int nb, G4double st)
97 {
98  fNbOfSteps += nb;
99  fNbOfSteps2 += nb*nb;
100  fStepSize += st ;
101  fStepSize2 += st*st;
102 }
103 
104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
105 
107 {
108  fCsdaRange = value;
109 }
110 
111 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
112 
114 {
115  return fCsdaRange;
116 }
117 
118 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
119 
120 void Run::Merge(const G4Run* run)
121 {
122  const Run* localRun = static_cast<const Run*>(run);
123 
124  // pass information about primary particle
125  fParticle = localRun->fParticle;
126  fEkin = localRun->fEkin;
127 
128  // accumulate sums
129  fEdeposit += localRun->fEdeposit;
130  fEdeposit2 += localRun->fEdeposit2;
131  fTrackLen += localRun->fTrackLen;
132  fTrackLen2 += localRun->fTrackLen2;
133  fProjRange += localRun->fProjRange;
134  fProjRange2 += localRun->fProjRange2;
135  fNbOfSteps += localRun->fNbOfSteps ;
136  fNbOfSteps2 += localRun->fNbOfSteps2;
137  fStepSize += localRun->fStepSize;
138  fStepSize2 += localRun->fStepSize2;
139 
140  fCsdaRange = localRun->fCsdaRange;
141 
142  G4Run::Merge(run);
143 }
144 
145 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
146 
147 void Run::EndOfRun()
148 {
149  std::ios::fmtflags mode = G4cout.flags();
150  G4cout.setf(std::ios::fixed,std::ios::floatfield);
151  G4int prec = G4cout.precision(2);
152 
153  //run conditions
154  //
156  G4double density = material->GetDensity();
157  G4String partName = fParticle->GetParticleName();
158 
159  G4cout << "\n ======================== run summary =====================\n";
160  G4cout
161  << "\n The run is " << numberOfEvent << " "<< partName << " of "
162  << G4BestUnit(fEkin,"Energy") << " through "
163  << G4BestUnit(fDetector->GetAbsorRadius(),"Length") << " of "
164  << material->GetName() << " (density: "
165  << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
166 
167  if (numberOfEvent == 0) {
168  G4cout.setf(mode,std::ios::floatfield);
169  G4cout.precision(prec);
170  return;
171  }
172 
175  if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
176 
177  G4cout.precision(3);
178  G4cout
179  << "\n Total Energy deposited = " << G4BestUnit(fEdeposit,"Energy")
180  << " +- " << G4BestUnit( rms,"Energy")
181  << G4endl;
182 
183  //compute track length of primary track
184  //
186  rms = fTrackLen2 - fTrackLen*fTrackLen;
187  if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
188 
189  G4cout.precision(3);
190  G4cout
191  << "\n Track length of primary track = " << G4BestUnit(fTrackLen,"Length")
192  << " +- " << G4BestUnit( rms,"Length");
193 
194  //compare with csda range
195  //
196  G4cout
197  << "\n Range from EmCalculator = " << G4BestUnit(fCsdaRange,"Length")
198  << " (from full dE/dx)" << G4endl;
199 
200 
201  //compute projected range of primary track
202  //
205  if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
206 
207  G4cout
208  << "\n Projected range = " << G4BestUnit(fProjRange,"Length")
209  << " +- " << G4BestUnit( rms,"Length")
210  << G4endl;
211 
212  //nb of steps and step size of primary track
213  //
214  G4double dNofEvents = double(numberOfEvent);
215  G4double fNbSteps = fNbOfSteps/dNofEvents,
216  fNbSteps2 = fNbOfSteps2/dNofEvents;
217  rms = fNbSteps2 - fNbSteps*fNbSteps;
218  if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
219 
220  G4cout.precision(2);
221  G4cout << "\n Nb of steps of primary track = " << fNbSteps << " +- " << rms;
222 
224  rms = fStepSize2 - fStepSize*fStepSize;
225  if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
226 
227  G4cout.precision(3);
228  G4cout
229  << "\t Step size= " << G4BestUnit(fStepSize,"Length")
230  << " +- " << G4BestUnit( rms,"Length")
231  << G4endl;
232 
233  // normalize histograms of longitudinal energy profile
234  //
235  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
236  G4int ih = 1;
237  G4double binWidth = analysisManager->GetH1Width(ih)
238  *analysisManager->GetH1Unit(ih);
239  G4double fac = (1./(numberOfEvent*binWidth))*(mm/MeV);
240  analysisManager->ScaleH1(ih,fac);
241 
242  // normalize histogram d(E/E0)/d(r/r0)
243  //
244  ih = 8;
245  binWidth = analysisManager->GetH1Width(ih);
246  fac = 1./(numberOfEvent*binWidth*fEkin);
247  analysisManager->ScaleH1(ih,fac);
248 
249  // reset default formats
250  G4cout.setf(mode,std::ios::floatfield);
251  G4cout.precision(prec);
252 }
253 
254 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......