Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-04 07:52:23

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 fAnalysisManager::RunAction class
0028 
0029 #include "RunAction.hh"
0030 
0031 #include "DetectorConstruction.hh"
0032 #include "EmAcceptance.hh"
0033 #include "PrimaryGeneratorAction.hh"
0034 #include "Run.hh"
0035 #include "RunActionMessenger.hh"
0036 
0037 #include "G4Run.hh"
0038 #include "G4RunManager.hh"
0039 #include "G4SystemOfUnits.hh"
0040 #include "Randomize.hh"
0041 
0042 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0043 
0044 RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* kin) : fDet(det), fKin(kin)
0045 {
0046   fRunMessenger = new RunActionMessenger(this);
0047 
0048   // Create analysis manager
0049   // The choice of analysis technology is done via selection of a namespace
0050   fAnalysisManager = G4AnalysisManager::Instance();
0051   fAnalysisManager->SetDefaultFileType("root");
0052   fAnalysisManager->SetVerboseLevel(1);
0053 
0054   // Set the default file name "testem2"
0055   // which can be then redefine in a macro via UI command
0056   fAnalysisManager->SetFileName("testem2");
0057 }
0058 
0059 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0060 
0061 RunAction::~RunAction()
0062 {
0063   delete fRunMessenger;
0064 }
0065 
0066 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0067 
0068 void RunAction::BookHisto()
0069 {
0070   // Open an output file
0071   fAnalysisManager->OpenFile();
0072 
0073   // Creating histograms
0074   //
0075   G4double Ekin = fKin->GetParticleGun()->GetParticleEnergy();
0076   G4int nLbin = fDet->GetnLtot();
0077   G4int nRbin = fDet->GetnRtot();
0078   G4double dLradl = fDet->GetdLradl();
0079   G4double dRradl = fDet->GetdRradl();
0080 
0081   fAnalysisManager->SetFirstHistoId(1);
0082   fAnalysisManager->CreateH1("h1", "total energy deposit(percent of Einc)", 110, 0., 110.);
0083 
0084   fAnalysisManager->CreateH1("h2", "total charged tracklength (radl)", 110, 0., 110. * Ekin / GeV);
0085 
0086   fAnalysisManager->CreateH1("h3", "total neutral tracklength (radl)", 110, 0., 1100. * Ekin / GeV);
0087 
0088   fAnalysisManager->CreateH1("h4", "longit energy profile (% of E inc)", nLbin, 0., nLbin * dLradl);
0089 
0090   fAnalysisManager->CreateP1("p4", "longit energy profile (% of E inc)", nLbin, 0., nLbin * dLradl,
0091                              0., 1000.);
0092 
0093   fAnalysisManager->CreateH1("h5", "rms on longit Edep (% of E inc)", nLbin, 0., nLbin * dLradl);
0094 
0095   G4double Zmin = 0.5 * dLradl, Zmax = Zmin + nLbin * dLradl;
0096   fAnalysisManager->CreateH1("h6", "cumul longit energy dep (% of E inc)", nLbin, Zmin, Zmax);
0097 
0098   fAnalysisManager->CreateH1("h7", "rms on cumul longit Edep (% of E inc)", nLbin, Zmin, Zmax);
0099 
0100   fAnalysisManager->CreateH1("h8", "radial energy profile (% of E inc)", nRbin, 0., nRbin * dRradl);
0101 
0102   fAnalysisManager->CreateP1("p8", "radial energy profile (% of E inc)", nRbin, 0., nRbin * dRradl,
0103                              0., 1000.);
0104 
0105   fAnalysisManager->CreateH1("h9", "rms on radial Edep (% of E inc)", nRbin, 0., nRbin * dRradl);
0106 
0107   G4double Rmin = 0.5 * dRradl, Rmax = Rmin + nRbin * dRradl;
0108   fAnalysisManager->CreateH1("h10", "cumul radial energy dep (% of E inc)", nRbin, Rmin, Rmax);
0109 
0110   fAnalysisManager->CreateH1("h11", "rms on cumul radial Edep (% of E inc)", nRbin, Rmin, Rmax);
0111 
0112   G4String fileName = fAnalysisManager->GetFileName();
0113   G4String extension = fAnalysisManager->GetFileType();
0114   G4String fullFileName = fileName + "." + extension;
0115   G4cout << "\n----> Histogram file is opened in " << fullFileName << G4endl;
0116 }
0117 
0118 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0119 
0120 G4Run* RunAction::GenerateRun()
0121 {
0122   fRun = new Run(fDet, fKin);
0123   fRun->SetVerbose(fVerbose);
0124   return fRun;
0125 }
0126 
0127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0128 
0129 void RunAction::BeginOfRunAction(const G4Run*)
0130 {
0131   // show Rndm status
0132   if (isMaster) G4Random::showEngineStatus();
0133 
0134   // histograms
0135   //
0136   BookHisto();
0137 }
0138 
0139 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0140 
0141 void RunAction::EndOfRunAction(const G4Run*)
0142 {
0143   // compute and print statistic
0144   //
0145   if (isMaster) fRun->EndOfRun(fEdeptrue, fRmstrue, fLimittrue);
0146 
0147   // show Rndm status
0148   if (isMaster) G4Random::showEngineStatus();
0149 
0150   // save histos and close analysis
0151   fAnalysisManager->Write();
0152   fAnalysisManager->CloseFile();
0153   fAnalysisManager->Clear();
0154 }
0155 
0156 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0157 
0158 void RunAction::SetEdepAndRMS(G4ThreeVector Value)
0159 {
0160   fEdeptrue = Value(0);
0161   fRmstrue = Value(1);
0162   fLimittrue = Value(2);
0163 }
0164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0165 
0166 void RunAction::SetVerbose(G4int val)
0167 {
0168   fVerbose = val;
0169   if (fRun) fRun->SetVerbose(val);
0170 }
0171 
0172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......