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/TestEm15/src/RunActi << 26 // $Id: RunAction.cc,v 1.5 2006/06/29 16:47:13 gunter Exp $ 27 /// \brief Implementation of the RunAction cla << 27 // GEANT4 tag $Name: geant4-08-01-patch-01 $ 28 // << 28 // 29 // << 30 //....oooOO0OOooo........oooOO0OOooo........oo 29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 31 33 #include "RunAction.hh" 32 #include "RunAction.hh" 34 33 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 "G4EmCalculator.hh" << 40 #include "G4Run.hh" 38 #include "G4Run.hh" 41 #include "G4RunManager.hh" 39 #include "G4RunManager.hh" 42 #include "G4SystemOfUnits.hh" << 43 #include "G4UnitsTable.hh" 40 #include "G4UnitsTable.hh" 44 #include "Randomize.hh" << 41 #include "G4EmCalculator.hh" 45 42 >> 43 #include "Randomize.hh" 46 #include <iomanip> 44 #include <iomanip> 47 45 48 //....oooOO0OOooo........oooOO0OOooo........oo 46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 49 47 50 RunAction::RunAction(DetectorConstruction* det << 48 RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* prim, 51 : G4UserRunAction(), fDetector(det), fPrimar << 49 HistoManager* histo) 52 { << 50 : detector(det), primary(prim), ProcCounter(0), histoManager(histo) 53 fHistoManager = new HistoManager(); << 51 { } 54 } << 55 52 56 //....oooOO0OOooo........oooOO0OOooo........oo 53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 57 54 58 RunAction::~RunAction() 55 RunAction::~RunAction() 59 { << 56 { } 60 delete fHistoManager; << 61 } << 62 57 63 //....oooOO0OOooo........oooOO0OOooo........oo 58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 64 59 65 void RunAction::BeginOfRunAction(const G4Run*) << 60 void RunAction::BeginOfRunAction(const G4Run* aRun) 66 { << 61 { >> 62 G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl; >> 63 67 // save Rndm status 64 // save Rndm status 68 ////G4RunManager::GetRunManager()->SetRandom << 65 G4RunManager::GetRunManager()->SetRandomNumberStore(false); 69 CLHEP::HepRandom::showEngineStatus(); 66 CLHEP::HepRandom::showEngineStatus(); 70 67 71 fProcCounter = new ProcessesCount; << 68 ProcCounter = new ProcessesCount; 72 fTotalCount = 0; << 69 totalCount = 0; 73 << 70 74 fTruePL = fTruePL2 = fGeomPL = fGeomPL2 = 0. << 71 truePL = truePL2 = geomPL = geomPL2 = 0.; 75 fLDispl = fLDispl2 = fPsiSpa = fPsiSpa2 = 0. << 72 lDispl = lDispl2 = psiSpa = psiSpa2 = 0.; 76 fTetPrj = fTetPrj2 = 0.; << 73 tetPrj = tetPrj2 = 0.; 77 fPhiCor = fPhiCor2 = 0.; << 74 phiCor = phiCor2 = 0.; 78 << 75 79 // histograms << 76 histoManager->book(); 80 // << 81 G4AnalysisManager* analysisManager = G4Analy << 82 if (analysisManager->IsActive()) { << 83 analysisManager->OpenFile(); << 84 } << 85 } 77 } 86 78 87 //....oooOO0OOooo........oooOO0OOooo........oo 79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 88 80 89 void RunAction::CountProcesses(G4String procNa 81 void RunAction::CountProcesses(G4String procName) 90 { 82 { 91 // does the process already encounted ? << 83 //does the process already encounted ? 92 size_t nbProc = fProcCounter->size(); << 84 size_t nbProc = ProcCounter->size(); 93 size_t i = 0; << 85 size_t i = 0; 94 while ((i < nbProc) && ((*fProcCounter)[i]-> << 86 while ((i<nbProc)&&((*ProcCounter)[i]->GetName()!=procName)) i++; 95 i++; << 87 if (i == nbProc) ProcCounter->push_back( new OneProcessCount(procName)); 96 if (i == nbProc) fProcCounter->push_back(new << 97 88 98 (*fProcCounter)[i]->Count(); << 89 (*ProcCounter)[i]->Count(); 99 } 90 } 100 91 101 //....oooOO0OOooo........oooOO0OOooo........oo 92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 102 93 103 void RunAction::EndOfRunAction(const G4Run* aR 94 void RunAction::EndOfRunAction(const G4Run* aRun) 104 { 95 { 105 G4int NbOfEvents = aRun->GetNumberOfEvent(); 96 G4int NbOfEvents = aRun->GetNumberOfEvent(); 106 if (NbOfEvents == 0) return; 97 if (NbOfEvents == 0) return; 107 << 98 108 G4int prec = G4cout.precision(5); << 99 G4int prec = G4cout.precision(5); 109 << 100 110 G4Material* material = fDetector->GetMateria << 101 G4Material* material = detector->GetMaterial(); 111 G4double density = material->GetDensity(); 102 G4double density = material->GetDensity(); 112 << 103 113 G4ParticleDefinition* particle = fPrimary->G << 104 G4ParticleDefinition* particle = 114 G4String Particle = particle->GetParticleNam << 105 primary->GetParticleGun()->GetParticleDefinition(); 115 G4double energy = fPrimary->GetParticleGun() << 106 G4String Particle = particle->GetParticleName(); 116 G4cout << "\n The run consists of " << NbOfE << 107 G4double energy = primary->GetParticleGun()->GetParticleEnergy(); 117 << G4BestUnit(energy, "Energy") << " << 108 G4cout << "\n The run consists of " << NbOfEvents << " "<< Particle << " of " 118 << G4BestUnit(fDetector->GetBoxSize() << 109 << G4BestUnit(energy,"Energy") << " through " 119 << " (density: " << G4BestUnit(densit << 110 << G4BestUnit(detector->GetBoxSize(),"Length") << " of " 120 << 111 << material->GetName() << " (density: " 121 // frequency of processes << 112 << G4BestUnit(density,"Volumic Mass") << ")" << G4endl; >> 113 >> 114 //frequency of processes 122 G4cout << "\n Process calls frequency --->"; 115 G4cout << "\n Process calls frequency --->"; 123 for (size_t i = 0; i < fProcCounter->size(); << 116 for (size_t i=0; i< ProcCounter->size();i++) { 124 G4String procName = (*fProcCounter)[i]->Ge << 117 G4String procName = (*ProcCounter)[i]->GetName(); 125 G4int count = (*fProcCounter)[i]->GetCount << 118 G4int count = (*ProcCounter)[i]->GetCounter(); 126 G4cout << "\t" << procName << " = " << cou << 119 G4cout << "\t" << procName << " = " << count; 127 } 120 } >> 121 >> 122 if (totalCount == 0) return; >> 123 >> 124 //compute path length and related quantities >> 125 // >> 126 G4double MeanTPL = truePL /totalCount; >> 127 G4double MeanTPL2 = truePL2/totalCount; >> 128 G4double rmsTPL = std::sqrt(std::fabs(MeanTPL2 - MeanTPL*MeanTPL)); >> 129 >> 130 G4double MeanGPL = geomPL /totalCount; >> 131 G4double MeanGPL2 = geomPL2/totalCount; >> 132 G4double rmsGPL = std::sqrt(std::fabs(MeanGPL2 - MeanGPL*MeanGPL)); >> 133 >> 134 G4double MeanLaD = lDispl /totalCount; >> 135 G4double MeanLaD2 = lDispl2/totalCount; >> 136 G4double rmsLaD = std::sqrt(std::fabs(MeanLaD2 - MeanLaD*MeanLaD)); >> 137 >> 138 G4double MeanPsi = psiSpa /(totalCount); >> 139 G4double MeanPsi2 = psiSpa2/(totalCount); >> 140 G4double rmsPsi = std::sqrt(std::fabs(MeanPsi2 - MeanPsi*MeanPsi)); >> 141 >> 142 G4double MeanTeta = tetPrj /(2*totalCount); >> 143 G4double MeanTeta2 = tetPrj2/(2*totalCount); >> 144 G4double rmsTeta = std::sqrt(std::fabs(MeanTeta2 - MeanTeta*MeanTeta)); >> 145 >> 146 G4double MeanCorrel = phiCor /(totalCount); >> 147 G4double MeanCorrel2 = phiCor2/(totalCount); >> 148 G4double rmsCorrel = std::sqrt(std::fabs(MeanCorrel2-MeanCorrel*MeanCorrel)); >> 149 >> 150 G4cout << "\n\n truePathLength :\t" << G4BestUnit(MeanTPL,"Length") >> 151 << " +- " << G4BestUnit( rmsTPL,"Length") >> 152 << "\n geomPathLength :\t" << G4BestUnit(MeanGPL,"Length") >> 153 << " +- " << G4BestUnit( rmsGPL,"Length") >> 154 << "\n lateralDisplac :\t" << G4BestUnit(MeanLaD,"Length") >> 155 << " +- " << G4BestUnit( rmsLaD,"Length") >> 156 << "\n Psi :\t" << MeanPsi/mrad << " mrad" >> 157 << " +- " << rmsPsi /mrad << " mrad" >> 158 << " (" << MeanPsi/deg << " deg" >> 159 << " +- " << rmsPsi /deg << " deg)" >> 160 << G4endl; >> 161 >> 162 G4cout << "\n Theta_plane :\t" << rmsTeta/mrad << " mrad" >> 163 << " (" << rmsTeta/deg << " deg)" >> 164 << "\n phi correlation:\t" << MeanCorrel >> 165 << " +- " << rmsCorrel >> 166 << " (std::cos(phi_pos - phi_dir))" >> 167 << G4endl; >> 168 128 169 129 if (fTotalCount > 0) { << 170 //cross check from G4EmCalculator 130 // compute path length and related quantit << 171 // 131 // << 172 G4cout << "\n Verification from G4EmCalculator. \n"; 132 G4double MeanTPL = fTruePL / fTotalCount; << 173 133 G4double MeanTPL2 = fTruePL2 / fTotalCount << 174 G4EmCalculator emCal; 134 G4double rmsTPL = std::sqrt(std::fabs(Mean << 175 135 << 176 //get transport mean free path (for multiple scattering) 136 G4double MeanGPL = fGeomPL / fTotalCount; << 177 G4double MSmfp = emCal.GetMeanFreePath(energy,particle,"msc",material); 137 G4double MeanGPL2 = fGeomPL2 / fTotalCount << 178 138 G4double rmsGPL = std::sqrt(std::fabs(Mean << 179 //get range from restricted dedx 139 << 180 G4double range = emCal.GetRangeFromRestricteDEDX(energy,particle,material); 140 G4double MeanLaD = fLDispl / fTotalCount; << 181 141 G4double MeanLaD2 = fLDispl2 / fTotalCount << 182 //effective facRange 142 G4double rmsLaD = std::sqrt(std::fabs(Mean << 183 G4double efFacrange = MeanTPL/std::max(MSmfp, range); 143 << 184 if (MeanTPL/range >= 0.99) efFacrange = 1.; 144 G4double MeanPsi = fPsiSpa / (fTotalCount) << 185 145 G4double MeanPsi2 = fPsiSpa2 / (fTotalCoun << 186 G4cout << "\n transport mean free path :\t" << G4BestUnit(MSmfp,"Length") 146 G4double rmsPsi = std::sqrt(std::fabs(Mean << 187 << "\n range from restrict dE/dx:\t" << G4BestUnit(range,"Length") 147 << 188 << "\n ---> effective facRange :\t" << efFacrange 148 G4double MeanTeta = fTetPrj / (2 * fTotalC << 189 << G4endl; 149 G4double MeanTeta2 = fTetPrj2 / (2 * fTota << 190 150 G4double rmsTeta = std::sqrt(std::fabs(Mea << 191 G4cout << "\n compute theta0 from Highland :\t" 151 << 192 << ComputeMscHighland(MeanTPL)/mrad << " mrad" 152 G4double MeanCorrel = fPhiCor / (fTotalCou << 193 << " (" << ComputeMscHighland(MeanTPL)/deg << " deg)" 153 G4double MeanCorrel2 = fPhiCor2 / (fTotalC << 194 << G4endl; 154 G4double rmsCorrel = std::sqrt(std::fabs(M << 195 155 << 196 //restore default format 156 G4cout << "\n\n truePathLength :\t" << G4B << 197 G4cout.precision(prec); 157 << G4BestUnit(rmsTPL, "Length") << << 198 158 << G4BestUnit(MeanGPL, "Length") << << 199 // delete and remove all contents in ProcCounter 159 << "\n lateralDisplac :\t" << G4Bes << 200 while (ProcCounter->size()>0){ 160 << G4BestUnit(rmsLaD, "Length") << << 201 OneProcessCount* aProcCount=ProcCounter->back(); 161 << " +- " << rmsPsi / mrad << " mra << 202 ProcCounter->pop_back(); 162 << " (" << MeanPsi / deg << " deg" << 163 << " +- " << rmsPsi / deg << " deg) << 164 << 165 G4cout << "\n Theta_plane :\t" << rmsTe << 166 << " (" << rmsTeta / deg << " deg) << 167 << "\n phi correlation:\t" << MeanC << 168 << " (std::cos(phi_pos - phi_dir)) << 169 << 170 // cross check from G4EmCalculator << 171 // << 172 G4cout << "\n Verification from G4EmCalcul << 173 << 174 G4EmCalculator emCal; << 175 << 176 // get transport mean free path (for multi << 177 G4double MSmfp = emCal.GetMeanFreePath(ene << 178 << 179 // get range from restricted dedx << 180 G4double range = emCal.GetRangeFromRestric << 181 << 182 // effective facRange << 183 G4double efFacrange = MeanTPL / std::max(M << 184 if (MeanTPL / range >= 0.99) efFacrange = << 185 << 186 G4cout << "\n transport mean free path :\t << 187 << "\n range from restrict dE/dx:\t << 188 << "\n ---> effective facRange :\t << 189 << 190 G4cout << "\n compute theta0 from Highland << 191 << " (" << ComputeMscHighland(Mean << 192 } << 193 else << 194 G4cout << G4endl; << 195 << 196 // restore default format << 197 G4cout.precision(prec); << 198 << 199 // delete and remove all contents in fProcCo << 200 while (fProcCounter->size() > 0) { << 201 OneProcessCount* aProcCount = fProcCounter << 202 fProcCounter->pop_back(); << 203 delete aProcCount; 203 delete aProcCount; 204 } 204 } 205 delete fProcCounter; << 205 delete ProcCounter; 206 << 206 207 // save histograms << 207 histoManager->save(); 208 G4AnalysisManager* analysisManager = G4Analy << 209 if (analysisManager->IsActive()) { << 210 analysisManager->Write(); << 211 analysisManager->CloseFile(); << 212 } << 213 208 214 // show Rndm status 209 // show Rndm status 215 CLHEP::HepRandom::showEngineStatus(); 210 CLHEP::HepRandom::showEngineStatus(); 216 } 211 } 217 212 218 //....oooOO0OOooo........oooOO0OOooo........oo 213 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 219 214 220 G4double RunAction::ComputeMscHighland(G4doubl 215 G4double RunAction::ComputeMscHighland(G4double pathLength) 221 { 216 { 222 // compute the width of the Gaussian central << 217 //compute the width of the Gaussian central part of the MultipleScattering 223 // projected angular distribution. << 218 //projected angular distribution. 224 // Eur. Phys. Jour. C15 (2000) page 166, for << 219 //Eur. Phys. Jour. C15 (2000) page 166, formule 23.9 225 << 220 226 G4double t = pathLength / (fDetector->GetMat << 221 G4double t = pathLength/(detector->GetMaterial()->GetRadlen()); 227 if (t < DBL_MIN) return 0.; << 222 if (t < DBL_MIN) return 0.; 228 << 223 229 G4ParticleGun* particle = fPrimary->GetParti << 224 G4ParticleGun* particle = primary->GetParticleGun(); 230 G4double T = particle->GetParticleEnergy(); << 225 G4double T = particle->GetParticleEnergy(); 231 G4double M = particle->GetParticleDefinition << 226 G4double M = particle->GetParticleDefinition()->GetPDGMass(); 232 G4double z = std::abs(particle->GetParticleD << 227 G4double z = std::abs(particle->GetParticleDefinition()->GetPDGCharge()/eplus); 233 << 228 234 G4double bpc = T * (T + 2 * M) / (T + M); << 229 G4double bpc = T*(T+2*M)/(T+M); 235 G4double teta0 = 13.6 * MeV * z * std::sqrt( << 230 G4double teta0 = 13.6*MeV*z*std::sqrt(t)*(1.+0.038*std::log(t))/bpc; 236 return teta0; << 231 return teta0; 237 } 232 } 238 233 239 //....oooOO0OOooo........oooOO0OOooo........oo 234 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 240 235