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.4 2006/09/06 09:56:06 maire Exp $ 27 /// \brief Implementation of the RunAction cla << 27 // GEANT4 tag $Name: geant4-09-03-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" 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 eTransfer = 0.; >> 73 >> 74 histoManager->book(); 68 } 75 } >> 76 69 //....oooOO0OOooo........oooOO0OOooo........oo 77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 70 78 71 void RunAction::BeginOfRunAction(const G4Run*) << 79 void RunAction::CountProcesses(G4String procName) 72 { 80 { 73 // show Rndm status << 81 //does the process already encounted ? 74 if (isMaster) G4Random::showEngineStatus(); << 82 size_t nbProc = ProcCounter->size(); 75 << 83 size_t i = 0; 76 // keep run condition << 84 while ((i<nbProc)&&((*ProcCounter)[i]->GetName()!=procName)) i++; 77 if (fPrimary) { << 85 if (i == nbProc) ProcCounter->push_back( new OneProcessCount(procName)); 78 G4ParticleDefinition* particle = fPrimary- << 79 G4double energy = fPrimary->GetParticleGun << 80 fRun->SetPrimary(particle, energy); << 81 } << 82 86 83 // histograms << 87 (*ProcCounter)[i]->Count(); 84 // << 85 G4AnalysisManager* analysisManager = G4Analy << 86 if (analysisManager->IsActive()) { << 87 analysisManager->OpenFile(); << 88 } << 89 } 88 } 90 89 91 //....oooOO0OOooo........oooOO0OOooo........oo 90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 92 91 93 void RunAction::EndOfRunAction(const G4Run*) << 92 void RunAction::EndOfRunAction(const G4Run* aRun) 94 { 93 { 95 // compute and print statistic << 94 G4int NbOfEvents = aRun->GetNumberOfEvent(); 96 if (isMaster) fRun->EndOfRun(); << 95 if (NbOfEvents == 0) return; 97 << 96 98 // save histograms << 97 G4int prec = G4cout.precision(5); 99 G4AnalysisManager* analysisManager = G4Analy << 98 100 if (analysisManager->IsActive()) { << 99 G4Material* material = detector->GetMaterial(); 101 analysisManager->Write(); << 100 G4double density = material->GetDensity(); 102 analysisManager->CloseFile(); << 101 G4int survive = 0; >> 102 >> 103 G4ParticleDefinition* particle = >> 104 primary->GetParticleGun()->GetParticleDefinition(); >> 105 G4String Particle = particle->GetParticleName(); >> 106 G4double energy = primary->GetParticleGun()->GetParticleEnergy(); >> 107 G4cout << "\n The run consists of " << NbOfEvents << " "<< Particle << " of " >> 108 << G4BestUnit(energy,"Energy") << " through " >> 109 << G4BestUnit(detector->GetSize(),"Length") << " of " >> 110 << material->GetName() << " (density: " >> 111 << G4BestUnit(density,"Volumic Mass") << ")" << G4endl; >> 112 >> 113 //frequency of processes >> 114 G4cout << "\n Process calls frequency --->"; >> 115 for (size_t i=0; i< ProcCounter->size();i++) { >> 116 G4String procName = (*ProcCounter)[i]->GetName(); >> 117 G4int count = (*ProcCounter)[i]->GetCounter(); >> 118 G4cout << "\t" << procName << " = " << count; >> 119 if (procName == "Transportation") survive = count; >> 120 } >> 121 >> 122 if (survive > 0) { >> 123 G4cout << "\n\n Nb of incident particles surviving after " >> 124 << G4BestUnit(detector->GetSize(),"Length") << " of " >> 125 << material->GetName() << " : " << survive << G4endl; >> 126 } >> 127 >> 128 if (totalCount == 0) totalCount = 1; //force printing anyway >> 129 >> 130 //compute mean free path and related quantities >> 131 // >> 132 G4double MeanFreePath = sumTrack /totalCount; >> 133 G4double MeanTrack2 = sumTrack2/totalCount; >> 134 G4double rms = std::sqrt(std::fabs(MeanTrack2 - MeanFreePath*MeanFreePath)); >> 135 G4double CrossSection = 1./MeanFreePath; >> 136 G4double massicMFP = MeanFreePath*density; >> 137 G4double massicCS = 1./massicMFP; >> 138 >> 139 G4cout << "\n\n MeanFreePath:\t" << G4BestUnit(MeanFreePath,"Length") >> 140 << " +- " << G4BestUnit( rms,"Length") >> 141 << "\tmassic: " << G4BestUnit(massicMFP, "Mass/Surface") >> 142 << "\n CrossSection:\t" << CrossSection*cm << " cm^-1 " >> 143 << "\t\t\tmassic: " << G4BestUnit(massicCS, "Surface/Mass") >> 144 << G4endl; >> 145 >> 146 //compute energy transfer coefficient >> 147 // >> 148 G4double MeanTransfer = eTransfer/totalCount; >> 149 G4double massTransfCoef = massicCS*MeanTransfer/energy; >> 150 >> 151 G4cout << "\n mean energy of charged secondaries: " << G4BestUnit(MeanTransfer, "Energy") >> 152 << "\tmass_energy_transfer coef: " << G4BestUnit(massTransfCoef, "Surface/Mass") >> 153 << G4endl; >> 154 >> 155 //check cross section from G4EmCalculator >> 156 // >> 157 G4cout << "\n Verification : " >> 158 << "crossSections from G4EmCalculator \n"; >> 159 >> 160 G4EmCalculator emCalculator; >> 161 G4double sumc = 0.0; >> 162 for (size_t i=0; i< ProcCounter->size();i++) { >> 163 G4String procName = (*ProcCounter)[i]->GetName(); >> 164 G4double massSigma = >> 165 emCalculator.GetCrossSectionPerVolume(energy,particle, >> 166 procName,material)/density; >> 167 if (particle == G4Gamma::Gamma()) >> 168 massSigma = >> 169 emCalculator.ComputeCrossSectionPerVolume(energy,particle, >> 170 procName,material)/density; >> 171 sumc += massSigma; >> 172 G4cout << "\t" << procName << "= " >> 173 << G4BestUnit(massSigma, "Surface/Mass"); >> 174 } >> 175 G4cout << "\ttotal= " >> 176 << G4BestUnit(sumc, "Surface/Mass") << G4endl; >> 177 >> 178 //restore default format >> 179 G4cout.precision(prec); >> 180 >> 181 // delete and remove all contents in ProcCounter >> 182 while (ProcCounter->size()>0){ >> 183 OneProcessCount* aProcCount=ProcCounter->back(); >> 184 ProcCounter->pop_back(); >> 185 delete aProcCount; 103 } 186 } >> 187 delete ProcCounter; >> 188 >> 189 histoManager->save(); 104 190 105 // show Rndm status 191 // show Rndm status 106 if (isMaster) G4Random::showEngineStatus(); << 192 CLHEP::HepRandom::showEngineStatus(); 107 } 193 } 108 194 109 //....oooOO0OOooo........oooOO0OOooo........oo 195 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 110 196