Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 /// \file electromagnetic/TestEm5/src/RunActio << 23 // $Id: RunAction.cc,v 1.19 2005/03/16 16:03:47 maire Exp $ 27 /// \brief Implementation of the RunAction cla << 24 // GEANT4 tag $Name: geant4-07-01 $ 28 // << 29 // 25 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 26 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 27 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 28 33 #include "RunAction.hh" 29 #include "RunAction.hh" 34 << 35 #include "DetectorConstruction.hh" 30 #include "DetectorConstruction.hh" 36 #include "HistoManager.hh" << 37 #include "PrimaryGeneratorAction.hh" 31 #include "PrimaryGeneratorAction.hh" 38 #include "Run.hh" << 32 #include "HistoManager.hh" 39 33 40 #include "G4EmCalculator.hh" << 41 #include "G4Run.hh" 34 #include "G4Run.hh" 42 #include "G4SystemOfUnits.hh" << 35 #include "G4RunManager.hh" 43 #include "G4UnitsTable.hh" 36 #include "G4UnitsTable.hh" 44 #include "Randomize.hh" << 37 #include "G4EmCalculator.hh" 45 38 >> 39 #include "Randomize.hh" 46 #include <iomanip> 40 #include <iomanip> 47 41 48 //....oooOO0OOooo........oooOO0OOooo........oo 42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 49 43 50 RunAction::RunAction(DetectorConstruction* det << 44 RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* kin, 51 : fDetector(det), fPrimary(kin) << 45 HistoManager* histo) 52 { << 46 :detector(det), primary(kin), histoManager(histo) 53 // Book predefined histograms << 47 { } 54 fHistoManager = new HistoManager(); << 55 } << 56 48 57 //....oooOO0OOooo........oooOO0OOooo........oo 49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 58 50 59 RunAction::~RunAction() 51 RunAction::~RunAction() 60 { << 52 { } 61 delete fHistoManager; << 62 } << 63 53 64 //....oooOO0OOooo........oooOO0OOooo........oo 54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 65 55 66 G4Run* RunAction::GenerateRun() << 56 void RunAction::BeginOfRunAction(const G4Run* aRun) 67 { 57 { 68 fRun = new Run(fDetector); << 58 G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl; 69 return fRun; << 59 >> 60 //initialisation >> 61 EnergyDeposit = EnergyDeposit2 = 0.; >> 62 TrakLenCharged = TrakLenCharged2 = 0.; >> 63 TrakLenNeutral = TrakLenNeutral2 = 0.; >> 64 nbStepsCharged = nbStepsCharged2 = 0.; >> 65 nbStepsNeutral = nbStepsNeutral2 = 0.; >> 66 MscProjecTheta = MscProjecTheta2 = 0.; >> 67 >> 68 nbGamma = nbElect = nbPosit = 0; >> 69 >> 70 Transmit[0] = Transmit[1] = Reflect[0] = Reflect[1] = 0; >> 71 >> 72 histoManager->book(); >> 73 >> 74 // save Rndm status >> 75 G4RunManager::GetRunManager()->SetRandomNumberStore(true); >> 76 HepRandom::showEngineStatus(); 70 } 77 } 71 78 72 //....oooOO0OOooo........oooOO0OOooo........oo 79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 73 80 74 void RunAction::BeginOfRunAction(const G4Run*) << 81 void RunAction::EndOfRunAction(const G4Run* aRun) 75 { 82 { 76 // show Rndm status << 83 // compute mean and rms 77 if (isMaster) G4Random::showEngineStatus(); << 84 // >> 85 G4int TotNbofEvents = aRun->GetNumberOfEvent(); >> 86 if (TotNbofEvents == 0) return; 78 87 79 // keep run condition << 88 EnergyDeposit /= TotNbofEvents; EnergyDeposit2 /= TotNbofEvents; 80 if (fPrimary) { << 89 G4double rmsEdep = EnergyDeposit2 - EnergyDeposit*EnergyDeposit; 81 G4ParticleDefinition* particle = fPrimary- << 90 if (rmsEdep>0.) rmsEdep = std::sqrt(rmsEdep/TotNbofEvents); 82 G4double energy = fPrimary->GetParticleGun << 91 else rmsEdep = 0.; 83 fRun->SetPrimary(particle, energy); << 92 >> 93 TrakLenCharged /= TotNbofEvents; TrakLenCharged2 /= TotNbofEvents; >> 94 G4double rmsTLCh = TrakLenCharged2 - TrakLenCharged*TrakLenCharged; >> 95 if (rmsTLCh>0.) rmsTLCh = std::sqrt(rmsTLCh/TotNbofEvents); >> 96 else rmsTLCh = 0.; >> 97 >> 98 TrakLenNeutral /= TotNbofEvents; TrakLenNeutral2 /= TotNbofEvents; >> 99 G4double rmsTLNe = TrakLenNeutral2 - TrakLenNeutral*TrakLenNeutral; >> 100 if (rmsTLNe>0.) rmsTLNe = std::sqrt(rmsTLNe/TotNbofEvents); >> 101 else rmsTLNe = 0.; >> 102 >> 103 nbStepsCharged /= TotNbofEvents; nbStepsCharged2 /= TotNbofEvents; >> 104 G4double rmsStCh = nbStepsCharged2 - nbStepsCharged*nbStepsCharged; >> 105 if (rmsStCh>0.) rmsStCh = std::sqrt(rmsTLCh/TotNbofEvents); >> 106 else rmsStCh = 0.; >> 107 >> 108 nbStepsNeutral /= TotNbofEvents; nbStepsNeutral2 /= TotNbofEvents; >> 109 G4double rmsStNe = nbStepsNeutral2 - nbStepsNeutral*nbStepsNeutral; >> 110 if (rmsStNe>0.) rmsStNe = std::sqrt(rmsTLCh/TotNbofEvents); >> 111 else rmsStNe = 0.; >> 112 >> 113 G4double Gamma = (double)nbGamma/TotNbofEvents; >> 114 G4double Elect = (double)nbElect/TotNbofEvents; >> 115 G4double Posit = (double)nbPosit/TotNbofEvents; >> 116 >> 117 G4double transmit[2]; >> 118 transmit[0] = 100.*Transmit[0]/TotNbofEvents; >> 119 transmit[1] = 100.*Transmit[1]/TotNbofEvents; >> 120 >> 121 G4double reflect[2]; >> 122 reflect[0] = 100.*Reflect[0]/TotNbofEvents; >> 123 reflect[1] = 100.*Reflect[1]/TotNbofEvents; >> 124 >> 125 G4double rmsMsc = 0.; >> 126 if (Transmit[1] > 0) { >> 127 MscProjecTheta /= (2*Transmit[1]); MscProjecTheta2 /= (2*Transmit[1]); >> 128 rmsMsc = MscProjecTheta2 - MscProjecTheta*MscProjecTheta; >> 129 if (rmsMsc > 0.) rmsMsc = std::sqrt(rmsMsc); 84 } 130 } 85 << 131 86 // histograms << 132 //Stopping Power from input Table. 87 // 133 // 88 G4AnalysisManager* analysisManager = G4Analy << 134 G4Material* material = detector->GetAbsorberMaterial(); 89 if (analysisManager->IsActive()) { << 135 G4double length = detector->GetAbsorberThickness(); 90 analysisManager->OpenFile(); << 136 G4double density = material->GetDensity(); >> 137 >> 138 G4ParticleDefinition* particle = primary->GetParticleGun() >> 139 ->GetParticleDefinition(); >> 140 G4String partName = particle->GetParticleName(); >> 141 G4double energy = primary->GetParticleGun()->GetParticleEnergy(); >> 142 >> 143 G4EmCalculator emCalculator; >> 144 G4double dEdxTable = 0.; >> 145 if (particle->GetPDGCharge()!= 0.) { >> 146 dEdxTable = emCalculator.GetDEDX(energy,particle,material); 91 } 147 } 92 } << 148 G4double stopTable = dEdxTable/density; >> 149 >> 150 //Stopping Power from simulation. >> 151 // >> 152 G4double meandEdx = EnergyDeposit/length; >> 153 G4double stopPower = meandEdx/density; >> 154 >> 155 G4cout << "\n ======================== run summary ======================\n"; >> 156 >> 157 G4int prec = G4cout.precision(2); >> 158 >> 159 G4cout << "\n The run was " << TotNbofEvents << " " << partName << " of " >> 160 << G4BestUnit(energy,"Energy") << " through " >> 161 << G4BestUnit(length,"Length") << " of " >> 162 << material->GetName() << " (density: " >> 163 << G4BestUnit(density,"Volumic Mass") << ")" << G4endl; >> 164 >> 165 G4cout.precision(4); >> 166 G4cout << "\n Total energy deposit in absorber per event = " >> 167 << G4BestUnit(EnergyDeposit,"Energy") << " +- " >> 168 << G4BestUnit(rmsEdep, "Energy") >> 169 << G4endl; >> 170 >> 171 G4cout << "\n Mean dE/dx = " << meandEdx/(MeV/cm) << " MeV/cm" >> 172 << "\t stopping Power = " << stopPower/(MeV*cm2/g) << " MeV*cm2/g" >> 173 << G4endl; >> 174 >> 175 G4cout << " (from Table = " << dEdxTable/(MeV/cm) << " MeV/cm)" >> 176 << "\t (from Table = " << stopTable/(MeV*cm2/g) << " MeV*cm2/g)" >> 177 << G4endl; >> 178 >> 179 G4cout << "\n Total track length (charged) in absorber per event = " >> 180 << G4BestUnit(TrakLenCharged,"Length") << " +- " >> 181 << G4BestUnit(rmsTLCh, "Length") << G4endl; >> 182 >> 183 G4cout << " Total track length (neutral) in absorber per event = " >> 184 << G4BestUnit(TrakLenNeutral,"Length") << " +- " >> 185 << G4BestUnit(rmsTLNe, "Length") << G4endl; >> 186 >> 187 G4cout << "\n Number of steps (charged) in absorber per event = " >> 188 << nbStepsCharged << " +- " << rmsStCh << G4endl; >> 189 >> 190 G4cout << " Number of steps (neutral) in absorber per event = " >> 191 << nbStepsNeutral << " +- " << rmsStNe << G4endl; >> 192 >> 193 G4cout << "\n Number of secondaries per event : Gammas = " << Gamma >> 194 << "; electrons = " << Elect >> 195 << "; positrons = " << Posit << G4endl; >> 196 >> 197 G4cout << "\n Number of events with the primary particle transmitted = " >> 198 << transmit[1] << " %" << G4endl; >> 199 >> 200 G4cout << " Number of events with at least 1 particle transmitted " >> 201 << "(same charge as primary) = " << transmit[0] << " %" << G4endl; 93 202 94 //....oooOO0OOooo........oooOO0OOooo........oo << 203 G4cout << "\n Number of events with the primary particle reflected = " >> 204 << reflect[1] << " %" << G4endl; 95 205 96 void RunAction::EndOfRunAction(const G4Run*) << 206 G4cout << " Number of events with at least 1 particle reflected " 97 { << 207 << "(same charge as primary) = " << reflect[0] << " %" << G4endl; 98 // print Run summary << 208 >> 209 // compute width of the Gaussian central part of the MultipleScattering 99 // 210 // 100 if (isMaster) fRun->EndOfRun(); << 211 if (histoManager->HistoExist(6)) { >> 212 G4cout << "\n MultipleScattering: rms proj angle of transmit primary particle = " >> 213 << rmsMsc/mrad << " mrad " << G4endl; 101 214 102 // save histograms << 215 G4cout << " MultipleScattering: computed theta0 (Highland formula) = " 103 G4AnalysisManager* analysisManager = G4Analy << 216 << ComputeMscHighland()/mrad << " mrad" << G4endl; 104 if (analysisManager->IsActive()) { << 217 } 105 analysisManager->Write(); << 218 106 analysisManager->CloseFile(); << 219 G4cout.precision(prec); 107 } << 220 >> 221 histoManager->save(); 108 222 109 // show Rndm status 223 // show Rndm status 110 if (isMaster) G4Random::showEngineStatus(); << 224 HepRandom::showEngineStatus(); >> 225 } >> 226 >> 227 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 228 >> 229 G4double RunAction::ComputeMscHighland() >> 230 { >> 231 //compute the width of the Gaussian central part of the MultipleScattering >> 232 //projected angular distribution. >> 233 //Eur. Phys. Jour. C15 (2000) page 166, formule 23.9 >> 234 >> 235 G4double t = (detector->GetAbsorberThickness()) >> 236 /(detector->GetAbsorberMaterial()->GetRadlen()); >> 237 if (t < DBL_MIN) return 0.; >> 238 >> 239 G4ParticleGun* particle = primary->GetParticleGun(); >> 240 G4double T = particle->GetParticleEnergy(); >> 241 G4double M = particle->GetParticleDefinition()->GetPDGMass(); >> 242 G4double z = std::abs(particle->GetParticleDefinition()->GetPDGCharge()/eplus); >> 243 >> 244 G4double bpc = T*(T+2*M)/(T+M); >> 245 G4double teta0 = 13.6*MeV*z*std::sqrt(t)*(1.+0.038*std::log(t))/bpc; >> 246 return teta0; 111 } 247 } 112 248 113 //....oooOO0OOooo........oooOO0OOooo........oo 249 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 114 250