125 lines
4.5 KiB
C++
125 lines
4.5 KiB
C++
//
|
|
// ********************************************************************
|
|
// * License and Disclaimer *
|
|
// * *
|
|
// * The Geant4 software is copyright of the Copyright Holders of *
|
|
// * the Geant4 Collaboration. It is provided under the terms and *
|
|
// * conditions of the Geant4 Software License, included in the file *
|
|
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
|
// * include a list of copyright holders. *
|
|
// * *
|
|
// * Neither the authors of this software system, nor their employing *
|
|
// * institutes,nor the agencies providing financial support for this *
|
|
// * work make any representation or warranty, express or implied, *
|
|
// * regarding this software system or assume any liability for its *
|
|
// * use. Please see the license in the file LICENSE and URL above *
|
|
// * for the full disclaimer and the limitation of liability. *
|
|
// * *
|
|
// * This code implementation is the result of the scientific and *
|
|
// * technical work of the GEANT4 collaboration. *
|
|
// * By using, copying, modifying or distributing the software (or *
|
|
// * any work based on the software) you agree to acknowledge its *
|
|
// * use in resulting scientific publications, and indicate your *
|
|
// * acceptance of all terms of the Geant4 Software license. *
|
|
// ********************************************************************
|
|
//
|
|
//
|
|
/// \file B4/B4a/src/RunAction.cc
|
|
/// \brief Implementation of the B4::RunAction class
|
|
|
|
#include "RunAction.hh"
|
|
|
|
#include "G4AnalysisManager.hh"
|
|
#include "G4Run.hh"
|
|
#include "G4RunManager.hh"
|
|
#include "G4UnitsTable.hh"
|
|
#include "G4SystemOfUnits.hh"
|
|
|
|
namespace B4
|
|
{
|
|
|
|
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|
|
|
RunAction::RunAction()
|
|
{
|
|
// set printing event number per each event
|
|
G4RunManager::GetRunManager()->SetPrintProgress(1);
|
|
|
|
// Create analysis manager
|
|
// The choice of the output format is done via the specified
|
|
// file extension.
|
|
auto analysisManager = G4AnalysisManager::Instance();
|
|
|
|
// Create directories
|
|
//analysisManager->SetHistoDirectoryName("histograms");
|
|
//analysisManager->SetNtupleDirectoryName("ntuple");
|
|
analysisManager->SetVerboseLevel(1);
|
|
analysisManager->SetNtupleMerging(true);
|
|
// Note: merging ntuples is available only with Root output
|
|
|
|
// Book histograms, ntuple
|
|
//
|
|
|
|
// Creating ntuple
|
|
//
|
|
analysisManager->CreateNtuple("Hits", "Hits");
|
|
|
|
analysisManager->CreateNtupleDColumn("true_energy");
|
|
analysisManager->CreateNtupleDColumn("total_dep_energy");
|
|
analysisManager->CreateNtupleIColumn("N_layers");
|
|
analysisManager->CreateNtupleIColumn("N_sensors");
|
|
|
|
analysisManager->CreateNtupleDColumn("sensor_energy",hitEnergy);
|
|
analysisManager->CreateNtupleDColumn("sensor_x",hitX);
|
|
analysisManager->CreateNtupleDColumn("sensor_y",hitY);
|
|
analysisManager->CreateNtupleDColumn("sensor_z",hitZ);
|
|
analysisManager->CreateNtupleDColumn("sensor_dx",hitDX);
|
|
analysisManager->CreateNtupleDColumn("sensor_dy",hitDY);
|
|
analysisManager->CreateNtupleDColumn("sensor_dz",hitDZ);
|
|
analysisManager->CreateNtupleIColumn("sensor_layer",hitLayer);
|
|
analysisManager->CreateNtupleIColumn("sensor_copy_number",hitCopyNumber);
|
|
|
|
|
|
analysisManager->FinishNtuple();
|
|
}
|
|
|
|
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|
|
|
void RunAction::BeginOfRunAction(const G4Run* /*run*/)
|
|
{
|
|
//inform the runManager to save random number seed
|
|
//G4RunManager::GetRunManager()->SetRandomNumberStore(true);
|
|
|
|
// Get analysis manager
|
|
auto analysisManager = G4AnalysisManager::Instance();
|
|
|
|
// Open an output file
|
|
//
|
|
G4String fileName = "B4.root";
|
|
// Other supported output types:
|
|
// G4String fileName = "B4.csv";
|
|
// G4String fileName = "B4.hdf5";
|
|
// G4String fileName = "B4.xml";
|
|
analysisManager->OpenFile(fileName);
|
|
G4cout << "Using " << analysisManager->GetType() << G4endl;
|
|
}
|
|
|
|
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|
|
|
void RunAction::EndOfRunAction(const G4Run* /*run*/)
|
|
{
|
|
// print histogram statistics
|
|
//
|
|
auto analysisManager = G4AnalysisManager::Instance();
|
|
|
|
|
|
// save histograms & ntuple
|
|
//
|
|
analysisManager->Write();
|
|
analysisManager->CloseFile();
|
|
}
|
|
|
|
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
|
|
|
}
|