Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:21:48

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 // ********************************************************************
0027 //
0028 //  CaTS (Calorimetry and Tracking Simulation)
0029 //
0030 //  Authors : Hans Wenzel
0031 //            Soon Yung Jun
0032 //            (Fermi National Accelerator Laboratory)
0033 //
0034 // History
0035 //   October 18th, 2021 : first implementation
0036 //
0037 // ********************************************************************
0038 //
0039 /// \file RunAction.cc
0040 /// \brief Implementation of the CaTS::RunAction class
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 // project headers
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         // Create the generic analysis manager
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         // Book histograms, ntuple
0075         //
0076         // Creating 1D histograms
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; // required for alignment
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; // -1:means no angular info
0104                 int sensor_identifier =
0105                         0xc0ffee + i; // mockup a detector specific identifier
0106                 unsigned sensorIndex = 1 + i; // 1-based
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 }