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