Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-15 07:42:21

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 // Authors: S. Meylan and C. Villagrasa (IRSN, France)
0026 // Updated: H. Tran (IRSN), France: 20/12/2018
0027 //
0028 /// \file RunAction.cc
0029 /// \brief Implementation of the RunAction class
0030 
0031 #include "RunAction.hh"
0032 
0033 #include "G4AnalysisManager.hh"
0034 #include "G4Run.hh"
0035 #include "globals.hh"
0036 
0037 #include <map>
0038 
0039 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0040 
0041 RunAction::RunAction() : G4UserRunAction() {}
0042 
0043 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0044 
0045 void RunAction::BeginOfRunAction(const G4Run*)
0046 {
0047   CreateNtuple("output.root");
0048 }
0049 
0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0051 
0052 void RunAction::EndOfRunAction(const G4Run*)
0053 {
0054   WriteNtuple();
0055 }
0056 
0057 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0058 
0059 void RunAction::CreateNtuple(const G4String& name)
0060 {
0061   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0062   analysisManager->SetDefaultFileType("root");
0063   analysisManager->SetVerboseLevel(0);
0064   analysisManager->SetNtupleDirectoryName("ntuple");
0065 
0066   // open output file
0067   //
0068   G4bool fileOpen = analysisManager->OpenFile(name);
0069   if (!fileOpen) {
0070     G4cout << "\n---> HistoManager::book(): cannot open " << name << G4endl;
0071     return;
0072   }
0073 
0074   analysisManager->SetFirstNtupleId(1);
0075   analysisManager->CreateNtuple("ntuple_1", "physical_stage");
0076   analysisManager->CreateNtupleDColumn(1, "x");
0077   analysisManager->CreateNtupleDColumn(1, "y");
0078   analysisManager->CreateNtupleDColumn(1, "z");
0079   analysisManager->CreateNtupleDColumn(1, "edep");
0080   analysisManager->CreateNtupleDColumn(1, "diffKin");
0081   analysisManager->CreateNtupleIColumn(1, "volumeName");
0082   analysisManager->CreateNtupleDColumn(1, "CopyNumber");
0083   analysisManager->CreateNtupleIColumn(1, "EventID");
0084   analysisManager->FinishNtuple(1);
0085 
0086   // For chemistry
0087 
0088   analysisManager->CreateNtuple("ntuple_2", "chem_stage");
0089   analysisManager->CreateNtupleDColumn(2, "x");
0090   analysisManager->CreateNtupleDColumn(2, "y");
0091   analysisManager->CreateNtupleDColumn(2, "z");
0092   analysisManager->CreateNtupleSColumn(2, "RadName");
0093   analysisManager->CreateNtupleIColumn(2, "EventID");
0094   analysisManager->FinishNtuple(2);
0095 
0096   G4cout << "\n----> Histogram file is opened in " << name << G4endl;
0097 }
0098 
0099 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0100 void RunAction::WriteNtuple()
0101 {
0102   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0103   analysisManager->Write();
0104   analysisManager->CloseFile();
0105   analysisManager->Clear();
0106   G4cout << "\n----> Histograms are saved" << G4endl;
0107 }