Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 //
28 /// \file common/analysis/include/ExG4HbookH2Manager.hh
29 /// \brief Definition of the ExG4HbookH2Manager class
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 "globals.hh"
40 
41 #include <tools/hbook/h2>
42 
43 #include <vector>
44 #include <map>
45 
46 class ExG4HbookFileManager;
47 
48 struct h2_booking {
49  h2_booking(G4int nxbins, G4double xmin, G4double xmax,
50  G4int nybins, G4double ymin, G4double ymax)
51  : fTitle(""),
52  fNxbins(nxbins),
53  fXmin(xmin),
54  fXmax(xmax),
55  fNybins(nybins),
56  fYmin(ymin),
57  fYmax(ymax) {}
58  G4String fTitle;
59  G4int fNxbins;
60  G4double fXmin;
61  G4double fXmax;
62  G4int fNybins;
63  G4double fYmin;
64  G4double fYmax;
65 };
66 
67 /// Manager class for HBook H2 histograms
68 ///
69 /// The class implements the G4VH2Manager manager for HBook.
70 /// It is provided separately from geant4/source/analysis in order
71 /// to avoid a need of linking Geant4 kernel libraries with cerblib.
72 
73 class ExG4HbookH2Manager : public G4VH2Manager
74 {
75  friend class ExG4HbookAnalysisManager;
76 
77  protected:
78  ExG4HbookH2Manager(const G4AnalysisManagerState& state);
79  virtual ~ExG4HbookH2Manager();
80 
81  // Functions specific to the output type
82  //
83 
84  // Set the offset of HBOOK ID for H2
85  // ( default value = firstHistoID + 100 if firstHistoID > 0;
86  // otherwise = 101 )
87  G4bool SetH2HbookIdOffset(G4int offset);
88  G4int GetH2HbookIdOffset() const;
89 
90  // Set methods
91  void SetFileManager(ExG4HbookFileManager* fileManager);
92 
93  // Access methods
94  tools::hbook::h2* GetH2(G4int id, G4bool warn = true,
95  G4bool onlyIfActive = true) const;
96 
97  protected:
98  // Virtual functions from base class
99  //
100 
101  // Methods to create histogrammes, ntuples
102  virtual G4int CreateH2(const G4String& name, const G4String& title,
103  G4int nxbins, G4double xmin, G4double xmax,
104  G4int nybins, G4double ymin, G4double ymax,
105  const G4String& xunitName = "none",
106  const G4String& yunitName = "none",
107  const G4String& xfcnName = "none",
108  const G4String& yfcnName = "none",
109  const G4String& xbinScheme = "linear",
110  const G4String& ybinScheme = "linear");
111 
112  virtual G4int CreateH2(const G4String& name, const G4String& title,
113  const std::vector<G4double>& xedges,
114  const std::vector<G4double>& yedges,
115  const G4String& xunitName = "none",
116  const G4String& yunitName = "none",
117  const G4String& xfcnName = "none",
118  const G4String& yfcnName = "none");
119 
120  virtual G4bool SetH2(G4int id,
121  G4int nxbins, G4double xmin, G4double xmax,
122  G4int nybins, G4double ymin, G4double ymax,
123  const G4String& xunitName = "none",
124  const G4String& yunitName = "none",
125  const G4String& xfcnName = "none",
126  const G4String& yfcnName = "none",
127  const G4String& xbinScheme = "linear",
128  const G4String& ybinScheme = "linear");
129 
130  virtual G4bool SetH2(G4int id,
131  const std::vector<G4double>& xedges,
132  const std::vector<G4double>& yedges,
133  const G4String& xunitName = "none",
134  const G4String& yunitName = "none",
135  const G4String& xfcnName = "none",
136  const G4String& yfcnName = "none");
137 
138  virtual G4bool ScaleH2(G4int id, G4double factor);
139 
140  // Methods to fill histogrammes, ntuples
141  virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue,
142  G4double weight = 1.0);
143 
144  // Access methods via names
145  virtual G4int GetH2Id(const G4String& name, G4bool warn = true) const;
146 
147  // Access to H2 parameters
148  virtual G4int GetH2Nxbins(G4int id) const;
149  virtual G4double GetH2Xmin(G4int id) const;
150  virtual G4double GetH2Xmax(G4int id) const;
151  virtual G4double GetH2XWidth(G4int id) const;
152  virtual G4int GetH2Nybins(G4int id) const;
153  virtual G4double GetH2Ymin(G4int id) const;
154  virtual G4double GetH2Ymax(G4int id) const;
155  virtual G4double GetH2YWidth(G4int id) const;
156 
157  // Setters for attributes for plotting
158  virtual G4bool SetH2Title(G4int id, const G4String& title);
159  virtual G4bool SetH2XAxisTitle(G4int id, const G4String& title);
160  virtual G4bool SetH2YAxisTitle(G4int id, const G4String& title);
161  virtual G4bool SetH2ZAxisTitle(G4int id, const G4String& title);
162 
163  // Access attributes for plotting
164  virtual G4String GetH2Title(G4int id) const;
165  virtual G4String GetH2XAxisTitle(G4int id) const;
166  virtual G4String GetH2YAxisTitle(G4int id) const;
167  virtual G4String GetH2ZAxisTitle(G4int id) const;
168 
169  // Write data on ASCII file
170  virtual G4bool WriteOnAscii(std::ofstream& output);
171 
172  private:
173  // static data members
174  //
175  static const G4int fgkDefaultH2HbookIdOffset;
176 
177  // methods
178  //
179  void SetH2HbookIdOffset();
180  void CreateH2sFromBooking();
181 
182  void Reset();
183  virtual h2_booking* GetH2Booking(G4int id, G4bool warn = true) const;
184 
185  virtual tools::hbook::h2* GetH2InFunction(G4int id, G4String function,
186  G4bool warn = true,
187  G4bool onlyIfActive = true) const;
188 
189  // data members
190  //
191  ExG4HbookFileManager* fFileManager;
192  G4int fH2HbookIdOffset;
193  std::vector<tools::hbook::h2*> fH2Vector;
194  std::vector<h2_booking*> fH2BookingVector;
195  std::map<G4String, G4int> fH2NameIdMap;
196 };
197 
198 // inline functions
199 
200 inline void ExG4HbookH2Manager::SetFileManager(ExG4HbookFileManager* fileManager)
201 { fFileManager = fileManager; }
202 
203 inline G4int ExG4HbookH2Manager::GetH2HbookIdOffset() const {
204  return fH2HbookIdOffset;
205 }
206 
207 #endif
208 
209 #endif
virtual G4bool SetH2YAxisTitle(G4int id, const G4String &title)=0
virtual G4String GetH2Title(G4int id) const =0
virtual G4double GetH2Xmax(G4int id) const =0
const XML_Char * name
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
virtual G4double GetH2Ymin(G4int id) const =0
virtual G4String GetH2ZAxisTitle(G4int id) const =0
subroutine title(NA, NB, NCA, NCB)
Definition: dpm25nuc7.f:1744
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