Geant4_10
HistoManager.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: HistoManager.cc 78171 2013-12-04 13:22:18Z gunter $
30 //
31 //---------------------------------------------------------------------------
32 //
33 // ClassName: HistoManager
34 //
35 // Author: V.Ivanchenko 01.09.2010
36 //
37 //----------------------------------------------------------------------------
38 //
39 
40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
42 
43 #include "HistoManager.hh"
44 #include "G4UnitsTable.hh"
45 #include "Histo.hh"
46 #include "G4Step.hh"
47 #include "G4LossTableManager.hh"
48 #include "G4ElectronIonPair.hh"
49 #include "G4SystemOfUnits.hh"
50 #include "G4PhysicalConstants.hh"
51 
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
53 
54 HistoManager* HistoManager::fManager = 0;
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
57 
59 {
60  if(!fManager) {
61  fManager = new HistoManager();
62  }
63  return fManager;
64 }
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
67 
69  : fHisto(0),
70  fElIonPair(0)
71 {
72  fNHisto = 2;
73  fVerbose = 1;
74  fMaxEnergy = 100.*keV;
75  fBinsE = 100;
76  fBinsCluster = 200;
77 
78  // normalisation to PAI
79  fFactorALICE = 325;
80 
81  // normalisation to Opt0
82  //fFactorALICE = 275;
83 
84  fEvt = 0.0;
85  fTotStepGas = 0.0;
86  fTotCluster = 0.0;
87  fMeanCluster= 0.0;
88  fOverflow = 0.0;
89 
90  fTotEdep = 0.0;
91  fStepGas = 0;
92  fCluster = 0;
93 
94  fHistoBooked = false;
95 
96  fHisto = new Histo();
98 }
99 
100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
101 
103 {
104  delete fHisto;
105 }
106 
107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
108 
110 {
111  // initilise scoring
112  fEvt = 0.0;
113  fTotStepGas = 0.0;
114  fTotCluster = 0.0;
115  fMeanCluster= 0.0;
116  fOverflow = 0.0;
117 
118  if(fHisto->IsActive() && !fHistoBooked) {
119 
120  fHisto->Add1D("10","Energy deposition in detector (keV)",
121  fBinsE,0.0,fMaxEnergy/keV,1.0);
122  fHisto->Add1D("11","Number of primary clusters",
123  fBinsCluster,-0.5,fBinsCluster-0.5,1.0);
124  fHisto->Add1D("12","Energy deposition in detector (ADC)",
125  200,0.0,2000,1.0);
126 
127  fHisto->Activate(0, true);
128  fHisto->Activate(1, true);
129  fHisto->Activate(2, true);
130  }
131  fHisto->Book();
132 
133  fEgas.resize(fBinsE,0.0);
134 
135  if(fVerbose > 0) {
136  G4cout << "HistoManager: Histograms are booked and run has been started"
137  << G4endl;
138  G4cout << " BinsCluster= " << fBinsCluster << " BinsE= " << fBinsE
139  << " Emax(keV)= " << fMaxEnergy/keV << G4endl;
140  }
141 }
142 
143 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
144 
146 {
147  G4double norm = fEvt;
148  if(fEvt > 0.0) { norm = 1.0/norm; }
149 
150  fTotStepGas *= norm;
151  fTotCluster *= norm;
152  fMeanCluster *= norm;
153  fOverflow *= norm;
154 
155  G4double y1 = 0.0;
156  G4double y2 = 0.0;
157 
158  G4double de = fMaxEnergy/G4double(fBinsE);
159  G4double x1 = -de*0.5;
160 
161  for(G4int j=0; j<fBinsE; ++j) {
162  x1 += de;
163  G4double y = fEgas[j]*norm;
164  y1 += y*x1;
165  y2 += y*x1*x1;
166  }
167  G4double norm1 = G4double(fBinsE);
168  if(norm1 > 0.0) { norm1 = 1.0/norm1; }
169  y1 *= norm1;
170  y2 *= norm1;
171  y2 -= y1*y1;
172  if(y2 >= 0.0) { y2 = std::sqrt(y2); }
173 
174  G4cout << " ================== run summary =====================" << G4endl;
175  G4int prec = G4cout.precision(5);
176  G4cout << " End of Run TotNbofEvents = "
177  << G4int(fEvt) << G4endl;
178  G4cout << " Energy(keV) per ADC channel = "
179  << 1.0/(keV*fFactorALICE) << G4endl;
180  /*
181  G4double p1 = 1*GeV;
182  G4double p2 = 3*GeV;
183  G4double mass = proton_mass_c2;
184  G4cout << std::sqrt(p1*p1 + mass*mass) - mass << " "
185  << std::sqrt(p2*p2 + mass*mass) - mass << G4endl;
186  */
187  G4cout << G4endl;
188  G4cout << " Mean energy deposit in absorber = " <<
189  y1/keV << " +- " << y2*std::sqrt(norm)/keV << " keV; ";
190  if(y1 > 0.0) { G4cout << " RMS/Emean = " << y2/y1; }
191  G4cout << G4endl;
192  G4cout << " Mean number of steps in absorber= "
193  << fTotStepGas << "; mean number of ion-clusters = "
194  << fTotCluster
195  << " MeanCluster= " << fMeanCluster
196  << G4endl;
197  G4cout << G4endl;
198 
199  G4cout << " ====== Energy deposit distribution Noverflows= " << fOverflow
200  << " ====== " << G4endl ;
201  G4cout << " bin nb Elow entries normalized " << G4endl;
202 
203  std::ofstream fileOut("distribution.out", std::ios::out );
204  fileOut.setf( std::ios::scientific, std::ios::floatfield );
205 
206  x1 = 0.0;
207 
208  fileOut << fBinsE << G4endl;
209 
210  for(G4int j=0; j<fBinsE; ++j)
211  {
212  G4cout << std::setw(5) << j << std::setw(10) << x1/keV
213  << std::setw(12) << fEgas[j] << std::setw(12) << fEgas[j]*norm
214  << G4endl ;
215  fileOut << x1/keV << "\t" << fEgas[j] << G4endl;
216  x1 += de;
217  }
218  G4cout.precision(prec);
219 
220  // normalise histograms
221  if(fHisto->IsActive() && !fHistoBooked) {
222  fHisto->ScaleH1(0,norm);
223  fHisto->ScaleH1(1,norm);
224  // fHisto->ScaleH1(2,0.05);
225  fHisto->ScaleH1(2,0.1);
226  fHisto->Save();
227  }
228  G4cout << " ================== run end ==========================" << G4endl;
229 }
230 
231 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
232 
234 {
235  fEvt += 1.0;
236  fTotEdep = 0.0;
237  fStepGas = 0;
238  fCluster = 0;
239 }
240 
241 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
242 
244 {
245  fTotStepGas += fStepGas;
246  fTotCluster += fCluster;
247 
248  G4int idx = G4int(fTotEdep*fBinsE/fMaxEnergy);
249  if(idx < 0) { idx = 0; }
250  if(idx >= fBinsE) { fOverflow += 1.0; }
251  else { fEgas[idx] += 1.0; }
252 
253  // fill histo
254  fHisto->Fill(0,fTotEdep/keV,1.0);
255  fHisto->Fill(1,fCluster,1.0);
256  fHisto->Fill(2,fTotEdep*fFactorALICE/keV,1.0);
257 }
258 
259 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
260 
262 {
263  if(1 < fVerbose) {
264  G4cout << "HistoManager::AddEnergy: e(keV)= " << edep/keV
265  << G4endl;
266  }
267  fTotEdep += edep;
268  if(step) {
269  if(1 == step->GetTrack()->GetTrackID()) { fStepGas += 1.0; }
270 
271  fMeanCluster += fElIonPair->MeanNumberOfIonsAlongStep(step);
272  fCluster += fElIonPair->SampleNumberOfIonsAlongStep(step);
273  }
274 }
275 
276 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
277 
Double_t y2[nxs]
Definition: Style.C:21
G4double MeanNumberOfIonsAlongStep(const G4ParticleDefinition *, const G4Material *, G4double edepTotal, G4double edepNIEL=0.0)
static G4LossTableManager * Instance()
Double_t y1[nxs]
Definition: Style.C:20
void EndOfEvent()
Definition: Histo.hh:56
Float_t norm
void AddEnergy(G4double edep, const G4Step *)
int G4int
Definition: G4Types.hh:78
Double_t edep
Definition: macro.C:13
Double_t y
Definition: plot.C:279
G4GLOB_DLL std::ostream G4cout
void BeginOfEvent()
G4int SampleNumberOfIonsAlongStep(const G4Step *)
G4ElectronIonPair * ElectronIonPair()
void BeginOfRun()
Double_t x1[nxs]
Definition: Style.C:18
Definition: G4Step.hh:76
G4int GetTrackID() const
#define G4endl
Definition: G4ios.hh:61
static HistoManager * GetPointer()
Definition: HistoManager.cc:58
double G4double
Definition: G4Types.hh:76
G4Track * GetTrack() const