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 "HistoManager.hh" 37 #include "PrimaryGeneratorAction.hh" 38 39 #include "G4SystemOfUnits.hh" 40 #include "G4UnitsTable.hh" 41 42 //....oooOO0OOooo........oooOO0OOooo........oo 43 44 Run::Run(DetectorConstruction* det) : fDetecto 45 46 //....oooOO0OOooo........oooOO0OOooo........oo 47 48 void Run::SetPrimary(G4ParticleDefinition* par 49 { 50 fParticle = particle; 51 fEkin = energy; 52 } 53 54 //....oooOO0OOooo........oooOO0OOooo........oo 55 56 void Run::CountProcesses(const G4VProcess* pro 57 { 58 if (process == nullptr) return; 59 G4String procName = process->GetProcessName( 60 std::map<G4String, G4int>::iterator it = fPr 61 if (it == fProcCounter.end()) { 62 fProcCounter[procName] = 1; 63 } 64 else { 65 fProcCounter[procName]++; 66 } 67 } 68 69 //....oooOO0OOooo........oooOO0OOooo........oo 70 71 void Run::ParticleCount(G4String name, G4doubl 72 { 73 std::map<G4String, ParticleData>::iterator i 74 if (it == fParticleDataMap1.end()) { 75 fParticleDataMap1[name] = ParticleData(1, 76 } 77 else { 78 ParticleData& data = it->second; 79 data.fCount++; 80 data.fEmean += Ekin; 81 // update min max 82 G4double emin = data.fEmin; 83 if (Ekin < emin) data.fEmin = Ekin; 84 G4double emax = data.fEmax; 85 if (Ekin > emax) data.fEmax = Ekin; 86 data.fTmean = meanLife; 87 } 88 } 89 90 //....oooOO0OOooo........oooOO0OOooo........oo 91 92 void Run::AddEdep(G4double edep) 93 { 94 fEnergyDeposit += edep; 95 fEnergyDeposit2 += edep * edep; 96 } 97 98 //....oooOO0OOooo........oooOO0OOooo........oo 99 100 void Run::AddEflow(G4double eflow) 101 { 102 fEnergyFlow += eflow; 103 fEnergyFlow2 += eflow * eflow; 104 } 105 //....oooOO0OOooo........oooOO0OOooo........oo 106 107 void Run::ParticleFlux(G4String name, G4double 108 { 109 std::map<G4String, ParticleData>::iterator i 110 if (it == fParticleDataMap2.end()) { 111 fParticleDataMap2[name] = ParticleData(1, 112 } 113 else { 114 ParticleData& data = it->second; 115 data.fCount++; 116 data.fEmean += Ekin; 117 // update min max 118 G4double emin = data.fEmin; 119 if (Ekin < emin) data.fEmin = Ekin; 120 G4double emax = data.fEmax; 121 if (Ekin > emax) data.fEmax = Ekin; 122 data.fTmean = -1 * ns; 123 } 124 } 125 126 //....oooOO0OOooo........oooOO0OOooo........oo 127 128 void Run::Merge(const G4Run* run) 129 { 130 const Run* localRun = static_cast<const Run* 131 132 // primary particle info 133 // 134 fParticle = localRun->fParticle; 135 fEkin = localRun->fEkin; 136 137 // accumulate sums 138 // 139 fEnergyDeposit += localRun->fEnergyDeposit; 140 fEnergyDeposit2 += localRun->fEnergyDeposit2 141 fEnergyFlow += localRun->fEnergyFlow; 142 fEnergyFlow2 += localRun->fEnergyFlow2; 143 144 // map: processes count 145 std::map<G4String, G4int>::const_iterator it 146 for (itp = localRun->fProcCounter.begin(); i 147 G4String procName = itp->first; 148 G4int localCount = itp->second; 149 if (fProcCounter.find(procName) == fProcCo 150 fProcCounter[procName] = localCount; 151 } 152 else { 153 fProcCounter[procName] += localCount; 154 } 155 } 156 157 // map: created particles count 158 std::map<G4String, ParticleData>::const_iter 159 for (itc = localRun->fParticleDataMap1.begin 160 G4String name = itc->first; 161 const ParticleData& localData = itc->secon 162 if (fParticleDataMap1.find(name) == fParti 163 fParticleDataMap1[name] = ParticleData(l 164 l 165 } 166 else { 167 ParticleData& data = fParticleDataMap1[n 168 data.fCount += localData.fCount; 169 data.fEmean += localData.fEmean; 170 G4double emin = localData.fEmin; 171 if (emin < data.fEmin) data.fEmin = emin 172 G4double emax = localData.fEmax; 173 if (emax > data.fEmax) data.fEmax = emax 174 data.fTmean = localData.fTmean; 175 } 176 } 177 178 // map: particles flux count 179 std::map<G4String, ParticleData>::const_iter 180 for (itn = localRun->fParticleDataMap2.begin 181 G4String name = itn->first; 182 const ParticleData& localData = itn->secon 183 if (fParticleDataMap2.find(name) == fParti 184 fParticleDataMap2[name] = ParticleData(l 185 l 186 } 187 else { 188 ParticleData& data = fParticleDataMap2[n 189 data.fCount += localData.fCount; 190 data.fEmean += localData.fEmean; 191 G4double emin = localData.fEmin; 192 if (emin < data.fEmin) data.fEmin = emin 193 G4double emax = localData.fEmax; 194 if (emax > data.fEmax) data.fEmax = emax 195 data.fTmean = localData.fTmean; 196 } 197 } 198 199 G4Run::Merge(run); 200 } 201 202 //....oooOO0OOooo........oooOO0OOooo........oo 203 204 void Run::EndOfRun() 205 { 206 G4int prec = 5, wid = prec + 2; 207 G4int dfprec = G4cout.precision(prec); 208 209 // run condition 210 // 211 G4Material* material = fDetector->GetAbsorMa 212 G4String Particle = fParticle->GetParticleNa 213 G4cout << "\n The run is " << numberOfEvent 214 << G4BestUnit(fEkin, "Energy") << " w 215 << " (D = " << G4BestUnit(2 * (fDete 216 << " L = " << G4BestUnit(fDetector->G 217 218 if (numberOfEvent == 0) { 219 G4cout.precision(dfprec); 220 return; 221 } 222 223 // frequency of processes 224 // 225 G4cout << "\n Process calls frequency :" << 226 G4int index = 0; 227 std::map<G4String, G4int>::iterator it; 228 for (it = fProcCounter.begin(); it != fProcC 229 G4String procName = it->first; 230 G4int count = it->second; 231 G4String space = " "; 232 if (++index % 3 == 0) space = "\n"; 233 G4cout << " " << std::setw(20) << procName 234 } 235 G4cout << G4endl; 236 237 // particles count 238 // 239 G4cout << "\n List of generated particles (w 240 241 std::map<G4String, ParticleData>::iterator i 242 for (itc = fParticleDataMap1.begin(); itc != 243 G4String name = itc->first; 244 ParticleData data = itc->second; 245 G4int count = data.fCount; 246 G4double eMean = data.fEmean / count; 247 G4double eMin = data.fEmin; 248 G4double eMax = data.fEmax; 249 G4double meanLife = data.fTmean; 250 251 G4cout << " " << std::setw(13) << name << 252 << " Emean = " << std::setw(wid) < 253 << G4BestUnit(eMin, "Energy") << " 254 if (meanLife >= 0.) 255 G4cout << "\tmean life = " << G4BestUnit 256 else 257 G4cout << "\tstable" << G4endl; 258 } 259 260 // compute mean Energy deposited and rms 261 // 262 G4int TotNbofEvents = numberOfEvent; 263 fEnergyDeposit /= TotNbofEvents; 264 fEnergyDeposit2 /= TotNbofEvents; 265 G4double rmsEdep = fEnergyDeposit2 - fEnergy 266 if (rmsEdep > 0.) 267 rmsEdep = std::sqrt(rmsEdep); 268 else 269 rmsEdep = 0.; 270 271 G4cout << "\n Mean energy deposit per event 272 << "; rms = " << G4BestUnit(rmsEdep, 273 274 // compute mean Energy flow and rms 275 // 276 fEnergyFlow /= TotNbofEvents; 277 fEnergyFlow2 /= TotNbofEvents; 278 G4double rmsEflow = fEnergyFlow2 - fEnergyFl 279 if (rmsEflow > 0.) 280 rmsEflow = std::sqrt(rmsEflow); 281 else 282 rmsEflow = 0.; 283 284 G4cout << " Mean energy flow per event = 285 << "; rms = " << G4BestUnit(rmsEflow 286 287 // particles flux 288 // 289 G4cout << "\n List of particles emerging fro 290 291 std::map<G4String, ParticleData>::iterator i 292 for (itn = fParticleDataMap2.begin(); itn != 293 G4String name = itn->first; 294 ParticleData data = itn->second; 295 G4int count = data.fCount; 296 G4double eMean = data.fEmean / count; 297 G4double eMin = data.fEmin; 298 G4double eMax = data.fEmax; 299 G4double Eflow = data.fEmean / TotNbofEven 300 301 G4cout << " " << std::setw(13) << name << 302 << " Emean = " << std::setw(wid) < 303 << G4BestUnit(eMin, "Energy") << " 304 << ") \tEflow/event = " << G4BestUn 305 } 306 307 // remove all contents in fProcCounter, fCou 308 fProcCounter.clear(); 309 fParticleDataMap2.clear(); 310 311 // restore default format 312 G4cout.precision(dfprec); 313 } 314 315 //....oooOO0OOooo........oooOO0OOooo........oo 316