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 "PrimaryGeneratorAction.hh"
32 
33 #include "G4Material.hh"
34 #include "G4SystemOfUnits.hh"
35 #include "G4UnitsTable.hh"
36 
37 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
38 
39 Run::Run(const DetectorConstruction* detector)
40 : G4Run(),
41  fDetector(detector),
42  fParticle(0), fEkin(0.),
43  fSP(0.), fSP2(0.)
44 {}
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 
48 Run::~Run()
49 {}
50 
51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
52 
54 {
56  fEkin = energy;
57 }
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
62 {
63  fSP += t;
64  fSP2 += t*t;
65 }
66 
67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
68 
69 void Run::Merge(const G4Run* run)
70 {
71  const Run* localRun = static_cast<const Run*>(run);
72 
73  // pass information about primary particle
74  fParticle = localRun->fParticle;
75  fEkin = localRun->fEkin;
76 
77  // accumulate sums
78  fSP += localRun->fSP;
79  fSP2 += localRun->fSP2;
80 
81  G4Run::Merge(run);
82 }
83 
84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
85 
86 void Run::EndOfRun()
87 {
88  std::ios::fmtflags mode = G4cout.flags();
89  G4cout.setf(std::ios::fixed,std::ios::floatfield);
90  G4int prec = G4cout.precision(2);
91 
92  //run conditions
93  //
95  G4double density = material->GetDensity();
96  G4String partName = fParticle->GetParticleName();
97 
98  G4cout << "\n ======================== run summary =====================\n";
99  G4cout
100  << "\n The run is " << numberOfEvent << " "<< partName << " of "
101  << G4BestUnit(fEkin,"Energy") << " through a sphere of radius "
102  << G4BestUnit(fDetector->GetAbsorRadius(),"Length") << "of "
103  << material->GetName() << " (density: "
104  << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
105 
106  if (numberOfEvent == 0) {
107  G4cout.setf(mode,std::ios::floatfield);
108  G4cout.precision(prec);
109  return;
110  }
111 
112  //compute stopping power
113  //
115  G4double rms = fSP2 - fSP*fSP;
116 
117  if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
118 
119  G4cout
120  << "\n total Stopping Power (keV/um) = "<< fSP/(keV/um)
121  << " +- " << rms/(keV/um)
122  << G4endl;
123 
124  //output file
125  //
126  FILE* myFile;
127  myFile=fopen("spower.txt","a");
128  fprintf(myFile,"%e %e %e \n",
129  fEkin/eV,
130  fSP/(keV/um),
131  rms/(keV/um));
132  fclose(myFile);
133 
134  //reset default formats
135  //
136  G4cout.setf(mode,std::ios::floatfield);
137  G4cout.precision(prec);
138 
139 }