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