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