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" << 38 36 39 #include "G4SystemOfUnits.hh" << 40 #include "G4UnitsTable.hh" 37 #include "G4UnitsTable.hh" >> 38 #include "G4SystemOfUnits.hh" 41 39 42 //....oooOO0OOooo........oooOO0OOooo........oo 40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 43 41 44 Run::Run(DetectorConstruction* det) : fDetecto << 42 Run::Run(DetectorConstruction* det) 45 << 43 : G4Run(), >> 44 fDetector(det), >> 45 fNbStep1(0), fNbStep2(0), >> 46 fTrackLen1(0.), fTrackLen2(0.), >> 47 fTime1(0.),fTime2(0.) >> 48 { } 46 //....oooOO0OOooo........oooOO0OOooo........oo 49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 47 50 48 void Run::SetPrimary(G4ParticleDefinition* par << 51 Run::~Run() 49 { << 52 { } 50 fParticle = particle; << 51 fEkin = energy; << 52 } << 53 53 54 //....oooOO0OOooo........oooOO0OOooo........oo 54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 55 55 56 void Run::CountProcesses(const G4VProcess* pro << 56 void Run::CountProcesses(const G4VProcess* process) 57 { 57 { 58 if (process == nullptr) return; << 58 std::map<const G4VProcess*,G4int>::iterator it = fProcCounter.find(process); 59 G4String procName = process->GetProcessName( << 59 if ( it == fProcCounter.end()) { 60 std::map<G4String, G4int>::iterator it = fPr << 60 fProcCounter[process] = 1; 61 if (it == fProcCounter.end()) { << 62 fProcCounter[procName] = 1; << 63 } 61 } 64 else { 62 else { 65 fProcCounter[procName]++; << 63 fProcCounter[process]++; 66 } 64 } 67 } << 65 } 68 << 66 69 //....oooOO0OOooo........oooOO0OOooo........oo 67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 70 68 71 void Run::ParticleCount(G4String name, G4doubl 69 void Run::ParticleCount(G4String name, G4double Ekin) 72 { 70 { 73 std::map<G4String, ParticleData>::iterator i 71 std::map<G4String, ParticleData>::iterator it = fParticleDataMap.find(name); 74 if (it == fParticleDataMap.end()) { << 72 if ( it == fParticleDataMap.end()) { 75 fParticleDataMap[name] = ParticleData(1, E 73 fParticleDataMap[name] = ParticleData(1, Ekin, Ekin, Ekin); 76 } 74 } 77 else { 75 else { 78 ParticleData& data = it->second; 76 ParticleData& data = it->second; 79 data.fCount++; 77 data.fCount++; 80 data.fEmean += Ekin; 78 data.fEmean += Ekin; 81 // update min max << 79 //update min max 82 G4double emin = data.fEmin; 80 G4double emin = data.fEmin; 83 if (Ekin < emin) data.fEmin = Ekin; 81 if (Ekin < emin) data.fEmin = Ekin; 84 G4double emax = data.fEmax; 82 G4double emax = data.fEmax; 85 if (Ekin > emax) data.fEmax = Ekin; << 83 if (Ekin > emax) data.fEmax = Ekin; 86 } << 84 } 87 } 85 } 88 86 89 //....oooOO0OOooo........oooOO0OOooo........oo 87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 90 88 91 void Run::SumTrackLength(G4int nstep1, G4int n << 89 void Run::SumTrackLength(G4int nstep1, G4int nstep2, >> 90 G4double trackl1, G4double trackl2, 92 G4double time1, G4dou 91 G4double time1, G4double time2) 93 { 92 { 94 fNbStep1 += nstep1; << 93 fNbStep1 += nstep1; fNbStep2 += nstep2; 95 fNbStep2 += nstep2; << 94 fTrackLen1 += trackl1; fTrackLen2 += trackl2; 96 fTrackLen1 += trackl1; << 95 fTime1 += time1; fTime2 += time2; 97 fTrackLen2 += trackl2; << 96 } 98 fTime1 += time1; << 97 99 fTime2 += time2; << 98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 99 >> 100 void Run::ComputeStatistics() >> 101 { >> 102 G4int prec = 5, wid = prec + 2; >> 103 G4int dfprec = G4cout.precision(prec); >> 104 >> 105 //frequency of processes >> 106 // >> 107 G4cout << "\n Process calls frequency --->"; >> 108 G4int survive = 0; >> 109 std::map<const G4VProcess*,G4int>::iterator it; >> 110 for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) { >> 111 G4String procName = it->first->GetProcessName(); >> 112 G4int count = it->second; >> 113 G4cout << "\t" << procName << "= " << count; >> 114 if (procName == "Transportation") survive = count; >> 115 } >> 116 G4cout << G4endl; >> 117 >> 118 if (survive > 0) { >> 119 G4cout << "\n Nb of incident particles surviving after " >> 120 << G4BestUnit(0.5*(fDetector->GetSize()),"Length") << " of " >> 121 << fDetector->GetMaterial()->GetName() << " : " << survive << G4endl; >> 122 } >> 123 >> 124 // total track length of incident neutron >> 125 // >> 126 G4cout << "\n Parcours of incident neutron:"; >> 127 >> 128 G4double meanCollision1 = (G4double)fNbStep1/numberOfEvent; >> 129 G4double meanCollision2 = (G4double)fNbStep2/numberOfEvent; >> 130 G4double meanCollisTota = meanCollision1 + meanCollision2; >> 131 >> 132 G4cout << "\n nb of collisions E>1*eV= " << meanCollision1 >> 133 << " E<1*eV= " << meanCollision2 >> 134 << " total= " << meanCollisTota; >> 135 >> 136 G4double meanTrackLen1 = fTrackLen1/numberOfEvent; >> 137 G4double meanTrackLen2 = fTrackLen2/numberOfEvent; >> 138 G4double meanTrackLtot = meanTrackLen1 + meanTrackLen2; >> 139 >> 140 G4cout >> 141 << "\n track length E>1*eV= " << G4BestUnit(meanTrackLen1,"Length") >> 142 << " E<1*eV= " << G4BestUnit(meanTrackLen2, "Length") >> 143 << " total= " << G4BestUnit(meanTrackLtot, "Length"); >> 144 >> 145 G4double meanTime1 = fTime1/numberOfEvent; >> 146 G4double meanTime2 = fTime2/numberOfEvent; >> 147 G4double meanTimeTo = meanTime1 + meanTime2; >> 148 >> 149 G4cout >> 150 << "\n time of flight E>1*eV= " << G4BestUnit(meanTime1,"Time") >> 151 << " E<1*eV= " << G4BestUnit(meanTime2, "Time") >> 152 << " total= " << G4BestUnit(meanTimeTo, "Time") << G4endl; >> 153 >> 154 //particles count >> 155 // >> 156 G4cout << "\n List of generated particles:" << G4endl; >> 157 >> 158 std::map<G4String,ParticleData>::iterator itn; >> 159 for (itn = fParticleDataMap.begin(); itn != fParticleDataMap.end(); itn++) { >> 160 G4String name = itn->first; >> 161 ParticleData data = itn->second; >> 162 G4int count = data.fCount; >> 163 G4double eMean = data.fEmean/count; >> 164 G4double eMin = data.fEmin; >> 165 G4double eMax = data.fEmax; >> 166 >> 167 G4cout << " " << std::setw(13) << name << ": " << std::setw(7) << count >> 168 << " Emean = " << std::setw(wid) << G4BestUnit(eMean, "Energy") >> 169 << "\t( " << G4BestUnit(eMin, "Energy") >> 170 << " --> " << G4BestUnit(eMax, "Energy") >> 171 << ")" << G4endl; >> 172 } >> 173 >> 174 //restore default format >> 175 G4cout.precision(dfprec); >> 176 >> 177 // remove all contents in fProcCounter >> 178 fProcCounter.clear(); >> 179 // remove all contents in fCount >> 180 fParticleDataMap.clear(); 100 } 181 } 101 182 102 //....oooOO0OOooo........oooOO0OOooo........oo 183 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 103 184 104 void Run::Merge(const G4Run* run) 185 void Run::Merge(const G4Run* run) 105 { 186 { 106 const Run* localRun = static_cast<const Run* 187 const Run* localRun = static_cast<const Run*>(run); 107 188 108 // primary particle info << 109 // << 110 fParticle = localRun->fParticle; << 111 fEkin = localRun->fEkin; << 112 << 113 // accumulate sums 189 // accumulate sums 114 // 190 // 115 fNbStep1 += localRun->fNbStep1; << 191 fNbStep1 += localRun->fNbStep1; 116 fNbStep2 += localRun->fNbStep2; << 192 fNbStep2 += localRun->fNbStep2; 117 fTrackLen1 += localRun->fTrackLen1; << 193 fTrackLen1 += localRun->fTrackLen1; 118 fTrackLen2 += localRun->fTrackLen2; 194 fTrackLen2 += localRun->fTrackLen2; 119 fTime1 += localRun->fTime1; << 195 fTime1 += localRun->fTime1; 120 fTime2 += localRun->fTime2; << 196 fTime2 += localRun->fTime2; >> 197 >> 198 //maps >> 199 std::map<const G4VProcess*,G4int>::const_iterator itp; >> 200 for ( itp = localRun->fProcCounter.begin(); >> 201 itp != localRun->fProcCounter.end(); ++itp ) { 121 202 122 // map: processes count << 203 const G4VProcess* process = itp->first; 123 std::map<G4String, G4int>::const_iterator it << 124 for (itp = localRun->fProcCounter.begin(); i << 125 G4String procName = itp->first; << 126 G4int localCount = itp->second; 204 G4int localCount = itp->second; 127 if (fProcCounter.find(procName) == fProcCo << 205 if ( fProcCounter.find(process) == fProcCounter.end()) { 128 fProcCounter[procName] = localCount; << 206 fProcCounter[process] = localCount; 129 } 207 } 130 else { 208 else { 131 fProcCounter[procName] += localCount; << 209 fProcCounter[process] += localCount; 132 } << 210 } 133 } << 211 } 134 << 212 135 // map: created particles count << 213 std::map<G4String,ParticleData>::const_iterator itn; 136 std::map<G4String, ParticleData>::const_iter << 214 for (itn = localRun->fParticleDataMap.begin(); 137 for (itn = localRun->fParticleDataMap.begin( << 215 itn != localRun->fParticleDataMap.end(); ++itn) { >> 216 138 G4String name = itn->first; 217 G4String name = itn->first; 139 const ParticleData& localData = itn->secon << 218 const ParticleData& localData = itn->second; 140 if (fParticleDataMap.find(name) == fPartic << 219 if ( fParticleDataMap.find(name) == fParticleDataMap.end()) { 141 fParticleDataMap[name] = << 220 fParticleDataMap[name] 142 ParticleData(localData.fCount, localDa << 221 = ParticleData(localData.fCount, >> 222 localData.fEmean, >> 223 localData.fEmin, >> 224 localData.fEmax); 143 } 225 } 144 else { 226 else { 145 ParticleData& data = fParticleDataMap[na << 227 ParticleData& data = fParticleDataMap[name]; 146 data.fCount += localData.fCount; 228 data.fCount += localData.fCount; 147 data.fEmean += localData.fEmean; 229 data.fEmean += localData.fEmean; 148 G4double emin = localData.fEmin; 230 G4double emin = localData.fEmin; 149 if (emin < data.fEmin) data.fEmin = emin 231 if (emin < data.fEmin) data.fEmin = emin; 150 G4double emax = localData.fEmax; 232 G4double emax = localData.fEmax; 151 if (emax > data.fEmax) data.fEmax = emax << 233 if (emax > data.fEmax) data.fEmax = emax; 152 } << 234 } 153 } 235 } 154 236 155 G4Run::Merge(run); << 237 G4Run::Merge(run); 156 } << 238 } 157 << 158 //....oooOO0OOooo........oooOO0OOooo........oo << 159 << 160 void Run::EndOfRun() << 161 { << 162 G4int prec = 5, wid = prec + 2; << 163 G4int dfprec = G4cout.precision(prec); << 164 << 165 // run condition << 166 // << 167 G4Material* material = fDetector->GetMateria << 168 G4double density = material->GetDensity(); << 169 << 170 G4String Particle = fParticle->GetParticleNa << 171 G4cout << "\n The run is " << numberOfEvent << 172 << G4BestUnit(fEkin, "Energy") << " t << 173 << G4BestUnit(0.5 * (fDetector->GetSi << 174 << " (density: " << G4BestUnit(densit << 175 << 176 if (numberOfEvent == 0) { << 177 G4cout.precision(dfprec); << 178 return; << 179 } << 180 << 181 // frequency of processes << 182 // << 183 G4cout << "\n Process calls frequency :" << << 184 G4int survive = 0; << 185 std::map<G4String, G4int>::iterator it; << 186 for (it = fProcCounter.begin(); it != fProcC << 187 G4String procName = it->first; << 188 G4int count = it->second; << 189 G4cout << "\t" << procName << "= " << coun << 190 if (procName == "Transportation") survive << 191 } << 192 G4cout << G4endl; << 193 << 194 if (survive > 0) { << 195 G4cout << "\n Nb of incident particles sur << 196 << G4BestUnit(0.5 * (fDetector->Get << 197 << fDetector->GetMaterial()->GetNam << 198 } << 199 << 200 // total track length of incident neutron << 201 // << 202 G4cout << "\n Parcours of incident neutron:" << 203 << 204 G4double meanCollision1 = (G4double)fNbStep1 << 205 G4double meanCollision2 = (G4double)fNbStep2 << 206 G4double meanCollisTota = meanCollision1 + m << 207 << 208 G4cout << "\n nb of collisions E>1*eV= << 209 << " E<1*eV= " << meanCollision2 << 210 << 211 G4double meanTrackLen1 = fTrackLen1 / number << 212 G4double meanTrackLen2 = fTrackLen2 / number << 213 G4double meanTrackLtot = meanTrackLen1 + mea << 214 << 215 G4cout << "\n track length E>1*eV= << 216 << " E<1*eV= " << G4BestUnit(meanTra << 217 << " total= " << G4BestUnit(meanTra << 218 << 219 G4double meanTime1 = fTime1 / numberOfEvent; << 220 G4double meanTime2 = fTime2 / numberOfEvent; << 221 G4double meanTimeTo = meanTime1 + meanTime2; << 222 << 223 G4cout << "\n time of flight E>1*eV= << 224 << " E<1*eV= " << G4BestUnit(meanTim << 225 << " total= " << G4BestUnit(meanTim << 226 << 227 // particles count << 228 // << 229 G4cout << "\n List of generated particles:" << 230 << 231 std::map<G4String, ParticleData>::iterator i << 232 for (itn = fParticleDataMap.begin(); itn != << 233 G4String name = itn->first; << 234 ParticleData data = itn->second; << 235 G4int count = data.fCount; << 236 G4double eMean = data.fEmean / count; << 237 G4double eMin = data.fEmin; << 238 G4double eMax = data.fEmax; << 239 << 240 G4cout << " " << std::setw(13) << name << << 241 << " Emean = " << std::setw(wid) < << 242 << G4BestUnit(eMin, "Energy") << " << 243 } << 244 << 245 // normalize histograms << 246 ////G4AnalysisManager* analysisManager = G4A << 247 ////G4double factor = 1./numberOfEvent; << 248 ////analysisManager->ScaleH1(3,factor); << 249 << 250 // remove all contents in fProcCounter, fCou << 251 fProcCounter.clear(); << 252 fParticleDataMap.clear(); << 253 << 254 // restore default format << 255 G4cout.precision(dfprec); << 256 } << 257 239 258 //....oooOO0OOooo........oooOO0OOooo........oo 240 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 259 241