Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:20:57

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