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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/mfp/src/Run.cc (Version 11.3.0) and /examples/extended/medical/dna/mfp/src/Run.cc (Version 11.0.p2)


  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 Run.cc                                   26 /// \file 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"
 40                                                <<  30 #include "DetectorConstruction.hh"
 41 #include "PrimaryGeneratorAction.hh"               31 #include "PrimaryGeneratorAction.hh"
 42                                                    32 
 43 #include "G4Material.hh"                           33 #include "G4Material.hh"
 44 #include "G4SystemOfUnits.hh"                      34 #include "G4SystemOfUnits.hh"
 45 #include "G4UnitsTable.hh"                         35 #include "G4UnitsTable.hh"
 46                                                    36 
 47 //....oooOO0OOooo........oooOO0OOooo........oo     37 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 48                                                    38 
 49 Run::Run(const DetectorConstruction* detector)     39 Run::Run(const DetectorConstruction* detector)
 50   : G4Run(),                                   <<  40 : G4Run(),
 51     fDetector(detector),                       <<  41   fDetector(detector),
 52     fParticle(0),                              <<  42   fParticle(0), fEkin(0.),  
 53     fEkin(0.),                                 <<  43   fTotalCount(0), fSumTrack(0.), fSumTrack2(0.), fEnTransfer(0.)
 54     fTotalCount(0),                            << 
 55     fSumTrack(0.),                             << 
 56     fSumTrack2(0.),                            << 
 57     fEnTransfer(0.)                            << 
 58 {}                                                 44 {}
 59                                                    45 
 60 //....oooOO0OOooo........oooOO0OOooo........oo     46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 61                                                    47 
 62 Run::~Run() {}                                 <<  48 Run::~Run()
                                                   >>  49 {}
 63                                                    50 
 64 //....oooOO0OOooo........oooOO0OOooo........oo     51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 65                                                    52 
 66 void Run::SetPrimary(G4ParticleDefinition* par <<  53 void Run::SetPrimary (G4ParticleDefinition* particle, G4double energy)
 67 {                                              <<  54 { 
 68   fParticle = particle;                            55   fParticle = particle;
 69   fEkin = energy;                              <<  56   fEkin     = energy;
 70 }                                                  57 }
 71                                                    58 
 72 //....oooOO0OOooo........oooOO0OOooo........oo     59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 73                                                    60 
 74 void Run::CountProcesses(G4String procName)    <<  61 void Run::CountProcesses(G4String procName) 
 75 {                                                  62 {
 76   std::map<G4String, G4int>::iterator it = fPr <<  63   std::map<G4String,G4int>::iterator it = fProcCounter.find(procName);
 77   if (it == fProcCounter.end()) {              <<  64   if ( it == fProcCounter.end()) {
 78     fProcCounter[procName] = 1;                    65     fProcCounter[procName] = 1;
 79   }                                                66   }
 80   else {                                           67   else {
 81     fProcCounter[procName]++;                  <<  68     fProcCounter[procName]++; 
 82   }                                                69   }
 83 }                                                  70 }
 84                                                    71 
 85 //....oooOO0OOooo........oooOO0OOooo........oo     72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 86                                                    73 
 87 void Run::SumTrack(G4double track)             <<  74 void Run::SumTrack (G4double track)
 88 {                                                  75 {
 89   fTotalCount++;                                   76   fTotalCount++;
 90   fSumTrack += track;                              77   fSumTrack += track;
 91   fSumTrack2 += track * track;                 <<  78   fSumTrack2 += track*track;
 92 }                                                  79 }
 93                                                    80 
 94 //....oooOO0OOooo........oooOO0OOooo........oo     81 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 95                                                    82 
 96 void Run::SumeTransf(G4double energy)          <<  83 void Run::SumeTransf (G4double energy)
 97 {                                                  84 {
 98   fEnTransfer += energy;                           85   fEnTransfer += energy;
 99 }                                                  86 }
100                                                    87 
101 //....oooOO0OOooo........oooOO0OOooo........oo     88 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
102                                                    89 
103 void Run::Merge(const G4Run* run)                  90 void Run::Merge(const G4Run* run)
104 {                                                  91 {
105   const Run* localRun = static_cast<const Run*     92   const Run* localRun = static_cast<const Run*>(run);
106                                                <<  93   
107   // Pass information about primary particle   <<  94   // pass information about primary particle
108   fParticle = localRun->fParticle;                 95   fParticle = localRun->fParticle;
109   fEkin = localRun->fEkin;                     <<  96   fEkin     = localRun->fEkin;
110                                                    97 
111   // map: processes count                          98   // map: processes count
112   std::map<G4String, G4int>::const_iterator it <<  99   std::map<G4String,G4int>::const_iterator it;
113   for (it = localRun->fProcCounter.begin(); it << 100   for (it = localRun->fProcCounter.begin(); 
                                                   >> 101        it !=localRun->fProcCounter.end(); ++it) {
                                                   >> 102        
114     G4String procName = it->first;                103     G4String procName = it->first;
115     G4int localCount = it->second;             << 104     G4int localCount  = it->second;
116                                                << 105     if ( fProcCounter.find(procName) == fProcCounter.end()) {
117     if (fProcCounter.find(procName) == fProcCo << 
118       fProcCounter[procName] = localCount;        106       fProcCounter[procName] = localCount;
119     }                                             107     }
120     else {                                        108     else {
121       fProcCounter[procName] += localCount;       109       fProcCounter[procName] += localCount;
122     }                                             110     }
123   }                                               111   }
124                                                << 112   
125   fTotalCount += localRun->fTotalCount;           113   fTotalCount += localRun->fTotalCount;
126   fSumTrack += localRun->fSumTrack;            << 114   fSumTrack   += localRun->fSumTrack;
127   fSumTrack2 += localRun->fSumTrack2;          << 115   fSumTrack2  += localRun->fSumTrack2;
128   fEnTransfer += localRun->fEnTransfer;           116   fEnTransfer += localRun->fEnTransfer;
129                                                   117 
130   G4Run::Merge(run);                           << 118   G4Run::Merge(run); 
131 }                                              << 119 } 
132                                                   120 
133 //....oooOO0OOooo........oooOO0OOooo........oo    121 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
134                                                   122 
135 void Run::EndOfRun()                           << 123 void Run::EndOfRun() 
136 {                                                 124 {
137   std::ios::fmtflags mode = G4cout.flags();       125   std::ios::fmtflags mode = G4cout.flags();
138   G4cout.setf(std::ios::fixed, std::ios::float << 126   G4cout.setf(std::ios::fixed,std::ios::floatfield);
139   G4int prec = G4cout.precision(2);               127   G4int prec = G4cout.precision(2);
140                                                << 128   
141   // Run conditions                            << 129   // run conditions  
142   G4Material* material = fDetector->GetAbsorMa    130   G4Material* material = fDetector->GetAbsorMaterial();
143   G4double density = material->GetDensity();   << 131   G4double density  = material->GetDensity();       
144   G4String partName = fParticle->GetParticleNa    132   G4String partName = fParticle->GetParticleName();
145                                                << 133   
146   G4cout << "\n ======================== run s << 134   G4cout << 
147   G4cout << "\n The run is " << numberOfEvent  << 135    "\n ======================== run summary =====================\n";  
148          << G4BestUnit(fEkin, "Energy") << " t << 136   G4cout 
149          << G4BestUnit(fDetector->GetAbsorRadi << 137     << "\n The run is " << numberOfEvent << " "<< partName << " of "
150          << " (density: " << G4BestUnit(densit << 138     << G4BestUnit(fEkin,"Energy") << " through a sphere of radius "
                                                   >> 139     << G4BestUnit(fDetector->GetAbsorRadius(),"Length") << "of "
                                                   >> 140     << material->GetName() << " (density: " 
                                                   >> 141     << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;    
151                                                   142 
152   if (numberOfEvent == 0) {                       143   if (numberOfEvent == 0) {
153     G4cout.setf(mode, std::ios::floatfield);   << 144     G4cout.setf(mode,std::ios::floatfield);
154     G4cout.precision(prec);                    << 145     G4cout.precision(prec);  
155     return;                                       146     return;
156   }                                               147   }
157                                                << 148                     
158   // Frequency of processes                    << 149   // frequency of processes
159   G4int survive = 0;                           << 150   G4int survive = 0;  
160   G4cout << "\n Process calls frequency --->";    151   G4cout << "\n Process calls frequency --->";
161   std::map<G4String, G4int>::iterator it;      << 152   std::map<G4String,G4int>::iterator it;  
162   for (it = fProcCounter.begin(); it != fProcC    153   for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
163     G4String procName = it->first;             << 154      G4String procName = it->first;
164     G4int count = it->second;                  << 155      G4int    count    = it->second;
165     G4cout << "\t" << procName << " = " << cou << 156      G4cout << "\t" << procName << " = " << count;
166     if (procName == "Transportation") survive  << 157      if (procName == "Transportation") survive = count;
167   }                                               158   }
168                                                   159 
169   if (survive > 0) {                              160   if (survive > 0) {
170     G4cout << "\n\n Nb of incident particles s    161     G4cout << "\n\n Nb of incident particles surviving after "
171            << "a radius of " << G4BestUnit(fDe << 162            << "a radius of "
                                                   >> 163            << G4BestUnit(fDetector->GetAbsorRadius(),"Length") << " of "
172            << material->GetName() << " : " <<     164            << material->GetName() << " : " << survive << G4endl;
173   }                                               165   }
174                                                   166 
175   if (fTotalCount == 0) fTotalCount = 1;  // f << 167   if (fTotalCount == 0) fTotalCount = 1;   //force printing anyway
176                                                << 
177   // Compute mean free path and related quanti << 
178   G4double MeanFreePath = fSumTrack / fTotalCo << 
179   G4double MeanTrack2 = fSumTrack2 / fTotalCou << 
180   G4double rmsBis = std::sqrt(std::fabs(MeanTr << 
181   G4double CrossSection = 1. / MeanFreePath;   << 
182   G4double massicMFP = MeanFreePath * density; << 
183   G4double massicCS = 1. / massicMFP;          << 
184                                                << 
185   G4cout << "\n\n MeanFreePath:\t" << G4BestUn << 
186          << G4BestUnit(rmsBis, "Length")       << 
187          << "\t\t\tmassic: " << G4BestUnit(mas << 
188          << CrossSection * cm << " cm^-1 "     << 
189          << "\t\t\tmassic: " << G4BestUnit(mas << 
190                                                << 
191   // Compute energy transfer coefficient       << 
192   G4double MeanTransfer = fEnTransfer / fTotal << 
193   G4double massTransfCoef = massicCS * MeanTra << 
194                                                   168 
195   G4cout << "\n mean energy of charged seconda << 169   // compute mean free path and related quantities
196          << "\tmass_energy_transfer coef: " << << 170   G4double MeanFreePath = fSumTrack /fTotalCount;     
                                                   >> 171   G4double MeanTrack2   = fSumTrack2/fTotalCount;     
                                                   >> 172   G4double rmsBis = 
                                                   >> 173     std::sqrt(std::fabs(MeanTrack2 - MeanFreePath*MeanFreePath));
                                                   >> 174   G4double CrossSection = 1./MeanFreePath;     
                                                   >> 175   G4double massicMFP = MeanFreePath*density;
                                                   >> 176   G4double massicCS  = 1./massicMFP;
                                                   >> 177 
                                                   >> 178   G4cout << "\n\n MeanFreePath:\t"   << G4BestUnit(MeanFreePath,"Length")
                                                   >> 179          << " +- "                   << G4BestUnit(rmsBis,"Length")
                                                   >> 180          << "\t\t\tmassic: "         << G4BestUnit(massicMFP, "Mass/Surface")
                                                   >> 181          << "\n CrossSection:\t"     << CrossSection*cm << " cm^-1 "
                                                   >> 182          << "\t\t\tmassic: "         << G4BestUnit(massicCS, "Surface/Mass")
                                                   >> 183          << G4endl;
                                                   >> 184          
                                                   >> 185   // compute energy transfer coefficient
                                                   >> 186   G4double MeanTransfer   = fEnTransfer/fTotalCount;
                                                   >> 187   G4double massTransfCoef = massicCS*MeanTransfer/fEkin;
                                                   >> 188    
                                                   >> 189   G4cout << "\n mean energy of charged secondaries: " 
                                                   >> 190          << G4BestUnit(MeanTransfer, "Energy")
                                                   >> 191          << "\tmass_energy_transfer coef: "          
                                                   >> 192          << G4BestUnit(massTransfCoef, "Surface/Mass")
                                                   >> 193          << G4endl;       
197                                                   194 
198   // Output file                               << 195   //output file
                                                   >> 196   //
199   FILE* myFile;                                   197   FILE* myFile;
200   myFile = fopen("mfp.txt", "a");              << 198   myFile=fopen("mfp.txt","a");
201   fprintf(myFile, "%e %e %e \n", fEkin / eV, M << 199   fprintf(myFile,"%e %e %e \n",
                                                   >> 200      fEkin/eV,
                                                   >> 201      MeanFreePath/nm,
                                                   >> 202      rmsBis/nm);
202   fclose(myFile);                                 203   fclose(myFile);
203                                                   204 
204   // Remove all contents in fProcCounter       << 205   // remove all contents in fProcCounter 
205   fProcCounter.clear();                           206   fProcCounter.clear();
206                                                   207 
207   // Reset default formats                     << 208   //reset default formats
208   G4cout.setf(mode, std::ios::floatfield);     << 209   //
                                                   >> 210   G4cout.setf(mode,std::ios::floatfield);
209   G4cout.precision(prec);                         211   G4cout.precision(prec);
                                                   >> 212 
210 }                                                 213 }
211                                                   214