Geant4 11.1.1
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
34#include "G4VTBaseHnManager.hh"
35#include "G4THnManager.hh"
36#include "globals.hh"
37
38#include <memory>
39#include <array>
40#include <string_view>
41
43class G4HnManager;
44class G4UImessenger;
45
46template <unsigned int DIM, typename HT>
48 public G4THnManager<HT>
49
50{
51 // Disable using the object managers outside
52 friend class G4VAnalysisManager;
53 friend class G4VAnalysisReader;
54
55 public:
57 virtual ~G4THnToolsManager() = default;
58
59 // deleted copy constructor & assignment operator
62
63 // Methods for handling histograms
64 G4int Create(const G4String& name, const G4String& title,
65 const std::array<G4HnDimension, DIM>& bins,
66 const std::array<G4HnDimensionInformation, DIM>& hnInfo) override;
67
69 const std::array<G4HnDimension, DIM>& bins,
70 const std::array<G4HnDimensionInformation, DIM>& hnInfo) override;
71
72 virtual G4bool Scale(G4int id, G4double factor) override;
73
74 // Methods to fill histograms
75 virtual G4bool Fill(G4int id, std::array<G4double, DIM> value, G4double weight = 1.0) override;
76
77 // Access methods
78 virtual G4int GetId(const G4String& name, G4bool warn = true) const override;
79
80 // Access to bins parameters
81 virtual G4int GetNbins(unsigned int idim, G4int id) const override;
82 virtual G4double GetMinValue(unsigned int idim, G4int id) const override;
83 virtual G4double GetMaxValue(unsigned int idim, G4int id) const override;
84 virtual G4double GetWidth(unsigned int idim, G4int id) const override;
85
86 // Setters for attributes for plotting
87 virtual G4bool SetTitle(G4int id, const G4String& title) override;
88 virtual G4bool SetAxisTitle(unsigned int idim, G4int id, const G4String& title) override;
89
90 // Access attributes for plotting
91 virtual G4String GetTitle(G4int id) const override;
92 virtual G4String GetAxisTitle(unsigned int idim, G4int id) const override;
93
94 // Methods to list/print histograms
95 virtual G4bool WriteOnAscii(std::ofstream& output) override;
96 // Function with specialization per histo type
97 virtual G4bool List(std::ostream& output, G4bool onlyIfActive = true) override;
98
99 // // Access to Hn manager
100 virtual std::shared_ptr<G4HnManager> GetHnManager() override;
101 virtual const std::shared_ptr<G4HnManager> GetHnManager() const override;
102
103 protected:
104 // Functions from base class
105 using G4THnManager<HT>::RegisterT;
108 using G4THnManager<HT>::GetTId;
109 using G4THnManager<HT>::IsVerbose;
110 using G4THnManager<HT>::Message;
111
112 static constexpr std::string_view fkClass { "G4THnToolsManager" };
113
114 private:
115 void UpdateInformation(G4HnInformation* hnInformation,
116 const std::array<G4HnDimensionInformation, DIM>& hnInfo);
117
118 G4HnInformation* AddInformation(const G4String& name,
119 const std::array<G4HnDimensionInformation, DIM>& hnInfo);
120
121 void AddAnnotation(HT* ht,
122 const std::array<G4HnDimensionInformation, DIM>& hnInfo);
123
124 G4bool CheckName(const G4String& name) const;
125
126 // Functions with specialization per histo type
127
128 HT* CreateToolsHT(const G4String& title,
129 const std::array<G4HnDimension, DIM>& bins,
130 const std::array<G4HnDimensionInformation, DIM>& hnInfo);
131
132 void ConfigureToolsHT(HT* ht,
133 const std::array<G4HnDimension, DIM>& bins,
134 const std::array<G4HnDimensionInformation, DIM>& hnInfo);
135
136 G4bool FillHT(HT* ht, const G4HnInformation& hnInformation,
137 std::array<G4double, DIM>& value,
138 G4double weight = 1.0);
139
140 // redefine tools::histo::key_axis_x_title() - not available via upper types
141 static const std::array<std::string, 3> fkKeyAxisTitle;
142
143 std::unique_ptr<G4UImessenger> fMessenger;
144};
145
146// inline functions
147
148#include "G4THnMessenger.hh"
149#include "G4THnToolsManager.icc"
150#include "G4THnMessenger.icc"
151 // include messenger and its implementation here to avoid include recursion
152
153#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 GetNbins(unsigned int idim, G4int id) const 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