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 "HistoManager.hh" 36 #include "PrimaryGeneratorAction.hh" 37 38 #include "G4PhysicalConstants.hh" 39 #include "G4SystemOfUnits.hh" 40 #include "G4UnitsTable.hh" 41 42 //....oooOO0OOooo........oooOO0OOooo........oo 43 44 void Run::SetPrimary(G4ParticleDefinition* par 45 { 46 fParticle = particle; 47 fEkin = energy; 48 } 49 50 //....oooOO0OOooo........oooOO0OOooo........oo 51 52 void Run::ParticleCount(G4String name, G4doubl 53 { 54 std::map<G4String, ParticleData>::iterator i 55 if (it == fParticleDataMap.end()) { 56 fParticleDataMap[name] = ParticleData(1, E 57 } 58 else { 59 ParticleData& data = it->second; 60 data.fCount++; 61 data.fEmean += Ekin; 62 // update min max 63 G4double emin = data.fEmin; 64 if (Ekin < emin) data.fEmin = Ekin; 65 G4double emax = data.fEmax; 66 if (Ekin > emax) data.fEmax = Ekin; 67 data.fTmean = meanLife; 68 } 69 } 70 71 //....oooOO0OOooo........oooOO0OOooo........oo 72 73 void Run::SetTimeWindow(G4double t1, G4double 74 { 75 fTimeWindow1 = t1; 76 fTimeWindow2 = t2; 77 } 78 79 //....oooOO0OOooo........oooOO0OOooo........oo 80 81 void Run::CountInTimeWindow(G4String name, G4b 82 { 83 std::map<G4String, ActivityData>::iterator i 84 if (it == fActivityMap.end()) { 85 G4int n1(0), n2(0), nd(0); 86 if (life1) n1 = 1; 87 if (life2) n2 = 1; 88 if (decay) nd = 1; 89 fActivityMap[name] = ActivityData(n1, n2, 90 } 91 else { 92 ActivityData& data = it->second; 93 if (life1) data.fNlife_t1++; 94 if (life2) data.fNlife_t2++; 95 if (decay) data.fNdecay_t1t2++; 96 } 97 } 98 99 //....oooOO0OOooo........oooOO0OOooo........oo 100 101 void Run::Balance(G4double Ekin, G4double Pbal 102 { 103 fDecayCount++; 104 fEkinTot[0] += Ekin; 105 // update min max 106 if (fDecayCount == 1) fEkinTot[1] = fEkinTot 107 if (Ekin < fEkinTot[1]) fEkinTot[1] = Ekin; 108 if (Ekin > fEkinTot[2]) fEkinTot[2] = Ekin; 109 110 fPbalance[0] += Pbal; 111 // update min max 112 if (fDecayCount == 1) fPbalance[1] = fPbalan 113 if (Pbal < fPbalance[1]) fPbalance[1] = Pbal 114 if (Pbal > fPbalance[2]) fPbalance[2] = Pbal 115 } 116 117 //....oooOO0OOooo........oooOO0OOooo........oo 118 119 void Run::EventTiming(G4double time) 120 { 121 fTimeCount++; 122 fEventTime[0] += time; 123 if (fTimeCount == 1) fEventTime[1] = fEventT 124 if (time < fEventTime[1]) fEventTime[1] = ti 125 if (time > fEventTime[2]) fEventTime[2] = ti 126 } 127 128 //....oooOO0OOooo........oooOO0OOooo........oo 129 130 void Run::PrimaryTiming(G4double ptime) 131 { 132 fPrimaryTime += ptime; 133 } 134 135 //....oooOO0OOooo........oooOO0OOooo........oo 136 137 void Run::EvisEvent(G4double Evis) 138 { 139 fEvisEvent[0] += Evis; 140 if (fTimeCount == 1) fEvisEvent[1] = fEvisEv 141 if (Evis < fEvisEvent[1]) fEvisEvent[1] = Ev 142 if (Evis > fEvisEvent[2]) fEvisEvent[2] = Ev 143 } 144 145 //....oooOO0OOooo........oooOO0OOooo........oo 146 147 void Run::Merge(const G4Run* run) 148 { 149 const Run* localRun = static_cast<const Run* 150 151 // primary particle info 152 // 153 fParticle = localRun->fParticle; 154 fEkin = localRun->fEkin; 155 156 // accumulate sums 157 // 158 fDecayCount += localRun->fDecayCount; 159 fTimeCount += localRun->fTimeCount; 160 fPrimaryTime += localRun->fPrimaryTime; 161 162 fEkinTot[0] += localRun->fEkinTot[0]; 163 fPbalance[0] += localRun->fPbalance[0]; 164 fEventTime[0] += localRun->fEventTime[0]; 165 fEvisEvent[0] += localRun->fEvisEvent[0]; 166 167 G4double min, max; 168 min = localRun->fEkinTot[1]; 169 max = localRun->fEkinTot[2]; 170 if (fEkinTot[1] > min) fEkinTot[1] = min; 171 if (fEkinTot[2] < max) fEkinTot[2] = max; 172 // 173 min = localRun->fPbalance[1]; 174 max = localRun->fPbalance[2]; 175 if (fPbalance[1] > min) fPbalance[1] = min; 176 if (fPbalance[2] < max) fPbalance[2] = max; 177 // 178 min = localRun->fEventTime[1]; 179 max = localRun->fEventTime[2]; 180 if (fEventTime[1] > min) fEventTime[1] = min 181 if (fEventTime[2] < max) fEventTime[2] = max 182 // 183 min = localRun->fEvisEvent[1]; 184 max = localRun->fEvisEvent[2]; 185 if (fEvisEvent[1] > min) fEvisEvent[1] = min 186 if (fEvisEvent[2] < max) fEvisEvent[2] = max 187 188 // maps 189 std::map<G4String, ParticleData>::const_iter 190 for (itn = localRun->fParticleDataMap.begin( 191 G4String name = itn->first; 192 const ParticleData& localData = itn->secon 193 if (fParticleDataMap.find(name) == fPartic 194 fParticleDataMap[name] = ParticleData(lo 195 lo 196 } 197 else { 198 ParticleData& data = fParticleDataMap[na 199 data.fCount += localData.fCount; 200 data.fEmean += localData.fEmean; 201 G4double emin = localData.fEmin; 202 if (emin < data.fEmin) data.fEmin = emin 203 G4double emax = localData.fEmax; 204 if (emax > data.fEmax) data.fEmax = emax 205 data.fTmean = localData.fTmean; 206 } 207 } 208 209 // activity 210 fTimeWindow1 = localRun->fTimeWindow1; 211 fTimeWindow2 = localRun->fTimeWindow2; 212 213 std::map<G4String, ActivityData>::const_iter 214 for (ita = localRun->fActivityMap.begin(); i 215 G4String name = ita->first; 216 const ActivityData& localData = ita->secon 217 if (fActivityMap.find(name) == fActivityMa 218 fActivityMap[name] = 219 ActivityData(localData.fNlife_t1, loca 220 } 221 else { 222 ActivityData& data = fActivityMap[name]; 223 data.fNlife_t1 += localData.fNlife_t1; 224 data.fNlife_t2 += localData.fNlife_t2; 225 data.fNdecay_t1t2 += localData.fNdecay_t 226 } 227 } 228 229 G4Run::Merge(run); 230 } 231 232 //....oooOO0OOooo........oooOO0OOooo........oo 233 234 void Run::EndOfRun() 235 { 236 G4int nbEvents = numberOfEvent; 237 G4String partName = fParticle->GetParticleNa 238 239 G4cout << "\n ======================== run s 240 G4cout << "\n The run was " << nbEvents << " 241 << G4BestUnit(fEkin, "Energy"); 242 G4cout << "\n ============================== 243 G4cout << G4endl; 244 if (nbEvents == 0) { 245 return; 246 } 247 248 G4int prec = 4, wid = prec + 2; 249 G4int dfprec = G4cout.precision(prec); 250 251 // particle count 252 // 253 G4cout << " Nb of generated particles: \n" < 254 255 std::map<G4String, ParticleData>::iterator i 256 for (it = fParticleDataMap.begin(); it != fP 257 G4String name = it->first; 258 ParticleData data = it->second; 259 G4int count = data.fCount; 260 G4double eMean = data.fEmean / count; 261 G4double eMin = data.fEmin; 262 G4double eMax = data.fEmax; 263 G4double meanLife = data.fTmean; 264 265 G4cout << " " << std::setw(15) << name << 266 << " Emean = " << std::setw(wid) < 267 << G4BestUnit(eMin, "Energy") << " 268 if (meanLife > 0.) 269 G4cout << "\tmean life = " << G4BestUnit 270 else if (meanLife < 0.) 271 G4cout << "\tstable" << G4endl; 272 else 273 G4cout << G4endl; 274 } 275 276 // energy momentum balance 277 // 278 279 if (fDecayCount > 0) { 280 G4double Ebmean = fEkinTot[0] / fDecayCoun 281 G4double Pbmean = fPbalance[0] / fDecayCou 282 283 G4cout << "\n Ekin Total (Q single decay 284 << G4BestUnit(Ebmean, "Energy") << 285 << G4BestUnit(fEkinTot[2], "Energy" 286 287 G4cout << "\n Momentum balance (excludin 288 << G4BestUnit(Pbmean, "Energy") << 289 << " --> " << G4BestUnit(fPbalance[ 290 } 291 292 // total time of life 293 // 294 if (fTimeCount > 0) { 295 G4double Tmean = fEventTime[0] / fTimeCoun 296 G4double halfLife = Tmean * std::log(2.); 297 298 G4cout << "\n Total time of life (full c 299 << G4BestUnit(Tmean, "Time") << " 300 << G4BestUnit(halfLife, "Time") << 301 << " --> " << G4BestUnit(fEventTime 302 } 303 304 // total visible Energy 305 // 306 if (fTimeCount > 0) { 307 G4double Evmean = fEvisEvent[0] / fTimeCou 308 309 G4cout << "\n Total visible energy (full 310 << G4BestUnit(Evmean, "Energy") << 311 << " --> " << G4BestUnit(fEvisEvent 312 } 313 314 // activity of primary ion 315 // 316 G4double pTimeMean = fPrimaryTime / nbEvents 317 G4double molMass = fParticle->GetAtomicMass( 318 G4double nAtoms_perUnitOfMass = Avogadro / m 319 G4double Activity_perUnitOfMass = 0.0; 320 if (pTimeMean > 0.0) { 321 Activity_perUnitOfMass = nAtoms_perUnitOfM 322 } 323 324 G4cout << "\n Activity of " << partName << 325 << Activity_perUnitOfMass * g / becqu 326 << Activity_perUnitOfMass * g / curie 327 << G4endl; 328 329 // activities in time window 330 // 331 if (fTimeWindow2 > 0.) { 332 G4double dt = fTimeWindow2 - fTimeWindow1; 333 G4cout << " Activities in time window [t 334 << ", " << G4BestUnit(fTimeWindow2, 335 << "] (delta time = " << G4BestUni 336 << G4endl; 337 338 std::map<G4String, ActivityData>::iterator 339 for (ita = fActivityMap.begin(); ita != fA 340 G4String name = ita->first; 341 ActivityData data = ita->second; 342 G4int n1 = data.fNlife_t1; 343 G4int n2 = data.fNlife_t2; 344 G4int ndecay = data.fNdecay_t1t2; 345 G4double actv = ndecay / dt; 346 347 G4cout << " " << std::setw(15) << name 348 << " n(t1) = " << std::setw(7) < 349 << "\t decays = " << std::setw( 350 << " ---> <actv> = " << G4BestU 351 } 352 } 353 G4cout << G4endl; 354 355 // normalize histograms 356 // 357 G4AnalysisManager* analysisManager = G4Analy 358 G4double factor = 100. / nbEvents; 359 analysisManager->ScaleH1(1, factor); 360 analysisManager->ScaleH1(2, factor); 361 analysisManager->ScaleH1(3, factor); 362 analysisManager->ScaleH1(4, factor); 363 analysisManager->ScaleH1(5, factor); 364 365 // remove all contents in fParticleDataMap 366 // 367 fParticleDataMap.clear(); 368 fActivityMap.clear(); 369 370 // restore default precision 371 // 372 G4cout.precision(dfprec); 373 } 374 375 //....oooOO0OOooo........oooOO0OOooo........oo 376