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