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