Geant4 Cross Reference |
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/wvalue/src/Run.cc 26 /// \file medical/dna/wvalue/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" 40 << 41 #include "DetectorConstruction.hh" 30 #include "DetectorConstruction.hh" 42 #include "HistoManager.hh" 31 #include "HistoManager.hh" 43 #include "PrimaryGeneratorAction.hh" 32 #include "PrimaryGeneratorAction.hh" 44 33 45 #include "G4Material.hh" 34 #include "G4Material.hh" 46 #include "G4SystemOfUnits.hh" 35 #include "G4SystemOfUnits.hh" 47 #include "G4UnitsTable.hh" 36 #include "G4UnitsTable.hh" 48 37 49 //....oooOO0OOooo........oooOO0OOooo........oo 38 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 50 39 51 Run::Run(const DetectorConstruction* detector) 40 Run::Run(const DetectorConstruction* detector) 52 : G4Run(), << 41 : G4Run(), 53 fDetector(detector), << 42 fDetector(detector), 54 fParticle(0), << 43 fParticle(0), fEkin(0.), 55 fEkin(0.), << 44 fNbInelastic(0), fNbInelastic2(0), 56 fNbInelastic(0), << 45 fEdeposit(0.), fEdeposit2(0.), 57 fNbInelastic2(0), << 46 fTrackLen(0.), fTrackLen2(0.), 58 fEdeposit(0.), << 47 fProjRange(0.), fProjRange2(0.), 59 fEdeposit2(0.), << 48 fNbOfSteps(0), fNbOfSteps2(0), 60 fTrackLen(0.), << 49 fStepSize(0.), fStepSize2(0.) 61 fTrackLen2(0.), << 50 { } 62 fProjRange(0.), << 63 fProjRange2(0.), << 64 fNbOfSteps(0), << 65 fNbOfSteps2(0), << 66 fStepSize(0.), << 67 fStepSize2(0.) << 68 {} << 69 51 70 //....oooOO0OOooo........oooOO0OOooo........oo 52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 71 53 72 Run::~Run() {} << 54 Run::~Run() >> 55 { } 73 56 74 //....oooOO0OOooo........oooOO0OOooo........oo 57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 75 58 76 void Run::SetPrimary(G4ParticleDefinition* par << 59 void Run::SetPrimary (G4ParticleDefinition* particle, G4double energy) 77 { << 60 { 78 fParticle = particle; 61 fParticle = particle; 79 fEkin = energy; << 62 fEkin = energy; 80 } 63 } 81 64 82 //....oooOO0OOooo........oooOO0OOooo........oo 65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 83 66 84 void Run::AddInelastic(G4int nb) << 67 void Run::AddInelastic (G4int nb) 85 { 68 { 86 fNbInelastic += nb; << 69 fNbInelastic += nb; 87 fNbInelastic2 += nb * nb; << 70 fNbInelastic2 += nb*nb; 88 } 71 } 89 72 90 //....oooOO0OOooo........oooOO0OOooo........oo 73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 91 74 92 void Run::AddEdep(G4double e) << 75 void Run::AddEdep (G4double e) 93 { 76 { 94 fEdeposit += e; << 77 fEdeposit += e; 95 fEdeposit2 += e * e; << 78 fEdeposit2 += e*e; 96 } 79 } 97 80 98 //....oooOO0OOooo........oooOO0OOooo........oo 81 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 99 << 82 100 void Run::AddTrackLength(G4double t) << 83 void Run::AddTrackLength (G4double t) 101 { 84 { 102 fTrackLen += t; << 85 fTrackLen += t; 103 fTrackLen2 += t * t; << 86 fTrackLen2 += t*t; 104 } 87 } 105 88 106 //....oooOO0OOooo........oooOO0OOooo........oo 89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 107 << 90 108 void Run::AddProjRange(G4double x) << 91 void Run::AddProjRange (G4double x) 109 { 92 { 110 fProjRange += x; << 93 fProjRange += x; 111 fProjRange2 += x * x; << 94 fProjRange2 += x*x; 112 } 95 } 113 96 114 //....oooOO0OOooo........oooOO0OOooo........oo 97 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 115 << 98 116 void Run::AddStepSize(G4int nb, G4double st) << 99 void Run::AddStepSize (G4int nb, G4double st) 117 { 100 { 118 fNbOfSteps += nb; << 101 fNbOfSteps += nb; 119 fNbOfSteps2 += nb * nb; << 102 fNbOfSteps2 += nb*nb; 120 fStepSize += st; << 103 fStepSize += st ; 121 fStepSize2 += st * st; << 104 fStepSize2 += st*st; 122 } 105 } 123 106 124 //....oooOO0OOooo........oooOO0OOooo........oo 107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 125 108 126 void Run::Merge(const G4Run* run) 109 void Run::Merge(const G4Run* run) 127 { 110 { 128 const Run* localRun = static_cast<const Run* 111 const Run* localRun = static_cast<const Run*>(run); 129 << 112 130 // Pass information about primary particle << 113 // pass information about primary particle 131 << 132 fParticle = localRun->fParticle; 114 fParticle = localRun->fParticle; 133 fEkin = localRun->fEkin; << 115 fEkin = localRun->fEkin; 134 << 135 // Accumulate sums << 136 116 137 fNbInelastic += localRun->fNbInelastic; << 117 // accumulate sums 138 fNbInelastic2 += localRun->fNbInelastic2; << 118 fNbInelastic += localRun->fNbInelastic; 139 fEdeposit += localRun->fEdeposit; << 119 fNbInelastic2 += localRun->fNbInelastic2; 140 fEdeposit2 += localRun->fEdeposit2; << 120 fEdeposit += localRun->fEdeposit; 141 fTrackLen += localRun->fTrackLen; << 121 fEdeposit2 += localRun->fEdeposit2; 142 fTrackLen2 += localRun->fTrackLen2; << 122 fTrackLen += localRun->fTrackLen; 143 fProjRange += localRun->fProjRange; << 123 fTrackLen2 += localRun->fTrackLen2; >> 124 fProjRange += localRun->fProjRange; 144 fProjRange2 += localRun->fProjRange2; 125 fProjRange2 += localRun->fProjRange2; 145 fNbOfSteps += localRun->fNbOfSteps; << 126 fNbOfSteps += localRun->fNbOfSteps ; 146 fNbOfSteps2 += localRun->fNbOfSteps2; 127 fNbOfSteps2 += localRun->fNbOfSteps2; 147 fStepSize += localRun->fStepSize; << 128 fStepSize += localRun->fStepSize; 148 fStepSize2 += localRun->fStepSize2; << 129 fStepSize2 += localRun->fStepSize2; 149 130 150 G4Run::Merge(run); << 131 G4Run::Merge(run); 151 } << 132 } 152 133 153 //....oooOO0OOooo........oooOO0OOooo........oo 134 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 154 135 155 void Run::EndOfRun() << 136 void Run::EndOfRun() 156 { 137 { 157 std::ios::fmtflags mode = G4cout.flags(); 138 std::ios::fmtflags mode = G4cout.flags(); 158 G4cout.setf(std::ios::fixed, std::ios::float << 139 G4cout.setf(std::ios::fixed,std::ios::floatfield); 159 G4int prec = G4cout.precision(2); 140 G4int prec = G4cout.precision(2); 160 << 141 161 // Run conditions << 142 //run conditions 162 << 143 // 163 G4Material* material = fDetector->GetAbsorMa 144 G4Material* material = fDetector->GetAbsorMaterial(); 164 G4double density = material->GetDensity(); << 145 G4double density = material->GetDensity(); 165 G4String partName = fParticle->GetParticleNa 146 G4String partName = fParticle->GetParticleName(); 166 << 147 167 G4cout << "\n ======================== run s << 148 G4cout << "\n ======================== run summary =====================\n"; 168 G4cout << "\n The run is " << numberOfEvent << 149 G4cout 169 << G4BestUnit(fEkin, "Energy") << " t << 150 << "\n The run is " << numberOfEvent << " "<< partName << " of " 170 << G4BestUnit(fDetector->GetAbsorRadi << 151 << G4BestUnit(fEkin,"Energy") << " through a sphere of radius " 171 << " (density: " << G4BestUnit(densit << 152 << G4BestUnit(fDetector->GetAbsorRadius(),"Length") << "of " >> 153 << material->GetName() << " (density: " >> 154 << G4BestUnit(density,"Volumic Mass") << ")" << G4endl; 172 155 173 if (numberOfEvent == 0) { 156 if (numberOfEvent == 0) { 174 G4cout.setf(mode, std::ios::floatfield); << 157 G4cout.setf(mode,std::ios::floatfield); 175 G4cout.precision(prec); << 158 G4cout.precision(prec); 176 return; 159 return; 177 } 160 } 178 161 179 fNbInelastic /= numberOfEvent; << 162 fNbInelastic /= numberOfEvent; fNbInelastic2 /= numberOfEvent; 180 fNbInelastic2 /= numberOfEvent; << 163 >> 164 G4double rms = fNbInelastic2 - fNbInelastic*fNbInelastic; >> 165 if (rms>0.) rms = std::sqrt(rms); else rms = 0.; 181 166 182 G4double rms = fNbInelastic2 - fNbInelastic << 167 G4cout.precision(3); 183 if (rms > 0.) << 168 G4cout 184 rms = std::sqrt(rms); << 169 << "\n Nb of ionisations = " << fNbInelastic 185 else << 170 << " +- " << rms 186 rms = 0.; << 171 << G4endl; 187 << 172 188 G4cout.precision(3); << 173 G4cout.precision(3); 189 G4cout << "\n Nb of ionisations = " << fNbIn << 174 G4cout 190 << 175 << "\n w = " << G4BestUnit((fEkin)/fNbInelastic,"Energy") 191 G4cout.precision(3); << 176 << " +- " << G4BestUnit((fEkin)*rms/(fNbInelastic*fNbInelastic),"Energy") 192 G4cout << "\n w = " << G4BestUnit((fEkin) / << 177 << G4endl; 193 << G4BestUnit((fEkin)*rms / (fNbInela << 178 194 << 179 //output file 195 // Output file << 180 if(fNbInelastic>0.) 196 << 181 { 197 if (fNbInelastic > 0.) { << 182 FILE *myFile; 198 FILE* myFile; << 183 myFile = fopen ("wvalue.txt","a"); 199 myFile = fopen("wvalue.txt", "a"); << 184 fprintf (myFile, "%e %e %e %e %e \n", fEkin/eV, fNbInelastic, rms, 200 fprintf(myFile, "%e %e %e %e %e \n", fEkin << 185 fEkin/eV/fNbInelastic, (fEkin/eV)*rms/(fNbInelastic*fNbInelastic) ); 201 (fEkin / eV) * rms / (fNbInelastic << 186 fclose (myFile); 202 fclose(myFile); << 203 } 187 } 204 // 188 // 205 189 206 fEdeposit /= numberOfEvent; << 190 fEdeposit /= numberOfEvent; fEdeposit2 /= numberOfEvent; 207 fEdeposit2 /= numberOfEvent; << 191 rms = fEdeposit2 - fEdeposit*fEdeposit; 208 rms = fEdeposit2 - fEdeposit * fEdeposit; << 192 if (rms>0.) rms = std::sqrt(rms); else rms = 0.; 209 if (rms > 0.) << 193 210 rms = std::sqrt(rms); << 194 G4cout.precision(3); 211 else << 195 G4cout 212 rms = 0.; << 196 << "\n Total Energy deposited = " << G4BestUnit(fEdeposit,"Energy") 213 << 197 << " +- " << G4BestUnit( rms,"Energy") 214 G4cout.precision(3); << 198 << G4endl; 215 G4cout << "\n Total Energy deposited << 199 216 << G4BestUnit(rms, "Energy") << G4end << 200 //compute track length of primary track 217 << 201 // 218 // Compute track length of primary track << 202 fTrackLen /= numberOfEvent; fTrackLen2 /= numberOfEvent; 219 << 203 rms = fTrackLen2 - fTrackLen*fTrackLen; 220 fTrackLen /= numberOfEvent; << 204 if (rms>0.) rms = std::sqrt(rms); else rms = 0.; 221 fTrackLen2 /= numberOfEvent; << 205 222 rms = fTrackLen2 - fTrackLen * fTrackLen; << 206 G4cout.precision(3); 223 if (rms > 0.) << 207 G4cout 224 rms = std::sqrt(rms); << 208 << "\n Track length of primary track = " << G4BestUnit(fTrackLen,"Length") 225 else << 209 << " +- " << G4BestUnit( rms,"Length"); 226 rms = 0.; << 210 227 << 211 //compute projected range of primary track 228 G4cout.precision(3); << 212 // 229 G4cout << "\n Track length of primary track << 213 fProjRange /= numberOfEvent; fProjRange2 /= numberOfEvent; 230 << G4BestUnit(rms, "Length"); << 214 rms = fProjRange2 - fProjRange*fProjRange; 231 << 215 if (rms>0.) rms = std::sqrt(rms); else rms = 0.; 232 // Compute projected range of primary track << 216 233 << 217 G4cout 234 fProjRange /= numberOfEvent; << 218 << "\n Projected range = " << G4BestUnit(fProjRange,"Length") 235 fProjRange2 /= numberOfEvent; << 219 << " +- " << G4BestUnit( rms,"Length") 236 rms = fProjRange2 - fProjRange * fProjRange; << 220 << G4endl; 237 if (rms > 0.) << 221 238 rms = std::sqrt(rms); << 222 //nb of steps and step size of primary track 239 else << 223 // 240 rms = 0.; << 241 << 242 G4cout << "\n Projected range << 243 << G4BestUnit(rms, "Length") << G4end << 244 << 245 // Nb of steps and step size of primary trac << 246 << 247 G4double dNofEvents = double(numberOfEvent); 224 G4double dNofEvents = double(numberOfEvent); 248 G4double fNbSteps = fNbOfSteps / dNofEvents, << 225 G4double fNbSteps = fNbOfSteps/dNofEvents, 249 rms = fNbSteps2 - fNbSteps * fNbSteps; << 226 fNbSteps2 = fNbOfSteps2/dNofEvents; 250 if (rms > 0.) << 227 rms = fNbSteps2 - fNbSteps*fNbSteps; 251 rms = std::sqrt(rms); << 228 if (rms>0.) rms = std::sqrt(rms); else rms = 0.; 252 else << 229 253 rms = 0.; << 230 G4cout.precision(2); 254 << 231 G4cout << "\n Nb of steps of primary track = " << fNbSteps << " +- " << rms 255 G4cout.precision(2); << 232 << G4endl; 256 G4cout << "\n Nb of steps of primary track << 233 257 << 234 fStepSize /= numberOfEvent; fStepSize2 /= numberOfEvent; 258 fStepSize /= numberOfEvent; << 235 rms = fStepSize2 - fStepSize*fStepSize; 259 fStepSize2 /= numberOfEvent; << 236 if (rms>0.) rms = std::sqrt(rms); else rms = 0.; 260 rms = fStepSize2 - fStepSize * fStepSize; << 237 261 if (rms > 0.) << 238 G4cout.precision(3); 262 rms = std::sqrt(rms); << 239 G4cout 263 else << 240 << "\n Step size = " << G4BestUnit(fStepSize,"Length") 264 rms = 0.; << 241 << " +- " << G4BestUnit( rms,"Length") 265 << 242 << G4endl; 266 G4cout.precision(3); << 267 G4cout << "\n Step size << 268 << G4BestUnit(rms, "Length") << G4end << 269 << 270 // Normalize histograms of longitudinal ener << 271 243 >> 244 // normalize histograms of longitudinal energy profile >> 245 // 272 G4AnalysisManager* analysisManager = G4Analy 246 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 273 G4int ih = 1; 247 G4int ih = 1; 274 G4double binWidth = analysisManager->GetH1Wi 248 G4double binWidth = analysisManager->GetH1Width(ih); 275 G4double fac = (1. / (numberOfEvent * binWid << 249 G4double fac = (1./(numberOfEvent*binWidth))*(mm/MeV); 276 analysisManager->ScaleH1(ih, fac); << 250 analysisManager->ScaleH1(ih,fac); 277 << 251 278 // Reset default formats << 252 // reset default formats 279 << 253 G4cout.setf(mode,std::ios::floatfield); 280 G4cout.setf(mode, std::ios::floatfield); << 281 G4cout.precision(prec); 254 G4cout.precision(prec); >> 255 282 } 256 } 283 257