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 //
28 //
29 // $Id$
30 //
33 
34 // Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
35 
36 #ifdef G4_USE_HBOOK
37 
38 #ifndef ExG4HbookAnalysisManager_h
39 #define ExG4HbookAnalysisManager_h 1
40 
41 #include "G4VAnalysisManager.hh"
42 #include "globals.hh"
43 
44 #include <tools/hbook/wfile>
45 #include <tools/hbook/h1>
46 #include <tools/hbook/h2>
47 #include <tools/hbook/wntuple>
48 
49 #include <vector>
50 #include <map>
51 
52 #define setpawc setpawc_
53 #define setntuc setntuc_
54 //#define ntuc ntuc_
55 
56 class ExG4HbookAnalysisManager;
57 
58 namespace G4Hbook {
59 
60  typedef tools::hbook::h1 G4AnaH1;
61  typedef ExG4HbookAnalysisManager G4AnalysisManager;
62 }
63 
69 
70 class ExG4HbookAnalysisManager : public G4VAnalysisManager
71 {
72  public:
73  ExG4HbookAnalysisManager();
74  virtual ~ExG4HbookAnalysisManager();
75 
76  // static methods
77  static ExG4HbookAnalysisManager* Instance();
78 
79  // Methods to manipulate files
80  virtual G4bool OpenFile(const G4String& fileName);
81  virtual G4bool Write();
82  virtual G4bool CloseFile();
83 
84  // Methods to create histogrammes, ntuples
85  virtual G4int CreateH1(const G4String& name, const G4String& title,
86  G4int nbins, G4double xmin, G4double xmax);
87  virtual G4int CreateH2(const G4String& name, const G4String& title,
88  G4int nxbins, G4double xmin, G4double xmax,
89  G4int nybins, G4double ymin, G4double ymax);
90 
91  virtual void CreateNtuple(const G4String& name, const G4String& title);
92  virtual G4int CreateNtupleIColumn(const G4String& name);
93  virtual G4int CreateNtupleFColumn(const G4String& name);
94  virtual G4int CreateNtupleDColumn(const G4String& name);
95  virtual void FinishNtuple();
96 
97  // Methods to fill histogrammes, ntuples
98  virtual G4bool FillH1(G4int id, G4double value, G4double weight = 1.0);
99  virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue,
100  G4double weight = 1.0);
104  virtual G4bool AddNtupleRow();
105 
106  // Access methods
107  virtual tools::hbook::h1* GetH1(G4int id, G4bool warn = true) const;
108  virtual tools::hbook::h2* GetH2(G4int id, G4bool warn = true) const;
109  virtual tools::hbook::wntuple* GetNtuple() const;
110  //tools::hbook::h1* GetH1(const G4String& name, G4bool warn = true) const;
111 
112  // HBOOK does not allow IDs the same IDs for H1 and H2,
113  // and also IDs starting from 0; thats why there is defined an offset
114  // with respect to the G4AnalysisManager generic Ids.
115  // The default values of these offsets can be changed by the user.
116  //
117  // Set the offset of HBOOK ID for H1
118  // ( default value = firstHistoID if firstHistoID > 0; otherwise = 1)
119  G4bool SetH1HbookIdOffset(G4int offset);
120  //
121  // Set the offset of HBOOK ID for H2
122  // ( default value = firstHistoID + 100 if firstHistoID > 0; otherwise = 101 )
123  G4bool SetH2HbookIdOffset(G4int offset);
124  //
125  // Set the HBOOK ID for the ntuple
126  // (default value = 1 )
127  G4bool SetNtupleHbookId(G4int ntupleId);
128 
129  G4int GetH1HbookIdOffset() const;
130  G4int GetH2HbookIdOffset() const;
131  G4int GetNtupleHbookId() const;
132 
133  private:
134  // static data members
135  //
136  static ExG4HbookAnalysisManager* fgInstance;
137  static const G4int fgkDefaultH2HbookIdOffset;
138  static const G4int fgkDefaultNtupleHbookId;
139  static const G4String fgkDefaultNtupleDirectoryName;
140 
141  // methods
142  //
143  tools::hbook::wntuple::column<int>* GetNtupleIColumn(G4int id) const;
144  tools::hbook::wntuple::column<float>* GetNtupleFColumn(G4int id) const;
145  tools::hbook::wntuple::column<double>* GetNtupleDColumn(G4int id) const;
146 
147  // data members
148  //
149  G4int fH1HbookIdOffset;
150  G4int fH2HbookIdOffset;
151  G4int fNtupleHbookId;
152 
153  tools::hbook::wfile* fFile;
154 
155  std::vector<tools::hbook::h1*> fH1Vector;
156  std::map<G4String, tools::hbook::h1*> fH1MapByName;
157 
158  std::vector<tools::hbook::h2*> fH2Vector;
159  std::map<G4String, tools::hbook::h2*> fH2MapByName;
160 
161  G4String fNtupleName;
162  G4String fNtupleTitle;
163  tools::hbook::wntuple* fNtuple;
164  std::map<G4int, tools::hbook::wntuple::column<int>* > fNtupleIColumnMap;
165  std::map<G4int, tools::hbook::wntuple::column<float>* > fNtupleFColumnMap;
166  std::map<G4int, tools::hbook::wntuple::column<double>* > fNtupleDColumnMap;
167 };
168 
169 // inline functions
170 
171 inline G4int ExG4HbookAnalysisManager::GetH1HbookIdOffset() const {
172  return fH1HbookIdOffset;
173 }
174 
175 inline G4int ExG4HbookAnalysisManager::GetH2HbookIdOffset() const {
176  return fH2HbookIdOffset;
177 }
178 
179 inline G4int ExG4HbookAnalysisManager::GetNtupleHbookId() const {
180  return fNtupleHbookId;
181 }
182 
183 #endif
184 
185 #endif