Geant4  10.02.p01
ExG4HbookH1Manager.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 ExG4HbookH1Manager_h
36 #define ExG4HbookH1Manager_h 1
37 
38 #include "G4VH1Manager.hh"
39 #include "G4THnManager.hh"
40 #include "G4HnManager.hh"
42 #include "globals.hh"
43 
44 #include <tools/hbook/h1>
45 
46 #include <vector>
47 #include <map>
48 
49 class ExG4HbookFileManager;
50 
51 struct h1_booking {
52  h1_booking(G4int nbins, G4double xmin, G4double xmax)
53  : fTitle(""),
54  fXAxisTitle(""),
55  fYAxisTitle(""),
56  fNbins(nbins),
57  fXmin(xmin),
58  fXmax(xmax),
59  fEdges() {}
60  h1_booking(const std::vector<G4double>& edges)
61  : fTitle(""),
62  fXAxisTitle(""),
63  fYAxisTitle(""),
64  fNbins(0),
65  fXmin(0),
66  fXmax(0),
67  fEdges() {
68  for (G4int i=0; i<G4int(edges.size()); ++i) fEdges.push_back(edges[i]);
69  }
70  G4String fTitle;
71  G4String fXAxisTitle;
72  G4String fYAxisTitle;
73  G4int fNbins;
74  G4double fXmin;
75  G4double fXmax;
76  std::vector<G4double> fEdges;
77 };
78 
84 
85 class ExG4HbookH1Manager : public G4VH1Manager,
86  public G4THnManager<tools::hbook::h1>
87 {
88  friend class ExG4HbookAnalysisManager;
89 
90  protected:
91  ExG4HbookH1Manager(const G4AnalysisManagerState& state);
92  virtual ~ExG4HbookH1Manager();
93 
94  // Functions specific to the output type
95  //
96 
97  // HBOOK does not allow IDs the same IDs for H1 and H2,
98  // and also IDs starting from 0; thats why there is defined an offset
99  // with respect to the G4AnalysisManager generic Ids.
100  // The default values of these offsets can be changed by the user.
101  //
102  // Set the offset of HBOOK ID for H1
103  // ( default value = firstHistoID if firstHistoID > 0; otherwise = 1)
104  G4bool SetH1HbookIdOffset(G4int offset);
105  G4int GetH1HbookIdOffset() const;
106 
107  // Set methods
108  void SetFileManager(ExG4HbookFileManager* fileManager);
109 
110  // Access methods
111  //
112  tools::hbook::h1* GetH1(G4int id, G4bool warn = true,
113  G4bool onlyIfActive = true) const;
114 
115  // Iterators
116  std::vector<tools::hbook::h1*>::iterator BeginH1();
117  std::vector<tools::hbook::h1*>::iterator EndH1();
118  std::vector<tools::hbook::h1*>::const_iterator BeginConstH1() const;
119  std::vector<tools::hbook::h1*>::const_iterator EndConstH1() const;
120 
121  // Virtual functions from base class
122  //
123 
124  // Methods to create histogrammes, ntuples
125  virtual G4int CreateH1(const G4String& name, const G4String& title,
126  G4int nbins, G4double xmin, G4double xmax,
127  const G4String& unitName = "none",
128  const G4String& fcnName = "none",
129  const G4String& binSchemeName = "linear");
130  virtual G4int CreateH1(const G4String& name, const G4String& title,
131  const std::vector<G4double>& edges,
132  const G4String& unitName = "none",
133  const G4String& fcnName = "none");
134 
135  virtual G4bool SetH1(G4int id,
136  G4int nbins, G4double xmin, G4double xmax,
137  const G4String& unitName = "none",
138  const G4String& fcnName = "none",
139  const G4String& binSchemeName = "linear");
140  virtual G4bool SetH1(G4int id,
141  const std::vector<G4double>& edges,
142  const G4String& unitName = "none",
143  const G4String& fcnName = "none");
144 
145  virtual G4bool ScaleH1(G4int id, G4double factor);
146 
147 
148  // Methods to fill histogrammes, ntuples
149  virtual G4bool FillH1(G4int id, G4double value, G4double weight = 1.0);
150 
151  // Access methods
152  //
153  virtual G4int GetH1Id(const G4String& name, G4bool warn = true) const;
154 
155  // Access to H1 parameters
156  virtual G4int GetH1Nbins(G4int id) const;
157  virtual G4double GetH1Xmin(G4int id) const;
158  virtual G4double GetH1Xmax(G4int id) const;
159  virtual G4double GetH1Width(G4int id) const;
160 
161  // Setters for attributes for plotting
162  virtual G4bool SetH1Title(G4int id, const G4String& title);
163  virtual G4bool SetH1XAxisTitle(G4int id, const G4String& title);
164  virtual G4bool SetH1YAxisTitle(G4int id, const G4String& title);
165 
166  // Access attributes for plotting
167  virtual G4String GetH1Title(G4int id) const;
168  virtual G4String GetH1XAxisTitle(G4int id) const;
169  virtual G4String GetH1YAxisTitle(G4int id) const;
170 
171  // Write data on ASCII file
172  virtual G4bool WriteOnAscii(std::ofstream& output);
173 
174  // Access to Hn manager
175  virtual std::shared_ptr<G4HnManager> GetHnManager();
176 
177  private:
178  // methods
179  //
180  void SetH1HbookIdOffset();
181  void AddH1Information(const G4String& name,
182  const G4String& unitName,
183  const G4String& fcnName,
184  G4BinScheme binScheme) const;
185 
186  G4int CreateH1FromBooking(h1_booking* h1Booking,
187  G4bool chDir = true);
188  G4int RegisterH1Booking(const G4String& name,
189  h1_booking* h1Booking);
190 
191  void BeginCreateH1(const G4String& name);
192  G4int FinishCreateH1(const G4String& name, h1_booking* h1Booking,
193  const G4String& unitName, const G4String& fcnName,
194  G4BinScheme binScheme);
195 
196  G4bool FinishSetH1(G4int id,
197  G4HnInformation* info,
198  const G4String& unitName, const G4String& fcnName,
199  G4BinScheme binScheme);
200 
201  void CreateH1sFromBooking();
202  void Reset();
203  virtual h1_booking* GetH1Booking(G4int id, G4bool warn = true) const;
204 
205  virtual tools::hbook::h1* GetH1InFunction(G4int id, G4String function,
206  G4bool warn = true,
207  G4bool onlyIfActive = true) const;
208 
209  // data members
210  //
211  ExG4HbookBaseHnManager fBaseToolsManager;
212  ExG4HbookFileManager* fFileManager;
213  G4int fH1HbookIdOffset;
214  std::vector<tools::hbook::h1*> fH1Vector;
215  std::vector<h1_booking*> fH1BookingVector;
216  std::map<G4String, G4int> fH1NameIdMap;
217 };
218 
219 // inline functions
220 
221 inline void ExG4HbookH1Manager::SetFileManager(ExG4HbookFileManager* fileManager)
222 { fFileManager = fileManager; }
223 
224 inline G4int ExG4HbookH1Manager::GetH1HbookIdOffset() const {
225  return fH1HbookIdOffset;
226 }
227 
228 inline std::vector<tools::hbook::h1*>::iterator ExG4HbookH1Manager::BeginH1()
229 { return BeginT(); }
230 
231 inline std::vector<tools::hbook::h1*>::iterator ExG4HbookH1Manager::EndH1()
232 { return EndT(); }
233 
234 inline std::vector<tools::hbook::h1*>::const_iterator
235 ExG4HbookH1Manager::BeginConstH1() const
236 { return BeginConstT(); }
237 
238 inline std::vector<tools::hbook::h1*>::const_iterator
239 ExG4HbookH1Manager::EndConstH1() const
240 { return EndConstT(); }
241 
242 inline std::shared_ptr<G4HnManager> ExG4HbookH1Manager::GetHnManager()
243 { return std::shared_ptr<G4HnManager>(fHnManager); }
244 
245 
246 #endif
247 
248 #endif
virtual G4bool SetH1YAxisTitle(G4int id, const G4String &title)=0
virtual G4double GetH1Width(G4int id) const =0
G4String name
Definition: TRTMaterials.hh:40
virtual G4String GetH1Title(G4int id) const =0
int G4int
Definition: G4Types.hh:78
virtual G4String GetH1YAxisTitle(G4int id) const =0
G4bool Reset()
virtual std::shared_ptr< G4HnManager > GetHnManager()=0
virtual G4double GetH1Xmin(G4int id) const =0
bool G4bool
Definition: G4Types.hh:79
virtual G4int GetH1Nbins(G4int id) const =0
Manager class for tools::hbook::base_histo functions.
Definition of the ExG4HbookBaseHnManager class.
virtual G4double GetH1Xmax(G4int id) const =0
virtual G4int GetH1Id(const G4String &name, G4bool warn=true) const =0
virtual G4bool SetH1XAxisTitle(G4int id, const G4String &title)=0
virtual G4bool FillH1(G4int id, G4double value, G4double weight=1.0)=0
virtual G4String GetH1XAxisTitle(G4int id) const =0
static const G4double factor
virtual G4bool SetH1Title(G4int id, const G4String &title)=0
G4BinScheme
Definition: G4BinScheme.hh:40
virtual G4bool SetH1(G4int id, G4int nbins, G4double xmin, G4double xmax, const G4String &unitName="none", const G4String &fcnName="none", const G4String &binSchemeName="linear")=0
virtual G4bool ScaleH1(G4int id, G4double factor)=0
double G4double
Definition: G4Types.hh:76
virtual G4bool WriteOnAscii(std::ofstream &output)=0
virtual G4int CreateH1(const G4String &name, const G4String &title, G4int nbins, G4double xmin, G4double xmax, const G4String &unitName="none", const G4String &fcnName="none", const G4String &binSchemeName="linear")=0