Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExG4HbookAnalysisManager.hh
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 // $Id$
27 //
30 
31 // Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
32 
33 #ifdef G4_USE_HBOOK
34 
35 #ifndef ExG4HbookAnalysisManager_h
36 #define ExG4HbookAnalysisManager_h 1
37 
38 #include "G4VAnalysisManager.hh"
39 #include "globals.hh"
40 
41 #include <tools/hbook/wfile>
42 #include <tools/hbook/h1>
43 #include <tools/hbook/h2>
44 #include <tools/hbook/wntuple>
45 
46 #include <vector>
47 #include <map>
48 
49 #define setpawc setpawc_
50 #define setntuc setntuc_
51 //#define ntuc ntuc_
52 
53 class ExG4HbookAnalysisManager;
54 
55 namespace G4Hbook {
56 
57  typedef tools::hbook::h1 G4AnaH1;
58  typedef ExG4HbookAnalysisManager G4AnalysisManager;
59 }
60 
61 struct h1_booking {
62  h1_booking(G4int nbins, G4double xmin, G4double xmax)
63  : fTitle(""),
64  fNbins(nbins),
65  fXmin(xmin),
66  fXmax(xmax) {}
67  G4String fTitle;
68  G4int fNbins;
69  G4double fXmin;
70  G4double fXmax;
71 };
72 
73 struct h2_booking {
74  h2_booking(G4int nxbins, G4double xmin, G4double xmax,
75  G4int nybins, G4double ymin, G4double ymax)
76  : fTitle(""),
77  fNxbins(nxbins),
78  fXmin(xmin),
79  fXmax(xmax),
80  fNybins(nybins),
81  fYmin(ymin),
82  fYmax(ymax) {}
83  G4String fTitle;
84  G4int fNxbins;
85  G4double fXmin;
86  G4double fXmax;
87  G4int fNybins;
88  G4double fYmin;
89  G4double fYmax;
90 };
91 
97 
98 class ExG4HbookAnalysisManager : public G4VAnalysisManager
99 {
100  public:
101  ExG4HbookAnalysisManager();
102  virtual ~ExG4HbookAnalysisManager();
103 
104  // static methods
105  static ExG4HbookAnalysisManager* Instance();
106 
107  // Methods to manipulate files
109  virtual G4bool OpenFile(const G4String& fileName);
110  virtual G4bool Write();
111  virtual G4bool CloseFile();
112 
113  // Methods to create histogrammes, ntuples
114  virtual G4int CreateH1(const G4String& name, const G4String& title,
115  G4int nbins, G4double xmin, G4double xmax,
116  const G4String& unitName = "none",
117  const G4String& fcnName = "none");
118  virtual G4int CreateH2(const G4String& name, const G4String& title,
119  G4int nxbins, G4double xmin, G4double xmax,
120  G4int nybins, G4double ymin, G4double ymax,
121  const G4String& xunitName = "none",
122  const G4String& yunitName = "none",
123  const G4String& xfcnName = "none",
124  const G4String& yfcnName = "none");
125 
126  virtual G4bool SetH1(G4int id,
127  G4int nbins, G4double xmin, G4double xmax,
128  const G4String& unitName = "none",
129  const G4String& fcnName = "none");
130  virtual G4bool SetH2(G4int id,
131  G4int nxbins, G4double xmin, G4double xmax,
132  G4int nybins, G4double ymin, G4double ymax,
133  const G4String& xunitName = "none",
134  const G4String& yunitName = "none",
135  const G4String& xfcnName = "none",
136  const G4String& yfcnName = "none");
137 
138  virtual G4bool ScaleH1(G4int id, G4double factor);
139  virtual G4bool ScaleH2(G4int id, G4double factor);
140 
141  virtual void CreateNtuple(const G4String& name, const G4String& title);
142  virtual G4int CreateNtupleIColumn(const G4String& name);
143  virtual G4int CreateNtupleFColumn(const G4String& name);
144  virtual G4int CreateNtupleDColumn(const G4String& name);
145  virtual void FinishNtuple();
146 
147  // Methods to fill histogrammes, ntuples
148  virtual G4bool FillH1(G4int id, G4double value, G4double weight = 1.0);
149  virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue,
150  G4double weight = 1.0);
154  virtual G4bool AddNtupleRow();
155 
156  // Access methods
157  virtual tools::hbook::h1* GetH1(G4int id, G4bool warn = true,
158  G4bool onlyIfActive = true) const;
159  virtual tools::hbook::h2* GetH2(G4int id, G4bool warn = true,
160  G4bool onlyIfActive = true) const;
161  virtual tools::hbook::wntuple* GetNtuple() const;
162 
163  // Access methods via names
164  virtual G4int GetH1Id(const G4String& name, G4bool warn = true) const;
165  virtual G4int GetH2Id(const G4String& name, G4bool warn = true) const;
166 
167  // Access to H1 parameters
168  virtual G4int GetH1Nbins(G4int id) const;
169  virtual G4double GetH1Xmin(G4int id) const;
170  virtual G4double GetH1Xmax(G4int id) const;
171  virtual G4double GetH1Width(G4int id) const;
172 
173  // Access to H2 parameters
174  virtual G4int GetH2Nxbins(G4int id) const;
175  virtual G4double GetH2Xmin(G4int id) const;
176  virtual G4double GetH2Xmax(G4int id) const;
177  virtual G4double GetH2XWidth(G4int id) const;
178  virtual G4int GetH2Nybins(G4int id) const;
179  virtual G4double GetH2Ymin(G4int id) const;
180  virtual G4double GetH2Ymax(G4int id) const;
181  virtual G4double GetH2YWidth(G4int id) const;
182 
183  // Setters for attributes for plotting
184  virtual G4bool SetH1Title(G4int id, const G4String& title);
185  virtual G4bool SetH1XAxisTitle(G4int id, const G4String& title);
186  virtual G4bool SetH1YAxisTitle(G4int id, const G4String& title);
187  virtual G4bool SetH2Title(G4int id, const G4String& title);
188  virtual G4bool SetH2XAxisTitle(G4int id, const G4String& title);
189  virtual G4bool SetH2YAxisTitle(G4int id, const G4String& title);
190  virtual G4bool SetH2ZAxisTitle(G4int id, const G4String& title);
191 
192  // Access attributes for plotting
193  virtual G4String GetH1Title(G4int id) const;
194  virtual G4String GetH1XAxisTitle(G4int id) const;
195  virtual G4String GetH1YAxisTitle(G4int id) const;
196  virtual G4String GetH2Title(G4int id) const;
197  virtual G4String GetH2XAxisTitle(G4int id) const;
198  virtual G4String GetH2YAxisTitle(G4int id) const;
199  virtual G4String GetH2ZAxisTitle(G4int id) const;
200 
201  // HBOOK does not allow IDs the same IDs for H1 and H2,
202  // and also IDs starting from 0; thats why there is defined an offset
203  // with respect to the G4AnalysisManager generic Ids.
204  // The default values of these offsets can be changed by the user.
205  //
206  // Set the offset of HBOOK ID for H1
207  // ( default value = firstHistoID if firstHistoID > 0; otherwise = 1)
208  G4bool SetH1HbookIdOffset(G4int offset);
209  //
210  // Set the offset of HBOOK ID for H2
211  // ( default value = firstHistoID + 100 if firstHistoID > 0; otherwise = 101 )
212  G4bool SetH2HbookIdOffset(G4int offset);
213  //
214  // Set the HBOOK ID for the ntuple
215  // (default value = 1 )
216  G4bool SetNtupleHbookId(G4int ntupleId);
217 
218  G4int GetH1HbookIdOffset() const;
219  G4int GetH2HbookIdOffset() const;
220  G4int GetNtupleHbookId() const;
221 
222  protected:
223  virtual G4bool WriteOnAscii(std::ofstream& output);
224 
225  private:
226  // static data members
227  //
228  static ExG4HbookAnalysisManager* fgInstance;
229  static const G4int fgkDefaultH2HbookIdOffset;
230  static const G4int fgkDefaultNtupleHbookId;
231  static const G4String fgkDefaultNtupleDirectoryName;
232 
233  // methods
234  //
235  void SetH1HbookIdOffset();
236  void SetH2HbookIdOffset();
237  void CreateH1FromBooking();
238  void CreateH2FromBooking();
239  void CreateNtupleFromBooking();
240  tools::hbook::wntuple::column<int>* GetNtupleIColumn(G4int id) const;
241  tools::hbook::wntuple::column<float>* GetNtupleFColumn(G4int id) const;
242  tools::hbook::wntuple::column<double>* GetNtupleDColumn(G4int id) const;
243  void Reset();
244 
245  virtual h1_booking* GetH1Booking(G4int id, G4bool warn = true) const;
246  virtual h2_booking* GetH2Booking(G4int id, G4bool warn = true) const;
247 
248  virtual tools::hbook::h1* GetH1InFunction(G4int id, G4String function,
249  G4bool warn = true,
250  G4bool onlyIfActive = true) const;
251  virtual tools::hbook::h2* GetH2InFunction(G4int id, G4String function,
252  G4bool warn = true,
253  G4bool onlyIfActive = true) const;
254  void UpdateTitle(G4String& title,
255  const G4String& unitName, const G4String& fcnName) const;
256 
257  // data members
258  //
259  G4int fH1HbookIdOffset;
260  G4int fH2HbookIdOffset;
261  G4int fNtupleHbookId;
262 
263  tools::hbook::wfile* fFile;
264 
265  std::vector<tools::hbook::h1*> fH1Vector;
266  std::vector<tools::hbook::h2*> fH2Vector;
267  std::vector<h1_booking*> fH1BookingVector;
268  std::vector<h2_booking*> fH2BookingVector;
269  std::map<G4String, G4int> fH1NameIdMap;
270  std::map<G4String, G4int> fH2NameIdMap;
271 
272  tools::hbook::wntuple* fNtuple;
273  tools::ntuple_booking* fNtupleBooking;
274  std::map<G4int, tools::hbook::wntuple::column<int>* > fNtupleIColumnMap;
275  std::map<G4int, tools::hbook::wntuple::column<float>* > fNtupleFColumnMap;
276  std::map<G4int, tools::hbook::wntuple::column<double>* > fNtupleDColumnMap;
277 };
278 
279 // inline functions
280 
281 inline G4int ExG4HbookAnalysisManager::GetH1HbookIdOffset() const {
282  return fH1HbookIdOffset;
283 }
284 
285 inline G4int ExG4HbookAnalysisManager::GetH2HbookIdOffset() const {
286  return fH2HbookIdOffset;
287 }
288 
289 inline G4int ExG4HbookAnalysisManager::GetNtupleHbookId() const {
290  return fNtupleHbookId;
291 }
292 
293 #endif
294 
295 #endif