Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-06 07:55:38

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 /// \file RunAction.cc
0027 /// \brief Implementation of the B4b::RunAction class
0028 
0029 #include "RunAction.hh"
0030 
0031 #include "RunData.hh"
0032 
0033 #include "G4AnalysisManager.hh"
0034 #include "G4Run.hh"
0035 #include "G4RunManager.hh"
0036 #include "G4SystemOfUnits.hh"
0037 #include "G4UnitsTable.hh"
0038 #include "globals.hh"
0039 
0040 namespace B4b
0041 {
0042 
0043 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0044 
0045 RunAction::RunAction()
0046 {
0047   // set printing event number per each event
0048   G4RunManager::GetRunManager()->SetPrintProgress(1);
0049 
0050   // Create analysis manager
0051   // The choice of analysis technology is done via selectin of a namespace
0052   // in Analysis.hh
0053   auto analysisManager = G4AnalysisManager::Instance();
0054 
0055   // Create directories
0056   // analysisManager->SetHistoDirectoryName("histograms");
0057   // analysisManager->SetNtupleDirectoryName("ntuple");
0058   analysisManager->SetVerboseLevel(1);
0059   analysisManager->SetNtupleMerging(true);
0060   // Note: merging ntuples is available only with Root output
0061 
0062   // Book histograms, ntuple
0063   //
0064 
0065   // Creating histograms
0066   analysisManager->CreateH1("Eabs", "Edep in absorber", 110, 0., 330 * MeV);
0067   analysisManager->CreateH1("Egap", "Edep in gap", 100, 0., 30 * MeV);
0068   analysisManager->CreateH1("Labs", "trackL in absorber", 100, 0., 50 * cm);
0069   analysisManager->CreateH1("Lgap", "trackL in gap", 100, 0., 50 * cm);
0070 
0071   // Creating ntuple
0072   //
0073   analysisManager->CreateNtuple("B4", "Edep and TrackL");
0074   analysisManager->CreateNtupleDColumn("Eabs");
0075   analysisManager->CreateNtupleDColumn("Egap");
0076   analysisManager->CreateNtupleDColumn("Labs");
0077   analysisManager->CreateNtupleDColumn("Lgap");
0078   analysisManager->FinishNtuple();
0079 }
0080 
0081 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0082 
0083 G4Run* RunAction::GenerateRun()
0084 {
0085   return (new RunData);
0086 }
0087 
0088 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0089 
0090 void RunAction::BeginOfRunAction(const G4Run* run)
0091 {
0092   G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
0093 
0094   // inform the runManager to save random number seed
0095   // G4RunManager::GetRunManager()->SetRandomNumberStore(true);
0096 
0097   // Get analysis manager
0098   auto analysisManager = G4AnalysisManager::Instance();
0099 
0100   // Open an output file
0101   //
0102   G4String fileName = "B4.root";
0103   // Other supported output types:
0104   // G4String fileName = "B4.csv";
0105   // G4String fileName = "B4.hdf5";
0106   // G4String fileName = "B4.xml";
0107   analysisManager->OpenFile(fileName);
0108   G4cout << "Using " << analysisManager->GetType() << G4endl;
0109 }
0110 
0111 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0112 
0113 void RunAction::EndOfRunAction(const G4Run* /*run*/)
0114 {
0115   // print histogram statistics
0116   //
0117   auto analysisManager = G4AnalysisManager::Instance();
0118   if (analysisManager->GetH1(1)) {
0119     G4cout << G4endl << " ----> print histograms statistic ";
0120     if (isMaster) {
0121       G4cout << "for the entire run " << G4endl << G4endl;
0122     }
0123     else {
0124       G4cout << "for the local thread " << G4endl << G4endl;
0125     }
0126 
0127     G4cout << " EAbs : mean = " << G4BestUnit(analysisManager->GetH1(0)->mean(), "Energy")
0128            << " rms = " << G4BestUnit(analysisManager->GetH1(0)->rms(), "Energy") << G4endl;
0129 
0130     G4cout << " EGap : mean = " << G4BestUnit(analysisManager->GetH1(1)->mean(), "Energy")
0131            << " rms = " << G4BestUnit(analysisManager->GetH1(1)->rms(), "Energy") << G4endl;
0132 
0133     G4cout << " LAbs : mean = " << G4BestUnit(analysisManager->GetH1(2)->mean(), "Length")
0134            << " rms = " << G4BestUnit(analysisManager->GetH1(2)->rms(), "Length") << G4endl;
0135 
0136     G4cout << " LGap : mean = " << G4BestUnit(analysisManager->GetH1(3)->mean(), "Length")
0137            << " rms = " << G4BestUnit(analysisManager->GetH1(3)->rms(), "Length") << G4endl;
0138   }
0139 
0140   // save histograms & ntuple
0141   //
0142   analysisManager->Write();
0143   analysisManager->CloseFile();
0144 }
0145 
0146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0147 
0148 }  // namespace B4b