File indexing completed on 2025-01-31 09:22:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #include "RunAction.hh"
0027 #include "EventAction.hh"
0028
0029 #include "G4UserRunAction.hh"
0030 #include "G4GenericMessenger.hh"
0031 #include "G4String.hh"
0032 #include "G4AnalysisManager.hh"
0033 #include <iostream>
0034
0035
0036
0037 RunAction::RunAction(EventAction *eventAction)
0038 : G4UserRunAction(), fEventAction(eventAction),
0039 fOutputFileDir("sim_HGCalTB_G4Standalone") {
0040
0041 fMessenger =
0042 new G4GenericMessenger(this, "/HGCalTestbeam/output/", "Output control");
0043
0044
0045 auto &fileNameCommand = fMessenger->DeclareProperty("file", fOutputFileDir);
0046 G4String guidance = "Define output file location.";
0047 fileNameCommand.SetGuidance(guidance);
0048 fileNameCommand.SetParameterName("filename", true);
0049 fileNameCommand.SetDefaultValue("sim_HGCalTB_G4Standalone");
0050 }
0051
0052
0053
0054 RunAction::~RunAction() {}
0055
0056
0057
0058 void RunAction::BeginOfRunAction(const G4Run *) {
0059
0060
0061 auto analysisManager = G4AnalysisManager::Instance();
0062 analysisManager->SetDefaultFileType("root");
0063 G4cout << "Using " << analysisManager->GetType() << G4endl;
0064
0065
0066 analysisManager->SetNtupleMerging(true);
0067 analysisManager->SetVerboseLevel(1);
0068 std::cout << "Output file is: " << fOutputFileDir << std::endl;
0069 analysisManager->SetFileName(fOutputFileDir);
0070
0071 if (fEventAction) {
0072 analysisManager->CreateNtuple("hits", "hits");
0073 analysisManager->CreateNtupleIColumn("event");
0074 analysisManager->CreateNtupleIColumn(
0075 "pdgID", fEventAction->fPrimariesPDG);
0076 analysisManager->CreateNtupleDColumn(
0077 "beamEnergy", fEventAction->fPrimariesEnergy);
0078 analysisManager->CreateNtupleDColumn(
0079 "beamX_cm", fEventAction->fPrimariesX);
0080 analysisManager->CreateNtupleDColumn(
0081 "beamY_cm", fEventAction->fPrimariesY);
0082 analysisManager->CreateNtupleDColumn(
0083 "beamZ_cm", fEventAction->fPrimariesZ);
0084 analysisManager->CreateNtupleIColumn("siliconHits_ID",
0085 fEventAction->fSiHitsID);
0086 analysisManager->CreateNtupleDColumn("siliconHits_x_cm",
0087 fEventAction->fSiHitsX);
0088 analysisManager->CreateNtupleDColumn("siliconHits_y_cm",
0089 fEventAction->fSiHitsY);
0090 analysisManager->CreateNtupleDColumn("siliconHits_z_cm",
0091 fEventAction->fSiHitsZ);
0092 analysisManager->CreateNtupleDColumn("siliconHits_Edep_keV",
0093 fEventAction->fSiHitsEdep);
0094 analysisManager->CreateNtupleDColumn("siliconHits_EdepNonIonizing_keV",
0095 fEventAction->fSiHitsEdepNonIonising);
0096 analysisManager->CreateNtupleDColumn("siliconHits_TOA_ns",
0097 fEventAction->fSiHitsTOA);
0098 analysisManager->CreateNtupleDColumn("siliconHits_TOA_last_ns",
0099 fEventAction->fSiHitsTOA);
0100 analysisManager->CreateNtupleIColumn("siliconHits_type",
0101 fEventAction->fSiHitsType);
0102
0103 analysisManager->CreateNtupleIColumn("SiPMHits_ID",
0104 fEventAction->fSiPMhitsID);
0105 analysisManager->CreateNtupleDColumn("SiPMHits_x_cm",
0106 fEventAction->fSiPMhitsX);
0107 analysisManager->CreateNtupleDColumn("SiPMHits_y_cm",
0108 fEventAction->fSiPMhitsY);
0109 analysisManager->CreateNtupleDColumn("SiPMHits_z_cm",
0110 fEventAction->fSiPMhitsZ);
0111 analysisManager->CreateNtupleDColumn("SiPMHits_Edep_keV",
0112 fEventAction->fSiPMhitsEdep);
0113 analysisManager->CreateNtupleDColumn(
0114 "SiPMHits_EdepNonIonizing_keV", fEventAction->fSiPMhitsEdepNonIonising);
0115 analysisManager->CreateNtupleDColumn("SiPMHits_TOA_ns",
0116 fEventAction->fSiPMhitsTOA);
0117 analysisManager->CreateNtupleIColumn("SiPMHits_type",
0118 fEventAction->fSiPMhitsType);
0119
0120 analysisManager->CreateNtupleDColumn(
0121 "signalSum_HGCAL_GeV");
0122 analysisManager->CreateNtupleDColumn("COGZ_HGCAL_cm");
0123 analysisManager->CreateNtupleIColumn("NHits_HGCAL");
0124
0125 analysisManager->CreateNtupleDColumn(
0126 "signalSum_AHCAL_GeV");
0127 analysisManager->CreateNtupleDColumn("COGZ_AHCAL_cm");
0128 analysisManager->CreateNtupleIColumn("NHits_AHCAL");
0129 analysisManager->FinishNtuple();
0130 }
0131
0132 analysisManager->OpenFile();
0133 }
0134
0135
0136
0137 void RunAction::EndOfRunAction(const G4Run *) {
0138 auto analysisManager = G4AnalysisManager::Instance();
0139 analysisManager->Write();
0140 analysisManager->CloseFile();
0141 }
0142
0143