Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-08 08:29:32

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 RunAction.cc
0027 /// \brief Implementation of the RunAction class
0028 
0029 #include "RunAction.hh"
0030 
0031 #include "HistoManager.hh"
0032 #include "PrimaryGeneratorAction.hh"
0033 #include "Run.hh"
0034 
0035 #include "G4Run.hh"
0036 #include "G4UnitsTable.hh"
0037 
0038 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0039 
0040 RunAction::RunAction(PrimaryGeneratorAction* prim)
0041   : G4UserRunAction(), fRun(nullptr), fHistoManager(nullptr), fPrimary(prim)
0042 {
0043   fHistoManager = new HistoManager();
0044 }
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 
0048 RunAction::~RunAction()
0049 {
0050   delete fHistoManager;
0051 }
0052 
0053 G4Run* RunAction::GenerateRun()
0054 {
0055   fRun = new Run();
0056   return fRun;
0057 }
0058 
0059 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0060 
0061 void RunAction::BeginOfRunAction(const G4Run*)
0062 {
0063   if (fPrimary) {
0064     G4ParticleDefinition* particle = fPrimary->GetParticleGun()->GetParticleDefinition();
0065     G4double energy = fPrimary->GetParticleGun()->GetParticleEnergy();
0066     G4bool polarized = fPrimary->GetPolarized();
0067     G4double polarization = fPrimary->GetPolarization();
0068     fRun->SetPrimary(particle, energy, polarized, polarization);
0069   }
0070 
0071   // histograms
0072   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0073   if (analysisManager->IsActive()) {
0074     analysisManager->OpenFile();
0075   }
0076 }
0077 
0078 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0079 
0080 void RunAction::EndOfRunAction(const G4Run*)
0081 {
0082   if (isMaster) fRun->EndOfRun();
0083 
0084   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0085 
0086   G4cout << G4endl << " Histogram statistics for the ";
0087   if (isMaster) {
0088     G4cout << "entire run:" << G4endl << G4endl;
0089   }
0090   else {
0091     G4cout << "local thread:" << G4endl << G4endl;
0092   }
0093 
0094   G4int id = analysisManager->GetH1Id("Cerenkov spectrum");
0095   if (analysisManager->GetH1Activation(id)) {
0096     G4cout << " Cerenkov spectrum: mean = " << analysisManager->GetH1(id)->mean()
0097            << " eV; rms = " << analysisManager->GetH1(id)->rms() << " eV." << G4endl;
0098   }
0099   id = analysisManager->GetH1Id("Scintillation spectrum");
0100   if (analysisManager->GetH1Activation(id)) {
0101     G4cout << " Scintillation spectrum: mean = " << analysisManager->GetH1(id)->mean()
0102            << " eV; rms = " << analysisManager->GetH1(id)->rms() << " eV." << G4endl;
0103   }
0104   id = analysisManager->GetH1Id("Scintillation time");
0105   if (analysisManager->GetH1Activation(id)) {
0106     G4cout << " Scintillation time: mean = " << analysisManager->GetH1(id)->mean()
0107            << " ns; rms = " << analysisManager->GetH1(id)->rms() << " ns." << G4endl;
0108   }
0109   id = analysisManager->GetH1Id("WLS abs");
0110   if (analysisManager->GetH1Activation(id)) {
0111     G4cout << " WLS absorption spectrum: mean = " << analysisManager->GetH1(id)->mean()
0112            << " eV; rms = " << analysisManager->GetH1(id)->rms() << " eV." << G4endl;
0113   }
0114   id = analysisManager->GetH1Id("WLS em");
0115   if (analysisManager->GetH1Activation(id)) {
0116     G4cout << " WLS emission spectrum: mean = " << analysisManager->GetH1(id)->mean()
0117            << " eV; rms = " << analysisManager->GetH1(id)->rms() << " eV." << G4endl;
0118   }
0119   id = analysisManager->GetH1Id("WLS time");
0120   if (analysisManager->GetH1Activation(id)) {
0121     G4cout << " WLS emission time: mean = " << analysisManager->GetH1(id)->mean()
0122            << " ns; rms = " << analysisManager->GetH1(id)->rms() << " ns." << G4endl;
0123   }
0124   id = analysisManager->GetH1Id("WLS2 abs");
0125   if (analysisManager->GetH1Activation(id)) {
0126     G4cout << " WLS emission time: mean = " << analysisManager->GetH1(id)->mean()
0127            << " ns; rms = " << analysisManager->GetH1(id)->rms() << " ns." << G4endl;
0128   }
0129   id = analysisManager->GetH1Id("WLS2 em");
0130   if (analysisManager->GetH1Activation(id)) {
0131     G4cout << " WLS2 emission spectrum: mean = " << analysisManager->GetH1(id)->mean()
0132            << " eV; rms = " << analysisManager->GetH1(id)->rms() << " eV." << G4endl;
0133   }
0134   id = analysisManager->GetH1Id("WLS2 time");
0135   if (analysisManager->GetH1Activation(id)) {
0136     G4cout << " WLS2 emission time: mean = " << analysisManager->GetH1(id)->mean()
0137            << " ns; rms = " << analysisManager->GetH1(id)->rms() << " ns." << G4endl;
0138   }
0139   id = analysisManager->GetH1Id("x_backward");
0140   if (analysisManager->GetH1Activation(id)) {
0141     G4cout << " X momentum dir of backward-going photons: mean = "
0142            << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms()
0143            << G4endl;
0144   }
0145   id = analysisManager->GetH1Id("y_backward");
0146   if (analysisManager->GetH1Activation(id)) {
0147     G4cout << " Y momentum dir of backward-going photons: mean = "
0148            << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms()
0149            << G4endl;
0150   }
0151   id = analysisManager->GetH1Id("z_backward");
0152   if (analysisManager->GetH1Activation(id)) {
0153     G4cout << " Z momentum dir of backward-going photons: mean = "
0154            << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms()
0155            << G4endl;
0156   }
0157   id = analysisManager->GetH1Id("x_forward");
0158   if (analysisManager->GetH1Activation(id)) {
0159     G4cout << " X momentum dir of forward-going photons: mean = "
0160            << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms()
0161            << G4endl;
0162   }
0163   id = analysisManager->GetH1Id("y_forward");
0164   if (analysisManager->GetH1Activation(id)) {
0165     G4cout << " Y momentum dir of forward-going photons: mean = "
0166            << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms()
0167            << G4endl;
0168   }
0169   id = analysisManager->GetH1Id("z_forward");
0170   if (analysisManager->GetH1Activation(id)) {
0171     G4cout << " Z momentum dir of forward-going photons: mean = "
0172            << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms()
0173            << G4endl;
0174   }
0175   id = analysisManager->GetH1Id("x_fresnel");
0176   if (analysisManager->GetH1Activation(id)) {
0177     G4cout << " X momentum dir of Fresnel-refracted photons: mean = "
0178            << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms()
0179            << G4endl;
0180   }
0181   id = analysisManager->GetH1Id("y_fresnel");
0182   if (analysisManager->GetH1Activation(id)) {
0183     G4cout << " Y momentum dir of Fresnel-refracted photons: mean = "
0184            << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms()
0185            << G4endl;
0186   }
0187   id = analysisManager->GetH1Id("z_fresnel");
0188   if (analysisManager->GetH1Activation(id)) {
0189     G4cout << " Z momentum dir of Fresnel-refracted photons: mean = "
0190            << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms()
0191            << G4endl;
0192   }
0193   id = analysisManager->GetH1Id("Transmitted");
0194   if (analysisManager->GetH1Activation(id)) {
0195     G4cout << " Angle of transmitted photons: mean = " << analysisManager->GetH1(id)->mean()
0196            << "; rms = " << analysisManager->GetH1(id)->rms() << G4endl;
0197   }
0198   id = analysisManager->GetH1Id("Fresnel reflection");
0199   if (analysisManager->GetH1Activation(id)) {
0200     G4cout << " Angle of Fresnel-reflected photons: mean = " << analysisManager->GetH1(id)->mean()
0201            << "; rms = " << analysisManager->GetH1(id)->rms() << G4endl;
0202   }
0203   id = analysisManager->GetH1Id("Total internal reflection");
0204   if (analysisManager->GetH1Activation(id)) {
0205     G4cout << " Angle of total internal reflected photons: mean = "
0206            << analysisManager->GetH1(id)->mean() << "; rms = " << analysisManager->GetH1(id)->rms()
0207            << G4endl;
0208   }
0209 
0210   id = analysisManager->GetH1Id("Fresnel refraction");
0211   if (analysisManager->GetH1Activation(id)) {
0212     G4cout << " Angle of Fresnel-refracted photons: mean = " << analysisManager->GetH1(id)->mean()
0213            << "; rms = " << analysisManager->GetH1(id)->rms() << G4endl;
0214   }
0215 
0216   id = analysisManager->GetH1Id("Absorption");
0217   if (analysisManager->GetH1Activation(id)) {
0218     G4cout << " Angle of absorbed photons: mean = " << analysisManager->GetH1(id)->mean()
0219            << "; rms = " << analysisManager->GetH1(id)->rms() << G4endl;
0220   }
0221 
0222   G4cout << G4endl;
0223 
0224   if (analysisManager->IsActive()) {
0225     analysisManager->Write();
0226     analysisManager->CloseFile();
0227   }
0228 }
0229 
0230 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......