ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HistoManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HistoManager.cc
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 //
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "HistoManager.hh"
35 #include "G4SystemOfUnits.hh"
36 #include "DetectorConstruction.hh"
37 
38 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
39 
41 {
42 
43  fNBinsZ = 60;
44  fNBinsR = 80;
45  fNBinsE = 200;
46 
47  fAbsorberZ = 300.*mm;
48  fAbsorberR = 200.*mm;
49  fScoreZ = 100.*mm;
50  fMaxEnergy = 50.*MeV;
51 
52  fStepZ = fStepR = fStepE = 0.0;
53 
54  Book();
55 
56 }
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
61 {
63 }
64 
65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66 
67 void HistoManager::Book()
68 {
69 
71 
72  // Create or get analysis manager
73  // The choice of analysis technology is done via selection of a namespace
74  // in HistoManager.hh
75  analysisManager->SetVerboseLevel(1);
76  analysisManager->SetActivation(true); // enable inactivation of histograms
77 
78  // Creating an 1-dimensional histograms in the root directory of the tree
79  fHisto.assign(10,0);
80  int iHisto=0;
81  fHisto[iHisto] = analysisManager->CreateH1("10",
82  "Energy deposit at radius (mm) normalised on 1st channel",
83  fNBinsR, 0., fAbsorberR/mm);
84 
85  iHisto++;
86  fHisto[iHisto] = analysisManager->CreateH1("11",
87  "Energy deposit at radius (mm) normalised to integral",
88  fNBinsR, 0., fAbsorberR/mm);
89 
90  iHisto++;
91  fHisto[iHisto] = analysisManager->CreateH1("12",
92  "Energy deposit (MeV/kg/electron) at radius (mm)",
93  fNBinsR, 0., fAbsorberR/mm);
94 
95  iHisto++;
96  fHisto[iHisto] = analysisManager->CreateH1("13",
97  "Energy profile (MeV/kg/electron) over Z (mm)",fNBinsZ,0.,fAbsorberZ/mm);
98 
99  iHisto++;
100  fHisto[iHisto] = analysisManager->CreateH1("14",
101  "Energy profile (MeV/kg/electron) over Z (mm) at Central Voxel",
102  fNBinsZ, 0., fAbsorberZ/mm);
103 
104  iHisto++;
105  fHisto[iHisto] = analysisManager->CreateH1("15",
106  "Energy (MeV) of fGamma produced in the target",
107  fNBinsE, 0., fMaxEnergy/MeV);
108 
109  iHisto++;
110  fHisto[iHisto] = analysisManager->CreateH1("16",
111  "Energy (MeV) of fGamma before phantom",fNBinsE,0.,fMaxEnergy/MeV);
112 
113  iHisto++;
114  fHisto[iHisto] = analysisManager->CreateH1("17",
115  "Energy (MeV) of electrons produced in phantom",fNBinsE,0.,fMaxEnergy/MeV);
116 
117  iHisto++;
118  fHisto[iHisto] = analysisManager->CreateH1("18",
119  "Energy (MeV) of electrons produced in target",fNBinsE,0.,fMaxEnergy/MeV);
120 
121  iHisto++;
122  fHisto[iHisto] = analysisManager->CreateH1("19",
123  "Gamma Energy Fluence (MeV/cm2) at radius(mm) in front of phantom",
124  fNBinsR, 0., fAbsorberR/mm);
125 
126  // Create all histograms as inactivated
127  // as we have not yet set nbins, vmin, vmax
128  for(int i=0; i<iHisto+1; i++) analysisManager->SetH1Activation(i, false);
129 
130 }
131 
132 
133 void HistoManager::Update(DetectorConstruction* det, bool bForceActivation)
134 {
135 
136  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
137 
138  if(bForceActivation) {
139  for(int i=0; i<(int)fHisto.size(); i++)
140  analysisManager->SetH1Activation(fHisto[i], true);
141  analysisManager->SetActivation(true);
142  }
143 
144  if(analysisManager->IsActive()) {
145 
146  // Check nBinsR / fAbsorberR histograms
147  if(det->GetNumberDivR()!=fNBinsR||
148  std::fabs(det->GetAbsorberR()-fAbsorberR)>0.01*mm)
149  {
150  fNBinsR = det->GetNumberDivR();
151  fAbsorberR = det->GetAbsorberR();
152  std::vector<G4int> histoId { 0, 1, 2, 9 };
153  for(auto v : histoId)
154  {
155  analysisManager->SetH1(fHisto[v], fNBinsR, 0., fAbsorberR/mm);
156  }
157 
158  }
159 
160  // Check nBinsZ / fAbsorberZ histograms
161  if(det->GetNumberDivZ()!=fNBinsZ||
162  std::fabs(det->GetAbsorberZ()-fAbsorberZ)>0.01*mm)
163  {
164  fNBinsZ = det->GetNumberDivZ();
165  fAbsorberZ = det->GetAbsorberZ();
166  std::vector<G4int> histoId { 3, 4 };
167  for(auto v : histoId)
168  {
169  analysisManager->SetH1(fHisto[v], fNBinsZ, 0., fAbsorberZ/mm);
170  }
171  }
172 
173  // Check nBinsE / fAbsorberE histograms
174  if(det->GetNumberDivE()!=fNBinsE||
175  std::fabs(det->GetMaxEnergy()-fMaxEnergy)>0.01)
176  {
177  fNBinsE = det->GetNumberDivE();
178  fMaxEnergy = det->GetMaxEnergy();
179  std::vector<G4int> histoId { 5, 6, 7 ,8 };
180  for(auto v : histoId)
181  {
182  analysisManager->SetH1(fHisto[v], fNBinsE, 0., fMaxEnergy/MeV);
183  }
184  }
185  }
186 
187 }
188 
189 
190 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
191 
193 {
194  if(!G4AnalysisManager::Instance()->IsActive()) return;
195 
196  for(int i=0; i<(int)fHisto.size(); i++)
197  {
198  G4int histoId=fHisto[i];
200  G4int nbins = G4AnalysisManager::Instance()->GetH1Nbins(histoId);
204  G4cout<<"Histogram parameters : "<<i<<" "<<histoId<<" : "<<nbins<<" ";
205  G4cout<<xmin<<"/"<<xmax<<" "<<width<<G4endl;
206 
207  }
208 
209 }
210 
211 
212 
213