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