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 electromagnetic/TestEm13/src/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 "PrimaryGeneratorAction.hh" 36 #include "PrimaryGeneratorAction.hh" 37 37 >> 38 #include "G4UnitsTable.hh" >> 39 #include "G4SystemOfUnits.hh" 38 #include "G4EmCalculator.hh" 40 #include "G4EmCalculator.hh" 39 #include "G4Gamma.hh" 41 #include "G4Gamma.hh" 40 #include "G4SystemOfUnits.hh" << 41 #include "G4UnitsTable.hh" << 42 42 43 #include <iomanip> 43 #include <iomanip> 44 44 45 //....oooOO0OOooo........oooOO0OOooo........oo 45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 46 46 47 Run::Run(DetectorConstruction* det) : fDetecto << 47 Run::Run(DetectorConstruction* det) >> 48 : G4Run(), >> 49 fDetector(det), >> 50 fParticle(0), fEkin(0.) >> 51 { } >> 52 >> 53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 54 >> 55 Run::~Run() >> 56 { } 48 57 49 //....oooOO0OOooo........oooOO0OOooo........oo 58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 50 59 51 void Run::SetPrimary(G4ParticleDefinition* par 60 void Run::SetPrimary(G4ParticleDefinition* particle, G4double energy) 52 { << 61 { 53 fParticle = particle; 62 fParticle = particle; 54 fEkin = energy; 63 fEkin = energy; 55 } 64 } 56 //....oooOO0OOooo........oooOO0OOooo........oo 65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 57 66 58 void Run::CountProcesses(G4String procName) << 67 void Run::CountProcesses(G4String procName) 59 { 68 { 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::Merge(const G4Run* run) 80 void Run::Merge(const G4Run* run) 72 { 81 { 73 const Run* localRun = static_cast<const Run* 82 const Run* localRun = static_cast<const Run*>(run); 74 83 75 // pass information about primary particle 84 // pass information about primary particle 76 fParticle = localRun->fParticle; 85 fParticle = localRun->fParticle; 77 fEkin = localRun->fEkin; << 86 fEkin = localRun->fEkin; 78 << 87 79 // map: processes count << 88 //map: processes count 80 std::map<G4String, G4int>::const_iterator it << 89 std::map<G4String,G4int>::const_iterator it; 81 for (it = localRun->fProcCounter.begin(); it << 90 for (it = localRun->fProcCounter.begin(); >> 91 it !=localRun->fProcCounter.end(); ++it) { >> 92 82 G4String procName = it->first; 93 G4String procName = it->first; 83 G4int localCount = it->second; << 94 G4int localCount = it->second; 84 if (fProcCounter.find(procName) == fProcCo << 95 if ( fProcCounter.find(procName) == fProcCounter.end()) { 85 fProcCounter[procName] = localCount; 96 fProcCounter[procName] = localCount; 86 } 97 } 87 else { 98 else { 88 fProcCounter[procName] += localCount; 99 fProcCounter[procName] += localCount; 89 } << 100 } 90 } 101 } 91 << 102 92 G4Run::Merge(run); << 103 G4Run::Merge(run); 93 } << 104 } 94 105 95 //....oooOO0OOooo........oooOO0OOooo........oo 106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 96 107 97 void Run::EndOfRun() 108 void Run::EndOfRun() 98 { 109 { 99 G4int prec = 5; << 110 G4int prec = 5; 100 G4int dfprec = G4cout.precision(prec); 111 G4int dfprec = G4cout.precision(prec); 101 << 112 102 // run condition << 113 //run condition 103 // << 114 // 104 G4String partName = fParticle->GetParticleNa << 115 G4String partName = fParticle->GetParticleName(); 105 G4Material* material = fDetector->GetMateria 116 G4Material* material = fDetector->GetMaterial(); 106 G4double density = material->GetDensity(); << 117 G4double density = material->GetDensity(); 107 G4double tickness = fDetector->GetSize(); 118 G4double tickness = fDetector->GetSize(); 108 << 119 109 G4cout << "\n ======================== run s 120 G4cout << "\n ======================== run summary ======================\n"; 110 G4cout << "\n The run is: " << numberOfEvent 121 G4cout << "\n The run is: " << numberOfEvent << " " << partName << " of " 111 << G4BestUnit(fEkin, "Energy") << " t << 122 << G4BestUnit(fEkin,"Energy") << " through " 112 << material->GetName() << " (density: << 123 << G4BestUnit(tickness,"Length") << " of " 113 << G4endl; << 124 << material->GetName() << " (density: " >> 125 << G4BestUnit(density,"Volumic Mass") << ")" << G4endl; 114 126 115 // frequency of processes << 127 //frequency of processes 116 G4int totalCount = 0; 128 G4int totalCount = 0; 117 G4int survive = 0; << 129 G4int survive = 0; 118 G4cout << "\n Process calls frequency --->"; 130 G4cout << "\n Process calls frequency --->"; 119 std::map<G4String, G4int>::iterator it; << 131 std::map<G4String,G4int>::iterator it; 120 for (it = fProcCounter.begin(); it != fProcC 132 for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) { 121 G4String procName = it->first; << 133 G4String procName = it->first; 122 G4int count = it->second; << 134 G4int count = it->second; 123 totalCount += count; << 135 totalCount += count; 124 G4cout << "\t" << procName << " = " << cou << 136 G4cout << "\t" << procName << " = " << count; 125 if (procName == "Transportation") survive << 137 if (procName == "Transportation") survive = count; 126 } 138 } 127 G4cout << G4endl; 139 G4cout << G4endl; 128 140 129 if (totalCount == 0) { << 141 if (totalCount == 0) { G4cout.precision(dfprec); return;}; 130 G4cout.precision(dfprec); << 142 G4double ratio = double(survive)/totalCount; 131 return; << 132 }; << 133 G4double ratio = double(survive) / totalCoun << 134 << 135 G4cout << "\n Nb of incident particles unalt << 136 << " of " << material->GetName() << " << 137 << " incident particles." << 138 << " Ratio = " << 100 * ratio << " % << 139 143 >> 144 G4cout << "\n Nb of incident particles unaltered after " >> 145 << G4BestUnit(tickness,"Length") << " of " >> 146 << material->GetName() << " : " << survive >> 147 << " over " << totalCount << " incident particles." >> 148 << " Ratio = " << 100*ratio << " %" << G4endl; >> 149 140 if (ratio == 0.) return; 150 if (ratio == 0.) return; 141 << 151 142 // compute cross section and related quantit << 152 //compute cross section and related quantities 143 // 153 // 144 G4double CrossSection = -std::log(ratio) / t << 154 G4double CrossSection = - std::log(ratio)/tickness; 145 G4double massicCS = CrossSection / density; << 155 G4double massicCS = CrossSection/density; 146 << 156 147 G4cout << " ---> CrossSection per volume:\t" << 157 G4cout << " ---> CrossSection per volume:\t" << CrossSection*cm << " cm^-1 " 148 << "\tCrossSection per mass: " << G4B << 158 << "\tCrossSection per mass: " << G4BestUnit(massicCS, "Surface/Mass") >> 159 << G4endl; 149 160 150 // check cross section from G4EmCalculator << 161 //check cross section from G4EmCalculator 151 // 162 // 152 G4cout << "\n Verification from G4EmCalculat << 163 G4cout << "\n Verification from G4EmCalculator: \n"; 153 G4EmCalculator emCalculator; 164 G4EmCalculator emCalculator; 154 G4double sumc = 0.0; << 165 G4double sumc = 0.0; 155 for (it = fProcCounter.begin(); it != fProcC 166 for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) { 156 G4String procName = it->first; << 167 G4String procName = it->first; 157 G4double massSigma = << 168 G4double massSigma = 158 emCalculator.GetCrossSectionPerVolume(fE << 169 emCalculator.GetCrossSectionPerVolume(fEkin,fParticle, >> 170 procName,material)/density; 159 if (fParticle == G4Gamma::Gamma()) 171 if (fParticle == G4Gamma::Gamma()) 160 massSigma = << 172 massSigma = 161 emCalculator.ComputeCrossSectionPerVol << 173 emCalculator.ComputeCrossSectionPerVolume(fEkin,fParticle, >> 174 procName,material)/density; 162 sumc += massSigma; 175 sumc += massSigma; 163 if (procName != "Transportation") 176 if (procName != "Transportation") 164 G4cout << "\t" << procName << "= " << G4 << 177 G4cout << "\t" << procName << "= " 165 } << 178 << G4BestUnit(massSigma, "Surface/Mass"); 166 G4cout << "\ttotal= " << G4BestUnit(sumc, "S << 179 } 167 << 180 G4cout << "\ttotal= " 168 // expected ratio of transmitted particles << 181 << G4BestUnit(sumc, "Surface/Mass") << G4endl; 169 G4double Ratio = std::exp(-sumc * density * << 182 170 G4cout << "\tExpected ratio of transmitted p << 183 //expected ratio of transmitted particles 171 << 184 G4double Ratio = std::exp(-sumc*density*tickness); 172 // remove all contents in fProcCounter << 185 G4cout << "\tExpected ratio of transmitted particles= " >> 186 << 100*Ratio << " %" << G4endl; >> 187 >> 188 // remove all contents in fProcCounter 173 fProcCounter.clear(); 189 fProcCounter.clear(); 174 << 190 175 // restore default format << 191 //restore default format 176 G4cout.precision(dfprec); << 192 G4cout.precision(dfprec); 177 } 193 } 178 194 179 //....oooOO0OOooo........oooOO0OOooo........oo 195 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 180 196