Back to home page

EIC code displayed by LXR

 
 

    


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

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 B5/src/RunAction.cc
0028 /// \brief Implementation of the B5::RunAction class
0029 
0030 #include "RunAction.hh"
0031 
0032 #include "EventAction.hh"
0033 
0034 #include "G4AnalysisManager.hh"
0035 
0036 namespace B5
0037 {
0038 
0039 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0040 
0041 RunAction::RunAction(EventAction* eventAction) : fEventAction(eventAction)
0042 {
0043   // Create the generic analysis manager
0044   auto analysisManager = G4AnalysisManager::Instance();
0045   analysisManager->SetDefaultFileType("root");
0046   // If the filename extension is not provided, the default file type (root)
0047   // will be used for all files specified without extension.
0048   analysisManager->SetVerboseLevel(1);
0049 
0050   // Default settings
0051   analysisManager->SetNtupleMerging(true);
0052   // Note: merging ntuples is available only with Root output
0053   analysisManager->SetFileName("B5");
0054 
0055   // Book histograms, ntuple
0056 
0057   // Creating 1D histograms
0058   analysisManager->CreateH1("Chamber1", "Drift Chamber 1 # Hits", 50, 0., 50);  // h1 Id = 0
0059   analysisManager->CreateH1("Chamber2", "Drift Chamber 2 # Hits", 50, 0., 50);  // h1 Id = 1
0060 
0061   // Creating 2D histograms
0062   analysisManager->CreateH2("Chamber1 XY", "Drift Chamber 1 X vs Y",  // h2 Id = 0
0063                             50, -1000., 1000, 50, -300., 300.);
0064   analysisManager->CreateH2("Chamber2 XY", "Drift Chamber 2 X vs Y",  // h2 Id = 1
0065                             50, -1500., 1500, 50, -300., 300.);
0066 
0067   // Creating ntuple
0068   if (fEventAction) {
0069     analysisManager->CreateNtuple("B5", "Hits");
0070     analysisManager->CreateNtupleIColumn("Dc1Hits");  // column Id = 0
0071     analysisManager->CreateNtupleIColumn("Dc2Hits");  // column Id = 1
0072     analysisManager->CreateNtupleDColumn("ECEnergy");  // column Id = 2
0073     analysisManager->CreateNtupleDColumn("HCEnergy");  // column Id = 3
0074     analysisManager->CreateNtupleDColumn("Time1");  // column Id = 4
0075     analysisManager->CreateNtupleDColumn("Time2");  // column Id = 5
0076     analysisManager  // column Id = 6
0077       ->CreateNtupleDColumn("ECEnergyVector", fEventAction->GetEmCalEdep());
0078     analysisManager  // column Id = 7
0079       ->CreateNtupleDColumn("HCEnergyVector", fEventAction->GetHadCalEdep());
0080     analysisManager->FinishNtuple();
0081   }
0082 
0083   // Set ntuple output file
0084   analysisManager->SetNtupleFileName(0, "B5ntuple");
0085 }
0086 
0087 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0088 
0089 void RunAction::BeginOfRunAction(const G4Run* /*run*/)
0090 {
0091   // inform the runManager to save random number seed
0092   // G4RunManager::GetRunManager()->SetRandomNumberStore(true);
0093 
0094   // Get analysis manager
0095   auto analysisManager = G4AnalysisManager::Instance();
0096 
0097   // Reset histograms from previous run
0098   analysisManager->Reset();
0099 
0100   // Open an output file
0101   // The default file name is set in RunAction::RunAction(),
0102   // it can be overwritten in a macro
0103   analysisManager->OpenFile();
0104 }
0105 
0106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0107 
0108 void RunAction::EndOfRunAction(const G4Run* /*run*/)
0109 {
0110   // save histograms & ntuple
0111   //
0112   auto analysisManager = G4AnalysisManager::Instance();
0113   analysisManager->Write();
0114   analysisManager->CloseFile(false);
0115   // Keep content of histos so that they are plotted.
0116   // The content will be reset at start of the next run.
0117 }
0118 
0119 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0120 
0121 }  // namespace B5