Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 {
50  fTotStepGas = fTotCluster = fMeanCluster = fOverflow = fTotEdep
51  = fStepGas = fCluster = fMaxEnergy = 0.0;
52  fEvt = fNbins = 0;
53  fFactorALICE = fParam->GetFactorALICE();
54  fWidthALICE = fParam->GetEnergySmear();
55 }
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
59 Run::~Run()
60 {}
61 
62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
63 
65 {
66  // initilise scoring
67  fTotStepGas = fTotCluster = fMeanCluster = fOverflow = fTotEdep
68  = fStepGas = fCluster = 0.0;
69  fEvt = 0;
70 
71  fFactorALICE = fParam->GetFactorALICE();
72  fWidthALICE = fParam->GetEnergySmear();
73 
74  SetVerbose(1);
75 
76  fNbins = fParam->GetNumberBins();
77  fMaxEnergy = fParam->GetMaxEnergy();
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(keV)= " << fWidthALICE/keV
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 > 0) ? 1.0/(G4double)nEvt : 0.0;
98 
99  fTotStepGas *= norm;
100  fTotCluster *= norm;
101  fMeanCluster *= norm;
102  fOverflow *= norm;
103 
104  G4double y1 = fEdep.mean();
105  G4double y2 = fEdep.rms();
106 
107  G4double de = fMaxEnergy/G4double(fNbins);
108  G4double x1 = -de*0.5;
109 
110  fFactorALICE = fParam->GetFactorALICE();
111 
112  G4cout << " ====================================================" << G4endl;
113  G4cout << " Beam Particle: "
114  << fParam->GetBeamParticle()->GetParticleName() << G4endl
115  << " Ekin(MeV) = " << fParam->GetBeamEnergy()/MeV
116  << G4endl
117  << " Z(mm) = " << fParam->GetPositionZ()/mm
118  << G4endl;
119  G4cout << " ================== run summary =====================" << G4endl;
120  G4int prec = G4cout.precision(5);
121  G4cout << " End of Run TotNbofEvents = "
122  << nEvt << G4endl;
123  G4cout << " Energy(keV) per ADC channel = "
124  << 1.0/(keV*fFactorALICE) << G4endl;
125 
126  G4cout << G4endl;
127  G4cout << " Mean energy deposit in absorber = " <<
128  y1/keV << " +- " << y2*std::sqrt(norm)/keV << " keV; ";
129  if(y1 > 0.0) { G4cout << " RMS/Emean = " << y2/y1; }
130  G4cout << G4endl;
131  G4cout << " Mean number of steps in absorber= "
132  << fTotStepGas << "; mean number of ion-clusters = "
133  << fTotCluster << " MeanCluster= " << fMeanCluster
134  << G4endl;
135  G4cout << G4endl;
136 
137  G4cout << " ====== Energy deposit distribution Noverflows= " << fOverflow
138  << " ====== " << G4endl ;
139  G4cout << " bin nb Elow entries normalized " << G4endl;
140 
141  std::ofstream fileOut("distribution.out", std::ios::out );
142  fileOut.setf( std::ios::scientific, std::ios::floatfield );
143 
144  x1 = 0.0;
145 
146  fileOut << fNbins << G4endl;
147 
148  for(G4int j=0; j<fNbins; ++j)
149  {
150  G4cout << std::setw(5) << j << std::setw(10) << x1/keV
151  << std::setw(12) << fEgas[j] << std::setw(12) << fEgas[j]*norm
152  << G4endl ;
153  fileOut << x1/keV << "\t" << fEgas[j] << G4endl;
154  x1 += de;
155  }
156  G4cout.precision(prec);
157 
158  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
159  // normalize histograms
160  G4double normf = fParam->GetNormFactor();
161  analysisManager->ScaleH1(1,norm);
162  analysisManager->ScaleH1(2,norm);
163  analysisManager->ScaleH1(3,norm*normf);
164 
165  G4cout << " ================== run end ==========================" << G4endl;
166 }
167 
168 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
169 
171 {
172  fTotEdep = 0.0;
173  fStepGas = 0;
174  fCluster = 0;
175  ++fEvt;
176 }
177 
178 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
179 
181 {
182  fTotStepGas += fStepGas;
183  fTotCluster += fCluster;
184 
185  if(fWidthALICE > 0.0) {
186  G4double x = G4RandGauss::shoot(0.,fWidthALICE);
187  fTotEdep += x;
188  fTotEdep = std::max(fTotEdep, 0.0);
189  }
190 
191  G4int idx = G4int(fTotEdep*fNbins/fMaxEnergy);
192 
193  if(idx < 0) { fEgas[0] += 1.0; }
194  if(idx >= fNbins) { fOverflow += 1.0; }
195  else { fEgas[idx] += 1.0; }
196 
197  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
198  // fill histo
199  analysisManager->FillH1(1,fTotEdep/keV,1.0);
200  analysisManager->FillH1(2,fCluster,1.0);
201  analysisManager->FillH1(3,fTotEdep*fFactorALICE,1.0);
202  fEdep.fill(fTotEdep, 1.0);
203 }
204 
205 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
206 
207 void Run::Merge(const G4Run* run)
208 {
209  const Run* localRun = static_cast<const Run*>(run);
210 
211  fTotStepGas += localRun->fTotStepGas;
212  fTotCluster += localRun->fTotCluster;
213  fMeanCluster += localRun->fMeanCluster;
214  fOverflow += localRun->fOverflow;
215 
216  G4StatDouble* stat = const_cast<G4StatDouble*>(localRun->GetStat());
217 
218  fEdep.add(stat);
219 
220  for(G4int j=0; j<fNbins; ++j)
221  {
222  fEgas[j] += localRun->fEgas[j];
223  }
224 
225  G4Run::Merge(run);
226 }
227 
228 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
229 
230 void Run::AddEnergy(G4double edep, const G4Step* step)
231 {
232  if(1 < fVerbose) {
233  G4cout << "Run::AddEnergy: e(keV)= " << edep/keV
234  << G4endl;
235  }
236  fTotEdep += edep;
237  if(step) {
238  if(1 == step->GetTrack()->GetTrackID()) { fStepGas += 1.0; }
239 
240  fMeanCluster += fElIonPair->MeanNumberOfIonsAlongStep(step);
241  fCluster += fElIonPair->SampleNumberOfIonsAlongStep(step);
242  }
243 }
244 
245 //....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)
Definition of the TestParameters class.
static G4LossTableManager * Instance()
static constexpr double mm
Definition: G4SIunits.hh:115
void BeginOfRun()
Definition: Run.cc:64
G4int GetNumberBins() const
Run()
Definition: Run.cc:43
G4int GetNumberBinsCluster() const
G4double GetFactorALICE() const
const G4ParticleDefinition * GetBeamParticle() const
void SetVerbose(G4int val)
Definition: Run.hh:70
const G4StatDouble * GetStat() const
Definition: Run.hh:130
tuple x
Definition: test.py:50
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
G4double GetPositionZ() const
static const double prec
Definition: RanecuEngine.cc:58
void EndOfEvent()
Definition: Run.cc:180
G4GLOB_DLL std::ostream G4cout
void BeginOfEvent()
Definition: Run.cc:170
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
G4int SampleNumberOfIonsAlongStep(const G4Step *)
G4ElectronIonPair * ElectronIonPair()
Definition: G4Run.hh:46
Definition: G4Step.hh:76
G4double GetEnergySmear() const
G4int GetTrackID() const
G4double GetNormFactor() const
G4double GetBeamEnergy() const
T max(const T t1, const T t2)
brief Return the largest of the two arguments
void EndOfRun()
Definition: Run.cc:147
#define G4endl
Definition: G4ios.hh:61
static constexpr double MeV
Definition: G4SIunits.hh:214
double G4double
Definition: G4Types.hh:76
Definition: Run.hh:46
G4Track * GetTrack() const
static constexpr double keV
Definition: G4SIunits.hh:216
virtual void Merge(const G4Run *)
Definition: Run.cc:115
G4CsvAnalysisManager G4AnalysisManager
Definition: g4csv_defs.hh:77
~Run()
Definition: Run.cc:72