Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4HnInformation.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, 10/08/2022 (ivana@ipno.in2p3.fr)
28
29#include "G4HnInformation.hh"
31
32
33//_____________________________________________________________________________
35{
36 G4cout
37 << "NBins: " << fNBins << " minValue: " << fMinValue << " maxValue: "
38 << fMaxValue << ";" << " edges: ";
39 for ( auto value : fEdges ) {
40 G4cout << value << ", ";
41 }
42 G4cout << G4endl;
43}
44
45//_____________________________________________________________________________
47{
48 G4cout
49 << "Unit name: " << fUnitName << " Fcn Name: " << fFcnName << " BinSchemeName: "
50 << fBinSchemeName << " Unit: " << fUnit << " BinScheme: " << static_cast<int>(fBinScheme)
51 << G4endl;
52}
53
54namespace G4Analysis
55{
56
57//_____________________________________________________________________________
58void Update(G4double& value, const G4HnDimensionInformation& hnInfo)
59{
60// Apply hnInfo to a value
61
62 auto unit = hnInfo.fUnit;
63 auto fcn = hnInfo.fFcn;
64
65 if (unit == 0.) {
66 // Should never happen
67 Warn("Illegal unit value (0), 1. will be used instead",
68 kNamespaceName, "UpdateBins");
69 unit = 1.;
70 }
71 value = fcn(value/unit);
72}
73
74//_____________________________________________________________________________
76 G4HnDimension& bins, const G4HnDimensionInformation& hnInfo)
77{
78// Apply hnInfo to bins min and max value
79
80 auto unit = hnInfo.fUnit;
81 auto fcn = hnInfo.fFcn;
82
83 if (unit == 0.) {
84 // Should never happen
85 Warn("Illegal unit value (0), 1. will be used instead",
86 kNamespaceName, "UpdateBins");
87 unit = 1.;
88 }
89 // Update min/max values
90 bins.fMinValue = fcn(bins.fMinValue/unit);
91 bins.fMaxValue = fcn(bins.fMaxValue/unit);
92}
93
94//_____________________________________________________________________________
95void Update(
96 G4HnDimension& bins, const G4HnDimensionInformation& hnInfo)
97{
98// Apply hnInfo to bins, compute edges
99
100 auto unit = hnInfo.fUnit;
101 auto fcn = hnInfo.fFcn;
102 auto binScheme = hnInfo.fBinScheme;
103
104 if (binScheme == G4BinScheme::kLinear) {
105 // Compute edges, as they may be needed in the context of 2D or 3D histograms
106 // with log binning in other dimension
108 bins.fNBins, bins.fMinValue, bins.fMaxValue, unit, fcn, binScheme, bins.fEdges);
109
110 // Update min/max Values
111 UpdateValues(bins, hnInfo);
112
113 return;
114 }
115
116 if (binScheme == G4BinScheme::kLog) {
117 // Logarithmic bin scheme
118 // compute edges from parameters
120 bins.fNBins, bins.fMinValue, bins.fMaxValue, unit, fcn, binScheme, bins.fEdges);
121 }
122
123 if (binScheme == G4BinScheme::kUser) {
124 G4Analysis::ComputeEdges(bins.fEdges, unit, fcn, bins.fEdges);
125 }
126}
127
128//_____________________________________________________________________________
130{
131 if ( hnInfo.fFcnName != "none" ) { title += " "; title += hnInfo.fFcnName; title += "("; }
132 if ( hnInfo.fUnitName != "none" ) { title += " ["; title += hnInfo.fUnitName; title += "]";}
133 if ( hnInfo.fFcnName != "none" ) { title += ")"; }
134}
135
136//_____________________________________________________________________________
138{
139 auto result = true;
140
141 // Do not check default values
142 if ( minValue == 0. && maxValue == 0. ) return result;
143
144 if ( maxValue <= minValue ) {
145 Warn("Illegal value of (minValue >= maxMaxValue)", kNamespaceName, "CheckMinMax");
146 result = false;
147 }
148
149 return result;
150}
151
152//_____________________________________________________________________________
153G4bool CheckDimension(unsigned int idim,
154 const G4HnDimension& dimension, const G4HnDimensionInformation& info)
155{
156 auto result = true;
157 G4String xyz {"xyz"};
158
159 // Check nbins
160 if ( (dimension.fNBins <= 0) && (info.fBinScheme != G4BinScheme::kUser) ) {
161 Warn("Illegal value of number of " + xyz.substr(idim,1) + " bins: nbins <= 0.",
162 kNamespaceName, "CheckDimension");
163 result = false;
164 }
165
166 // Check edges
167 if ( dimension.fEdges.empty() && (info.fBinScheme == G4BinScheme::kUser) ) {
168 Warn("Illegal value of number of " + xyz.substr(idim,1) + " edges vector size",
169 kNamespaceName, "CheckDimension");
170 result = false;
171 }
172
173 // Check min/max
174 if ( dimension.fMaxValue <= dimension.fMinValue ) {
175 Warn("Illegal value of " + xyz.substr(idim,1) + " (min >= max)",
176 kNamespaceName, "CheckDimension");
177 result = false;
178 }
179
180 // Check function
181 if ( ( info.fFcnName != "none" ) && ( info.fBinScheme != G4BinScheme::kLinear ) ) {
182 Warn("Combining " + xyz.substr(idim,1) + " Function and Binning scheme is not supported.",
183 kNamespaceName, "CheckDimension");
184 result = false;
185 }
186
187 // Check minValue if log binning or log function
188 if ( ( info.fBinScheme == G4BinScheme::kLog ||
189 info.fFcnName == "log" || info.fFcnName == "log10" ) && ( dimension.fMinValue == 0 ) ) {
190 Warn("Illegal value of " + xyz.substr(idim,1) + " (min = 0) with logarithmic function or binning",
191 kNamespaceName, "CheckDimension");
192 result = false;
193 }
194
195 return result;
196}
197
198}
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4bool CheckDimension(unsigned int idim, const G4HnDimension &dimension, const G4HnDimensionInformation &info)
void UpdateTitle(G4String &title, const G4HnDimensionInformation &hnInfo)
void Update(G4double &value, const G4HnDimensionInformation &hnInfo)
constexpr std::string_view kNamespaceName
void UpdateValues(G4HnDimension &bins, const G4HnDimensionInformation &hnInfo)
void ComputeEdges(G4int nbins, G4double xmin, G4double xmax, G4double unit, G4Fcn fcn, G4BinScheme, std::vector< G4double > &edges)
Definition: G4BinScheme.cc:50
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)
G4bool CheckMinMax(G4double min, G4double max)
G4double fMaxValue
std::vector< G4double > fEdges
G4double fMinValue
void Print() const