Geant4  10.02.p01
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 #include "Randomize.hh"
43 
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45 
46 Run::Run()
47  : G4Run(), fElIonPair(0), fParam(TestParameters::GetPointer())
48 {
51  = fStepGas = fCluster = fMaxEnergy = 0.0;
52  fEvt = fNbins = 0;
55 }
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
59 Run::~Run()
60 {}
61 
62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
63 
65 {
66  // initilise scoring
68  = fStepGas = fCluster = 0.0;
69  fEvt = 0;
70 
73 
74  SetVerbose(1);
75 
78 
79  fEgas.resize(fNbins,0.0);
80  fEdep.reset();
81 
82  if(fVerbose > 0) {
83  G4int binsCluster = fParam->GetNumberBinsCluster();
84  G4cout << " BinsCluster= " << binsCluster << " BinsE= " << fNbins
85  << " Emax(keV)= " << fMaxEnergy/keV << G4endl;
86  G4cout << " WidthALICE= " << fWidthALICE
87  << " FactorALICE= " << fFactorALICE << G4endl;
88 
89  }
90 }
91 
92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
93 
94 void Run::EndOfRun()
95 {
96  G4int nEvt = GetNumberOfEvent();
97  G4double norm = nEvt;
98  if(nEvt > 0) { norm = 1.0/norm; }
99 
100  fTotStepGas *= norm;
101  fTotCluster *= norm;
102  fMeanCluster *= norm;
103  fOverflow *= norm;
104 
105  G4double y1 = fEdep.mean();
106  G4double y2 = fEdep.rms();
107  if(y2 > 0.0) { y2 = std::sqrt(y2); }
108 
110  G4double x1 = -de*0.5;
111 
113 
114  G4cout << " ================== run summary =====================" << G4endl;
115  G4int prec = G4cout.precision(5);
116  G4cout << " End of Run TotNbofEvents = "
117  << nEvt << G4endl;
118  G4cout << " Energy(keV) per ADC channel = "
119  << 1.0/(keV*fFactorALICE) << G4endl;
120 
121  G4cout << G4endl;
122  G4cout << " Mean energy deposit in absorber = " <<
123  y1/keV << " +- " << y2*std::sqrt(norm)/keV << " keV; ";
124  if(y1 > 0.0) { G4cout << " RMS/Emean = " << y2/y1; }
125  G4cout << G4endl;
126  G4cout << " Mean number of steps in absorber= "
127  << fTotStepGas << "; mean number of ion-clusters = "
128  << fTotCluster << " MeanCluster= " << fMeanCluster
129  << G4endl;
130  G4cout << G4endl;
131 
132  G4cout << " ====== Energy deposit distribution Noverflows= " << fOverflow
133  << " ====== " << G4endl ;
134  G4cout << " bin nb Elow entries normalized " << G4endl;
135 
136  std::ofstream fileOut("distribution.out", std::ios::out );
137  fileOut.setf( std::ios::scientific, std::ios::floatfield );
138 
139  x1 = 0.0;
140 
141  fileOut << fNbins << G4endl;
142 
143  for(G4int j=0; j<fNbins; ++j)
144  {
145  G4cout << std::setw(5) << j << std::setw(10) << x1/keV
146  << std::setw(12) << fEgas[j] << std::setw(12) << fEgas[j]*norm
147  << G4endl ;
148  fileOut << x1/keV << "\t" << fEgas[j] << G4endl;
149  x1 += de;
150  }
151  G4cout.precision(prec);
152 
153  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
154  // normalize histograms
155  G4double normf = fParam->GetNormFactor();
156  analysisManager->ScaleH1(1,norm);
157  analysisManager->ScaleH1(2,norm);
158  analysisManager->ScaleH1(3,norm*normf);
159 
160  G4cout << " ================== run end ==========================" << G4endl;
161 }
162 
163 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
164 
166 {
167  fTotEdep = 0.0;
168  fStepGas = 0;
169  fCluster = 0;
170  ++fEvt;
171 }
172 
173 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
174 
176 {
179 
180  if(fWidthALICE > 0.0) {
182  if(x <= 0.0) { x = 1.0; }
183  fTotEdep *= x;
184  }
185 
186  G4int idx = G4int(fTotEdep*fNbins/fMaxEnergy);
187 
188  if(idx < 0) { fEgas[0] += 1.0; }
189  if(idx >= fNbins) { fOverflow += 1.0; }
190  else { fEgas[idx] += 1.0; }
191 
192  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
193  // fill histo
194  analysisManager->FillH1(1,fTotEdep/keV,1.0);
195  analysisManager->FillH1(2,fCluster,1.0);
196  analysisManager->FillH1(3,fTotEdep*fFactorALICE,1.0);
197  fEdep.fill(fTotEdep, 1.0);
198 }
199 
200 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
201 
202 void Run::Merge(const G4Run* run)
203 {
204  const Run* localRun = static_cast<const Run*>(run);
205 
206  fTotStepGas += localRun->fTotStepGas;
207  fTotCluster += localRun->fTotCluster;
208  fMeanCluster += localRun->fMeanCluster;
209  fOverflow += localRun->fOverflow;
210 
211  G4StatDouble* stat = const_cast<G4StatDouble*>(localRun->GetStat());
212 
213  fEdep.add(stat);
214 
215  for(G4int j=0; j<fNbins; ++j)
216  {
217  fEgas[j] += localRun->fEgas[j];
218  }
219 
220  G4Run::Merge(run);
221 }
222 
223 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
224 
225 void Run::AddEnergy(G4double edep, const G4Step* step)
226 {
227  if(1 < fVerbose) {
228  G4cout << "Run::AddEnergy: e(keV)= " << edep/keV
229  << G4endl;
230  }
231  fTotEdep += edep;
232  if(step) {
233  if(1 == step->GetTrack()->GetTrackID()) { fStepGas += 1.0; }
234 
237  }
238 }
239 
240 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4double GetMaxEnergy() const
void AddEnergy(G4double edep)
Definition: Run.hh:60
ThreeVector shoot(const G4int Ap, const G4int Af)
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:64
G4int GetNumberBins() const
Run()
Definition: Run.cc:43
G4int fNbins
Definition: Run.hh:83
G4int GetNumberBinsCluster() const
G4double GetFactorALICE() const
G4double fWidthALICE
Definition: Run.hh:91
void SetVerbose(G4int val)
Definition: Run.hh:70
const G4StatDouble * GetStat() const
Definition: Run.hh:130
TestParameters * fParam
Definition: Run.hh:100
G4double fTotCluster
Definition: Run.hh:88
int G4int
Definition: G4Types.hh:78
G4double fFactorALICE
Definition: Run.hh:90
G4double fEvt
Definition: Run.hh:92
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:175
G4GLOB_DLL std::ostream G4cout
void BeginOfEvent()
Definition: Run.cc:165
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:66
Definition: G4Step.hh:76
G4double GetEnergySmear() const
G4int GetTrackID() const
G4double GetNormFactor() const
G4double fStepGas
Definition: Run.hh:84
G4double fOverflow
Definition: Run.hh:96
G4double fTotEdep
Definition: Run.hh:94
G4ElectronIonPair * fElIonPair
Definition: Run.hh:99
G4DataVector fEgas
Definition: Run.hh:97
const G4double x[NPOINTSGL]
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:213
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