source: trunk/examples/extended/electromagnetic/TestEm16/src/HistoManager.cc@ 1036

Last change on this file since 1036 was 807, checked in by garnier, 17 years ago

update

File size: 6.8 KB
RevLine 
[807]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//
27//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
28//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
29
30#include "HistoManager.hh"
31#include "HistoMessenger.hh"
32#include "G4UnitsTable.hh"
33
34#ifdef G4ANALYSIS_USE
35#include "AIDA/AIDA.h"
36#endif
37
38//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
39
40HistoManager::HistoManager()
41:af(0),tree(0),factoryOn(false)
42{
43#ifdef G4ANALYSIS_USE
44 // Creating the analysis factory
45 af = AIDA_createAnalysisFactory();
46 if(!af) {
47 G4cout << " HistoManager::HistoManager() :"
48 << " problem creating the AIDA analysis factory."
49 << G4endl;
50 }
51#endif
52
53 fileName[0] = "testem16";
54 fileType = "hbook";
55 fileOption = "--noErrors uncompress";
56 // histograms
57 for (G4int k=0; k<MaxHisto; k++) {
58 histo[k] = 0;
59 exist[k] = false;
60 Unit[k] = 1.0;
61 Width[k] = 1.0;
62 }
63
64 histoMessenger = new HistoMessenger(this);
65}
66
67//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
68
69HistoManager::~HistoManager()
70{
71 delete histoMessenger;
72
73#ifdef G4ANALYSIS_USE
74 delete af;
75#endif
76}
77
78//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
79
80void HistoManager::book()
81{
82#ifdef G4ANALYSIS_USE
83 if(!af) {
84 G4cout << "HistoManager::book: WARNING AnalysisFactory is not created,"
85 << " there will be no AIDA histos" << G4endl;
86 return;
87 }
88 G4cout << "\n----> Book AIDA histograms "<< G4endl;
89
90 // Creating a tree mapped to an hbook file.
91 fileName[1] = fileName[0] + "." + fileType;
92 G4bool readOnly = false;
93 G4bool createNew = true;
94 AIDA::ITreeFactory* tf = af->createTreeFactory();
95 tree = tf->create(fileName[1], fileType, readOnly, createNew, fileOption);
96 delete tf;
97 if(!tree) {
98 G4cout << "HistoManager::book() :"
99 << " problem creating the AIDA tree with "
100 << " storeName = " << fileName[1]
101 << " storeType = " << fileType
102 << " readOnly = " << readOnly
103 << " createNew = " << createNew
104 << " options = " << fileOption
105 << G4endl;
106 return;
107 }
108
109 // Creating a histogram factory, whose histograms will be handled by the tree
110 AIDA::IHistogramFactory* hf = af->createHistogramFactory(*tree);
111
112 // create selected histograms
113 for (G4int k=0; k<MaxHisto; k++) {
114 if (exist[k]) {
115 histo[k] = hf->createHistogram1D( Label[k], Title[k],
116 Nbins[k], Vmin[k], Vmax[k]);
117 factoryOn = true;
118 }
119 }
120 delete hf;
121 if (factoryOn)
122 G4cout << "\n----> Histogram Tree is opened in " << fileName[1] << G4endl;
123#else
124 G4cout << "G4ANALYSIS_USE was not set, there will be no AIDA histos"
125 << G4endl;
126#endif
127}
128
129//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
130
131void HistoManager::save()
132{
133#ifdef G4ANALYSIS_USE
134 if (factoryOn) {
135 tree->commit(); // Writing the histograms to the file
136 tree->close(); // and closing the tree (and the file)
137 G4cout << "\n----> Histogram Tree is saved in " << fileName[1] << G4endl;
138
139 delete tree;
140 tree = 0;
141 factoryOn = false;
142 }
143#endif
144}
145
146//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
147
148void HistoManager::FillHisto(G4int ih, G4double e, G4double weight)
149{
150 if (ih > MaxHisto) {
151 G4cout << "---> warning from HistoManager::FillHisto() : histo " << ih
152 << "does not exist; e= " << e << " w= " << weight << G4endl;
153 return;
154 }
155#ifdef G4ANALYSIS_USE
156 if(exist[ih]) histo[ih]->fill(e/Unit[ih], weight);
157#endif
158}
159
160//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
161
162void HistoManager::SetHisto(G4int ih,
163 G4int nbins, G4double valmin, G4double valmax, const G4String& unit)
164{
165 if (ih > MaxHisto) {
166 G4cout << "---> warning from HistoManager::SetHisto() : histo " << ih
167 << "does not exist" << G4endl;
168 return;
169 }
170
171 const G4String id[] = { "0", "1", "2", "3" };
172 const G4String title[] =
173 { "dummy", //0
174 "SynRad Energy", //1
175 "SynRad Power ", //2
176 "Path Length" //3
177 };
178
179
180 G4String titl = title[ih];
181 G4double vmin = valmin, vmax = valmax;
182 Unit[ih] = 1.;
183
184 if (unit != "none") {
185 titl = title[ih] + " (" + unit + ")";
186 Unit[ih] = G4UnitDefinition::GetValueOf(unit);
187 vmin = valmin/Unit[ih]; vmax = valmax/Unit[ih];
188 }
189
190 exist[ih] = true;
191 Label[ih] = id[ih];
192 Title[ih] = titl;
193 Nbins[ih] = nbins;
194 Vmin[ih] = vmin;
195 Vmax[ih] = vmax;
196 Width[ih] = (valmax-valmin)/nbins;
197
198 G4cout << "----> SetHisto " << ih << ": " << titl << "; "
199 << nbins << " bins from "
200 << vmin << " " << unit << " to " << vmax << " " << unit << G4endl;
201
202}
203
204//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
205
206void HistoManager::RemoveHisto(G4int ih)
207{
208 if (ih > MaxHisto) {
209 G4cout << "---> warning from HistoManager::RemoveHisto() : histo " << ih
210 << "does not exist" << G4endl;
211 return;
212 }
213
214 histo[ih] = 0; exist[ih] = false;
215}
216
217//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
218
Note: See TracBrowser for help on using the repository browser.