Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 /// \file Run.cc 27 /// \brief Implementation of the Run class 28 // 29 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 31 //....oooOO0OOooo........oooOO0OOooo........oo 32 33 #include "Run.hh" 34 35 #include "DetectorConstruction.hh" 36 #include "EventAction.hh" 37 #include "HistoManager.hh" 38 #include "PrimaryGeneratorAction.hh" 39 40 #include "G4Event.hh" 41 #include "G4Material.hh" 42 #include "G4SystemOfUnits.hh" 43 #include "G4UnitsTable.hh" 44 45 #include <iomanip> 46 47 //....oooOO0OOooo........oooOO0OOooo........oo 48 49 Run::Run(DetectorConstruction* detector) : fDe 50 { 51 fTotEdep[1] = fEleak[1] = fEtotal[1] = joule 52 53 for (G4int i = 0; i < kMaxAbsor; ++i) { 54 fEdeposit[i] = 0.; 55 fEmin[i] = joule; 56 fEmax[i] = 0.; 57 } 58 } 59 60 //....oooOO0OOooo........oooOO0OOooo........oo 61 62 void Run::SetPrimary(G4ParticleDefinition* par 63 { 64 fParticle = particle; 65 fEkin = energy; 66 } 67 68 //....oooOO0OOooo........oooOO0OOooo........oo 69 70 void Run::CountProcesses(const G4VProcess* pro 71 { 72 if (process == nullptr) return; 73 G4String procName = process->GetProcessName( 74 std::map<G4String, G4int>::iterator it = fPr 75 if (it == fProcCounter.end()) { 76 fProcCounter[procName] = 1; 77 } 78 else { 79 fProcCounter[procName]++; 80 } 81 } 82 83 //....oooOO0OOooo........oooOO0OOooo........oo 84 85 void Run::ParticleCount(G4int k, G4String name 86 { 87 std::map<G4String, ParticleData>::iterator i 88 if (it == fParticleDataMap[k].end()) { 89 (fParticleDataMap[k])[name] = ParticleData 90 } 91 else { 92 ParticleData& data = it->second; 93 data.fCount++; 94 data.fEmean += Ekin; 95 // update min max 96 G4double emin = data.fEmin; 97 if (Ekin < emin) data.fEmin = Ekin; 98 G4double emax = data.fEmax; 99 if (Ekin > emax) data.fEmax = Ekin; 100 data.fTmean = meanLife; 101 } 102 } 103 104 //....oooOO0OOooo........oooOO0OOooo........oo 105 106 void Run::AddEdep(G4int i, G4double e) 107 { 108 if (e > 0.) { 109 fEdeposit[i] += e; 110 if (e < fEmin[i]) fEmin[i] = e; 111 if (e > fEmax[i]) fEmax[i] = e; 112 } 113 } 114 115 //....oooOO0OOooo........oooOO0OOooo........oo 116 117 void Run::AddTotEdep(G4double e) 118 { 119 if (e > 0.) { 120 fTotEdep[0] += e; 121 if (e < fTotEdep[1]) fTotEdep[1] = e; 122 if (e > fTotEdep[2]) fTotEdep[2] = e; 123 } 124 } 125 126 //....oooOO0OOooo........oooOO0OOooo........oo 127 128 void Run::AddEleak(G4double e) 129 { 130 if (e > 0.) { 131 fEleak[0] += e; 132 if (e < fEleak[1]) fEleak[1] = e; 133 if (e > fEleak[2]) fEleak[2] = e; 134 } 135 } 136 137 //....oooOO0OOooo........oooOO0OOooo........oo 138 139 void Run::AddEtotal(G4double e) 140 { 141 if (e > 0.) { 142 fEtotal[0] += e; 143 if (e < fEtotal[1]) fEtotal[1] = e; 144 if (e > fEtotal[2]) fEtotal[2] = e; 145 } 146 } 147 148 //....oooOO0OOooo........oooOO0OOooo........oo 149 150 void Run::AddTrackStatus(G4int i) 151 { 152 fStatus[i]++; 153 } 154 155 //....oooOO0OOooo........oooOO0OOooo........oo 156 157 void Run::Merge(const G4Run* run) 158 { 159 const Run* localRun = static_cast<const Run* 160 161 // pass information about primary particle 162 fParticle = localRun->fParticle; 163 fEkin = localRun->fEkin; 164 165 // Edep in absorbers 166 // 167 G4int nbOfAbsor = fDetector->GetNbOfAbsor(); 168 for (G4int i = 1; i <= nbOfAbsor; ++i) { 169 fEdeposit[i] += localRun->fEdeposit[i]; 170 // min, max 171 G4double min, max; 172 min = localRun->fEmin[i]; 173 max = localRun->fEmax[i]; 174 if (fEmin[i] > min) fEmin[i] = min; 175 if (fEmax[i] < max) fEmax[i] = max; 176 } 177 178 for (G4int i = 0; i < 3; ++i) 179 fStatus[i] += localRun->fStatus[i]; 180 181 // total Edep 182 fTotEdep[0] += localRun->fTotEdep[0]; 183 G4double min, max; 184 min = localRun->fTotEdep[1]; 185 max = localRun->fTotEdep[2]; 186 if (fTotEdep[1] > min) fTotEdep[1] = min; 187 if (fTotEdep[2] < max) fTotEdep[2] = max; 188 189 // Eleak 190 fEleak[0] += localRun->fEleak[0]; 191 min = localRun->fEleak[1]; 192 max = localRun->fEleak[2]; 193 if (fEleak[1] > min) fEleak[1] = min; 194 if (fEleak[2] < max) fEleak[2] = max; 195 196 // Etotal 197 fEtotal[0] += localRun->fEtotal[0]; 198 min = localRun->fEtotal[1]; 199 max = localRun->fEtotal[2]; 200 if (fEtotal[1] > min) fEtotal[1] = min; 201 if (fEtotal[2] < max) fEtotal[2] = max; 202 203 // map: processes count 204 std::map<G4String, G4int>::const_iterator it 205 for (itp = localRun->fProcCounter.begin(); i 206 G4String procName = itp->first; 207 G4int localCount = itp->second; 208 if (fProcCounter.find(procName) == fProcCo 209 fProcCounter[procName] = localCount; 210 } 211 else { 212 fProcCounter[procName] += localCount; 213 } 214 } 215 216 // map: created particles in absorbers count 217 for (G4int k = 0; k <= nbOfAbsor; ++k) { 218 std::map<G4String, ParticleData>::const_it 219 for (itc = localRun->fParticleDataMap[k].b 220 ++itc) 221 { 222 G4String name = itc->first; 223 const ParticleData& localData = itc->sec 224 if (fParticleDataMap[k].find(name) == fP 225 (fParticleDataMap[k])[name] = Particle 226 localData.fCount, localData.fEmean, 227 } 228 else { 229 ParticleData& data = (fParticleDataMap 230 data.fCount += localData.fCount; 231 data.fEmean += localData.fEmean; 232 G4double emin = localData.fEmin; 233 if (emin < data.fEmin) data.fEmin = em 234 G4double emax = localData.fEmax; 235 if (emax > data.fEmax) data.fEmax = em 236 data.fTmean = localData.fTmean; 237 } 238 } 239 } 240 241 G4Run::Merge(run); 242 } 243 244 //....oooOO0OOooo........oooOO0OOooo........oo 245 246 void Run::EndOfRun() 247 { 248 G4int prec = 5, wid = prec + 2; 249 G4int dfprec = G4cout.precision(prec); 250 251 // run conditions 252 // 253 G4String partName = fParticle->GetParticleNa 254 G4int nbOfAbsor = fDetector->GetNbOfAbsor(); 255 256 G4cout << "\n ======================== run s 257 G4cout << "\n The run is " << numberOfEvent 258 << G4BestUnit(fEkin, "Energy") << " t 259 for (G4int i = 1; i <= nbOfAbsor; i++) { 260 G4Material* material = fDetector->GetAbsor 261 G4double thickness = fDetector->GetAbsorTh 262 G4double density = material->GetDensity(); 263 G4cout << std::setw(5) << i << std::setw(1 264 << material->GetName() << " (densit 265 << G4endl; 266 } 267 268 if (numberOfEvent == 0) { 269 G4cout.precision(dfprec); 270 return; 271 } 272 273 G4cout.precision(3); 274 275 // frequency of processes 276 // 277 G4cout << "\n Process calls frequency :" << 278 G4int index = 0; 279 std::map<G4String, G4int>::iterator it; 280 for (it = fProcCounter.begin(); it != fProcC 281 G4String procName = it->first; 282 G4int count = it->second; 283 G4String space = " "; 284 if (++index % 3 == 0) space = "\n"; 285 G4cout << " " << std::setw(20) << procName 286 } 287 G4cout << G4endl; 288 289 // Edep in absorbers 290 // 291 for (G4int i = 1; i <= nbOfAbsor; i++) { 292 fEdeposit[i] /= numberOfEvent; 293 294 G4cout << "\n Edep in absorber " << i << " 295 << G4BestUnit(fEmin[i], "Energy") < 296 } 297 G4cout << G4endl; 298 299 if (nbOfAbsor > 1) { 300 fTotEdep[0] /= numberOfEvent; 301 G4cout << "\n Edep in all absorb = " << G4 302 << G4BestUnit(fTotEdep[1], "Energy" 303 << G4endl; 304 } 305 306 // Eleak 307 // 308 fEleak[0] /= numberOfEvent; 309 G4cout << " Energy leakage = " << G4Best 310 << G4BestUnit(fEleak[1], "Energy") << 311 << G4endl; 312 313 // Etotal 314 // 315 fEtotal[0] /= numberOfEvent; 316 G4cout << " Energy total = " << G4Best 317 << G4BestUnit(fEtotal[1], "Energy") < 318 << G4endl; 319 320 // particles count in absorbers 321 // 322 for (G4int k = 1; k <= nbOfAbsor; k++) { 323 G4cout << "\n List of created particles in 324 325 std::map<G4String, ParticleData>::iterator 326 for (itc = fParticleDataMap[k].begin(); it 327 G4String name = itc->first; 328 ParticleData data = itc->second; 329 G4int count = data.fCount; 330 G4double eMean = data.fEmean / count; 331 G4double eMin = data.fEmin; 332 G4double eMax = data.fEmax; 333 G4double meanLife = data.fTmean; 334 335 G4cout << " " << std::setw(13) << name 336 << " Emean = " << std::setw(wid) 337 << G4BestUnit(eMin, "Energy") << 338 if (meanLife >= 0.) 339 G4cout << "\tmean life = " << G4BestUn 340 else 341 G4cout << "\tstable" << G4endl; 342 } 343 } 344 // particles emerging from absorbers 345 // 346 G4cout << "\n List of particles emerging fro 347 348 std::map<G4String, ParticleData>::iterator i 349 for (itc = fParticleDataMap[0].begin(); itc 350 G4String name = itc->first; 351 ParticleData data = itc->second; 352 G4int count = data.fCount; 353 G4double eMean = data.fEmean / count; 354 G4double eMin = data.fEmin; 355 G4double eMax = data.fEmax; 356 /// G4double meanLife = data.fTmean; 357 358 G4cout << " " << std::setw(13) << name << 359 << " Emean = " << std::setw(wid) < 360 << G4BestUnit(eMin, "Energy") << " 361 } 362 363 // transmission coefficients 364 // 365 G4double dNofEvents = double(numberOfEvent); 366 G4double absorbed = 100. * fStatus[0] / dNof 367 G4double transmit = 100. * fStatus[1] / dNof 368 G4double reflected = 100. * fStatus[2] / dNo 369 370 G4cout.precision(2); 371 G4cout << "\n Nb of events with primary abso 372 << " transmit = " << transmit << " 373 << " reflected = " << reflected << 374 375 // normalize histograms of longitudinal ener 376 // 377 G4AnalysisManager* analysisManager = G4Analy 378 G4int ih = 10; 379 G4double binWidth = analysisManager->GetH1Wi 380 G4double fac = (1. / (numberOfEvent * binWid 381 analysisManager->ScaleH1(ih, fac); 382 383 // remove all contents in fProcCounter, fCou 384 fProcCounter.clear(); 385 for (G4int k = 0; k <= nbOfAbsor; k++) 386 fParticleDataMap[k].clear(); 387 388 // reset default formats 389 G4cout.precision(dfprec); 390 } 391 392 //....oooOO0OOooo........oooOO0OOooo........oo 393