Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-05 08:06:17

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 Par04RunAction.cc
0027 /// \brief Implementation of the Par04RunAction class
0028 
0029 #include "Par04RunAction.hh"
0030 
0031 #include "Par04DetectorConstruction.hh"  // for Par04DetectorConstruction
0032 #include "Par04EventAction.hh"  // for Par04EventAction
0033 
0034 #include "G4AnalysisManager.hh"  // for G4AnalysisManager
0035 
0036 #include <G4GenericAnalysisManager.hh>  // for G4GenericAnalysisManager
0037 #include <G4ThreeVector.hh>  // for G4ThreeVector
0038 #include <G4Types.hh>  // for G4int, G4double
0039 #include <G4UserRunAction.hh>  // for G4UserRunAction
0040 
0041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0042 
0043 Par04RunAction::Par04RunAction(Par04DetectorConstruction* aDetector, Par04EventAction* aEventAction)
0044   : G4UserRunAction(), fDetector(aDetector), fEventAction(aEventAction)
0045 {
0046   // Create analysis manager
0047   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0048   analysisManager->SetDefaultFileType("root");
0049 
0050   // Default filename, can be overriden with /analysis/setFileName
0051   analysisManager->SetFileName("Par04Output");
0052 }
0053 
0054 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0055 
0056 Par04RunAction::~Par04RunAction() = default;
0057 
0058 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0059 
0060 void Par04RunAction::BeginOfRunAction(const G4Run*)
0061 {
0062   // Get analysis manager
0063   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0064 
0065   // Create directories
0066   analysisManager->SetNtupleMerging(true);
0067   analysisManager->SetVerboseLevel(0);
0068 
0069   // Get detector dimensions
0070   G4int cellNumZ = fDetector->GetMeshNbOfCells().z();
0071   G4int cellNumRho = fDetector->GetMeshNbOfCells().x();
0072   G4int cellNumPhi = fDetector->GetMeshNbOfCells().y();
0073   G4double cellSizeZ = fDetector->GetMeshSizeOfCells().z();
0074   G4double cellSizeRho = fDetector->GetMeshSizeOfCells().x();
0075   G4double cellSizePhi = fDetector->GetMeshSizeOfCells().y();
0076   // Default max value of energy stored in histogram (in GeV)
0077   G4double maxEnergy = 1000;
0078 
0079   // Creating control histograms
0080   analysisManager->CreateH1("energyParticle", "Primary energy;E_{MC} (GeV);Entries", 1024, 0,
0081                             1.1 * maxEnergy);
0082   analysisManager->CreateH1("energyDepositedInVirtual", "Deposited energy;E_{MC} (GeV);Entries",
0083                             1024, 0, 1.1 * maxEnergy);
0084   analysisManager->CreateH1("energyRatioInVirtual",
0085                             "Ratio of energy deposited to primary;E_{dep} /  E_{MC};Entries", 1024,
0086                             0, 1);
0087   analysisManager->CreateH1("time", "Simulation time; time (s);Entries", 2048, 0, 100);
0088   analysisManager->CreateH1("longProfile", "Longitudinal profile;t (mm);#LTE#GT (MeV)", cellNumZ,
0089                             -0.5 * cellSizeZ, (cellNumZ - 0.5) * cellSizeZ);
0090   analysisManager->CreateH1("transProfile", "Transverse profile;r (mm);#LTE#GT (MeV)", cellNumRho,
0091                             -0.5 * cellSizeRho, (cellNumRho - 0.5) * cellSizeRho);
0092   analysisManager->CreateH1("longFirstMoment",
0093                             "First moment of longitudinal distribution;#LT#lambda#GT (mm);Entries",
0094                             1024, -0.5 * cellSizeZ,
0095                             cellNumZ * cellSizeZ / 2);  // arbitrary scaling of max value on axis
0096   analysisManager->CreateH1("transFirstMoment",
0097                             "First moment of transverse distribution;#LTr#GT "
0098                             "(mm);Entries",
0099                             1024, -0.5 * cellSizeRho,
0100                             cellNumRho * cellSizeRho
0101                               / 1);  // arbitrary scaling of max value on axis
0102   analysisManager->CreateH1(
0103     "longSecondMoment",
0104     "Second moment of longitudinal distribution;#LT#lambda^{2}#GT "
0105     "(mm^{2});Entries",
0106     1024, 0, std::pow(cellNumZ * cellSizeZ, 2) / 25);  // arbitrary scaling of max value on axis
0107   analysisManager->CreateH1(
0108     "transSecondMoment", "Second moment of transverse distribution;#LTr^{2}#GT (mm^{2});Entries",
0109     1024, 0, std::pow(cellNumRho * cellSizeRho, 2) / 5);  // arbitrary scaling of max value on axis
0110   analysisManager->CreateH1("hitType", "hit type;type (0=full, 1= fast);Entries", 2, -0.5, 1.5);
0111   analysisManager->CreateH1(
0112     "phiProfile", "Azimuthal angle profile, centred at mean;phi;#LTE#GT (MeV)", cellNumPhi,
0113     -(cellNumPhi - 0.5) * cellSizePhi, (cellNumPhi - 0.5) * cellSizePhi);
0114   analysisManager->CreateH1("numHitsInVirtual", "Number of hits above 0.5 keV", 4048, 0, 20000);
0115   analysisManager->CreateH1("cellEnergy", "Cell energy distribution;log10(E/MeV);Entries", 1024, -4,
0116                             2);
0117   analysisManager->CreateH1("numDepositsInVirtual", "Number of deposits in all cells per event",
0118                             4048, 0, 40000);
0119   analysisManager->CreateH1("cellDepositsInVirtual",
0120                             "Distribution of number of deposits per cell per event", 4048, 0, 1024);
0121   analysisManager->CreateH1("energyDepositedInPhysical",
0122                             "Deposited energy in physical detector readout;E_{MC} (GeV);Entries",
0123                             1024, 0, 1.1 * maxEnergy);
0124   analysisManager->CreateH1(
0125     "energyRatioInPhysical",
0126     "Ratio of energy deposited in physical readout to primary; E_{dep} /  E_{MC};Entries", 1024, 0,
0127     1);
0128   analysisManager->CreateH1("numHitsInPhysical", "Number of hits in physical readout above 0.5 keV",
0129                             4048, 0, 5000);
0130   analysisManager->CreateH1("cellEnergyInPhysical",
0131                             "Physical cell energy distribution;log10(E/MeV);Entries", 1024, -4, 2);
0132   analysisManager->CreateH1("numDepositsInPhysical",
0133                             "Number of deposits in all physical cells per event", 4048, 0, 40000);
0134   analysisManager->CreateH1("cellDepositsInPhysical",
0135                             "Distribution of number of deposits per physical cell per event", 4048,
0136                             0, 1024);
0137 
0138   // Creating ntuple
0139   analysisManager->CreateNtuple("global", "Event data");
0140   analysisManager->CreateNtupleDColumn("EnergyMC");
0141   analysisManager->CreateNtupleDColumn("SimTime");
0142   analysisManager->FinishNtuple();
0143 
0144   analysisManager->CreateNtuple("virtualReadout", "Cylindrical mesh readout");
0145   analysisManager->CreateNtupleDColumn("EnergyCell", fEventAction->GetCalEdep());
0146   analysisManager->CreateNtupleIColumn("rhoCell", fEventAction->GetCalRho());
0147   analysisManager->CreateNtupleIColumn("phiCell", fEventAction->GetCalPhi());
0148   analysisManager->CreateNtupleIColumn("zCell", fEventAction->GetCalZ());
0149   analysisManager->FinishNtuple();
0150 
0151   analysisManager->CreateNtuple("physicalReadout", "Detector physical readout");
0152   analysisManager->CreateNtupleDColumn("EnergyCell", fEventAction->GetPhysicalCalEdep());
0153   analysisManager->CreateNtupleIColumn("layerCell", fEventAction->GetPhysicalCalLayer());
0154   analysisManager->CreateNtupleIColumn("rowCell", fEventAction->GetPhysicalCalRow());
0155   analysisManager->CreateNtupleIColumn("sliceCell", fEventAction->GetPhysicalCalSlice());
0156   analysisManager->FinishNtuple();
0157 
0158   analysisManager->OpenFile();
0159 }
0160 
0161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0162 
0163 void Par04RunAction::EndOfRunAction(const G4Run*)
0164 {
0165   auto analysisManager = G4AnalysisManager::Instance();
0166   analysisManager->Write();
0167   analysisManager->CloseFile();
0168 }