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