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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 // This example is provided by the Geant4-DNA collaboration
 27 // Any report or published results obtained using the Geant4-DNA software
 28 // shall cite the following Geant4-DNA collaboration publications:
 29 // Med. Phys. 45 (2018) e722-e739
 30 // Phys. Med. 31 (2015) 861-874
 31 // Med. Phys. 37 (2010) 4692-4708
 32 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
 33 //
 34 // The Geant4-DNA web site is available at http://geant4-dna.org
 35 //
 36 /// \file medical/dna/range/src/Run.cc
 37 /// \brief Implementation of the Run class
 38 
 39 #include "Run.hh"
 40 
 41 #include "PrimaryGeneratorAction.hh"
 42 
 43 #include "G4Material.hh"
 44 #include "G4SystemOfUnits.hh"
 45 #include "G4UnitsTable.hh"
 46 
 47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 48 
 49 Run::Run(const DetectorConstruction* detector)
 50   : G4Run(),
 51     fDetector(detector),
 52     fParticle(0),
 53     fEkin(0.),
 54     fEdeposit(0.),
 55     fEdeposit2(0.),
 56     fTrackLen(0.),
 57     fTrackLen2(0.),
 58     fProjRange(0.),
 59     fProjRange2(0.),
 60     fPenetration(0.),
 61     fPenetration2(0.),
 62     fNbOfSteps(0),
 63     fNbOfSteps2(0),
 64     fStepSize(0.),
 65     fStepSize2(0.)
 66 {}
 67 
 68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 69 
 70 Run::~Run() {}
 71 
 72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 73 
 74 void Run::SetPrimary(G4ParticleDefinition* particle, G4double energy)
 75 {
 76   fParticle = particle;
 77   fEkin = energy;
 78 }
 79 
 80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 81 
 82 void Run::AddEdep(G4double e)
 83 {
 84   fEdeposit += e;
 85   fEdeposit2 += e * e;
 86 }
 87 
 88 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 89 
 90 void Run::AddTrackLength(G4double t)
 91 {
 92   fTrackLen += t;
 93   fTrackLen2 += t * t;
 94 }
 95 
 96 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 97 
 98 void Run::AddProjRange(G4double x)
 99 {
100   fProjRange += x;
101   fProjRange2 += x * x;
102 }
103 
104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
105 
106 void Run::AddPenetration(G4double x)
107 {
108   fPenetration += x;
109   fPenetration2 += x * x;
110 }
111 
112 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
113 
114 void Run::AddStepSize(G4int nb, G4double st)
115 {
116   fNbOfSteps += nb;
117   fNbOfSteps2 += nb * nb;
118   fStepSize += st;
119   fStepSize2 += st * st;
120 }
121 
122 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
123 
124 void Run::Merge(const G4Run* run)
125 {
126   const Run* localRun = static_cast<const Run*>(run);
127 
128   // Pass information about primary particle
129   fParticle = localRun->fParticle;
130   fEkin = localRun->fEkin;
131 
132   // Accumulate sums
133   fEdeposit += localRun->fEdeposit;
134   fEdeposit2 += localRun->fEdeposit2;
135   fTrackLen += localRun->fTrackLen;
136   fTrackLen2 += localRun->fTrackLen2;
137   fProjRange += localRun->fProjRange;
138   fProjRange2 += localRun->fProjRange2;
139   fPenetration += localRun->fPenetration;
140   fPenetration2 += localRun->fPenetration2;
141   fNbOfSteps += localRun->fNbOfSteps;
142   fNbOfSteps2 += localRun->fNbOfSteps2;
143   fStepSize += localRun->fStepSize;
144   fStepSize2 += localRun->fStepSize2;
145 
146   G4Run::Merge(run);
147 }
148 
149 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
150 
151 void Run::EndOfRun()
152 {
153   std::ios::fmtflags mode = G4cout.flags();
154   G4cout.setf(std::ios::fixed, std::ios::floatfield);
155   G4int prec = G4cout.precision(2);
156 
157   // Run conditions
158   G4Material* material = fDetector->GetAbsorMaterial();
159   G4double density = material->GetDensity();
160   G4String partName = fParticle->GetParticleName();
161 
162   G4cout << "\n ======================= run summary ====================\n";
163   G4cout << "\n The run is " << numberOfEvent << " " << partName << " of "
164          << G4BestUnit(fEkin, "Energy") << " through a sphere of radius "
165          << G4BestUnit(fDetector->GetAbsorRadius(), "Length") << "of " << material->GetName()
166          << " (density: " << G4BestUnit(density, "Volumic Mass") << ")" << G4endl;
167 
168   if (numberOfEvent == 0) {
169     G4cout.setf(mode, std::ios::floatfield);
170     G4cout.precision(prec);
171     return;
172   }
173 
174   // Compute track length of primary track
175   fTrackLen /= numberOfEvent;
176   fTrackLen2 /= numberOfEvent;
177   G4double rmsTrack = fTrackLen2 - fTrackLen * fTrackLen;
178 
179   if (rmsTrack > 0.)
180     rmsTrack = std::sqrt(rmsTrack);
181   else
182     rmsTrack = 0.;
183 
184   G4cout.precision(3);
185   G4cout << "\n Track length of primary track = " << G4BestUnit(fTrackLen, "Length") << " +- "
186          << G4BestUnit(rmsTrack, "Length");
187 
188   // Compute projected range of primary track
189   fProjRange /= numberOfEvent;
190   fProjRange2 /= numberOfEvent;
191   G4double rmsProj = fProjRange2 - fProjRange * fProjRange;
192   if (rmsProj > 0.)
193     rmsProj = std::sqrt(rmsProj);
194   else
195     rmsProj = 0.;
196 
197   G4cout << "\n Projected range               = " << G4BestUnit(fProjRange, "Length") << " +- "
198          << G4BestUnit(rmsProj, "Length");
199 
200   // Compute penetration of primary track
201   fPenetration /= numberOfEvent;
202   fPenetration2 /= numberOfEvent;
203   G4double rmsPene = fPenetration2 - fPenetration * fPenetration;
204   if (rmsPene > 0.)
205     rmsPene = std::sqrt(rmsPene);
206   else
207     rmsPene = 0.;
208 
209   G4cout << "\n Penetration                   = " << G4BestUnit(fPenetration, "Length") << " +- "
210          << G4BestUnit(rmsPene, "Length") << G4endl;
211 
212   //
213 
214   // Output file
215   FILE* myFile;
216   myFile = fopen("range.txt", "a");
217   fprintf(myFile, "%e %e %e %e %e %e %e\n", fEkin / eV, fTrackLen / nm, rmsTrack / nm,
218           fProjRange / nm, rmsProj / nm, fPenetration / nm, rmsPene / nm);
219   fclose(myFile);
220 
221   // Reset default formats
222   G4cout.setf(mode, std::ios::floatfield);
223   G4cout.precision(prec);
224 }
225