Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-03 09:04:07

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