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/TestEm12/src/RunActi << 26 // $Id: RunAction.cc,v 1.6 2006/06/29 16:43:36 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 << 35 #include "DetectorConstruction.hh" 33 #include "DetectorConstruction.hh" 36 #include "HistoManager.hh" << 37 #include "PhysicsList.hh" 34 #include "PhysicsList.hh" 38 #include "PrimaryGeneratorAction.hh" << 39 #include "Run.hh" << 40 #include "StepMax.hh" 35 #include "StepMax.hh" >> 36 #include "PrimaryGeneratorAction.hh" >> 37 #include "HistoManager.hh" 41 38 >> 39 #include "G4Run.hh" >> 40 #include "G4RunManager.hh" >> 41 #include "G4UnitsTable.hh" 42 #include "G4EmCalculator.hh" 42 #include "G4EmCalculator.hh" 43 #include "G4EmParameters.hh" << 43 44 #include "Randomize.hh" 44 #include "Randomize.hh" >> 45 #include <iomanip> 45 46 46 //....oooOO0OOooo........oooOO0OOooo........oo 47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 47 48 48 RunAction::RunAction(DetectorConstruction* det << 49 RunAction::RunAction(DetectorConstruction* det, PhysicsList* phys, 49 : fDetector(det), fPhysics(phys), fPrimary(k << 50 PrimaryGeneratorAction* kin, HistoManager* histo) 50 { << 51 :detector(det),physics(phys),kinematic(kin),histoManager(histo) 51 // Book predefined histograms << 52 { } 52 fHistoManager = new HistoManager(); << 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(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 //histograms >> 86 // >> 87 histoManager->book(); >> 88 >> 89 //set StepMax from histos >> 90 // >> 91 G4double stepMax = histoManager->GetStepMax(); >> 92 physics->GetStepMaxProcess()->SetMaxStep(stepMax); 68 } 93 } 69 94 70 //....oooOO0OOooo........oooOO0OOooo........oo 95 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 71 96 72 void RunAction::BeginOfRunAction(const G4Run*) << 97 void RunAction::EndOfRunAction(const G4Run* aRun) 73 { 98 { 74 // show Rndm status << 99 std::ios::fmtflags mode = G4cout.flags(); 75 if (isMaster) { << 100 G4cout.setf(std::ios::fixed,std::ios::floatfield); 76 G4Random::showEngineStatus(); << 101 77 G4EmParameters::Instance()->Dump(); << 102 G4int NbofEvents = aRun->GetNumberOfEvent(); 78 } << 103 if (NbofEvents == 0) return; 79 // histograms << 104 G4double fNbofEvents = double(NbofEvents); 80 // << 105 81 G4AnalysisManager* analysisManager = G4Analy << 106 //run conditions 82 if (analysisManager->IsActive()) { << 107 // 83 analysisManager->OpenFile(); << 108 G4Material* material = detector->GetAbsorMaterial(); 84 } << 109 G4double density = material->GetDensity(); 85 << 110 86 if (!fPrimary) return; << 111 G4ParticleDefinition* particle = kinematic->GetParticleGun() 87 << 112 ->GetParticleDefinition(); 88 // keep run condition << 113 G4String partName = particle->GetParticleName(); 89 G4ParticleDefinition* particle = fPrimary->G << 114 G4double energy = kinematic->GetParticleGun()->GetParticleEnergy(); 90 G4double energy = fPrimary->GetParticleGun() << 115 91 fRun->SetPrimary(particle, energy); << 116 G4cout << "\n ======================== run summary ======================\n"; 92 << 117 93 // get CsdaRange from EmCalculator << 118 G4int prec = G4cout.precision(2); >> 119 >> 120 G4cout << "\n The run consists of " << NbofEvents << " "<< partName << " of " >> 121 << G4BestUnit(energy,"Energy") << " through " >> 122 << G4BestUnit(detector->GetAbsorRadius(),"Length") << " of " >> 123 << material->GetName() << " (density: " >> 124 << G4BestUnit(density,"Volumic Mass") << ")" << G4endl; >> 125 >> 126 G4cout << "\n ============================================================\n"; >> 127 >> 128 //compute total energy deposit >> 129 // >> 130 Edeposit /= NbofEvents; Edeposit2 /= NbofEvents; >> 131 G4double rms = Edeposit2 - Edeposit*Edeposit; >> 132 if (rms>0.) rms = std::sqrt(rms); else rms = 0.; >> 133 >> 134 G4cout.precision(3); >> 135 G4cout >> 136 << "\n Total Energy deposited = " << G4BestUnit(Edeposit,"Energy") >> 137 << " +- " << G4BestUnit( rms,"Energy") >> 138 << G4endl; >> 139 >> 140 //compute track length of primary track >> 141 // >> 142 trackLen /= NbofEvents; trackLen2 /= NbofEvents; >> 143 rms = trackLen2 - trackLen*trackLen; >> 144 if (rms>0.) rms = std::sqrt(rms); else rms = 0.; >> 145 >> 146 G4cout.precision(3); >> 147 G4cout >> 148 << "\n Track length of primary track = " << G4BestUnit(trackLen,"Length") >> 149 << " +- " << G4BestUnit( rms,"Length"); >> 150 >> 151 //compare with csda range 94 // 152 // 95 G4EmCalculator emCalculator; 153 G4EmCalculator emCalculator; 96 G4Material* material = fDetector->GetAbsorMa << 154 G4double csdaRange = 0.; 97 << 155 if (particle->GetPDGCharge() != 0.) 98 G4double csdaRange = DBL_MAX; << 156 csdaRange = emCalculator.GetCSDARange(energy,particle,material); 99 if (particle->GetPDGCharge() != 0.) { << 157 G4cout 100 csdaRange = emCalculator.GetCSDARange(ener << 158 << "\n Range from EmCalculator = " << G4BestUnit(csdaRange,"Length") 101 fRun->SetCsdaRange(csdaRange); << 159 << " (from full dE/dx)" << G4endl; 102 } << 160 103 << 161 //compute projected range of primary track 104 // set StepMax from histos 1 and 8 << 162 // >> 163 projRange /= NbofEvents; projRange2 /= NbofEvents; >> 164 rms = projRange2 - projRange*projRange; >> 165 if (rms>0.) rms = std::sqrt(rms); else rms = 0.; >> 166 >> 167 G4cout >> 168 << "\n Projected range = " << G4BestUnit(projRange,"Length") >> 169 << " +- " << G4BestUnit( rms,"Length") >> 170 << G4endl; >> 171 >> 172 //nb of steps and step size of primary track >> 173 // >> 174 G4double fNbSteps = nbOfSteps/fNbofEvents, fNbSteps2 = nbOfSteps2/fNbofEvents; >> 175 rms = fNbSteps2 - fNbSteps*fNbSteps; >> 176 if (rms>0.) rms = std::sqrt(rms); else rms = 0.; >> 177 >> 178 G4cout.precision(2); >> 179 G4cout << "\n Nb of steps of primary track = " << fNbSteps << " +- " << rms; >> 180 >> 181 stepSize /= NbofEvents; stepSize2 /= NbofEvents; >> 182 rms = stepSize2 - stepSize*stepSize; >> 183 if (rms>0.) rms = std::sqrt(rms); else rms = 0.; >> 184 >> 185 G4cout.precision(3); >> 186 G4cout >> 187 << "\t Step size= " << G4BestUnit(stepSize,"Length") >> 188 << " +- " << G4BestUnit( rms,"Length") >> 189 << G4endl; >> 190 >> 191 // normalize histogram of longitudinal energy profile 105 // 192 // 106 G4double stepMax = csdaRange; << 107 G4int ih = 1; 193 G4int ih = 1; 108 if (analysisManager->GetH1Activation(ih)) << 194 G4double binWidth = histoManager->GetBinWidth(ih); 109 stepMax = analysisManager->GetH1Width(ih) << 195 G4double fac = (1./(NbofEvents*binWidth))*(mm/MeV); >> 196 histoManager->Scale(ih,fac); >> 197 >> 198 // normalize histogram d(E/E0)/d(r/r0) >> 199 // 110 ih = 8; 200 ih = 8; 111 if (analysisManager->GetH1Activation(ih)) { << 201 binWidth = histoManager->GetBinWidth(ih); 112 G4double width = analysisManager->GetH1Wid << 202 fac = 1./(NbofEvents*binWidth*energy); 113 stepMax = std::min(stepMax, width * csdaRa << 203 histoManager->Scale(ih,fac); 114 } << 204 115 fPhysics->GetStepMaxProcess()->SetMaxStep2(s << 205 // reset default formats 116 << 206 G4cout.setf(mode,std::ios::floatfield); 117 /// G4cout << "\n---> stepMax from histos 1 << 207 G4cout.precision(prec); 118 /// << G4BestUnit(stepMax,"Length") < << 208 119 } << 120 << 121 //....oooOO0OOooo........oooOO0OOooo........oo << 122 << 123 void RunAction::EndOfRunAction(const G4Run*) << 124 { << 125 if (isMaster) fRun->EndOfRun(); << 126 << 127 // save histograms 209 // save histograms 128 G4AnalysisManager* analysisManager = G4Analy << 210 histoManager->save(); 129 if (analysisManager->IsActive()) { << 211 130 analysisManager->Write(); << 131 analysisManager->CloseFile(); << 132 } << 133 << 134 // show Rndm status 212 // show Rndm status 135 if (isMaster) G4Random::showEngineStatus(); << 213 CLHEP::HepRandom::showEngineStatus(); 136 } 214 } 137 215 138 //....oooOO0OOooo........oooOO0OOooo........oo 216 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 139 217