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 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........oo 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........oo 69 70 Run::~Run() {} 71 72 //....oooOO0OOooo........oooOO0OOooo........oo 73 74 void Run::SetPrimary(G4ParticleDefinition* par 75 { 76 fParticle = particle; 77 fEkin = energy; 78 } 79 80 //....oooOO0OOooo........oooOO0OOooo........oo 81 82 void Run::AddEdep(G4double e) 83 { 84 fEdeposit += e; 85 fEdeposit2 += e * e; 86 } 87 88 //....oooOO0OOooo........oooOO0OOooo........oo 89 90 void Run::AddTrackLength(G4double t) 91 { 92 fTrackLen += t; 93 fTrackLen2 += t * t; 94 } 95 96 //....oooOO0OOooo........oooOO0OOooo........oo 97 98 void Run::AddProjRange(G4double x) 99 { 100 fProjRange += x; 101 fProjRange2 += x * x; 102 } 103 104 //....oooOO0OOooo........oooOO0OOooo........oo 105 106 void Run::AddPenetration(G4double x) 107 { 108 fPenetration += x; 109 fPenetration2 += x * x; 110 } 111 112 //....oooOO0OOooo........oooOO0OOooo........oo 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........oo 123 124 void Run::Merge(const G4Run* run) 125 { 126 const Run* localRun = static_cast<const 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........oo 150 151 void Run::EndOfRun() 152 { 153 std::ios::fmtflags mode = G4cout.flags(); 154 G4cout.setf(std::ios::fixed, std::ios::float 155 G4int prec = G4cout.precision(2); 156 157 // Run conditions 158 G4Material* material = fDetector->GetAbsorMa 159 G4double density = material->GetDensity(); 160 G4String partName = fParticle->GetParticleNa 161 162 G4cout << "\n ======================= run su 163 G4cout << "\n The run is " << numberOfEvent 164 << G4BestUnit(fEkin, "Energy") << " t 165 << G4BestUnit(fDetector->GetAbsorRadi 166 << " (density: " << G4BestUnit(densit 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 * 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 186 << G4BestUnit(rmsTrack, "Length"); 187 188 // Compute projected range of primary track 189 fProjRange /= numberOfEvent; 190 fProjRange2 /= numberOfEvent; 191 G4double rmsProj = fProjRange2 - fProjRange 192 if (rmsProj > 0.) 193 rmsProj = std::sqrt(rmsProj); 194 else 195 rmsProj = 0.; 196 197 G4cout << "\n Projected range 198 << G4BestUnit(rmsProj, "Length"); 199 200 // Compute penetration of primary track 201 fPenetration /= numberOfEvent; 202 fPenetration2 /= numberOfEvent; 203 G4double rmsPene = fPenetration2 - fPenetrat 204 if (rmsPene > 0.) 205 rmsPene = std::sqrt(rmsPene); 206 else 207 rmsPene = 0.; 208 209 G4cout << "\n Penetration 210 << G4BestUnit(rmsPene, "Length") << G 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", fE 218 fProjRange / nm, rmsProj / nm, fPene 219 fclose(myFile); 220 221 // Reset default formats 222 G4cout.setf(mode, std::ios::floatfield); 223 G4cout.precision(prec); 224 } 225