File indexing completed on 2025-01-31 09:21:48
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
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 #include <G4UserRunAction.hh>
0043 #include "G4Run.hh"
0044 #ifdef WITH_G4OPTICKS
0045 #include "G4TransportationManager.hh"
0046 #include "G4Opticks.hh"
0047 #endif
0048 #ifdef WITH_ROOT
0049 #include "G4AnalysisManager.hh"
0050 #include "RootIO.hh"
0051 #endif
0052
0053 #include "RunAction.hh"
0054 #include "ConfigurationManager.hh"
0055
0056 RunAction::RunAction()
0057 : G4UserRunAction() {
0058 }
0059
0060 void RunAction::BeginOfRunAction(const G4Run*) {
0061 #ifdef WITH_ROOT
0062 if (ConfigurationManager::getInstance()->isdoAnalysis()) {
0063
0064 auto analysisManager = G4AnalysisManager::Instance();
0065 analysisManager->SetDefaultFileType("root");
0066 G4cout << "Using " << analysisManager->GetType() << G4endl;
0067 analysisManager->SetVerboseLevel(1);
0068 G4String HistoFileName =
0069 ConfigurationManager::getInstance()->getHistoFileName();
0070 G4cout << "Opening Analysis output File: " << HistoFileName << G4endl;
0071 analysisManager->SetFileName(HistoFileName);
0072 analysisManager->OpenFile();
0073
0074
0075
0076
0077 analysisManager->CreateH1("ENeutron", "Energy of created Neutrons", 200, 0,
0078 100);
0079 analysisManager->CreateH1("EProton", "Energy of created Protons", 200, 0,
0080 100);
0081 }
0082 #endif
0083 #ifdef WITH_G4OPTICKS
0084 if (ConfigurationManager::getInstance()->isEnable_opticks()) {
0085 if (!geo_initialized) {
0086 G4cout << "\n\n###[ RunAction::BeginOfRunAction G4Opticks.setGeometry\n\n"
0087 << G4endl;
0088 G4VPhysicalVolume* world =
0089 G4TransportationManager::GetTransportationManager()
0090 ->GetNavigatorForTracking()
0091 ->GetWorldVolume();
0092 assert(world);
0093 bool standardize_geant4_materials = false;
0094 G4Opticks* g4ok = G4Opticks::Get();
0095 g4ok->setGeometry(world, standardize_geant4_materials);
0096 const std::vector<G4PVPlacement*>& sensor_placements =
0097 g4ok->getSensorPlacements();
0098 G4cout << "sensor_placements.size(): " << sensor_placements.size()
0099 << G4endl;
0100 for (unsigned i = 0; i < sensor_placements.size(); i++) {
0101 float efficiency_1 = 0.5f;
0102 float efficiency_2 = 1.0f;
0103 int sensor_cat = -1;
0104 int sensor_identifier =
0105 0xc0ffee + i;
0106 unsigned sensorIndex = 1 + i;
0107 g4ok->setSensorData(sensorIndex, efficiency_1, efficiency_2, sensor_cat,
0108 sensor_identifier);
0109 }
0110 G4cout << "\n\n###] RunAction::BeginOfRunAction G4Opticks.setGeometry\n\n"
0111 << G4endl;
0112 geo_initialized = true;
0113 }
0114 }
0115 #endif
0116 }
0117
0118 void RunAction::EndOfRunAction(const G4Run*) {
0119 #ifdef WITH_G4OPTICKS
0120 if (ConfigurationManager::getInstance()->isEnable_opticks()) {
0121 if (ConfigurationManager::getInstance()->isEnable_verbose()) {
0122 G4cout << "\n\n###[ RunAction::EndOfRunAction G4Opticks.Finalize\n\n"
0123 << G4endl;
0124 }
0125 G4Opticks::Finalize();
0126 if (ConfigurationManager::getInstance()->isEnable_verbose()) {
0127 G4cout << "\n\n###] RunAction::EndOfRunAction G4Opticks.Finalize\n\n"
0128 << G4endl;
0129 }
0130 }
0131 #endif
0132 #ifdef WITH_ROOT
0133 if (ConfigurationManager::getInstance()->isEnable_verbose()) {
0134 G4cout << "##############RunAction::EndOfRunAction" << G4endl;
0135 }
0136 if (ConfigurationManager::getInstance()->isWriteHits()) {
0137 if (G4Threading::IsMultithreadedApplication()) {
0138 RootIO::GetInstance()->Merge();
0139 } else {
0140 RootIO::GetInstance()->Close();
0141 }
0142 }
0143 if (ConfigurationManager::getInstance()->isdoAnalysis()) {
0144 auto analysisManager = G4AnalysisManager::Instance();
0145 analysisManager->Write();
0146 analysisManager->CloseFile();
0147 }
0148 #endif
0149 }