Geant4  10.01.p02
ExG4HbookH2Manager.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 ExG4HbookH2Manager_h
36 #define ExG4HbookH2Manager_h 1
37 
38 #include "G4VH2Manager.hh"
40 #include "globals.hh"
41 
42 #include <tools/hbook/h2>
43 
44 #include <vector>
45 #include <map>
46 
47 class ExG4HbookFileManager;
48 
49 struct h2_booking {
50  h2_booking(G4int nxbins, G4double xmin, G4double xmax,
51  G4int nybins, G4double ymin, G4double ymax)
52  : fTitle(""),
53  fNxbins(nxbins),
54  fXmin(xmin),
55  fXmax(xmax),
56  fNybins(nybins),
57  fYmin(ymin),
58  fYmax(ymax) {}
59  G4String fTitle;
60  G4int fNxbins;
61  G4double fXmin;
62  G4double fXmax;
63  G4int fNybins;
64  G4double fYmin;
65  G4double fYmax;
66 };
67 
73 
74 class ExG4HbookH2Manager : public G4VH2Manager
75 {
76  friend class ExG4HbookAnalysisManager;
77 
78  protected:
79  ExG4HbookH2Manager(const G4AnalysisManagerState& state);
80  virtual ~ExG4HbookH2Manager();
81 
82  // Functions specific to the output type
83  //
84 
85  // Set the offset of HBOOK ID for H2
86  // ( default value = firstHistoID + 100 if firstHistoID > 0;
87  // otherwise = 101 )
88  G4bool SetH2HbookIdOffset(G4int offset);
89  G4int GetH2HbookIdOffset() const;
90 
91  // Set methods
92  void SetFileManager(ExG4HbookFileManager* fileManager);
93 
94  // Access methods
95  tools::hbook::h2* GetH2(G4int id, G4bool warn = true,
96  G4bool onlyIfActive = true) const;
97 
98  // Iterators
99  std::vector<tools::hbook::h2*>::iterator BeginH2();
100  std::vector<tools::hbook::h2*>::iterator EndH2();
101  std::vector<tools::hbook::h2*>::const_iterator BeginConstH2() const;
102  std::vector<tools::hbook::h2*>::const_iterator EndConstH2() const;
103 
104  protected:
105  // Virtual functions from base class
106  //
107 
108  // Methods to create histogrammes, ntuples
109  virtual G4int CreateH2(const G4String& name, const G4String& title,
110  G4int nxbins, G4double xmin, G4double xmax,
111  G4int nybins, G4double ymin, G4double ymax,
112  const G4String& xunitName = "none",
113  const G4String& yunitName = "none",
114  const G4String& xfcnName = "none",
115  const G4String& yfcnName = "none",
116  const G4String& xbinScheme = "linear",
117  const G4String& ybinScheme = "linear");
118 
119  virtual G4int CreateH2(const G4String& name, const G4String& title,
120  const std::vector<G4double>& xedges,
121  const std::vector<G4double>& yedges,
122  const G4String& xunitName = "none",
123  const G4String& yunitName = "none",
124  const G4String& xfcnName = "none",
125  const G4String& yfcnName = "none");
126 
127  virtual G4bool SetH2(G4int id,
128  G4int nxbins, G4double xmin, G4double xmax,
129  G4int nybins, G4double ymin, G4double ymax,
130  const G4String& xunitName = "none",
131  const G4String& yunitName = "none",
132  const G4String& xfcnName = "none",
133  const G4String& yfcnName = "none",
134  const G4String& xbinScheme = "linear",
135  const G4String& ybinScheme = "linear");
136 
137  virtual G4bool SetH2(G4int id,
138  const std::vector<G4double>& xedges,
139  const std::vector<G4double>& yedges,
140  const G4String& xunitName = "none",
141  const G4String& yunitName = "none",
142  const G4String& xfcnName = "none",
143  const G4String& yfcnName = "none");
144 
145  virtual G4bool ScaleH2(G4int id, G4double factor);
146 
147  // Methods to fill histogrammes, ntuples
148  virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue,
149  G4double weight = 1.0);
150 
151  // Access methods via names
152  virtual G4int GetH2Id(const G4String& name, G4bool warn = true) const;
153 
154  // Access to H2 parameters
155  virtual G4int GetH2Nxbins(G4int id) const;
156  virtual G4double GetH2Xmin(G4int id) const;
157  virtual G4double GetH2Xmax(G4int id) const;
158  virtual G4double GetH2XWidth(G4int id) const;
159  virtual G4int GetH2Nybins(G4int id) const;
160  virtual G4double GetH2Ymin(G4int id) const;
161  virtual G4double GetH2Ymax(G4int id) const;
162  virtual G4double GetH2YWidth(G4int id) const;
163 
164  // Setters for attributes for plotting
165  virtual G4bool SetH2Title(G4int id, const G4String& title);
166  virtual G4bool SetH2XAxisTitle(G4int id, const G4String& title);
167  virtual G4bool SetH2YAxisTitle(G4int id, const G4String& title);
168  virtual G4bool SetH2ZAxisTitle(G4int id, const G4String& title);
169 
170  // Access attributes for plotting
171  virtual G4String GetH2Title(G4int id) const;
172  virtual G4String GetH2XAxisTitle(G4int id) const;
173  virtual G4String GetH2YAxisTitle(G4int id) const;
174  virtual G4String GetH2ZAxisTitle(G4int id) const;
175 
176  // Write data on ASCII file
177  virtual G4bool WriteOnAscii(std::ofstream& output);
178 
179  private:
180  // static data members
181  //
182  static const G4int fgkDefaultH2HbookIdOffset;
183 
184  // methods
185  //
186  void SetH2HbookIdOffset();
187  void CreateH2sFromBooking();
188 
189  void Reset();
190  virtual h2_booking* GetH2Booking(G4int id, G4bool warn = true) const;
191 
192  virtual tools::hbook::h2* GetH2InFunction(G4int id, G4String function,
193  G4bool warn = true,
194  G4bool onlyIfActive = true) const;
195 
196  // data members
197  //
198  ExG4HbookBaseHnManager fBaseToolsManager;
199  ExG4HbookFileManager* fFileManager;
200  G4int fH2HbookIdOffset;
201  std::vector<tools::hbook::h2*> fH2Vector;
202  std::vector<h2_booking*> fH2BookingVector;
203  std::map<G4String, G4int> fH2NameIdMap;
204 };
205 
206 // inline functions
207 
208 inline void ExG4HbookH2Manager::SetFileManager(ExG4HbookFileManager* fileManager)
209 { fFileManager = fileManager; }
210 
211 inline G4int ExG4HbookH2Manager::GetH2HbookIdOffset() const {
212  return fH2HbookIdOffset;
213 }
214 
215 inline std::vector<tools::hbook::h2*>::iterator ExG4HbookH2Manager::BeginH2()
216 { return fH2Vector.begin(); }
217 
218 inline std::vector<tools::hbook::h2*>::iterator ExG4HbookH2Manager::EndH2()
219 { return fH2Vector.end(); }
220 
221 inline std::vector<tools::hbook::h2*>::const_iterator
222 ExG4HbookH2Manager::BeginConstH2() const
223 { return fH2Vector.begin(); }
224 
225 inline std::vector<tools::hbook::h2*>::const_iterator
226 ExG4HbookH2Manager::EndConstH2() const
227 { return fH2Vector.end(); }
228 
229 
230 #endif
231 
232 #endif
virtual G4bool SetH2YAxisTitle(G4int id, const G4String &title)=0
virtual G4String GetH2Title(G4int id) const =0
virtual G4double GetH2Xmax(G4int id) const =0
G4String name
Definition: TRTMaterials.hh:40
virtual G4int GetH2Nybins(G4int id) const =0
int G4int
Definition: G4Types.hh:78
virtual G4bool ScaleH2(G4int id, G4double factor)=0
virtual G4bool WriteOnAscii(std::ofstream &output)=0
virtual G4bool SetH2ZAxisTitle(G4int id, const G4String &title)=0
virtual G4int GetH2Nxbins(G4int id) const =0
virtual G4double GetH2Xmin(G4int id) const =0
virtual G4bool SetH2Title(G4int id, const G4String &title)=0
bool G4bool
Definition: G4Types.hh:79
virtual G4double GetH2YWidth(G4int id) const =0
virtual G4int CreateH2(const G4String &name, const G4String &title, G4int nxbins, G4double xmin, G4double xmax, G4int nybins, G4double ymin, G4double ymax, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &xbinScheme="linear", const G4String &ybinScheme="linear")=0
virtual G4bool SetH2(G4int id, G4int nxbins, G4double xmin, G4double xmax, G4int nybins, G4double ymin, G4double ymax, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &xbinScheme="linear", const G4String &ybinScheme="linear")=0
Manager class for tools::hbook::base_histo functions.
virtual G4double GetH2Ymin(G4int id) const =0
Definition of the ExG4HbookBaseHnManager class.
virtual G4String GetH2ZAxisTitle(G4int id) const =0
static const G4double factor
virtual G4String GetH2YAxisTitle(G4int id) const =0
virtual G4int GetH2Id(const G4String &name, G4bool warn=true) const =0
virtual G4String GetH2XAxisTitle(G4int id) const =0
virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue, G4double weight=1.0)=0
double G4double
Definition: G4Types.hh:76
virtual G4double GetH2XWidth(G4int id) const =0
virtual G4bool SetH2XAxisTitle(G4int id, const G4String &title)=0
virtual G4double GetH2Ymax(G4int id) const =0