Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 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 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........oo 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........oo 61 62 Run::~Run() {} 63 64 //....oooOO0OOooo........oooOO0OOooo........oo 65 66 void Run::SetPrimary(G4ParticleDefinition* par 67 { 68 fParticle = particle; 69 fEkin = energy; 70 } 71 72 //....oooOO0OOooo........oooOO0OOooo........oo 73 74 void Run::CountProcesses(G4String procName) 75 { 76 std::map<G4String, G4int>::iterator it = fPr 77 if (it == fProcCounter.end()) { 78 fProcCounter[procName] = 1; 79 } 80 else { 81 fProcCounter[procName]++; 82 } 83 } 84 85 //....oooOO0OOooo........oooOO0OOooo........oo 86 87 void Run::SumTrack(G4double track) 88 { 89 fTotalCount++; 90 fSumTrack += track; 91 fSumTrack2 += track * track; 92 } 93 94 //....oooOO0OOooo........oooOO0OOooo........oo 95 96 void Run::SumeTransf(G4double energy) 97 { 98 fEnTransfer += energy; 99 } 100 101 //....oooOO0OOooo........oooOO0OOooo........oo 102 103 void Run::Merge(const G4Run* run) 104 { 105 const Run* localRun = static_cast<const 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 114 G4String procName = it->first; 115 G4int localCount = it->second; 116 117 if (fProcCounter.find(procName) == fProcCo 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........oo 134 135 void Run::EndOfRun() 136 { 137 std::ios::fmtflags mode = G4cout.flags(); 138 G4cout.setf(std::ios::fixed, std::ios::float 139 G4int prec = G4cout.precision(2); 140 141 // Run conditions 142 G4Material* material = fDetector->GetAbsorMa 143 G4double density = material->GetDensity(); 144 G4String partName = fParticle->GetParticleNa 145 146 G4cout << "\n ======================== run s 147 G4cout << "\n The run is " << numberOfEvent 148 << G4BestUnit(fEkin, "Energy") << " t 149 << G4BestUnit(fDetector->GetAbsorRadi 150 << " (density: " << G4BestUnit(densit 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 != fProcC 163 G4String procName = it->first; 164 G4int count = it->second; 165 G4cout << "\t" << procName << " = " << cou 166 if (procName == "Transportation") survive 167 } 168 169 if (survive > 0) { 170 G4cout << "\n\n Nb of incident particles s 171 << "a radius of " << G4BestUnit(fDe 172 << material->GetName() << " : " << 173 } 174 175 if (fTotalCount == 0) fTotalCount = 1; // f 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 195 G4cout << "\n mean energy of charged seconda 196 << "\tmass_energy_transfer coef: " << 197 198 // Output file 199 FILE* myFile; 200 myFile = fopen("mfp.txt", "a"); 201 fprintf(myFile, "%e %e %e \n", fEkin / eV, M 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