Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:29:14

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 /// \file FlashRunAction.cc
0028 /// \brief Implementation of the FlashRunAction class
0029 
0030 #include "FlashRunAction.hh"
0031 
0032 #include "FlashPrimaryGeneratorAction.hh"
0033 #include "G4LogicalVolume.hh"
0034 #include "G4Run.hh"
0035 #include "G4RunManager.hh"
0036 #include "G4SystemOfUnits.hh"
0037 #include "G4UnitsTable.hh"
0038 
0039 #include "G4AnalysisManager.hh"
0040 
0041 FlashRunAction::FlashRunAction() : G4UserRunAction()
0042 {
0043   // Create analysis manager
0044   G4AnalysisManager* fAnalysisManager = G4AnalysisManager::Instance();
0045   
0046   // Merging ntuples from multiple root files due to multithreading 
0047   // fAnalysisManager->SetNtupleMerging(true);
0048 
0049   // Creation of ntuple
0050   fAnalysisManager->CreateNtuple("fSensitiveDetector", "fSensitiveDetector");
0051   fAnalysisManager->CreateNtupleDColumn("fX");
0052   fAnalysisManager->CreateNtupleDColumn("fY");
0053   fAnalysisManager->CreateNtupleDColumn("fZ");
0054   fAnalysisManager->CreateNtupleDColumn("fDose");
0055   fAnalysisManager->CreateNtupleDColumn("fEdep");
0056   fAnalysisManager->CreateNtupleIColumn("fEventID");
0057   fAnalysisManager->CreateNtupleIColumn("fParentID");
0058   fAnalysisManager->CreateNtupleSColumn("fParticle");
0059   fAnalysisManager->FinishNtuple(0);
0060 
0061 
0062 }
0063 
0064 FlashRunAction::~FlashRunAction() {}
0065 
0066 void FlashRunAction::BeginOfRunAction(const G4Run *run) {
0067   G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
0068 
0069   // Create analysis manager
0070   G4AnalysisManager* fAnalysisManager = G4AnalysisManager::Instance();
0071   
0072   // Merging ntuples from multiple root files due to multithreading
0073   //fAnalysisManager->SetNtupleMerging(true); // uncomment this only for root files
0074 
0075   // Open an output file
0076   G4int runID = run -> GetRunID();
0077   std::stringstream strRunID;
0078   strRunID << runID;
0079   fAnalysisManager->OpenFile("output_"+strRunID.str()+".csv");
0080   
0081 
0082   G4RunManager::GetRunManager()->SetRandomNumberStore(false);
0083 }
0084 
0085 void FlashRunAction::EndOfRunAction(const G4Run *run) {
0086   G4int nofEvents = run->GetNumberOfEvent();
0087   if (nofEvents == 0)
0088     return;
0089 
0090   // close the output file
0091   G4AnalysisManager* fAnalysisManager = G4AnalysisManager::Instance();
0092   fAnalysisManager->Write();
0093   fAnalysisManager->CloseFile();
0094   
0095 
0096   if (IsMaster()) {
0097     G4cout << G4endl
0098            << "--------------------End of Global Run-----------------------"
0099            << G4endl << "  The run was " << nofEvents << " events ";
0100   } else {
0101     G4cout << G4endl
0102            << "--------------------End of Local Run------------------------"
0103            << G4endl << "  The run was " << nofEvents << " events ";
0104   }
0105   
0106 }