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