Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
extended/electromagnetic/TestEm9/src/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 //
26 /// \file electromagnetic/TestEm9/src/HistoManager.cc
27 /// \brief Implementation of the HistoManager class
28 //
29 // $Id: HistoManager.cc 67268 2013-02-13 11:38:40Z ihrivnac $
30 //
31 //---------------------------------------------------------------------------
32 //
33 // ClassName: HistoManager
34 //
35 //
36 // Author: V.Ivanchenko 30/01/01
37 //
38 //----------------------------------------------------------------------------
39 //
40 
41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
43 
44 #include "HistoManager.hh"
45 #include "G4MaterialCutsCouple.hh"
46 #include "G4EmProcessSubType.hh"
47 #include "G4VProcess.hh"
48 #include "G4VEmProcess.hh"
49 #include "G4VEnergyLossProcess.hh"
50 #include "G4UnitsTable.hh"
51 #include "Histo.hh"
52 #include "EmAcceptance.hh"
53 #include "G4Gamma.hh"
54 #include "G4Electron.hh"
55 #include "G4Positron.hh"
56 #include "G4SystemOfUnits.hh"
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
59 
60 HistoManager* HistoManager::fManager = 0;
61 
62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
63 
65 {
66  if(!fManager) {
67  fManager = new HistoManager();
68  }
69  return fManager;
70 }
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
73 
75  : fGamma(0),
76  fElectron(0),
77  fPositron(0),
78  fHisto(0)
79 {
80  fVerbose = 1;
81  fEvt1 = -1;
82  fEvt2 = -1;
83  fNmax = 3;
84  fMaxEnergy = 50.0*MeV;
85  fBeamEnergy= 1.*GeV;
86  fMaxEnergyAbs = 10.*MeV;
87  fBinsE = 100;
88  fBinsEA= 40;
89  fBinsED= 100;
90  fNHisto = 13;
91 
92  fHisto = new Histo();
93  bookHisto();
94 
95  fGamma = G4Gamma::Gamma();
96  fElectron = G4Electron::Electron();
97  fPositron = G4Positron::Positron();
98 }
99 
100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
101 
103 {
104  delete fHisto;
105 }
106 
107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
108 
110 {
111  fHisto->Add1D("10","Evis/E0 in central crystal",fBinsED,0.0,1,1.0);
112  fHisto->Add1D("11","Evis/E0 in 3x3",fBinsED,0.0,1.0,1.0);
113  fHisto->Add1D("12","Evis/E0 in 5x5",fBinsED,0.0,1.0,1.0);
114  fHisto->Add1D("13","Energy (MeV) of delta-electrons",
115  fBinsE,0.0,fMaxEnergy,MeV);
116  fHisto->Add1D("14","Energy (MeV) of gammas",fBinsE,0.0,fMaxEnergy,MeV);
117  fHisto->Add1D("15","Energy (MeV) in abs1",fBinsEA,0.0,fMaxEnergyAbs,MeV);
118  fHisto->Add1D("16","Energy (MeV) in abs2",fBinsEA,0.0,fMaxEnergyAbs,MeV);
119  fHisto->Add1D("17","Energy (MeV) in abs3",fBinsEA,0.0,fMaxEnergyAbs,MeV);
120  fHisto->Add1D("18","Energy (MeV) in abs4",fBinsEA,0.0,fMaxEnergyAbs,MeV);
121  fHisto->Add1D("19","Number of vertex hits",20,-0.5,19.5,1.0);
122  fHisto->Add1D("20","E1/E9 Ratio",fBinsED,0.0,1,1.0);
123  fHisto->Add1D("21","E1/E25 Ratio",fBinsED,0.0,1.0,1.0);
124  fHisto->Add1D("22","E9/E25 Ratio",fBinsED,0.0,1.0,1.0);
125 }
126 
127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
128 
130 {
131  // initilise scoring
132  fEvt = 0;
133  fElec = 0;
134  fPosit= 0;
135  fGam = 0;
136  fStep = 0;
137  fLowe = 0;
138 
139  for(G4int i=0; i<6; i++) {
140  fStat[i] = 0;
141  fEdep[i] = 0.0;
142  fErms[i] = 0.0;
143  if(i < 3) {
144  fEdeptr[i] = 0.0;
145  fErmstr[i] = 0.0;
146  }
147  }
148 
149  // initialise counters
150  fBrem.resize(93,0.0);
151  fPhot.resize(93,0.0);
152  fComp.resize(93,0.0);
153  fConv.resize(93,0.0);
154 
155  // initialise acceptance - by default is not applied
156  for(G4int i=0; i<fNmax; i++) {
157  fEdeptrue[i] = 1.0;
158  fRmstrue[i] = 1.0;
159  fLimittrue[i]= 10.;
160  }
161 
162  if(fHisto->IsActive()) {
163  for(G4int i=0; i<fNHisto; ++i) {fHisto->Activate(i, true); }
164  fHisto->Book();
165 
166  if(fVerbose > 0) {
167  G4cout << "HistoManager: Histograms are booked and run has been started"
168  << G4endl;
169  }
170  }
171 }
172 
173 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
174 
176 {
177 
178  G4cout << "HistoManager: End of run actions are started RunID# "
179  << runID << G4endl;
180  G4String nam[6] = {"1x1", "3x3", "5x5", "E1/E9 ", "E1/E25", "E9/E25"};
181 
182  // average
183 
184  G4cout<<"================================================================="
185  <<G4endl;
186  G4double x = (G4double)fEvt;
187  if(fEvt > 0) x = 1.0/x;
188  G4int j;
189  for(j=0; j<fNmax; j++) {
190 
191  // total mean
192  fEdep[j] *= x;
193  G4double y = fErms[j]*x - fEdep[j]*fEdep[j];
194  if(y < 0.0) y = 0.0;
195  fErms[j] = std::sqrt(y);
196 
197  // trancated mean
198  G4double xx = G4double(fStat[j]);
199  if(xx > 0.0) xx = 1.0/xx;
200  fEdeptr[j] *= xx;
201  y = fErmstr[j]*xx - fEdeptr[j]*fEdeptr[j];
202  if(y < 0.0) y = 0.0;
203  fErmstr[j] = std::sqrt(y);
204  }
205  G4double xe = x*(G4double)fElec;
206  G4double xg = x*(G4double)fGam;
207  G4double xp = x*(G4double)fPosit;
208  G4double xs = x*fStep;
209 
210  G4double f = 100.*std::sqrt(fBeamEnergy/GeV);
211 
212  G4cout << "Number of events " << fEvt <<G4endl;
213  G4cout << std::setprecision(4) << "Average number of e- " << xe << G4endl;
214  G4cout << std::setprecision(4) << "Average number of gamma " << xg << G4endl;
215  G4cout << std::setprecision(4) << "Average number of e+ " << xp << G4endl;
216  G4cout << std::setprecision(4) << "Average number of steps " << xs << G4endl;
217 
218  for(j=0; j<3; j++) {
219  G4double ex = fEdeptr[j];
220  G4double sx = fErmstr[j];
221  G4double xx= G4double(fStat[j]);
222  if(xx > 0.0) xx = 1.0/xx;
223  G4double r = sx*std::sqrt(xx);
224  G4cout << std::setprecision(4) << "Edep " << nam[j]
225  << " = " << ex
226  << " +- " << r;
227  if(ex > 0.1) G4cout << " res= " << f*sx/ex << " % " << fStat[j];
228  G4cout << G4endl;
229  }
230  if(fLimittrue[0] < 10. || fLimittrue[1] < 10. || fLimittrue[2] < 10.) {
231  G4cout<<"=========== Mean values without trancating ====================="<<G4endl;
232  for(j=0; j<fNmax; j++) {
233  G4double ex = fEdep[j];
234  G4double sx = fErms[j];
235  G4double rx = sx*std::sqrt(x);
236  G4cout << std::setprecision(4) << "Edep " << nam[j]
237  << " = " << ex
238  << " +- " << rx;
239  if(ex > 0.0) G4cout << " res= " << f*sx/ex << " %";
240  G4cout << G4endl;
241  }
242  }
243  G4cout<<"=========== Ratios without trancating ==========================="<<G4endl;
244  for(j=3; j<6; j++) {
245  G4double e = fEdep[j];
246  G4double xx= G4double(fStat[j]);
247  if(xx > 0.0) xx = 1.0/xx;
248  e *= xx;
249  G4double y = fErms[j]*xx - e*e;
250  G4double r = 0.0;
251  if(y > 0.0) r = std::sqrt(y*xx);
252  G4cout << " " << nam[j] << " = " << e
253  << " +- " << r;
254  G4cout << G4endl;
255  }
256  G4cout << std::setprecision(4) << "Beam Energy " << fBeamEnergy/GeV
257  << " GeV" << G4endl;
258  if(fLowe > 0) G4cout << "Number of events E/E0<0.8 " << fLowe << G4endl;
259  G4cout<<"=================================================================="<<G4endl;
260  G4cout<<G4endl;
261 
262  // normalise histograms
263  if(fHisto->IsActive()) {
264  for(G4int i=0; i<fNHisto; i++) {
265  fHisto->ScaleH1(i,x);
266  }
267  fHisto->Save();
268  }
269  if(0 < runID) { return; }
270 
271  // Acceptance only for the first run
272  EmAcceptance acc;
273  G4bool isStarted = false;
274  for (j=0; j<fNmax; j++) {
275 
276  G4double ltrue = fLimittrue[j];
277  if (ltrue < DBL_MAX) {
278  if (!isStarted) {
279  acc.BeginOfAcceptance("Crystal Calorimeter",fEvt);
280  isStarted = true;
281  }
282  G4double etrue = fEdeptrue[j];
283  G4double rtrue = fRmstrue[j];
284  acc.EmAcceptanceGauss("Edep"+nam[j],fEvt,fEdeptr[j],etrue,rtrue,ltrue);
285  acc.EmAcceptanceGauss("Erms"+nam[j],fEvt,fErmstr[j],rtrue,rtrue,2.0*ltrue);
286  }
287  }
288  if(isStarted) acc.EndOfAcceptance();
289 
290  // atom frequency
291  G4cout << " Z bremsstrahlung photoeffect compton conversion" << G4endl;
292  for(j=1; j<93; ++j) {
293  G4int n1 = G4int(fBrem[j]*x);
294  G4int n2 = G4int(fPhot[j]*x);
295  G4int n3 = G4int(fComp[j]*x);
296  G4int n4 = G4int(fConv[j]*x);
297  if(n1 + n2 + n3 + n4 > 0) {
298  G4cout << std::setw(4) << j << std::setw(12) << n1 << std::setw(12) << n2
299  << std::setw(12) << n3 << std::setw(12) << n4 << G4endl;
300  }
301  }
302 }
303 
304 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
305 
307 {
308  ++fEvt;
309 
310  fEabs1 = 0.0;
311  fEabs2 = 0.0;
312  fEabs3 = 0.0;
313  fEabs4 = 0.0;
314  fEvertex.clear();
315  fNvertex.clear();
316  for (G4int i=0; i<25; i++) {
317  fE[i] = 0.0;
318  }
319 }
320 
321 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
322 
324 {
325  G4double e9 = 0.0;
326  G4double e25= 0.0;
327  for (G4int i=0; i<25; i++) {
328  fE[i] /= fBeamEnergy;
329  e25 += fE[i];
330  if( ( 6<=i && 8>=i) || (11<=i && 13>=i) || (16<=i && 18>=i)) e9 += fE[i];
331  }
332 
333  if(1 < fVerbose && e25 < 0.8) {
334  ++fLowe;
335  G4cout << "### in the event# " << fEvt << " E25= " << e25 << G4endl;
336  }
337 
338  // compute ratios
339  G4double e0 = fE[12];
340  G4double e19 = 0.0;
341  G4double e125 = 0.0;
342  G4double e925 = 0.0;
343  if(e9 > 0.0) {
344  e19 = e0/e9;
345  e125 = e0/e25;
346  e925 = e9/e25;
347  fEdep[3] += e19;
348  fErms[3] += e19*e19;
349  fEdep[4] += e125;
350  fErms[4] += e125*e125;
351  fEdep[5] += e925;
352  fErms[5] += e925*e925;
353  fStat[3] += 1;
354  fStat[4] += 1;
355  fStat[5] += 1;
356  }
357 
358  // Fill histo
359  fHisto->Fill(0,e0,1.0);
360  fHisto->Fill(1,e9,1.0);
361  fHisto->Fill(2,e25,1.0);
362  fHisto->Fill(5,fEabs1,1.0);
363  fHisto->Fill(6,fEabs2,1.0);
364  fHisto->Fill(7,fEabs3,1.0);
365  fHisto->Fill(8,fEabs4,1.0);
366  fHisto->Fill(9,G4double(fNvertex.size()),1.0);
367  fHisto->Fill(10,e19,1.0);
368  fHisto->Fill(11,e125,1.0);
369  fHisto->Fill(12,e925,1.0);
370 
371  // compute sums
372  fEdep[0] += e0;
373  fErms[0] += e0*e0;
374  fEdep[1] += e9;
375  fErms[1] += e9*e9;
376  fEdep[2] += e25;
377  fErms[2] += e25*e25;
378 
379  // trancated mean
380  if(std::abs(e0-fEdeptrue[0])<fRmstrue[0]*fLimittrue[0]) {
381  fStat[0] += 1;
382  fEdeptr[0] += e0;
383  fErmstr[0] += e0*e0;
384  }
385  if(std::abs(e9-fEdeptrue[1])<fRmstrue[1]*fLimittrue[1]) {
386  fStat[1] += 1;
387  fEdeptr[1] += e9;
388  fErmstr[1] += e9*e9;
389  }
390  if(std::abs(e25-fEdeptrue[2])<fRmstrue[2]*fLimittrue[2]) {
391  fStat[2] += 1;
392  fEdeptr[2] += e25;
393  fErmstr[2] += e25*e25;
394  }
395 }
396 
397 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
398 
400 {
401  //Save primary parameters
403  const G4ParticleDefinition* particle = aTrack->GetDefinition();
404  const G4DynamicParticle* dynParticle = aTrack->GetDynamicParticle();
405 
406  G4int pid = aTrack->GetParentID();
407  G4double kinE = dynParticle->GetKineticEnergy();
408  G4ThreeVector pos = aTrack->GetVertexPosition();
409 
410  // primary
411  if(0 == pid) {
412 
413  G4double mass = 0.0;
414  if(particle) {
415  mass = particle->GetPDGMass();
416  }
417 
418  G4ThreeVector dir = dynParticle->GetMomentumDirection();
419  if(1 < fVerbose) {
420  G4cout << "TrackingAction: Primary kinE(MeV)= " << kinE/MeV
421  << "; m(MeV)= " << mass/MeV
422  << "; pos= " << pos << "; dir= " << dir << G4endl;
423  }
424 
425  // secondary
426  } else {
427  const G4VProcess* proc = aTrack->GetCreatorProcess();
428  G4int type = proc->GetProcessSubType();
429  if(type == fBremsstrahlung) {
430  const G4Element* elm =
431  static_cast<const G4VEnergyLossProcess*>(proc)->GetCurrentElement();
432  if(elm) {
433  G4int Z = G4lrint(elm->GetZ());
434  if(Z > 0 && Z < 93) { fBrem[Z] += 1.0; }
435  }
436  } else if(type == fPhotoElectricEffect) {
437  const G4Element* elm =
438  static_cast<const G4VEmProcess*>(proc)->GetCurrentElement();
439  if(elm) {
440  G4int Z = G4lrint(elm->GetZ());
441  if(Z > 0 && Z < 93) { fPhot[Z] += 1.0; }
442  }
443  } else if(type == fGammaConversion) {
444  const G4Element* elm =
445  static_cast<const G4VEmProcess*>(proc)->GetCurrentElement();
446  if(elm) {
447  G4int Z = G4lrint(elm->GetZ());
448  if(Z > 0 && Z < 93) { fConv[Z] += 1.0; }
449  }
450  } else if(type == fComptonScattering) {
451  const G4Element* elm =
452  static_cast<const G4VEmProcess*>(proc)->GetCurrentElement();
453  if(elm) {
454  G4int Z = G4lrint(elm->GetZ());
455  if(Z > 0 && Z < 93) { fComp[Z] += 1.0; }
456  }
457  }
458 
459  // delta-electron
460  if (particle == fElectron) {
461  if(1 < fVerbose) {
462  G4cout << "TrackingAction: Secondary electron " << G4endl;
463  }
464  AddDeltaElectron(dynParticle);
465 
466  } else if (particle == fPositron) {
467  if(1 < fVerbose) {
468  G4cout << "TrackingAction: Secondary positron " << G4endl;
469  }
470  AddPositron(dynParticle);
471 
472  } else if (particle == fGamma) {
473  if(1 < fVerbose) {
474  G4cout << "TrackingAction: Secondary gamma; parentID= " << pid
475  << " E= " << kinE << G4endl;
476  }
477  AddPhoton(dynParticle);
478  }
479  }
480 }
481 
482 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
483 
484 void HistoManager::AddEnergy(G4double edep, G4int volIndex, G4int copyNo)
485 {
486  if(1 < fVerbose) {
487  G4cout << "HistoManager::AddEnergy: e(keV)= " << edep/keV
488  << "; volIdx= " << volIndex
489  << "; copyNo= " << copyNo
490  << G4endl;
491  }
492  if(0 == volIndex) {
493  fE[copyNo] += edep;
494  } else if (1 == volIndex) {
495  fEabs1 += edep;
496  } else if (2 == volIndex) {
497  fEabs2 += edep;
498  } else if (3 == volIndex) {
499  fEabs3 += edep;
500  } else if (4 == volIndex) {
501  fEabs4 += edep;
502  } else if (5 == volIndex) {
503  G4int n = fNvertex.size();
504  G4bool newPad = true;
505  if (n > 0) {
506  for(G4int i=0; i<n; i++) {
507  if (copyNo == fNvertex[i]) {
508  newPad = false;
509  fEvertex[i] += edep;
510  break;
511  }
512  }
513  }
514  if(newPad) {
515  fNvertex.push_back(copyNo);
516  fEvertex.push_back(edep);
517  }
518  }
519 }
520 
521 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
522 
524 {
525  G4double e = elec->GetKineticEnergy()/MeV;
526  if(e > 0.0) fElec++;
527  fHisto->Fill(3,e,1.0);
528 }
529 
530 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
531 
533 {
534  G4double e = ph->GetKineticEnergy()/MeV;
535  if(e > 0.0) fGam++;
536  fHisto->Fill(4,e,1.0);
537 }
538 
539 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
540 
542 {
543  if(i<fNmax && i>=0) {
544  if(val[0] > 0.0) fEdeptrue[i] = val[0];
545  if(val[1] > 0.0) fRmstrue[i] = val[1];
546  if(val[2] > 0.0) fLimittrue[i] = val[2];
547  }
548 }
549 
550 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
551 
G4ParticleDefinition * GetDefinition() const
G4int GetParentID() const
void AddPhoton(const G4DynamicParticle *)
G4double GetKineticEnergy() const
const G4DynamicParticle * GetDynamicParticle() const
void EmAcceptanceGauss(const G4String &title, G4int stat, G4double avr, G4double avr0, G4double rms, G4double limit)
G4double GetZ() const
Definition: G4Element.hh:131
void BeginOfAcceptance(const G4String &title, G4int stat)
void AddEnergy(G4double edep, const G4Step *)
int G4int
Definition: G4Types.hh:78
const G4VProcess * GetCreatorProcess() const
G4GLOB_DLL std::ostream G4cout
void AddDeltaElectron(const G4DynamicParticle *)
bool G4bool
Definition: G4Types.hh:79
const G4ThreeVector & GetMomentumDirection() const
const G4int n
static G4Gamma * Gamma()
Definition: G4Gamma.cc:86
const G4ThreeVector & GetVertexPosition() const
static G4Positron * Positron()
Definition: G4Positron.cc:94
G4double GetPDGMass() const
int G4lrint(double ad)
Definition: templates.hh:163
static G4Electron * Electron()
Definition: G4Electron.cc:94
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
#define DBL_MAX
Definition: templates.hh:83
G4int GetProcessSubType() const
Definition: G4VProcess.hh:426