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/TestEm11/src/RunActi << 26 // $Id: RunAction.cc,v 1.7 2007/08/19 20:52:53 maire Exp $ 27 /// \brief Implementation of the RunAction cla << 27 // GEANT4 tag $Name: geant4-09-02 $ 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 #include "DetectorConstruction.hh" 35 #include "HistoManager.hh" << 36 #include "PhysicsList.hh" 34 #include "PhysicsList.hh" 37 #include "PrimaryGeneratorAction.hh" << 38 #include "Run.hh" << 39 #include "StepMax.hh" 35 #include "StepMax.hh" >> 36 #include "PrimaryGeneratorAction.hh" >> 37 #include "HistoManager.hh" 40 38 41 #include "G4EmCalculator.hh" << 42 #include "G4EmParameters.hh" << 43 #include "G4Run.hh" 39 #include "G4Run.hh" 44 #include "G4SystemOfUnits.hh" << 40 #include "G4RunManager.hh" 45 #include "G4UnitsTable.hh" 41 #include "G4UnitsTable.hh" >> 42 #include "G4EmCalculator.hh" >> 43 46 #include "Randomize.hh" 44 #include "Randomize.hh" >> 45 #include <iomanip> 47 46 48 //....oooOO0OOooo........oooOO0OOooo........oo 47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 49 48 50 RunAction::RunAction(DetectorConstruction* det << 49 RunAction::RunAction(DetectorConstruction* det, PhysicsList* phys, 51 : fDetector(det), fPhysics(phys), fPrimary(k << 50 PrimaryGeneratorAction* kin, HistoManager* histo) 52 { << 51 :detector(det),physics(phys),kinematic(kin),histoManager(histo) 53 // Book predefined histograms << 52 { } 54 fHistoManager = new HistoManager(); << 55 } << 56 53 57 //....oooOO0OOooo........oooOO0OOooo........oo 54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 58 55 59 RunAction::~RunAction() 56 RunAction::~RunAction() 60 { << 57 { } 61 delete fHistoManager; << 62 } << 63 58 64 //....oooOO0OOooo........oooOO0OOooo........oo 59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 65 60 66 G4Run* RunAction::GenerateRun() << 61 void RunAction::BeginOfRunAction(const G4Run* aRun) 67 { << 62 { 68 fRun = new Run(fDetector); << 63 G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl; 69 return fRun; << 64 >> 65 // save Rndm status >> 66 G4RunManager::GetRunManager()->SetRandomNumberStore(true); >> 67 CLHEP::HepRandom::showEngineStatus(); >> 68 >> 69 //initialize total energy deposit >> 70 // >> 71 Edeposit = Edeposit2 = 0.; >> 72 >> 73 //initialize track legth of primary >> 74 // >> 75 trackLen = trackLen2 = 0.; >> 76 >> 77 //initialize projected range >> 78 // >> 79 projRange = projRange2 = 0.; >> 80 >> 81 //initialize mean step size >> 82 // >> 83 nbOfSteps = nbOfSteps2 = 0; stepSize = stepSize2 = 0.; >> 84 >> 85 //initialize track status >> 86 // >> 87 status[0] = status[1] = status[2] = 0; >> 88 >> 89 //get csdaRange from EmCalculator >> 90 // >> 91 G4EmCalculator emCalculator; >> 92 G4Material* material = detector->GetAbsorMaterial(); >> 93 G4ParticleDefinition* particle = kinematic->GetParticleGun() >> 94 ->GetParticleDefinition(); >> 95 G4double energy = kinematic->GetParticleGun()->GetParticleEnergy(); >> 96 csdaRange = DBL_MAX; >> 97 if (particle->GetPDGCharge() != 0.) >> 98 csdaRange = emCalculator.GetCSDARange(energy,particle,material); >> 99 >> 100 //histograms >> 101 // >> 102 histoManager->book(); >> 103 >> 104 //set StepMax from histos >> 105 // >> 106 G4double stepMax = histoManager->ComputeStepMax(csdaRange); >> 107 physics->GetStepMaxProcess()->SetMaxStep(stepMax); 70 } 108 } 71 109 72 //....oooOO0OOooo........oooOO0OOooo........oo 110 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 73 111 74 void RunAction::BeginOfRunAction(const G4Run*) << 112 void RunAction::EndOfRunAction(const G4Run* aRun) 75 { 113 { 76 // show Rndm status << 114 std::ios::fmtflags mode = G4cout.flags(); 77 if (isMaster) { << 115 G4cout.setf(std::ios::fixed,std::ios::floatfield); 78 G4Random::showEngineStatus(); << 116 79 G4EmParameters::Instance()->Dump(); << 117 G4int NbofEvents = aRun->GetNumberOfEvent(); 80 } << 118 if (NbofEvents == 0) return; 81 << 119 G4double fNbofEvents = double(NbofEvents); 82 // keep run condition << 120 83 if (fPrimary) { << 121 //run conditions 84 G4ParticleDefinition* particle = fPrimary- << 122 // 85 G4double energy = fPrimary->GetParticleGun << 123 G4Material* material = detector->GetAbsorMaterial(); 86 fRun->SetPrimary(particle, energy); << 124 G4double density = material->GetDensity(); 87 } << 125 88 << 126 G4ParticleDefinition* particle = kinematic->GetParticleGun() 89 // histograms << 127 ->GetParticleDefinition(); 90 // << 128 G4String partName = particle->GetParticleName(); 91 G4AnalysisManager* analysisManager = G4Analy << 129 G4double energy = kinematic->GetParticleGun()->GetParticleEnergy(); 92 if (analysisManager->IsActive()) { << 130 93 analysisManager->OpenFile(); << 131 G4cout << "\n ======================== run summary ======================\n"; 94 } << 132 95 << 133 G4int prec = G4cout.precision(2); 96 if (!fPrimary) return; << 134 97 << 135 G4cout << "\n The run consists of " << NbofEvents << " "<< partName << " of " 98 // set StepMax from histos 1 and 8 << 136 << G4BestUnit(energy,"Energy") << " through " >> 137 << G4BestUnit(detector->GetAbsorSizeX(),"Length") << " of " >> 138 << material->GetName() << " (density: " >> 139 << G4BestUnit(density,"Volumic Mass") << ")" << G4endl; >> 140 >> 141 G4cout << "\n ============================================================\n"; >> 142 >> 143 //compute total energy deposit >> 144 // >> 145 Edeposit /= NbofEvents; Edeposit2 /= NbofEvents; >> 146 G4double rms = Edeposit2 - Edeposit*Edeposit; >> 147 if (rms>0.) rms = std::sqrt(rms); else rms = 0.; >> 148 >> 149 G4cout.precision(3); >> 150 G4cout >> 151 << "\n Total Energy deposited = " << G4BestUnit(Edeposit,"Energy") >> 152 << " +- " << G4BestUnit( rms,"Energy") >> 153 << G4endl; >> 154 >> 155 //compute track length of primary track >> 156 // >> 157 trackLen /= NbofEvents; trackLen2 /= NbofEvents; >> 158 rms = trackLen2 - trackLen*trackLen; >> 159 if (rms>0.) rms = std::sqrt(rms); else rms = 0.; >> 160 >> 161 G4cout.precision(3); >> 162 G4cout >> 163 << "\n Track length of primary track = " << G4BestUnit(trackLen,"Length") >> 164 << " +- " << G4BestUnit( rms,"Length"); >> 165 >> 166 //compare with csda range >> 167 // >> 168 //G4EmCalculator emCalculator; >> 169 //G4double csdaRange = 0.; >> 170 //if (particle->GetPDGCharge() != 0.) >> 171 // csdaRange = emCalculator.GetCSDARange(energy,particle,material); >> 172 G4cout >> 173 << "\n Range from EmCalculator = " << G4BestUnit(csdaRange,"Length") >> 174 << " (from full dE/dx)" << G4endl; >> 175 >> 176 //compute projected range of primary track >> 177 // >> 178 projRange /= NbofEvents; projRange2 /= NbofEvents; >> 179 rms = projRange2 - projRange*projRange; >> 180 if (rms>0.) rms = std::sqrt(rms); else rms = 0.; >> 181 >> 182 G4cout >> 183 << "\n Projected range = " << G4BestUnit(projRange,"Length") >> 184 << " +- " << G4BestUnit( rms,"Length") >> 185 << G4endl; >> 186 >> 187 //nb of steps and step size of primary track >> 188 // >> 189 G4double fNbSteps = nbOfSteps/fNbofEvents, fNbSteps2 = nbOfSteps2/fNbofEvents; >> 190 rms = fNbSteps2 - fNbSteps*fNbSteps; >> 191 if (rms>0.) rms = std::sqrt(rms); else rms = 0.; >> 192 >> 193 G4cout.precision(2); >> 194 G4cout << "\n Nb of steps of primary track = " << fNbSteps << " +- " << rms; >> 195 >> 196 stepSize /= NbofEvents; stepSize2 /= NbofEvents; >> 197 rms = stepSize2 - stepSize*stepSize; >> 198 if (rms>0.) rms = std::sqrt(rms); else rms = 0.; >> 199 >> 200 G4cout.precision(3); >> 201 G4cout >> 202 << "\t Step size= " << G4BestUnit(stepSize,"Length") >> 203 << " +- " << G4BestUnit( rms,"Length") >> 204 << G4endl; >> 205 >> 206 //transmission coefficients >> 207 // >> 208 G4double absorbed = 100.*status[0]/fNbofEvents; >> 209 G4double transmit = 100.*status[1]/fNbofEvents; >> 210 G4double reflected = 100.*status[2]/fNbofEvents; >> 211 >> 212 G4cout.precision(2); >> 213 G4cout >> 214 << "\n absorbed = " << absorbed << " %" >> 215 << " transmit = " << transmit << " %" >> 216 << " reflected = " << reflected << " %" << G4endl; >> 217 >> 218 // normalize histograms of longitudinal energy profile 99 // 219 // 100 G4double stepMax = DBL_MAX; << 101 G4int ih = 1; 220 G4int ih = 1; 102 if (analysisManager->GetH1Activation(ih)) { << 221 G4double binWidth = histoManager->GetBinWidth(ih); 103 stepMax = analysisManager->GetH1Width(ih) << 222 G4double fac = (1./(NbofEvents*binWidth))*(mm/MeV); 104 } << 223 histoManager->Scale(ih,fac); 105 << 224 106 ih = 8; 225 ih = 8; 107 G4ParticleDefinition* particle = fPrimary->G << 226 binWidth = histoManager->GetBinWidth(ih); 108 if (particle->GetPDGCharge() != 0.) { << 227 G4double range = histoManager->GetcsdaRange(); 109 G4double width = analysisManager->GetH1Wid << 228 fac = (1./(NbofEvents*binWidth*range*density))*(g/(MeV*cm2)); 110 if (width == 0.) width = 1.; << 229 histoManager->Scale(ih,fac); 111 G4EmCalculator emCalculator; << 230 112 G4double energy = fPrimary->GetParticleGun << 231 // reset default formats 113 G4int nbOfAbsor = fDetector->GetNbOfAbsor( << 232 G4cout.setf(mode,std::ios::floatfield); 114 for (G4int i = 1; i <= nbOfAbsor; i++) { << 233 G4cout.precision(prec); 115 G4Material* material = fDetector->GetAbs << 234 116 G4double newCsdaRange = emCalculator.Get << 117 fRun->SetCsdaRange(i, newCsdaRange); << 118 if (analysisManager->GetH1Activation(ih) << 119 if (i > 1) { << 120 G4double thickness = fDetector->GetAbs << 121 G4double xfrontNorm = fRun->GetXfrontN << 122 G4double csdaRange = fRun->GetCsdaRang << 123 G4double newXfrontNorm = xfrontNorm + << 124 fRun->SetXfrontNorm(i, newXfrontNorm); << 125 } << 126 } << 127 } << 128 fPhysics->GetStepMaxProcess()->SetMaxStep2(s << 129 } << 130 << 131 //....oooOO0OOooo........oooOO0OOooo........oo << 132 << 133 void RunAction::EndOfRunAction(const G4Run*) << 134 { << 135 if (isMaster) fRun->EndOfRun(); << 136 << 137 // save histograms 235 // save histograms 138 G4AnalysisManager* analysisManager = G4Analy << 236 histoManager->save(); 139 if (analysisManager->IsActive()) { << 237 140 analysisManager->Write(); << 141 analysisManager->CloseFile(); << 142 } << 143 << 144 // show Rndm status 238 // show Rndm status 145 if (isMaster) G4Random::showEngineStatus(); << 239 CLHEP::HepRandom::showEngineStatus(); 146 } 240 } 147 241 148 //....oooOO0OOooo........oooOO0OOooo........oo 242 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 149 243