![]() |
|
|||
File indexing completed on 2025-02-23 09:20:42
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 RunAction class 0028 // 0029 // 0030 // 0031 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0032 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0033 0034 #include "RunAction.hh" 0035 0036 #include "G4AnalysisManager.hh" 0037 #include "G4GenericMessenger.hh" 0038 #include "G4Run.hh" 0039 #include "G4RunManager.hh" 0040 #include "G4SystemOfUnits.hh" 0041 #include "G4UnitsTable.hh" 0042 0043 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0044 0045 RunAction::RunAction() 0046 { 0047 // Create or get analysis manager 0048 // The choice of analysis technology is done via selection of a namespace 0049 // in HistoManager.hh 0050 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 0051 analysisManager->SetDefaultFileType("root"); 0052 analysisManager->SetVerboseLevel(1); 0053 // Only merge in MT mode to avoid warning when running in Sequential mode 0054 #ifdef G4MULTITHREADED 0055 analysisManager->SetNtupleMerging(true); 0056 #endif 0057 0058 // Create directories 0059 analysisManager->SetHistoDirectoryName("histo"); 0060 analysisManager->SetNtupleDirectoryName("ntuple"); 0061 0062 // Create histograms. 0063 // Histogram ids are generated automatically starting from 0. 0064 // The start value can be changed by: 0065 // analysisManager->SetFirstHistoId(1); 0066 0067 // id = 0 0068 analysisManager->CreateH1("EAbs", "Edep in absorber (MeV)", 100, 0., 800 * MeV); 0069 // id = 1 0070 analysisManager->CreateH1("EGap", "Edep in gap (MeV)", 100, 0., 100 * MeV); 0071 // id = 2 0072 analysisManager->CreateH1("LAbs", "trackL in absorber (mm)", 100, 0., 1 * m); 0073 // id = 3 0074 analysisManager->CreateH1("LGap", "trackL in gap (mm)", 100, 0., 50 * cm); 0075 0076 // Create ntuples. 0077 // Ntuples ids are generated automatically starting from 0. 0078 // The start value can be changed by: 0079 // analysisManager->SetFirstMtupleId(1); 0080 0081 // Create 1st ntuple (id = 0) 0082 analysisManager->CreateNtuple("Ntuple1", "Edep"); 0083 analysisManager->CreateNtupleDColumn("Eabs"); // column Id = 0 0084 analysisManager->CreateNtupleDColumn("Egap"); // column Id = 1 0085 analysisManager->FinishNtuple(); 0086 0087 // Create 2nd ntuple (id = 1) 0088 // 0089 analysisManager->CreateNtuple("Ntuple2", "TrackL"); 0090 analysisManager->CreateNtupleDColumn("Labs"); // column Id = 0 0091 analysisManager->CreateNtupleDColumn("Lgap"); // column Id = 1 0092 analysisManager->FinishNtuple(); 0093 0094 DefineCommands(); 0095 } 0096 0097 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0098 0099 RunAction::~RunAction() = default; 0100 0101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0102 0103 void RunAction::BeginOfRunAction(const G4Run* run) 0104 { 0105 G4cout << "### Run " << run->GetRunID() << " start." << G4endl; 0106 } 0107 0108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0109 0110 void RunAction::EndOfRunAction(const G4Run* /*run*/) {} 0111 0112 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0113 0114 void RunAction::PrintStatistic() 0115 { 0116 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 0117 0118 G4cout << "\n ----> print histograms statistic \n" << G4endl; 0119 for (G4int i = 0; i < analysisManager->GetNofH1s(); ++i) { 0120 auto h1 = analysisManager->GetH1(i); 0121 // skip if histogram was deleted 0122 if (h1 == nullptr) continue; 0123 0124 G4String name = analysisManager->GetH1Name(i); 0125 G4String unitCategory; 0126 if (name[0U] == 'E') { 0127 unitCategory = "Energy"; 0128 } 0129 if (name[0U] == 'L') { 0130 unitCategory = "Length"; 0131 } 0132 // we use an explicit unsigned int type for operator [] argument 0133 // to avoid problems with windows compiler 0134 0135 G4cout << name << ": mean = " << G4BestUnit(h1->mean(), unitCategory) 0136 << " rms = " << G4BestUnit(h1->rms(), unitCategory) << G4endl; 0137 } 0138 } 0139 0140 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0141 0142 void RunAction::DefineCommands() 0143 { 0144 // Define /AnaEx03/runAction command directory using generic messenger class 0145 fMessenger = new G4GenericMessenger(this, "/AnaEx03/runAction/", "Run action commands"); 0146 0147 // printStatistic command 0148 auto& printStatisticCmd = fMessenger->DeclareMethod("printStatistic", &RunAction::PrintStatistic, 0149 "Print statistic at the end of Run."); 0150 printStatisticCmd.SetToBeBroadcasted(false); 0151 } 0152 0153 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |