Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-16 08:29:12

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /// \file Run.cc
0027 /// \brief Implementation of the Run class
0028 
0029 #include "Run.hh"
0030 
0031 #include "DetectorConstruction.hh"
0032 #include "PrimaryGeneratorAction.hh"
0033 
0034 #include "G4EmCalculator.hh"
0035 #include "G4Gamma.hh"
0036 #include "G4SystemOfUnits.hh"
0037 #include "G4UnitsTable.hh"
0038 
0039 #include <iomanip>
0040 
0041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0042 
0043 Run::Run(DetectorConstruction* det) : fDetector(det) {}
0044 
0045 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0046 
0047 void Run::SetPrimary(G4ParticleDefinition* particle, G4double energy)
0048 {
0049   fParticle = particle;
0050   fEkin = energy;
0051 }
0052 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0053 
0054 void Run::CountProcesses(G4String procName)
0055 {
0056   std::map<G4String, G4int>::iterator it = fProcCounter.find(procName);
0057   if (it == fProcCounter.end()) {
0058     fProcCounter[procName] = 1;
0059   }
0060   else {
0061     fProcCounter[procName]++;
0062   }
0063 }
0064 
0065 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0066 
0067 void Run::SumTrack(G4double track)
0068 {
0069   fTotalCount++;
0070   fSumTrack += track;
0071   fSumTrack2 += track * track;
0072 }
0073 
0074 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0075 
0076 void Run::SumeTransf(G4double energy)
0077 {
0078   fEnTransfer += energy;
0079 }
0080 
0081 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0082 
0083 void Run::Merge(const G4Run* run)
0084 {
0085   const Run* localRun = static_cast<const Run*>(run);
0086 
0087   // pass information about primary particle
0088   fParticle = localRun->fParticle;
0089   fEkin = localRun->fEkin;
0090 
0091   // map: processes count
0092   std::map<G4String, G4int>::const_iterator it;
0093   for (it = localRun->fProcCounter.begin(); it != localRun->fProcCounter.end(); ++it) {
0094     G4String procName = it->first;
0095     G4int localCount = it->second;
0096     if (fProcCounter.find(procName) == fProcCounter.end()) {
0097       fProcCounter[procName] = localCount;
0098     }
0099     else {
0100       fProcCounter[procName] += localCount;
0101     }
0102   }
0103 
0104   fTotalCount += localRun->fTotalCount;
0105   fSumTrack += localRun->fSumTrack;
0106   fSumTrack2 += localRun->fSumTrack2;
0107   fEnTransfer += localRun->fEnTransfer;
0108 
0109   G4Run::Merge(run);
0110 }
0111 
0112 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0113 
0114 void Run::EndOfRun()
0115 {
0116   G4int prec = 5;
0117   G4int dfprec = G4cout.precision(prec);
0118 
0119   // run condition
0120   //
0121   G4String partName = fParticle->GetParticleName();
0122   G4Material* material = fDetector->GetMaterial();
0123   G4double density = material->GetDensity();
0124   G4double tickness = fDetector->GetSize();
0125 
0126   G4cout << "\n ======================== run summary ======================\n";
0127   G4cout << "\n The run is: " << numberOfEvent << " " << partName << " of "
0128          << G4BestUnit(fEkin, "Energy") << " through " << G4BestUnit(tickness, "Length") << " of "
0129          << material->GetName() << " (density: " << G4BestUnit(density, "Volumic Mass") << ")"
0130          << G4endl;
0131 
0132   // frequency of processes
0133   G4int survive = 0;
0134   G4cout << "\n Process calls frequency --->";
0135   std::map<G4String, G4int>::iterator it;
0136   for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
0137     G4String procName = it->first;
0138     G4int count = it->second;
0139     G4cout << "\t" << procName << " = " << count;
0140     if (procName == "Transportation") survive = count;
0141   }
0142 
0143   if (survive > 0) {
0144     G4cout << "\n\n Nb of incident particles surviving after "
0145            << G4BestUnit(fDetector->GetSize(), "Length") << " of " << material->GetName() << " : "
0146            << survive << G4endl;
0147   }
0148 
0149   if (fTotalCount == 0) fTotalCount = 1;  // force printing anyway
0150 
0151   // compute mean free path and related quantities
0152   //
0153   G4double MeanFreePath = fSumTrack / fTotalCount;
0154   G4double MeanTrack2 = fSumTrack2 / fTotalCount;
0155   G4double rms = std::sqrt(std::fabs(MeanTrack2 - MeanFreePath * MeanFreePath));
0156   G4double CrossSection = 1. / MeanFreePath;
0157   G4double massicMFP = MeanFreePath * density;
0158   G4double massicCS = 1. / massicMFP;
0159 
0160   G4cout << "\n\n MeanFreePath:\t" << G4BestUnit(MeanFreePath, "Length") << " +- "
0161          << G4BestUnit(rms, "Length") << "\tmassic: " << G4BestUnit(massicMFP, "Mass/Surface")
0162          << "\n CrossSection:\t" << CrossSection * cm << " cm^-1 "
0163          << "\t\t\tmassic: " << G4BestUnit(massicCS, "Surface/Mass") << G4endl;
0164 
0165   // compute energy transfer coefficient
0166   //
0167   G4double MeanTransfer = fEnTransfer / fTotalCount;
0168   G4double massTransfCoef = massicCS * MeanTransfer / fEkin;
0169 
0170   G4cout << "\n mean energy of charged secondaries: " << G4BestUnit(MeanTransfer, "Energy")
0171          << "\n     ---> mass_energy_transfer coef: " << G4BestUnit(massTransfCoef, "Surface/Mass")
0172          << G4endl;
0173 
0174   // check cross section from G4EmCalculator
0175   //
0176   G4cout << "\n Verification : "
0177          << "crossSections from G4EmCalculator \n";
0178 
0179   G4EmCalculator emCalculator;
0180   G4double sumc = 0.0;
0181   for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
0182     G4String procName = it->first;
0183     G4double massSigma =
0184       emCalculator.GetCrossSectionPerVolume(fEkin, fParticle, procName, material) / density;
0185     if (fParticle == G4Gamma::Gamma())
0186       massSigma =
0187         emCalculator.ComputeCrossSectionPerVolume(fEkin, fParticle, procName, material) / density;
0188     sumc += massSigma;
0189     G4cout << "   " << procName << "= " << G4BestUnit(massSigma, "Surface/Mass");
0190   }
0191   G4cout << "   total= " << G4BestUnit(sumc, "Surface/Mass") << G4endl;
0192 
0193   // remove all contents in fProcCounter
0194   fProcCounter.clear();
0195 
0196   // restore default format
0197   G4cout.precision(dfprec);
0198 }
0199 
0200 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......