Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-21 08:30:22

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 Par03RunAction.cc
0027 /// \brief Implementation of the Par03RunAction class
0028 
0029 #include "Par03RunAction.hh"
0030 
0031 #include "Par03DetectorConstruction.hh"
0032 
0033 #include "G4AnalysisManager.hh"
0034 
0035 Par03RunAction::Par03RunAction(Par03DetectorConstruction* aDetector)
0036   : G4UserRunAction(), fDetector(aDetector)
0037 {
0038   // Create analysis manager
0039   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0040   analysisManager->SetDefaultFileType("root");
0041 
0042   // Default filename, can be overriden with /analysis/setFileName
0043   analysisManager->SetFileName("Par03Output");
0044 }
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 
0048 Par03RunAction::~Par03RunAction() = default;
0049 
0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0051 
0052 void Par03RunAction::BeginOfRunAction(const G4Run*)
0053 {
0054   // Get detector dimensions
0055   G4int cellNumZ = fDetector->GetNbOfLayers();
0056   G4int cellNumRho = fDetector->GetNbOfRhoCells();
0057   G4double cellSizeZ = fDetector->GetLength() / cellNumZ;
0058   G4double cellSizeRho = fDetector->GetRadius() / cellNumRho;
0059   // Default max value of energy stored in histogram (in GeV)
0060   G4double maxEnergy = 100;
0061 
0062   // Get analysis manager
0063   auto analysisManager = G4AnalysisManager::Instance();
0064 
0065   // Creating control histograms
0066   analysisManager->CreateH1("energyParticle", "Primary energy;E_{MC} (GeV);Entries", 256, 0,
0067                             1.1 * maxEnergy);
0068   analysisManager->CreateH1("energyDeposited", "Deposited energy;E_{MC} (GeV);Entries", 256, 0,
0069                             1.1 * maxEnergy);
0070   analysisManager->CreateH1(
0071     "energyRatio", "Ratio of energy deposited to primary;E_{dep} /  E_{MC};Entries", 1024, 0, 1);
0072   analysisManager->CreateH1("time", "Simulation time; time (s);Entries", 2048, 0, 30);
0073   analysisManager->CreateH1("longProfile", "Longitudinal profile;t (mm);#LTE#GT (MeV)", cellNumZ,
0074                             -0.5 * cellSizeZ, (cellNumZ - 0.5) * cellSizeZ);
0075   analysisManager->CreateH1("transProfile", "Transverse profile;r (mm);#LTE#GT (MeV)", cellNumRho,
0076                             -0.5 * cellSizeRho, (cellNumRho - 0.5) * cellSizeRho);
0077   analysisManager->CreateH1("longFirstMoment",
0078                             "First moment of longitudinal distribution;#LT#lambda#GT (mm);Entries",
0079                             1024, -0.5 * cellSizeZ,
0080                             cellNumZ * cellSizeZ / 2);  // arbitrary scaling of max value on axis
0081   analysisManager->CreateH1("transFirstMoment",
0082                             "First moment of transverse distribution;#LTr#GT "
0083                             "(mm);Entries",
0084                             1024, -0.5 * cellSizeRho,
0085                             cellNumRho * cellSizeRho
0086                               / 10);  // arbitrary scaling of max value on axis
0087   analysisManager->CreateH1(
0088     "longSecondMoment",
0089     "Second moment of longitudinal distribution;#LT#lambda^{2}#GT "
0090     "(mm^{2});Entries",
0091     1024, 0, std::pow(cellNumZ * cellSizeZ, 2) / 25);  // arbitrary scaling of max value on axis
0092   analysisManager->CreateH1(
0093     "transSecondMoment", "Second moment of transverse distribution;#LTr^{2}#GT (mm^{2});Entries",
0094     1024, 0, std::pow(cellNumRho * cellSizeRho, 2) / 25);  // arbitrary scaling of max value on axis
0095   analysisManager->CreateH1("hitType", "hit type;type (0=full, 1= fast);Entries", 2, -0.5, 1.5);
0096 
0097   // Open an output file
0098   analysisManager->OpenFile();
0099 }
0100 
0101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0102 
0103 void Par03RunAction::EndOfRunAction(const G4Run*)
0104 {
0105   auto analysisManager = G4AnalysisManager::Instance();
0106   analysisManager->Write();
0107   analysisManager->CloseFile();
0108   analysisManager->Clear();
0109 }