Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4THnToolsManager.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// Common implementation for histograms managers.
28//
29// Author: Ivana Hrivnacova, 10/08/2022 ([email protected])
30
31#ifndef G4THnToolsManager_h
32#define G4THnToolsManager_h 1
33
35#include "G4VTBaseHnManager.hh"
36#include "G4THnManager.hh"
37#include "globals.hh"
38
39#include <memory>
40#include <array>
41#include <string_view>
42
44class G4HnManager;
45class G4UImessenger;
46
47template <unsigned int DIM, typename HT>
49 public G4THnManager<HT>
50
51{
52 // Disable using the object managers outside
53 friend class G4VAnalysisManager;
54 friend class G4VAnalysisReader;
55
56 public:
58 virtual ~G4THnToolsManager() = default;
59
60 // deleted copy constructor & assignment operator
63
64 // Methods for handling histograms
65 G4int Create(const G4String& name, const G4String& title,
66 const std::array<G4HnDimension, DIM>& bins,
67 const std::array<G4HnDimensionInformation, DIM>& hnInfo) override;
68
70 const std::array<G4HnDimension, DIM>& bins,
71 const std::array<G4HnDimensionInformation, DIM>& hnInfo) override;
72
73 virtual G4bool Scale(G4int id, G4double factor) override;
74 virtual G4int GetNofHns(G4bool onlyIfExist) const override;
75
76 // Methods to fill histograms
77 virtual G4bool Fill(G4int id, std::array<G4double, DIM> value, G4double weight = 1.0) override;
78
79 // Access methods
80 virtual G4int GetId(const G4String& name, G4bool warn = true) const override;
81
82 // Access to bins parameters
83 virtual G4int GetNbins(unsigned int idim, G4int id) const override;
84 virtual G4double GetMinValue(unsigned int idim, G4int id) const override;
85 virtual G4double GetMaxValue(unsigned int idim, G4int id) const override;
86 virtual G4double GetWidth(unsigned int idim, G4int id) const override;
87
88 // Setters for attributes for plotting
89 virtual G4bool SetTitle(G4int id, const G4String& title) override;
90 virtual G4bool SetAxisTitle(unsigned int idim, G4int id, const G4String& title) override;
91
92 // Access attributes for plotting
93 virtual G4String GetTitle(G4int id) const override;
94 virtual G4String GetAxisTitle(unsigned int idim, G4int id) const override;
95
96 // Methods to list/print histograms
97 virtual G4bool WriteOnAscii(std::ofstream& output) override;
98 // Function with specialization per histo type
99 virtual G4bool List(std::ostream& output, G4bool onlyIfActive = true) override;
100
101 // Methods to delete selected histograms
102 virtual G4bool Delete(G4int id, G4bool keepSetting) override;
103
104 // // Access to Hn manager
105 virtual std::shared_ptr<G4HnManager> GetHnManager() override;
106 virtual const std::shared_ptr<G4HnManager> GetHnManager() const override;
107
108 protected:
109 // Functions from base class
110 using G4THnManager<HT>::RegisterT;
113 using G4THnManager<HT>::GetTId;
114 using G4THnManager<HT>::IsVerbose;
115 using G4THnManager<HT>::Message;
116
117 static constexpr std::string_view fkClass { "G4THnToolsManager" };
118
119 private:
120 void UpdateInformation(G4HnInformation* hnInformation,
121 const std::array<G4HnDimensionInformation, DIM>& hnInfo);
122
123 G4HnInformation* CreateInformation(const G4String& name,
124 const std::array<G4HnDimensionInformation, DIM>& hnInfo);
125
126 void AddAnnotation(HT* ht,
127 const std::array<G4HnDimensionInformation, DIM>& hnInfo);
128
129 G4bool CheckName(const G4String& name) const;
130
131 // Functions with specialization per histo type
132
133 HT* CreateToolsHT(const G4String& title,
134 const std::array<G4HnDimension, DIM>& bins,
135 const std::array<G4HnDimensionInformation, DIM>& hnInfo);
136
137 void ConfigureToolsHT(HT* ht,
138 const std::array<G4HnDimension, DIM>& bins,
139 const std::array<G4HnDimensionInformation, DIM>& hnInfo);
140
141 G4bool FillHT(HT* ht, const G4HnInformation& hnInformation,
142 std::array<G4double, DIM>& value,
143 G4double weight = 1.0);
144
145 // redefine tools::histo::key_axis_x_title() - not available via upper types
146 static const std::array<std::string, G4Analysis::kMaxDim> fkKeyAxisTitle;
147
148 std::unique_ptr<G4UImessenger> fMessenger;
149};
150
151// inline functions
152
153#include "G4THnMessenger.hh"
154#include "G4THnToolsManager.icc"
155#include "G4THnMessenger.icc"
156 // include messenger and its implementation here to avoid include recursion
157
158#endif
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
HT * GetTInFunction(G4int id, std::string_view functionName, G4bool warn=true, G4bool onlyIfActive=true) const
std::pair< HT *, G4HnInformation * > GetTHnInFunction(G4int id, std::string_view functionName, G4bool warn=true, G4bool onlyIfActive=true) const
G4int RegisterT(const G4String &name, HT *ht, G4HnInformation *info=nullptr)
G4int GetTId(const G4String &name, G4bool warn=true) const
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
G4bool IsVerbose(G4int verboseLevel) const
G4THnToolsManager(const G4THnToolsManager &rhs)=delete
G4THnToolsManager(const G4AnalysisManagerState &state)
G4int Create(const G4String &name, const G4String &title, const std::array< G4HnDimension, DIM > &bins, const std::array< G4HnDimensionInformation, DIM > &hnInfo) override
virtual G4String GetAxisTitle(unsigned int idim, G4int id) const override
virtual G4bool Fill(G4int id, std::array< G4double, DIM > value, G4double weight=1.0) override
virtual G4int GetId(const G4String &name, G4bool warn=true) const override
virtual G4double GetMaxValue(unsigned int idim, G4int id) const override
static constexpr std::string_view fkClass
G4bool Set(G4int id, const std::array< G4HnDimension, DIM > &bins, const std::array< G4HnDimensionInformation, DIM > &hnInfo) override
virtual ~G4THnToolsManager()=default
virtual G4bool SetTitle(G4int id, const G4String &title) override
virtual const std::shared_ptr< G4HnManager > GetHnManager() const override
virtual std::shared_ptr< G4HnManager > GetHnManager() override
virtual G4double GetWidth(unsigned int idim, G4int id) const override
virtual G4bool Scale(G4int id, G4double factor) override
virtual G4bool List(std::ostream &output, G4bool onlyIfActive=true) override
virtual G4int GetNofHns(G4bool onlyIfExist) const override
virtual G4int GetNbins(unsigned int idim, G4int id) const override
virtual G4bool Delete(G4int id, G4bool keepSetting) override
G4THnToolsManager & operator=(const G4THnToolsManager &rhs)=delete
virtual G4bool SetAxisTitle(unsigned int idim, G4int id, const G4String &title) override
virtual G4double GetMinValue(unsigned int idim, G4int id) const override
virtual G4String GetTitle(G4int id) const override
virtual G4bool WriteOnAscii(std::ofstream &output) override