Geant4  10.01.p03
Run.cc
Go to the documentation of this file.
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 // $Id: Run.cc 75577 2013-11-04 12:03:26Z vnivanch $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "Run.hh"
35 #include "G4Step.hh"
36 #include "G4Run.hh"
37 #include "G4LossTableManager.hh"
38 #include "G4ElectronIonPair.hh"
39 #include "G4SystemOfUnits.hh"
40 #include "G4PhysicalConstants.hh"
41 #include "TestParameters.hh"
42 
43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44 
45 Run::Run()
46  : G4Run(), fElIonPair(0), fParam(TestParameters::GetPointer())
47 {
50  = fStepGas = fCluster = fMaxEnergy = 0.0;
51  fEvt = fNbins = 0;
53 }
54 
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56 
57 Run::~Run()
58 {}
59 
60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
61 
63 {
64  // initilise scoring
66  = fStepGas = fCluster = 0.0;
67  fEvt = 0;
68 
69  SetVerbose(1);
70 
73 
74  fEgas.resize(fNbins,0.0);
75  fEdep.reset();
76 
77  if(fVerbose > 0) {
78  G4int binsCluster = fParam->GetNumberBinsCluster();
79  G4cout << " BinsCluster= " << binsCluster << " BinsE= " << fNbins
80  << " Emax(keV)= " << fMaxEnergy/keV << G4endl;
81  }
82 }
83 
84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
85 
86 void Run::EndOfRun()
87 {
88  G4int nEvt = GetNumberOfEvent();
89  G4double norm = nEvt;
90  if(nEvt > 0) { norm = 1.0/norm; }
91 
92  fTotStepGas *= norm;
93  fTotCluster *= norm;
94  fMeanCluster *= norm;
95  fOverflow *= norm;
96 
97  G4double y1 = fEdep.mean();
98  G4double y2 = fEdep.rms();
99  if(y2 > 0.0) { y2 = std::sqrt(y2); }
100 
102  G4double x1 = -de*0.5;
103 
105 
106  G4cout << " ================== run summary =====================" << G4endl;
107  G4int prec = G4cout.precision(5);
108  G4cout << " End of Run TotNbofEvents = "
109  << nEvt << G4endl;
110  G4cout << " Energy(keV) per ADC channel = "
111  << 1.0/(keV*fFactorALICE) << G4endl;
112 
113  G4cout << G4endl;
114  G4cout << " Mean energy deposit in absorber = " <<
115  y1/keV << " +- " << y2*std::sqrt(norm)/keV << " keV; ";
116  if(y1 > 0.0) { G4cout << " RMS/Emean = " << y2/y1; }
117  G4cout << G4endl;
118  G4cout << " Mean number of steps in absorber= "
119  << fTotStepGas << "; mean number of ion-clusters = "
120  << fTotCluster << " MeanCluster= " << fMeanCluster
121  << G4endl;
122  G4cout << G4endl;
123 
124  G4cout << " ====== Energy deposit distribution Noverflows= " << fOverflow
125  << " ====== " << G4endl ;
126  G4cout << " bin nb Elow entries normalized " << G4endl;
127 
128  std::ofstream fileOut("distribution.out", std::ios::out );
129  fileOut.setf( std::ios::scientific, std::ios::floatfield );
130 
131  x1 = 0.0;
132 
133  fileOut << fNbins << G4endl;
134 
135  for(G4int j=0; j<fNbins; ++j)
136  {
137  G4cout << std::setw(5) << j << std::setw(10) << x1/keV
138  << std::setw(12) << fEgas[j] << std::setw(12) << fEgas[j]*norm
139  << G4endl ;
140  fileOut << x1/keV << "\t" << fEgas[j] << G4endl;
141  x1 += de;
142  }
143  G4cout.precision(prec);
144 
145  G4AnalysisManager* fAnalysisManager = G4AnalysisManager::Instance();
146  // normalize histograms
147  fAnalysisManager->ScaleH1(1,norm);
148  fAnalysisManager->ScaleH1(2,norm);
149  fAnalysisManager->ScaleH1(3,0.1);
150  // fAnalysisManager->SetH1Ascii(1,true);
151  // fAnalysisManager->SetH1Ascii(2,true);
152  // fAnalysisManager->SetH1Ascii(3,true);
153 
154  G4cout << " ================== run end ==========================" << G4endl;
155 }
156 
157 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
158 
160 {
161  fTotEdep = 0.0;
162  fStepGas = 0;
163  fCluster = 0;
164  ++fEvt;
165 }
166 
167 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
168 
170 {
173 
174  G4int idx = G4int(fTotEdep*fNbins/fMaxEnergy);
175 
176  if(idx < 0) { fEgas[0] += 1.0; }
177  if(idx >= fNbins) { fOverflow += 1.0; }
178  else { fEgas[idx] += 1.0; }
179 
180  G4AnalysisManager* fAnalysisManager = G4AnalysisManager::Instance();
181  // fill histo
182  fAnalysisManager->FillH1(1,fTotEdep/keV,1.0);
183  fAnalysisManager->FillH1(2,fCluster,1.0);
184  fAnalysisManager->FillH1(3,fTotEdep*fFactorALICE/keV,1.0);
185  fEdep.fill(fTotEdep, 1.0);
186 }
187 
188 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
189 
190 void Run::Merge(const G4Run* run)
191 {
192  const Run* localRun = static_cast<const Run*>(run);
193 
194  fTotStepGas += localRun->fTotStepGas;
195  fTotCluster += localRun->fTotCluster;
196  fMeanCluster += localRun->fMeanCluster;
197  fOverflow += localRun->fOverflow;
198 
199  G4StatDouble* stat = const_cast<G4StatDouble*>(localRun->GetStat());
200 
201  fEdep.add(stat);
202 
203  for(G4int j=0; j<fNbins; ++j)
204  {
205  fEgas[j] += localRun->fEgas[j];
206  }
207 
208  G4Run::Merge(run);
209 }
210 
211 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
212 
213 void Run::AddEnergy(G4double edep, const G4Step* step)
214 {
215  if(1 < fVerbose) {
216  G4cout << "Run::AddEnergy: e(keV)= " << edep/keV
217  << G4endl;
218  }
219  fTotEdep += edep;
220  if(step) {
221  if(1 == step->GetTrack()->GetTrackID()) { fStepGas += 1.0; }
222 
225  }
226 }
227 
228 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4double GetMaxEnergy() const
void AddEnergy(G4double edep)
Definition: Run.hh:60
virtual void Merge(const G4Run *)
Definition: G4Run.cc:54
G4double MeanNumberOfIonsAlongStep(const G4ParticleDefinition *, const G4Material *, G4double edepTotal, G4double edepNIEL=0.0)
static G4LossTableManager * Instance()
void BeginOfRun()
Definition: Run.cc:62
G4int GetNumberBins() const
Run()
Definition: Run.cc:43
G4int fNbins
Definition: Run.hh:83
G4int GetNumberBinsCluster() const
G4double GetFactorALICE() const
void SetVerbose(G4int val)
Definition: Run.hh:70
const G4StatDouble * GetStat() const
Definition: Run.hh:129
TestParameters * fParam
Definition: Run.hh:99
G4double fTotCluster
Definition: Run.hh:88
int G4int
Definition: G4Types.hh:78
G4double fFactorALICE
Definition: Run.hh:90
G4double fEvt
Definition: Run.hh:91
G4double fTotStepGas
Definition: Run.hh:87
static const double prec
Definition: RanecuEngine.cc:58
G4double fMeanCluster
Definition: Run.hh:89
void EndOfEvent()
Definition: Run.cc:169
G4GLOB_DLL std::ostream G4cout
void BeginOfEvent()
Definition: Run.cc:159
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
G4double fEdep
Definition: Run.hh:76
G4int SampleNumberOfIonsAlongStep(const G4Step *)
G4ElectronIonPair * ElectronIonPair()
Definition: G4Run.hh:46
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:61
Definition: G4Step.hh:76
G4int GetTrackID() const
G4double fStepGas
Definition: Run.hh:84
G4double fOverflow
Definition: Run.hh:95
G4double fTotEdep
Definition: Run.hh:93
G4ElectronIonPair * fElIonPair
Definition: Run.hh:98
G4DataVector fEgas
Definition: Run.hh:96
G4double fMaxEnergy
Definition: Run.hh:85
void EndOfRun()
Definition: Run.cc:147
#define G4endl
Definition: G4ios.hh:61
static const double keV
Definition: G4SIunits.hh:195
double G4double
Definition: G4Types.hh:76
Definition: Run.hh:46
G4Track * GetTrack() const
virtual void Merge(const G4Run *)
Definition: Run.cc:115
G4int fVerbose
Definition: Run.hh:103
G4double fCluster
Definition: Run.hh:86
~Run()
Definition: Run.cc:72