ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RunAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RunAction.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
28 //
29 //
30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 
33 #include "RunAction.hh"
34 #include "PhysicsList.hh"
35 #include "StepMax.hh"
36 #include "PrimaryGeneratorAction.hh"
37 #include "HistoManager.hh"
38 #include "Run.hh"
39 
40 #include "G4Run.hh"
41 #include "G4EmCalculator.hh"
42 
43 #include "G4UnitsTable.hh"
44 #include "G4SystemOfUnits.hh"
45 
46 #include "Randomize.hh"
47 
48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
49 
52 :G4UserRunAction(),fDetector(det),fPhysics(phys),fPrimary(kin),fRun(0),
53  fHistoManager(0)
54 {
55  // Book predefined histograms
57 }
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
62 {
63  delete fHistoManager;
64 }
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 
69 {
70  fRun = new Run(fDetector);
71  return fRun;
72 }
73 
74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
75 
77 {
78  // shpw Rndm status
79  if (isMaster) G4Random::showEngineStatus();
80 
81  // keep run condition
82  if ( fPrimary ) {
86  fRun->SetPrimary(particle, energy);
87  }
88 
89  //histograms
90  //
92  if ( analysisManager->IsActive() ) {
93  analysisManager->OpenFile();
94  }
95 
96  if (!fPrimary) return;
97 
98  //set StepMax from histos 1 and 8
99  //
100  G4double stepMax = DBL_MAX;
101  G4int ih = 1;
102  if (analysisManager->GetH1Activation(ih)) {
103  stepMax = analysisManager->GetH1Width(ih)
104  *analysisManager->GetH1Unit(ih);
105  }
106 
107  ih = 8;
110  if (particle->GetPDGCharge() != 0.) {
111  G4double width = analysisManager->GetH1Width(ih);
112  if (width == 0.) width = 1.;
113  G4EmCalculator emCalculator;
115  G4int nbOfAbsor = fDetector->GetNbOfAbsor();
116  for (G4int i=1; i<= nbOfAbsor; i++) {
118  G4double newCsdaRange
119  = emCalculator.GetCSDARange(energy,particle,material);
120  fRun->SetCsdaRange(i, newCsdaRange);
121  if (analysisManager->GetH1Activation(ih))
122  stepMax = std::min(stepMax, width*newCsdaRange);
123  if (i>1) {
125  G4double xfrontNorm = fRun->GetXfrontNorm(i-1);
126  G4double csdaRange = fRun->GetCsdaRange(i-1);
127  G4double newXfrontNorm = xfrontNorm + thickness/csdaRange;
128  fRun->SetXfrontNorm(i, newXfrontNorm);
129  }
130  }
131  }
132  fPhysics->GetStepMaxProcess()->SetMaxStep2(stepMax);
133 }
134 
135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
136 
137 void RunAction::EndOfRunAction(const G4Run*)
138 {
139  if (isMaster) fRun->EndOfRun();
140 
141  // save histograms
142  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
143  if ( analysisManager->IsActive() ) {
144  analysisManager->Write();
145  analysisManager->CloseFile();
146  }
147 
148  // show Rndm status
149  if (isMaster) G4Random::showEngineStatus();
150 }
151 
152 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......