Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-13 08:05:23

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 #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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0058 
0059 RunAction::~RunAction()
0060 {
0061   if (isMaster && G4Threading::IsMultithreadedApplication()) delete fKinematic;
0062 
0063   delete fMessenger;
0064 }
0065 
0066 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0067 
0068 G4Run* RunAction::GenerateRun()
0069 {
0070   fRun = new Run(fDetector, fKinematic);
0071   return fRun;
0072 }
0073 
0074 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0075 
0076 void RunAction::BeginOfRunAction(const G4Run* aRun)
0077 {
0078   // Dump production cuts
0079   G4ProductionCutsTable::GetProductionCutsTable()->DumpCouples();
0080 
0081   G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
0082   // histograms
0083   //
0084   Book();
0085 }
0086 
0087 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0088 
0089 void RunAction::EndOfRunAction(const G4Run*)
0090 {
0091   // print Run summary
0092   //
0093   if (isMaster) fRun->EndOfRun(fBinLength);
0094 
0095   // save histograms
0096   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0097   if (analysisManager->IsActive()) {
0098     analysisManager->Write();
0099     analysisManager->CloseFile();
0100     analysisManager->Clear();
0101   }
0102 }
0103 
0104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0105 
0106 void RunAction::SetBinSize(G4double size)
0107 {
0108   fBinLength = size;
0109   if (fBinLength > fDetector->GetMaxStepSize()) {
0110     fBinLength = fDetector->GetMaxStepSize();
0111   }
0112 }
0113 
0114 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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   // Create histograms
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......