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