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