Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:22:13

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 //      GEANT 4 class implementation file
0029 //      CERN Geneva Switzerland
0030 //
0031 //
0032 //      ------------ GammaRayTelRunAction  ------
0033 //           by R.Giannitrapani, F.Longo & G.Santin (13 nov 2000)
0034 // 18.11.2001 G.Santin
0035 // - Modified the analysis management according to the new design
0036 //
0037 // ************************************************************
0038 
0039 #include "GammaRayTelRunAction.hh"
0040 #include "GammaRayTelAnalysis.hh"
0041 
0042 #include <cstdlib>
0043 
0044 #include "G4ios.hh"
0045 #include "G4Run.hh"
0046 #include "G4Threading.hh"
0047 #include "G4UImanager.hh"
0048 #include "G4VVisManager.hh"
0049 
0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0051 
0052 GammaRayTelRunAction::GammaRayTelRunAction() {
0053 }
0054 
0055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0056 
0057 GammaRayTelRunAction::~GammaRayTelRunAction() {
0058 }
0059 
0060 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0061 
0062 void GammaRayTelRunAction::BeginOfRunAction(const G4Run *run) {
0063     fRunID = run->GetRunID();
0064 
0065     // Master mode or sequential
0066     if (IsMaster()) {
0067         G4cout << "### Run " << run->GetRunID() << " starts (master)." << G4endl;
0068     } else {
0069         G4cout << "### Run " << run->GetRunID() << " starts (worker)." << G4endl;
0070     }
0071 
0072     // Prepare the visualization
0073     if (G4VVisManager::GetConcreteInstance() != nullptr) {
0074         auto *userInterface = G4UImanager::GetUIpointer();
0075         userInterface->ApplyCommand("/vis/scene/notifyHandlers");
0076     }
0077 
0078     // If analysis is used reset the histograms
0079     auto *analysis = GammaRayTelAnalysis::getInstance();
0080     // analysis->BeginOfRun(run->GetRunID());
0081     analysis->BeginOfRun();
0082 }
0083 
0084 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0085 
0086 void GammaRayTelRunAction::EndOfRunAction(const G4Run *run) {
0087     G4cout << "End of Run " << run->GetRunID() << G4endl;
0088 
0089     // Close the file with the hits information
0090 #ifdef G4STORE_DATA
0091     if (outFile != nullptr) {
0092         G4cout << "File " << fileName << G4endl;
0093         outFile->close();
0094         delete outFile;
0095         outFile = nullptr;
0096     }
0097 #endif
0098 
0099     // If analysis is used, print out the histograms
0100     auto *analysis = GammaRayTelAnalysis::getInstance();
0101     analysis->EndOfRun();
0102 }
0103 
0104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0105 
0106 auto GammaRayTelRunAction::GetOutputFile() -> std::ofstream* {
0107     if (outFile == nullptr) {
0108         OpenFile();
0109     }
0110     return outFile;
0111 }
0112 
0113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0114 
0115 void GammaRayTelRunAction::OpenFile() {
0116     // Open the file for the tracks of this run
0117 #ifdef G4STORE_DATA
0118     // check that we are in a worker: returns -1 in a master and -2 in sequential
0119     // one file per thread is produced
0120     // Tracks_runR.N.dat, where R = run number, N = thread ID
0121     std::stringstream name;
0122 
0123     if (G4Threading::G4GetThreadId() >= 0) {
0124         name << "Tracks_run" << fRunID << "." << G4Threading::G4GetThreadId() << ".dat";
0125     } else {
0126         name << "Tracks_run" << fRunID << "." << G4Threading::G4GetThreadId() << ".dat";
0127     }
0128 
0129     if (outFile == nullptr) {
0130         outFile = new std::ofstream;
0131         outFile->open(name.str());
0132         fileName = G4String(name.str());
0133     }
0134     G4cout << "Open file: " << fileName << G4endl;
0135 #endif
0136 }