Geant4  10.01.p02
G4H2ToolsManager.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: G4H2ToolsManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
27 
28 // Manager class for tools::histo::h2d.
29 // It implements functions specific to the H2 type
30 // (defined in g4tools).
31 //
32 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
33 
34 #ifndef G4H2ToolsManager_h
35 #define G4H2ToolsManager_h 1
36 
37 #include "G4VH2Manager.hh"
38 #include "G4BaseToolsManager.hh"
39 #include "G4HnManager.hh"
40 #include "globals.hh"
41 
42 #include <vector>
43 #include <map>
44 
45 namespace tools {
46 namespace histo {
47 class h2d;
48 }
49 }
50 
52 {
53  public:
55  virtual ~G4H2ToolsManager();
56 
57  // Method to add histograms read from a file
58  G4int AddH2(const G4String& name, tools::histo::h2d* h2d);
59  // Method for merge (MT)
60  void AddH2Vector(const std::vector<tools::histo::h2d*>& h2Vector);
61  // Reset data
62  G4bool Reset();
63  // Return true if the H2 vector is empty
64  G4bool IsEmpty() const;
65 
66  // Access methods
67  //
68  tools::histo::h2d* GetH2(G4int id, G4bool warn = true,
69  G4bool onlyIfActive = true) const;
70  // Iterators
71  std::vector<tools::histo::h2d*>::iterator BeginH2();
72  std::vector<tools::histo::h2d*>::iterator EndH2();
73  std::vector<tools::histo::h2d*>::const_iterator BeginConstH2() const;
74  std::vector<tools::histo::h2d*>::const_iterator EndConstH2() const;
75 
76  // Access to histogram vector (needed for Write())
77  const std::vector<tools::histo::h2d*>& GetH2Vector() const;
78  const std::vector<G4HnInformation*>& GetHnVector() const;
79 
80  protected:
81  // Virtual functions from base class
82  //
83 
84  // Methods to create histograms
85  //
86  virtual G4int CreateH2(const G4String& name, const G4String& title,
87  G4int nxbins, G4double xmin, G4double xmax,
88  G4int nybins, G4double ymin, G4double ymax,
89  const G4String& xunitName = "none",
90  const G4String& yunitName = "none",
91  const G4String& xfcnName = "none",
92  const G4String& yfcnName = "none",
93  const G4String& xbinScheme = "linear",
94  const G4String& ybinScheme = "linear");
95 
96  virtual G4int CreateH2(const G4String& name, const G4String& title,
97  const std::vector<G4double>& xedges,
98  const std::vector<G4double>& yedges,
99  const G4String& xunitName = "none",
100  const G4String& yunitName = "none",
101  const G4String& xfcnName = "none",
102  const G4String& yfcnName = "none");
103 
104  virtual G4bool SetH2(G4int id,
105  G4int nxbins, G4double xmin, G4double xmax,
106  G4int nybins, G4double ymin, G4double ymax,
107  const G4String& xunitName = "none",
108  const G4String& yunitName = "none",
109  const G4String& xfcnName = "none",
110  const G4String& yfcnName = "none",
111  const G4String& xbinScheme = "linear",
112  const G4String& ybinScheme = "linear");
113 
114  virtual G4bool SetH2(G4int id,
115  const std::vector<G4double>& xedges,
116  const std::vector<G4double>& yedges,
117  const G4String& xunitName = "none",
118  const G4String& yunitName = "none",
119  const G4String& xfcnName = "none",
120  const G4String& yfcnName = "none");
121 
122  virtual G4bool ScaleH2(G4int id, G4double factor);
123 
124  // Method to fill histograms
125  //
126  virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue,
127  G4double weight = 1.0);
128 
129 
130  // Methods to manipulate histograms
131  //
132 
133  // Access methods
134  virtual G4int GetH2Id(const G4String& name, G4bool warn = true) const;
135 
136  // Access to H2 parameters
137  virtual G4int GetH2Nxbins(G4int id) const;
138  virtual G4double GetH2Xmin(G4int id) const;
139  virtual G4double GetH2Xmax(G4int id) const;
140  virtual G4double GetH2XWidth(G4int id) const;
141  virtual G4int GetH2Nybins(G4int id) const;
142  virtual G4double GetH2Ymin(G4int id) const;
143  virtual G4double GetH2Ymax(G4int id) const;
144  virtual G4double GetH2YWidth(G4int id) const;
145 
146  // Setters for attributes for plotting
147  virtual G4bool SetH2Title(G4int id, const G4String& title);
148  virtual G4bool SetH2XAxisTitle(G4int id, const G4String& title);
149  virtual G4bool SetH2YAxisTitle(G4int id, const G4String& title);
150  virtual G4bool SetH2ZAxisTitle(G4int id, const G4String& title);
151 
152  // Access attributes for plotting
153  virtual G4String GetH2Title(G4int id) const;
154  virtual G4String GetH2XAxisTitle(G4int id) const;
155  virtual G4String GetH2YAxisTitle(G4int id) const;
156  virtual G4String GetH2ZAxisTitle(G4int id) const;
157 
158  // Write data on ASCII file
159  virtual G4bool WriteOnAscii(std::ofstream& output);
160 
161 
162  private:
163  virtual tools::histo::h2d* GetH2InFunction(G4int id, G4String function,
164  G4bool warn = true,
165  G4bool onlyIfActive = true) const;
166 
167  void AddH2Information(const G4String& name,
168  const G4String& xunitName,
169  const G4String& yunitName,
170  const G4String& xfcnName,
171  const G4String& yfcnName,
172  G4BinScheme xbinScheme,
173  G4BinScheme ybinScheme) const;
174 
175  G4int RegisterToolsH2(tools::histo::h2d* h2d,
176  const G4String& name);
177 
178  // data members
179  //
181  std::vector<tools::histo::h2d*> fH2Vector;
182  std::map<G4String, G4int> fH2NameIdMap;
183 };
184 // inline methods
185 
186 inline std::vector<tools::histo::h2d*>::iterator G4H2ToolsManager::BeginH2()
187 { return fH2Vector.begin(); }
188 
189 inline std::vector<tools::histo::h2d*>::iterator G4H2ToolsManager::EndH2()
190 { return fH2Vector.end(); }
191 
192 inline std::vector<tools::histo::h2d*>::const_iterator
194 { return fH2Vector.begin(); }
195 
196 inline std::vector<tools::histo::h2d*>::const_iterator
198 { return fH2Vector.end(); }
199 
200 inline const std::vector<tools::histo::h2d*>& G4H2ToolsManager::GetH2Vector() const
201 { return fH2Vector; }
202 
203 inline const std::vector<G4HnInformation*>& G4H2ToolsManager::GetHnVector() const
204 { return fHnManager->GetHnVector(); }
205 
206 #endif
207 
virtual G4int GetH2Nybins(G4int id) const
G4HnManager * fHnManager
virtual G4String GetH2YAxisTitle(G4int id) const
virtual G4bool SetH2YAxisTitle(G4int id, const G4String &title)
virtual G4String GetH2XAxisTitle(G4int id) const
void AddH2Information(const G4String &name, const G4String &xunitName, const G4String &yunitName, const G4String &xfcnName, const G4String &yfcnName, G4BinScheme xbinScheme, G4BinScheme ybinScheme) const
virtual ~G4H2ToolsManager()
virtual G4double GetH2Ymax(G4int id) const
G4String name
Definition: TRTMaterials.hh:40
std::vector< tools::histo::h2d * >::iterator EndH2()
G4bool IsEmpty() const
virtual G4double GetH2Xmin(G4int id) const
virtual tools::histo::h2d * GetH2InFunction(G4int id, G4String function, G4bool warn=true, G4bool onlyIfActive=true) const
virtual G4int GetH2Nxbins(G4int id) const
virtual G4bool SetH2ZAxisTitle(G4int id, const G4String &title)
int G4int
Definition: G4Types.hh:78
G4int RegisterToolsH2(tools::histo::h2d *h2d, const G4String &name)
virtual G4String GetH2Title(G4int id) const
std::vector< tools::histo::h2d * > fH2Vector
void AddH2Vector(const std::vector< tools::histo::h2d * > &h2Vector)
virtual G4double GetH2YWidth(G4int id) const
virtual G4bool WriteOnAscii(std::ofstream &output)
bool G4bool
Definition: G4Types.hh:79
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")
G4BaseToolsManager fBaseToolsManager
virtual G4bool SetH2XAxisTitle(G4int id, const G4String &title)
tools::histo::h2d * GetH2(G4int id, G4bool warn=true, G4bool onlyIfActive=true) const
virtual G4String GetH2ZAxisTitle(G4int id) const
std::vector< tools::histo::h2d * >::const_iterator EndConstH2() const
static const G4double factor
virtual G4double GetH2Ymin(G4int id) const
std::vector< tools::histo::h2d * >::iterator BeginH2()
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")
G4int AddH2(const G4String &name, tools::histo::h2d *h2d)
virtual G4double GetH2Xmax(G4int id) const
virtual G4double GetH2XWidth(G4int id) const
virtual G4int GetH2Id(const G4String &name, G4bool warn=true) const
const std::vector< G4HnInformation * > & GetHnVector() const
Definition: G4HnManager.hh:134
std::vector< tools::histo::h2d * >::const_iterator BeginConstH2() const
G4BinScheme
Definition: G4BinScheme.hh:40
const std::vector< G4HnInformation * > & GetHnVector() const
std::map< G4String, G4int > fH2NameIdMap
double G4double
Definition: G4Types.hh:76
virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue, G4double weight=1.0)
virtual G4bool SetH2Title(G4int id, const G4String &title)
virtual G4bool ScaleH2(G4int id, G4double factor)
const std::vector< tools::histo::h2d * > & GetH2Vector() const
G4H2ToolsManager(const G4AnalysisManagerState &state)