Geant4-11
G4BinScheme.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, 22/08/2013 (ivana@ipno.in2p3.fr)
28
29#include "G4BinScheme.hh"
31
32namespace G4Analysis
33{
34
35//_____________________________________________________________________________
36G4BinScheme GetBinScheme(const G4String& binSchemeName)
37{
39 if ( binSchemeName != "linear" ) {
40 if ( binSchemeName == "log" )
41 binScheme = G4BinScheme::kLog;
42 else {
43 // There is no name associated with G4BinScheme::kUser
44 Warn("\"" + binSchemeName + "\" binning scheme is not supported.\n"
45 "Linear binning will be applied.",
46 kNamespaceName, "GetBinScheme");
47 }
48 }
49 return binScheme;
50}
51
52//_____________________________________________________________________________
53void ComputeEdges(G4int nbins, G4double xmin, G4double xmax,
54 G4double unit, G4Fcn fcn, G4BinScheme binScheme,
55 std::vector<G4double>& edges)
56{
57// Compute edges from parameters
58
59 // Apply units
60 auto xumin = xmin/unit;
61 auto xumax = xmax/unit;
62
63 if ( binScheme == G4BinScheme::kLinear ) {
64 auto dx = (fcn(xumax) - fcn(xumin) ) / nbins;
65 auto binValue = fcn(xumin);
66 while ( G4int(edges.size()) <= nbins ) { // Loop checking, 23.06.2015, I. Hrivnacova
67 edges.push_back(binValue);
68 binValue += dx;
69 }
70 }
71 else if ( binScheme == G4BinScheme::kLog ) {
72 // do not apply fcn
73 auto dlog
74 = (std::log10(xumax) - std::log10(xumin))/ nbins;
75 auto dx = std::pow(10, dlog);
76 auto binValue = xumin;
77 while ( G4int(edges.size()) <= nbins ) { // Loop checking, 23.06.2015, I. Hrivnacova
78 edges.push_back(binValue);
79 binValue *= dx;
80 }
81 }
82 else if ( binScheme == G4BinScheme::kUser ) {
83 // This should never happen, but let's make sure about it
84 // by issuing a warning
85 Warn("User binning scheme setting was ignored.\n"
86 "Linear binning will be applied with given (nbins, xmin, xmax) values",
87 kNamespaceName, "GetBinScheme");
88 }
89}
90
91//_____________________________________________________________________________
92void ComputeEdges(const std::vector<G4double>& edges,
93 G4double unit, G4Fcn fcn,
94 std::vector<G4double>& newBins)
95{
96// Apply function to defined edges
97
98 for (auto element : edges) {
99 newBins.push_back(fcn(element/unit));
100 }
101}
102
103}
G4BinScheme
Definition: G4BinScheme.hh:39
G4double(*)(G4double) G4Fcn
Definition: G4Fcn.hh:35
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
G4BinScheme GetBinScheme(const G4String &binSchemeName)
Definition: G4BinScheme.cc:36
constexpr std::string_view kNamespaceName
void ComputeEdges(G4int nbins, G4double xmin, G4double xmax, G4double unit, G4Fcn fcn, G4BinScheme, std::vector< G4double > &edges)
Definition: G4BinScheme.cc:53
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)