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