Geant4-11
G4BaseHistoUtilities.cc
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// Author: Ivana Hrivnacova, 24/07/2014 (ivana@ipno.in2p3.fr)
28
31
32#include "tools/histo/axis"
33
34using std::to_string;
35
36namespace G4Analysis
37{
38
39//_____________________________________________________________________________
40G4int GetNbins(const G4ToolsBaseHisto& baseHisto, G4int dimension)
41{
42 return baseHisto.get_axis(dimension).bins();
43}
44
45//_____________________________________________________________________________
46G4double GetMin(const G4ToolsBaseHisto& baseHisto, G4int dimension)
47{
48// Returns min data value
49
50 return baseHisto.get_axis(dimension).lower_edge();
51}
52
53//_____________________________________________________________________________
54G4double GetMax(const G4ToolsBaseHisto& baseHisto, G4int dimension)
55{
56// Returns max data value
57
58 return baseHisto.get_axis(dimension).upper_edge();
59}
60
61//_____________________________________________________________________________
62G4double GetWidth(const G4ToolsBaseHisto& baseHisto, G4int dimension,
63 const G4String& hnType)
64{
65 auto nbins = baseHisto.get_axis(dimension).bins();
66 if ( ! nbins ) {
67 Warn("nbins = 0 ! for " + hnType, kNamespaceName, "GetWidth");
68 return 0.;
69 }
70
71 return ( baseHisto.get_axis(dimension).upper_edge()
72 - baseHisto.get_axis(dimension).lower_edge() )/nbins;
73}
74
75//_____________________________________________________________________________
76G4bool SetTitle(G4ToolsBaseHisto& baseHisto, const G4String& title)
77{
78 return baseHisto.set_title(title);
79}
80
81//_____________________________________________________________________________
83 const G4String& title)
84{
85 if ( dimension == kX ) {
86 baseHisto.add_annotation(tools::histo::key_axis_x_title(), title);
87 }
88 else if ( dimension == kY ) {
89 baseHisto.add_annotation(tools::histo::key_axis_y_title(), title);
90 }
91 else if ( dimension == kZ ) {
92 baseHisto.add_annotation(tools::histo::key_axis_z_title(), title);
93 }
94
95 return true;
96}
97
98//_____________________________________________________________________________
100{
101 return baseHisto.title();
102}
103
104
105//_____________________________________________________________________________
106G4String GetAxisTitle(const G4ToolsBaseHisto& baseHisto, G4int dimension,
107 const G4String& hnType)
108{
109 G4String title;
110 G4bool result = false;
111 if ( dimension == kX ) {
112 result = baseHisto.annotation(tools::histo::key_axis_x_title(), title);
113 }
114 else if ( dimension == kY ) {
115 result = baseHisto.annotation(tools::histo::key_axis_y_title(), title);
116 }
117 else if ( dimension == kZ ) {
118 result = baseHisto.annotation(tools::histo::key_axis_z_title(), title);
119 }
120
121 if ( ! result ) {
122 Warn("Got wrong dimension " + to_string(dimension) + " for " + hnType,
123 kNamespaceName, "GetAxisTitle");
124
125 return "";
126 }
127
128 return title;
129}
130
131}
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4int GetNbins(const G4ToolsBaseHisto &baseHisto, G4int dimension)
G4bool SetTitle(G4ToolsBaseHisto &baseHisto, const G4String &title)
G4double GetMin(const G4ToolsBaseHisto &baseHisto, G4int dimension)
G4double GetMax(const G4ToolsBaseHisto &baseHisto, G4int dimension)
constexpr std::string_view kNamespaceName
G4bool SetAxisTitle(G4ToolsBaseHisto &baseHisto, G4int dimension, const G4String &title)
G4String GetAxisTitle(const G4ToolsBaseHisto &baseHisto, G4int dimension, const G4String &hnType)
G4double GetWidth(const G4ToolsBaseHisto &baseHisto, G4int dimension, const G4String &hnType)
constexpr G4int kX
tools::histo::base_histo< double, unsigned int, unsigned int, double, double > G4ToolsBaseHisto
G4String GetTitle(const G4ToolsBaseHisto &baseHisto)
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)
constexpr G4int kZ
constexpr G4int kY