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 RunAction.cc << 26 // $Id: RunAction.cc,v 1.3 2006/06/29 16:45:59 gunter Exp $ 27 /// \brief Implementation of the RunAction cla << 27 // GEANT4 tag $Name: geant4-08-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" 38 #include "Run.hh" << 36 #include "HistoManager.hh" 39 37 40 #include "G4EmCalculator.hh" << 41 #include "G4Run.hh" 38 #include "G4Run.hh" >> 39 #include "G4RunManager.hh" 42 #include "G4UnitsTable.hh" 40 #include "G4UnitsTable.hh" 43 #include "Randomize.hh" << 41 #include "G4EmCalculator.hh" >> 42 #include "G4Gamma.hh" 44 43 >> 44 #include "Randomize.hh" 45 #include <iomanip> 45 #include <iomanip> 46 46 47 //....oooOO0OOooo........oooOO0OOooo........oo 47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 48 48 49 RunAction::RunAction(DetectorConstruction* det << 49 RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* prim, 50 : fDetector(det), fPrimary(kin) << 50 HistoManager* histo) 51 { << 51 : detector(det), primary(prim), ProcCounter(0), histoManager(histo) 52 fHistoManager = new HistoManager(); << 52 { } 53 } << 54 53 55 //....oooOO0OOooo........oooOO0OOooo........oo 54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 56 55 57 RunAction::~RunAction() 56 RunAction::~RunAction() 58 { << 57 { } 59 delete fHistoManager; << 60 } << 61 58 62 //....oooOO0OOooo........oooOO0OOooo........oo 59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 63 60 64 G4Run* RunAction::GenerateRun() << 61 void RunAction::BeginOfRunAction(const G4Run* aRun) 65 { << 62 { 66 fRun = new Run(fDetector); << 63 G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl; 67 return fRun; << 64 >> 65 // save Rndm status >> 66 G4RunManager::GetRunManager()->SetRandomNumberStore(false); >> 67 CLHEP::HepRandom::showEngineStatus(); >> 68 >> 69 ProcCounter = new ProcessesCount; >> 70 totalCount = 0; >> 71 sumTrack = sumTrack2 = 0.; >> 72 >> 73 histoManager->book(); 68 } 74 } >> 75 69 //....oooOO0OOooo........oooOO0OOooo........oo 76 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 70 77 71 void RunAction::BeginOfRunAction(const G4Run*) << 78 void RunAction::CountProcesses(G4String procName) 72 { 79 { 73 // show Rndm status << 80 //does the process already encounted ? 74 if (isMaster) G4Random::showEngineStatus(); << 81 size_t nbProc = ProcCounter->size(); >> 82 size_t i = 0; >> 83 while ((i<nbProc)&&((*ProcCounter)[i]->GetName()!=procName)) i++; >> 84 if (i == nbProc) ProcCounter->push_back( new OneProcessCount(procName)); 75 85 76 // keep run condition << 86 (*ProcCounter)[i]->Count(); 77 if (fPrimary) { << 78 G4ParticleDefinition* particle = fPrimary- << 79 G4double energy = fPrimary->GetParticleGun << 80 fRun->SetPrimary(particle, energy); << 81 } << 82 << 83 // histograms << 84 // << 85 G4AnalysisManager* analysisManager = G4Analy << 86 if (analysisManager->IsActive()) { << 87 analysisManager->OpenFile(); << 88 } << 89 } 87 } 90 88 91 //....oooOO0OOooo........oooOO0OOooo........oo 89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 92 90 93 void RunAction::EndOfRunAction(const G4Run*) << 91 void RunAction::EndOfRunAction(const G4Run* aRun) 94 { 92 { 95 // compute and print statistic << 93 G4int NbOfEvents = aRun->GetNumberOfEvent(); 96 if (isMaster) fRun->EndOfRun(); << 94 if (NbOfEvents == 0) return; >> 95 >> 96 G4int prec = G4cout.precision(5); >> 97 >> 98 G4Material* material = detector->GetMaterial(); >> 99 G4double density = material->GetDensity(); >> 100 G4int survive = 0; >> 101 >> 102 G4ParticleDefinition* particle = >> 103 primary->GetParticleGun()->GetParticleDefinition(); >> 104 G4String Particle = particle->GetParticleName(); >> 105 G4double energy = primary->GetParticleGun()->GetParticleEnergy(); >> 106 G4cout << "\n The run consists of " << NbOfEvents << " "<< Particle << " of " >> 107 << G4BestUnit(energy,"Energy") << " through " >> 108 << G4BestUnit(detector->GetSize(),"Length") << " of " >> 109 << material->GetName() << " (density: " >> 110 << G4BestUnit(density,"Volumic Mass") << ")" << G4endl; >> 111 >> 112 //frequency of processes >> 113 G4cout << "\n Process calls frequency --->"; >> 114 for (size_t i=0; i< ProcCounter->size();i++) { >> 115 G4String procName = (*ProcCounter)[i]->GetName(); >> 116 G4int count = (*ProcCounter)[i]->GetCounter(); >> 117 G4cout << "\t" << procName << " = " << count; >> 118 if (procName == "Transportation") survive = count; >> 119 } >> 120 >> 121 if (survive > 0) { >> 122 G4cout << "\n\n Nb of incident particles surviving after " >> 123 << G4BestUnit(detector->GetSize(),"Length") << " of " >> 124 << material->GetName() << " : " << survive << G4endl; >> 125 } >> 126 >> 127 if (totalCount == 0) totalCount = 1; //force printing anyway >> 128 >> 129 //compute mean free path and related quantities >> 130 // >> 131 G4double MeanFreePath = sumTrack /totalCount; >> 132 G4double MeanTrack2 = sumTrack2/totalCount; >> 133 G4double rms = std::sqrt(std::fabs(MeanTrack2 - MeanFreePath*MeanFreePath)); >> 134 G4double CrossSection = 1./MeanFreePath; >> 135 G4double massicMFP = MeanFreePath*density; >> 136 G4double massicCS = 1./massicMFP; >> 137 >> 138 G4cout << "\n\n MeanFreePath:\t" << G4BestUnit(MeanFreePath,"Length") >> 139 << " +- " << G4BestUnit( rms,"Length") >> 140 << "\tmassic: " << G4BestUnit(massicMFP, "Mass/Surface") >> 141 << "\n CrossSection:\t" << CrossSection*cm << " cm^-1 " >> 142 << "\t\t\tmassic: " << G4BestUnit(massicCS, "Surface/Mass") >> 143 << G4endl; 97 144 98 // save histograms << 145 //check cross section from G4EmCalculator 99 G4AnalysisManager* analysisManager = G4Analy << 146 // 100 if (analysisManager->IsActive()) { << 147 G4cout << "\n Verification : " 101 analysisManager->Write(); << 148 << "crossSections from G4EmCalculator. \n"; 102 analysisManager->CloseFile(); << 149 >> 150 G4EmCalculator emCalculator; >> 151 G4double sumc = 0.0; >> 152 for (size_t i=0; i< ProcCounter->size();i++) { >> 153 G4String procName = (*ProcCounter)[i]->GetName(); >> 154 G4double massSigma = >> 155 emCalculator.GetCrossSectionPerVolume(energy,particle, >> 156 procName,material)/density; >> 157 if (particle == G4Gamma::Gamma()) >> 158 massSigma = >> 159 emCalculator.ComputeCrossSectionPerVolume(energy,particle, >> 160 procName,material)/density; >> 161 sumc += massSigma; >> 162 G4cout << "\t" << procName << "= " >> 163 << G4BestUnit(massSigma, "Surface/Mass"); >> 164 } >> 165 G4cout << "\ttotal= " >> 166 << G4BestUnit(sumc, "Surface/Mass") << G4endl; >> 167 >> 168 //restore default format >> 169 G4cout.precision(prec); >> 170 >> 171 // delete and remove all contents in ProcCounter >> 172 while (ProcCounter->size()>0){ >> 173 OneProcessCount* aProcCount=ProcCounter->back(); >> 174 ProcCounter->pop_back(); >> 175 delete aProcCount; 103 } 176 } >> 177 delete ProcCounter; >> 178 >> 179 histoManager->save(); 104 180 105 // show Rndm status 181 // show Rndm status 106 if (isMaster) G4Random::showEngineStatus(); << 182 CLHEP::HepRandom::showEngineStatus(); 107 } 183 } 108 184 109 //....oooOO0OOooo........oooOO0OOooo........oo 185 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 110 186