Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:22: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 #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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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   // randomizePrimary command
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0053 
0054 RunAction::~RunAction() {}
0055 
0056 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0057 
0058 void RunAction::BeginOfRunAction(const G4Run *) {
0059   // Create analysis manager
0060   // The choice of analysis technology is done via selection of a namespaces
0061   auto analysisManager = G4AnalysisManager::Instance();
0062   analysisManager->SetDefaultFileType("root");
0063   G4cout << "Using " << analysisManager->GetType() << G4endl;
0064 
0065   // Default settings
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"); // column Id = 0
0074     analysisManager->CreateNtupleIColumn(
0075         "pdgID", fEventAction->fPrimariesPDG); // column Id = 1
0076     analysisManager->CreateNtupleDColumn(
0077         "beamEnergy", fEventAction->fPrimariesEnergy); // column Id = 2
0078     analysisManager->CreateNtupleDColumn(
0079         "beamX_cm", fEventAction->fPrimariesX); // column Id = 3
0080     analysisManager->CreateNtupleDColumn(
0081         "beamY_cm", fEventAction->fPrimariesY); // column Id = 4
0082     analysisManager->CreateNtupleDColumn(
0083         "beamZ_cm", fEventAction->fPrimariesZ); // column Id = 5
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");                            // column Id = 23
0122     analysisManager->CreateNtupleDColumn("COGZ_HGCAL_cm"); // column Id = 24
0123     analysisManager->CreateNtupleIColumn("NHits_HGCAL");   // column Id = 25
0124 
0125     analysisManager->CreateNtupleDColumn(
0126         "signalSum_AHCAL_GeV");                            // column Id = 26
0127     analysisManager->CreateNtupleDColumn("COGZ_AHCAL_cm"); // column Id = 27
0128     analysisManager->CreateNtupleIColumn("NHits_AHCAL");   // column Id = 28
0129     analysisManager->FinishNtuple();
0130   }
0131 
0132   analysisManager->OpenFile();
0133 }
0134 
0135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0136 
0137 void RunAction::EndOfRunAction(const G4Run *) {
0138   auto analysisManager = G4AnalysisManager::Instance();
0139   analysisManager->Write();
0140   analysisManager->CloseFile();
0141 }
0142 
0143 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......