Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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 ([email protected])
28
31
32#include "tools/histo/axis"
33
34namespace G4Analysis
35{
36
37//_____________________________________________________________________________
38G4int GetNbins(const G4ToolsBaseHisto& baseHisto, G4int dimension)
39{
40 return baseHisto.get_axis(dimension).bins();
41}
42
43//_____________________________________________________________________________
44G4double GetMin(const G4ToolsBaseHisto& baseHisto, G4int dimension)
45{
46// Returns min data value
47
48 return baseHisto.get_axis(dimension).lower_edge();
49}
50
51//_____________________________________________________________________________
52G4double GetMax(const G4ToolsBaseHisto& baseHisto, G4int dimension)
53{
54// Returns max data value
55
56 return baseHisto.get_axis(dimension).upper_edge();
57}
58
59//_____________________________________________________________________________
60G4double GetWidth(const G4ToolsBaseHisto& baseHisto, G4int dimension,
61 const G4String& hnType)
62{
63 auto nbins = baseHisto.get_axis(dimension).bins();
64 if ( ! nbins ) {
65 G4String functionName = "Get";
66 functionName += hnType;
67 functionName += "Width";
68 G4ExceptionDescription description;
69 description << " nbins = 0 (for " << hnType << ").";
70 G4Exception(functionName, "Analysis_W014", JustWarning, description);
71 return 0.;
72 }
73
74 return ( baseHisto.get_axis(dimension).upper_edge()
75 - baseHisto.get_axis(dimension).lower_edge() )/nbins;
76}
77
78//_____________________________________________________________________________
79G4bool SetTitle(G4ToolsBaseHisto& baseHisto, const G4String& title)
80{
81 return baseHisto.set_title(title);
82}
83
84//_____________________________________________________________________________
86 const G4String& title)
87{
88 if ( dimension == kX ) {
89 baseHisto.add_annotation(tools::histo::key_axis_x_title(), title);
90 }
91 else if ( dimension == kY ) {
92 baseHisto.add_annotation(tools::histo::key_axis_y_title(), title);
93 }
94 else if ( dimension == kZ ) {
95 baseHisto.add_annotation(tools::histo::key_axis_z_title(), title);
96 }
97
98 return true;
99}
100
101//_____________________________________________________________________________
103{
104 return baseHisto.title();
105}
106
107
108//_____________________________________________________________________________
109G4String GetAxisTitle(const G4ToolsBaseHisto& baseHisto, G4int dimension,
110 const G4String& hnType)
111{
112 G4String title;
113 G4bool result = false;
114 if ( dimension == kX ) {
115 result = baseHisto.annotation(tools::histo::key_axis_x_title(), title);
116 }
117 else if ( dimension == kY ) {
118 result = baseHisto.annotation(tools::histo::key_axis_y_title(), title);
119 }
120 else if ( dimension == kZ ) {
121 result = baseHisto.annotation(tools::histo::key_axis_z_title(), title);
122 }
123
124 if ( ! result ) {
125 G4String axes("xyz");
126 G4String axis = axes(dimension, 1);
127 G4String functionName = "Get";
128 functionName += hnType;
129 functionName += axis;
130 functionName += "Title";
131 G4ExceptionDescription description;
132 description << " Failed to get " << axis << " axis " << hnType << " title.";
133 G4Exception(functionName, "Analysis_W014", JustWarning, description);
134 return "";
135 }
136
137 return title;
138}
139
140}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
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)
const G4int kY
G4bool SetTitle(G4ToolsBaseHisto &baseHisto, const G4String &title)
const G4int kZ
G4double GetMin(const G4ToolsBaseHisto &baseHisto, G4int dimension)
G4double GetMax(const G4ToolsBaseHisto &baseHisto, G4int dimension)
const G4int kX
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)
tools::histo::base_histo< double, unsigned int, unsigned int, double, double > G4ToolsBaseHisto
G4String GetTitle(const G4ToolsBaseHisto &baseHisto)