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