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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 ]

Diff markup

Differences between /examples/extended/medical/dna/range/src/Run.cc (Version 11.3.0) and /examples/extended/medical/dna/range/src/Run.cc (Version 10.4.p3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // This example is provided by the Geant4-DNA  << 
 27 // Any report or published results obtained us << 
 28 // shall cite the following Geant4-DNA collabo << 
 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) << 
 33 //                                             << 
 34 // The Geant4-DNA web site is available at htt << 
 35 //                                             << 
 36 /// \file medical/dna/range/src/Run.cc             26 /// \file medical/dna/range/src/Run.cc
 37 /// \brief Implementation of the Run class         27 /// \brief Implementation of the Run class
 38                                                    28 
 39 #include "Run.hh"                                  29 #include "Run.hh"
                                                   >>  30 #include "DetectorConstruction.hh"
 40                                                    31 
                                                   >>  32 #include "HistoManager.hh"
 41 #include "PrimaryGeneratorAction.hh"               33 #include "PrimaryGeneratorAction.hh"
 42                                                    34 
 43 #include "G4Material.hh"                           35 #include "G4Material.hh"
 44 #include "G4SystemOfUnits.hh"                      36 #include "G4SystemOfUnits.hh"
 45 #include "G4UnitsTable.hh"                         37 #include "G4UnitsTable.hh"
 46                                                    38 
 47 //....oooOO0OOooo........oooOO0OOooo........oo     39 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 48                                                    40 
 49 Run::Run(const DetectorConstruction* detector)     41 Run::Run(const DetectorConstruction* detector)
 50   : G4Run(),                                   <<  42 : G4Run(),
 51     fDetector(detector),                       <<  43   fDetector(detector),
 52     fParticle(0),                              <<  44   fParticle(0), fEkin(0.),  
 53     fEkin(0.),                                 <<  45   fEdeposit(0.),  fEdeposit2(0.),
 54     fEdeposit(0.),                             <<  46   fTrackLen(0.),  fTrackLen2(0.),
 55     fEdeposit2(0.),                            <<  47   fProjRange(0.), fProjRange2(0.),
 56     fTrackLen(0.),                             <<  48   fPenetration(0.), fPenetration2(0.),
 57     fTrackLen2(0.),                            <<  49   fNbOfSteps(0),  fNbOfSteps2(0),
 58     fProjRange(0.),                            <<  50   fStepSize(0.),  fStepSize2(0.)
 59     fProjRange2(0.),                           << 
 60     fPenetration(0.),                          << 
 61     fPenetration2(0.),                         << 
 62     fNbOfSteps(0),                             << 
 63     fNbOfSteps2(0),                            << 
 64     fStepSize(0.),                             << 
 65     fStepSize2(0.)                             << 
 66 {}                                                 51 {}
 67                                                    52 
 68 //....oooOO0OOooo........oooOO0OOooo........oo     53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 69                                                    54 
 70 Run::~Run() {}                                 <<  55 Run::~Run()
                                                   >>  56 {}
 71                                                    57 
 72 //....oooOO0OOooo........oooOO0OOooo........oo     58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 73                                                    59 
 74 void Run::SetPrimary(G4ParticleDefinition* par <<  60 void Run::SetPrimary (G4ParticleDefinition* particle, G4double energy)
 75 {                                              <<  61 { 
 76   fParticle = particle;                            62   fParticle = particle;
 77   fEkin = energy;                              <<  63   fEkin     = energy;
 78 }                                                  64 }
 79                                                    65 
 80 //....oooOO0OOooo........oooOO0OOooo........oo     66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 81                                                    67 
 82 void Run::AddEdep(G4double e)                  <<  68 void Run::AddEdep (G4double e)        
 83 {                                                  69 {
 84   fEdeposit += e;                              <<  70   fEdeposit  += e;
 85   fEdeposit2 += e * e;                         <<  71   fEdeposit2 += e*e;
 86 }                                                  72 }
 87                                                    73 
 88 //....oooOO0OOooo........oooOO0OOooo........oo     74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 89                                                <<  75     
 90 void Run::AddTrackLength(G4double t)           <<  76 void Run::AddTrackLength (G4double t) 
 91 {                                                  77 {
 92   fTrackLen += t;                              <<  78   fTrackLen  += t;
 93   fTrackLen2 += t * t;                         <<  79   fTrackLen2 += t*t;
 94 }                                                  80 }
 95                                                    81 
 96 //....oooOO0OOooo........oooOO0OOooo........oo     82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 97                                                <<  83     
 98 void Run::AddProjRange(G4double x)             <<  84 void Run::AddProjRange (G4double x) 
 99 {                                                  85 {
100   fProjRange += x;                             <<  86   fProjRange  += x;
101   fProjRange2 += x * x;                        <<  87   fProjRange2 += x*x;
102 }                                                  88 }
103                                                    89 
104 //....oooOO0OOooo........oooOO0OOooo........oo     90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
105                                                <<  91     
106 void Run::AddPenetration(G4double x)           <<  92 void Run::AddPenetration (G4double x) 
107 {                                                  93 {
108   fPenetration += x;                           <<  94   fPenetration  += x;
109   fPenetration2 += x * x;                      <<  95   fPenetration2 += x*x;
110 }                                                  96 }
111                                                    97 
112 //....oooOO0OOooo........oooOO0OOooo........oo     98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
113                                                <<  99     
114 void Run::AddStepSize(G4int nb, G4double st)   << 100 void Run::AddStepSize (G4int nb, G4double st)
115 {                                                 101 {
116   fNbOfSteps += nb;                            << 102   fNbOfSteps  += nb; 
117   fNbOfSteps2 += nb * nb;                      << 103   fNbOfSteps2 += nb*nb;
118   fStepSize += st;                             << 104   fStepSize   += st ; 
119   fStepSize2 += st * st;                       << 105   fStepSize2  += st*st;  
120 }                                                 106 }
121                                                   107 
122 //....oooOO0OOooo........oooOO0OOooo........oo    108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
123                                                   109 
124 void Run::Merge(const G4Run* run)                 110 void Run::Merge(const G4Run* run)
125 {                                                 111 {
126   const Run* localRun = static_cast<const Run*    112   const Run* localRun = static_cast<const Run*>(run);
127                                                << 113   
128   // Pass information about primary particle   << 114   // pass information about primary particle
129   fParticle = localRun->fParticle;                115   fParticle = localRun->fParticle;
130   fEkin = localRun->fEkin;                     << 116   fEkin     = localRun->fEkin;
131                                                   117 
132   // Accumulate sums                           << 118   // accumulate sums
133   fEdeposit += localRun->fEdeposit;            << 119   fEdeposit   += localRun->fEdeposit;
134   fEdeposit2 += localRun->fEdeposit2;          << 120   fEdeposit2  += localRun->fEdeposit2;
135   fTrackLen += localRun->fTrackLen;            << 121   fTrackLen   += localRun->fTrackLen;  
136   fTrackLen2 += localRun->fTrackLen2;          << 122   fTrackLen2  += localRun->fTrackLen2;
137   fProjRange += localRun->fProjRange;          << 123   fProjRange  += localRun->fProjRange; 
138   fProjRange2 += localRun->fProjRange2;           124   fProjRange2 += localRun->fProjRange2;
139   fPenetration += localRun->fPenetration;      << 125   fPenetration  += localRun->fPenetration; 
140   fPenetration2 += localRun->fPenetration2;       126   fPenetration2 += localRun->fPenetration2;
141   fNbOfSteps += localRun->fNbOfSteps;          << 127   fNbOfSteps  += localRun->fNbOfSteps ;
142   fNbOfSteps2 += localRun->fNbOfSteps2;           128   fNbOfSteps2 += localRun->fNbOfSteps2;
143   fStepSize += localRun->fStepSize;            << 129   fStepSize   += localRun->fStepSize;  
144   fStepSize2 += localRun->fStepSize2;          << 130   fStepSize2  += localRun->fStepSize2;
145                                                   131 
146   G4Run::Merge(run);                           << 132   G4Run::Merge(run); 
147 }                                              << 133 } 
148                                                   134 
149 //....oooOO0OOooo........oooOO0OOooo........oo    135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
150                                                   136 
151 void Run::EndOfRun()                           << 137 void Run::EndOfRun() 
152 {                                                 138 {
153   std::ios::fmtflags mode = G4cout.flags();       139   std::ios::fmtflags mode = G4cout.flags();
154   G4cout.setf(std::ios::fixed, std::ios::float << 140   G4cout.setf(std::ios::fixed,std::ios::floatfield);
155   G4int prec = G4cout.precision(2);               141   G4int prec = G4cout.precision(2);
156                                                << 142   
157   // Run conditions                            << 143   //run conditions  
                                                   >> 144   //
158   G4Material* material = fDetector->GetAbsorMa    145   G4Material* material = fDetector->GetAbsorMaterial();
159   G4double density = material->GetDensity();   << 146   G4double density  = material->GetDensity();       
160   G4String partName = fParticle->GetParticleNa    147   G4String partName = fParticle->GetParticleName();
161                                                << 148   
162   G4cout << "\n ======================= run su << 149   G4cout << "\n ======================= run summary ====================\n";  
163   G4cout << "\n The run is " << numberOfEvent  << 150   G4cout 
164          << G4BestUnit(fEkin, "Energy") << " t << 151     << "\n The run is " << numberOfEvent << " "<< partName << " of "
165          << G4BestUnit(fDetector->GetAbsorRadi << 152     << G4BestUnit(fEkin,"Energy") << " through a sphere of radius "
166          << " (density: " << G4BestUnit(densit << 153     << G4BestUnit(fDetector->GetAbsorRadius(),"Length") << "of "
                                                   >> 154     << material->GetName() << " (density: " 
                                                   >> 155     << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;    
167                                                   156 
168   if (numberOfEvent == 0) {                       157   if (numberOfEvent == 0) {
169     G4cout.setf(mode, std::ios::floatfield);   << 158     G4cout.setf(mode,std::ios::floatfield);
170     G4cout.precision(prec);                    << 159     G4cout.precision(prec);  
171     return;                                       160     return;
172   }                                               161   }
173                                                << 162                     
174   // Compute track length of primary track     << 163   //compute track length of primary track
175   fTrackLen /= numberOfEvent;                  << 164   //
176   fTrackLen2 /= numberOfEvent;                 << 165   fTrackLen /= numberOfEvent; fTrackLen2 /= numberOfEvent;
177   G4double rmsTrack = fTrackLen2 - fTrackLen * << 166   G4double rmsTrack = fTrackLen2 - fTrackLen*fTrackLen;      
178                                                << 167         
179   if (rmsTrack > 0.)                           << 168   if (rmsTrack>0.) rmsTrack = std::sqrt(rmsTrack); else rmsTrack = 0.;
180     rmsTrack = std::sqrt(rmsTrack);            << 169 
181   else                                         << 170   G4cout.precision(3);       
182     rmsTrack = 0.;                             << 171   G4cout 
183                                                << 172     << "\n Track length of primary track = " << G4BestUnit(fTrackLen,"Length")
184   G4cout.precision(3);                         << 173     << " +- "                                
185   G4cout << "\n Track length of primary track  << 174     << G4BestUnit( rmsTrack,"Length");
186          << G4BestUnit(rmsTrack, "Length");    << 175     
187                                                << 176   //compute projected range of primary track
188   // Compute projected range of primary track  << 177   //
189   fProjRange /= numberOfEvent;                 << 178   fProjRange /= numberOfEvent; fProjRange2 /= numberOfEvent;
190   fProjRange2 /= numberOfEvent;                << 179   G4double rmsProj = fProjRange2 - fProjRange*fProjRange;        
191   G4double rmsProj = fProjRange2 - fProjRange  << 180   if (rmsProj>0.) rmsProj = std::sqrt(rmsProj); else rmsProj = 0.;
192   if (rmsProj > 0.)                            << 181    
193     rmsProj = std::sqrt(rmsProj);              << 182   G4cout 
194   else                                         << 183     << "\n Projected range               = " 
195     rmsProj = 0.;                              << 184     << G4BestUnit(fProjRange,"Length")
196                                                << 185     << " +- "                                << G4BestUnit( rmsProj,"Length");    
197   G4cout << "\n Projected range                << 186     
198          << G4BestUnit(rmsProj, "Length");     << 187   //compute penetration of primary track
199                                                << 188   //
200   // Compute penetration of primary track      << 189   fPenetration /= numberOfEvent; fPenetration2 /= numberOfEvent;
201   fPenetration /= numberOfEvent;               << 190   G4double rmsPene = fPenetration2 - fPenetration*fPenetration;        
202   fPenetration2 /= numberOfEvent;              << 191   if (rmsPene>0.) rmsPene = std::sqrt(rmsPene); else rmsPene = 0.;
203   G4double rmsPene = fPenetration2 - fPenetrat << 192    
204   if (rmsPene > 0.)                            << 193   G4cout 
205     rmsPene = std::sqrt(rmsPene);              << 194     << "\n Penetration                   = " 
206   else                                         << 195     << G4BestUnit(fPenetration,"Length")
207     rmsPene = 0.;                              << 196     << " +- "                                << G4BestUnit( rmsPene,"Length")    
208                                                << 197     << G4endl;
209   G4cout << "\n Penetration                    << 198     
210          << G4BestUnit(rmsPene, "Length") << G << 
211                                                << 
212   //                                              199   //
213                                                   200 
214   // Output file                               << 201   //output file
215   FILE* myFile;                                << 202     FILE *myFile;
216   myFile = fopen("range.txt", "a");            << 203     myFile = fopen ("range.txt","a");
217   fprintf(myFile, "%e %e %e %e %e %e %e\n", fE << 204     fprintf (myFile, "%e %e %e %e %e %e %e\n", 
218           fProjRange / nm, rmsProj / nm, fPene << 205      fEkin/eV, 
219   fclose(myFile);                              << 206      fTrackLen/nm,
                                                   >> 207      rmsTrack/nm,
                                                   >> 208      fProjRange/nm,
                                                   >> 209      rmsProj/nm,
                                                   >> 210      fPenetration/nm,
                                                   >> 211      rmsPene/nm     
                                                   >> 212      );
                                                   >> 213     fclose (myFile);
220                                                   214 
221   // Reset default formats                     << 215   // reset default formats
222   G4cout.setf(mode, std::ios::floatfield);     << 216   G4cout.setf(mode,std::ios::floatfield);
223   G4cout.precision(prec);                         217   G4cout.precision(prec);
                                                   >> 218     
224 }                                                 219 }
                                                   >> 220 
225                                                   221