Geant4-11
G4H1ToolsManager.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::h1d.
28// It implements functions specific to the H1 type
29// (defined in g4tools).
30//
31// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
32
33#ifndef G4H1ToolsManager_h
34#define G4H1ToolsManager_h 1
35
36#include "G4VH1Manager.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 h1d;
49}
50}
51
53 public G4THnManager<tools::histo::h1d>
54{
55 public:
56 explicit G4H1ToolsManager(const G4AnalysisManagerState& state);
57 G4H1ToolsManager() = delete;
58 virtual ~G4H1ToolsManager() = default;
59
60 // Method to add histograms read from a file
61 G4int AddH1(const G4String& name, tools::histo::h1d* h1d);
62 // Method for merge (MT)
63 void AddH1Vector(const std::vector<tools::histo::h1d*>& h1Vector);
64
65 // Access methods
66 //
67 tools::histo::h1d* GetH1(G4int id, G4bool warn = true,
68 G4bool onlyIfActive = true) const;
69
70 // Iterators
71 std::vector<tools::histo::h1d*>::iterator BeginH1();
72 std::vector<tools::histo::h1d*>::iterator EndH1();
73 std::vector<tools::histo::h1d*>::const_iterator BeginConstH1() const;
74 std::vector<tools::histo::h1d*>::const_iterator EndConstH1() const;
75
76 // Access to histogram vector (needed for Write())
77 const std::vector<tools::histo::h1d*>& GetH1Vector() 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 CreateH1(const G4String& name, const G4String& title,
87 G4int nbins, G4double xmin, G4double xmax,
88 const G4String& unitName = "none",
89 const G4String& fcnName = "none",
90 const G4String& binScheme = "linear") final;
91 virtual G4int CreateH1(const G4String& name, const G4String& title,
92 const std::vector<G4double>& edges,
93 const G4String& unitName = "none",
94 const G4String& fcnName = "none") final;
95
96 virtual G4bool SetH1(G4int id,
97 G4int nbins, G4double xmin, G4double xmax,
98 const G4String& unitName = "none",
99 const G4String& fcnName = "none",
100 const G4String& binSchemeName = "linear") final;
101 virtual G4bool SetH1(G4int id,
102 const std::vector<G4double>& edges,
103 const G4String& unitName = "none",
104 const G4String& fcnName = "none") final;
105 virtual G4bool ScaleH1(G4int id, G4double factor) final;
106
107 // Method to fill histograms
108 //
109 virtual G4bool FillH1(G4int id, G4double value, G4double weight = 1.0) final;
110
111 // Access methods
112 //
113 virtual G4int GetH1Id(const G4String& name, G4bool warn = true) const final;
114
115 // Access to H1 parameters
116 virtual G4int GetH1Nbins(G4int id) const final;
117 virtual G4double GetH1Xmin(G4int id) const final;
118 virtual G4double GetH1Xmax(G4int id) const final;
119 virtual G4double GetH1Width(G4int id) const final;
120
121 // Attributes for plotting
122 //
123
124 // Setters
125 virtual G4bool SetH1Title(G4int id, const G4String& title) final;
126 virtual G4bool SetH1XAxisTitle(G4int id, const G4String& title) final;
127 virtual G4bool SetH1YAxisTitle(G4int id, const G4String& title) final;
128
129 // Accessors
130 virtual G4String GetH1Title(G4int id) const final;
131 virtual G4String GetH1XAxisTitle(G4int id) const final;
132 virtual G4String GetH1YAxisTitle(G4int id) const final;
133
134 // Write data on ASCII file
135 virtual G4bool WriteOnAscii(std::ofstream& output) final;
136
137 // Access to Hn manager
138 virtual std::shared_ptr<G4HnManager> GetHnManager() final;
139
140 private:
141 // Methods
142 //
143 void AddH1Information(const G4String& name,
144 const G4String& unitName,
145 const G4String& fcnName,
146 G4BinScheme binScheme) const;
147
148 // Static data members
149 static constexpr std::string_view fkClass { "G4H1ToolsManager" };
150 static constexpr G4int fkDimension = 1;
151};
152
153// inline methods
154
155inline std::vector<tools::histo::h1d*>::iterator G4H1ToolsManager::BeginH1()
156{ return BeginT(); }
157
158inline std::vector<tools::histo::h1d*>::iterator G4H1ToolsManager::EndH1()
159{ return EndT(); }
160
161inline std::vector<tools::histo::h1d*>::const_iterator
163{ return BeginConstT(); }
164
165inline std::vector<tools::histo::h1d*>::const_iterator
167{ return EndConstT(); }
168
169inline const std::vector<tools::histo::h1d*>& G4H1ToolsManager::GetH1Vector() const
170{ return fTVector; }
171
172inline const std::vector<G4HnInformation*>& G4H1ToolsManager::GetHnVector() const
173{ return fHnManager->GetHnVector(); }
174
175inline std::shared_ptr<G4HnManager> G4H1ToolsManager::GetHnManager()
176{ return std::shared_ptr<G4HnManager>(fHnManager); }
177
178#endif
179
G4BinScheme
Definition: G4BinScheme.hh:39
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
virtual G4int GetH1Id(const G4String &name, G4bool warn=true) const final
const std::vector< G4HnInformation * > & GetHnVector() const
const std::vector< tools::histo::h1d * > & GetH1Vector() const
virtual G4String GetH1YAxisTitle(G4int id) const final
tools::histo::h1d * GetH1(G4int id, G4bool warn=true, G4bool onlyIfActive=true) const
virtual G4int GetH1Nbins(G4int id) const final
virtual G4String GetH1XAxisTitle(G4int id) const final
virtual G4bool SetH1YAxisTitle(G4int id, const G4String &title) final
virtual G4bool WriteOnAscii(std::ofstream &output) final
virtual G4bool SetH1(G4int id, G4int nbins, G4double xmin, G4double xmax, const G4String &unitName="none", const G4String &fcnName="none", const G4String &binSchemeName="linear") final
virtual std::shared_ptr< G4HnManager > GetHnManager() final
void AddH1Information(const G4String &name, const G4String &unitName, const G4String &fcnName, G4BinScheme binScheme) const
virtual G4double GetH1Width(G4int id) const final
virtual G4bool SetH1XAxisTitle(G4int id, const G4String &title) final
virtual G4String GetH1Title(G4int id) const final
G4int AddH1(const G4String &name, tools::histo::h1d *h1d)
static constexpr G4int fkDimension
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 &binScheme="linear") final
std::vector< tools::histo::h1d * >::const_iterator EndConstH1() const
virtual ~G4H1ToolsManager()=default
virtual G4bool ScaleH1(G4int id, G4double factor) final
virtual G4bool SetH1Title(G4int id, const G4String &title) final
static constexpr std::string_view fkClass
virtual G4double GetH1Xmin(G4int id) const final
void AddH1Vector(const std::vector< tools::histo::h1d * > &h1Vector)
std::vector< tools::histo::h1d * >::iterator BeginH1()
virtual G4bool FillH1(G4int id, G4double value, G4double weight=1.0) final
virtual G4double GetH1Xmax(G4int id) const final
G4H1ToolsManager()=delete
std::vector< tools::histo::h1d * >::const_iterator BeginConstH1() const
std::vector< tools::histo::h1d * >::iterator EndH1()
std::vector< tools::histo::h1d * >::const_iterator BeginConstT() const
std::vector< tools::histo::h1d * > fTVector
std::vector< tools::histo::h1d * >::iterator EndT()
std::vector< tools::histo::h1d * >::iterator BeginT()
std::shared_ptr< G4HnManager > fHnManager
std::vector< tools::histo::h1d * >::const_iterator EndConstT() const
std::shared_ptr< T > shared_ptr
Definition: memory.h:15
const char * name(G4int ptype)