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