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