Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:35

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