File indexing completed on 2026-05-13 08:05:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "RunAction.hh"
0030
0031 #include "DetectorConstruction.hh"
0032 #include "PrimaryGeneratorAction.hh"
0033 #include "Run.hh"
0034 #include "RunActionMessenger.hh"
0035
0036 #include "G4AnalysisManager.hh"
0037 #include "G4EmCalculator.hh"
0038 #include "G4ProductionCutsTable.hh"
0039 #include "G4SystemOfUnits.hh"
0040 #include "G4UnitsTable.hh"
0041 #include "G4ios.hh"
0042 #include "Randomize.hh"
0043
0044
0045
0046 RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* kin)
0047 : fDetector(det), fKinematic(kin)
0048 {
0049 fMessenger = new RunActionMessenger(this);
0050 fBinLength = 5 * CLHEP::mm;
0051 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0052 analysisManager->SetFileName("monopole.root");
0053 analysisManager->SetVerboseLevel(1);
0054 analysisManager->SetActivation(true);
0055 }
0056
0057
0058
0059 RunAction::~RunAction()
0060 {
0061 if (isMaster && G4Threading::IsMultithreadedApplication()) delete fKinematic;
0062
0063 delete fMessenger;
0064 }
0065
0066
0067
0068 G4Run* RunAction::GenerateRun()
0069 {
0070 fRun = new Run(fDetector, fKinematic);
0071 return fRun;
0072 }
0073
0074
0075
0076 void RunAction::BeginOfRunAction(const G4Run* aRun)
0077 {
0078
0079 G4ProductionCutsTable::GetProductionCutsTable()->DumpCouples();
0080
0081 G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
0082
0083
0084 Book();
0085 }
0086
0087
0088
0089 void RunAction::EndOfRunAction(const G4Run*)
0090 {
0091
0092
0093 if (isMaster) fRun->EndOfRun(fBinLength);
0094
0095
0096 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0097 if (analysisManager->IsActive()) {
0098 analysisManager->Write();
0099 analysisManager->CloseFile();
0100 analysisManager->Clear();
0101 }
0102 }
0103
0104
0105
0106 void RunAction::SetBinSize(G4double size)
0107 {
0108 fBinLength = size;
0109 if (fBinLength > fDetector->GetMaxStepSize()) {
0110 fBinLength = fDetector->GetMaxStepSize();
0111 }
0112 }
0113
0114
0115
0116 void RunAction::Book()
0117 {
0118 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0119 analysisManager->SetFirstHistoId(1);
0120
0121 G4double length = fDetector->GetAbsorSizeX();
0122 G4int nbBins = G4lrint(length / fBinLength);
0123
0124
0125 analysisManager->CreateH1("h1", "Edep (MeV/mm) along absorber (mm)", nbBins, 0, length);
0126 analysisManager->CreateH1("h2", "Total DEDX (MeV/mm) of proton", 100, -3., 7.);
0127 analysisManager->CreateH1("h3", "Total DEDX (MeV/mm) of monopole", 100, -3., 7.);
0128 analysisManager->CreateH1("h4", "Range(mm) of proton", 100, -3., 7., "mm");
0129 analysisManager->CreateH1("h5", "Range(mm) of monopole", 100, -3., 7., "mm");
0130 analysisManager->CreateH1("h6", "Restricted DEDX (MeV/mm) of proton", 100, -3., 7.);
0131 analysisManager->CreateH1("h7", "Restricted DEDX (MeV/mm) of monopole", 100, -3., 7.);
0132 analysisManager->CreateH1("h8", "Delta-electron x-section (1/mm) of proton", 100, -3., 7., "mm");
0133 analysisManager->CreateH1("h9", "Delta-electron x-section (1/mm) of monopole", 100, -3., 7.,
0134 "mm");
0135 analysisManager->OpenFile();
0136 }
0137
0138