ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4BinScheme.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4BinScheme.cc
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"
30 
31 namespace G4Analysis
32 {
33 
34 //_____________________________________________________________________________
35 G4BinScheme GetBinScheme(const G4String& binSchemeName)
36 {
37  G4BinScheme binScheme = G4BinScheme::kLinear;
38  if ( binSchemeName != "linear" ) {
39  if ( binSchemeName == "log" )
40  binScheme = G4BinScheme::kLog;
41  else {
42  // There is no name associated with G4BinScheme::kUser
43  G4ExceptionDescription description;
44  description
45  << " \"" << binSchemeName << "\" binning scheme is not supported." << G4endl
46  << " " << "Linear binning will be applied.";
47  G4Exception("G4Analysis::GetBinScheme",
48  "Analysis_W013", JustWarning, description);
49  }
50  }
51  return binScheme;
52 }
53 
54 //_____________________________________________________________________________
56  G4double unit, G4Fcn fcn, G4BinScheme binScheme,
57  std::vector<G4double>& edges)
58 {
59 // Compute edges from parameters
60 
61  // Apply units
62  auto xumin = xmin/unit;
63  auto xumax = xmax/unit;
64 
65  if ( binScheme == G4BinScheme::kLinear ) {
66  auto dx = (fcn(xumax) - fcn(xumin) ) / nbins;
67  auto binValue = fcn(xumin);
68  while ( G4int(edges.size()) <= nbins ) { // Loop checking, 23.06.2015, I. Hrivnacova
69  edges.push_back(binValue);
70  binValue += dx;
71  }
72  }
73  else if ( binScheme == G4BinScheme::kLog ) {
74  // do not apply fcn
75  auto dlog
76  = (std::log10(xumax) - std::log10(xumin))/ nbins;
77  auto dx = std::pow(10, dlog);
78  auto binValue = xumin;
79  while ( G4int(edges.size()) <= nbins ) { // Loop checking, 23.06.2015, I. Hrivnacova
80  edges.push_back(binValue);
81  binValue *= dx;
82  }
83  }
84  else if ( binScheme == G4BinScheme::kUser ) {
85  // This should never happen, but let's make sure about it
86  // by issuing a warning
87  G4ExceptionDescription description;
88  description
89  << " User binning scheme setting was ignored." << G4endl
90  << " Linear binning will be applied with given (nbins, xmin, xmax) values";
91  G4Exception("G4Analysis::ComputeEdges",
92  "Analysis_W013", JustWarning, description);
93  }
94 }
95 
96 //_____________________________________________________________________________
97 void ComputeEdges(const std::vector<G4double>& edges,
98  G4double unit, G4Fcn fcn,
99  std::vector<G4double>& newBins)
100 {
101 // Apply function to defined edges
102 
103  for (auto element : edges) {
104  newBins.push_back(fcn(element/unit));
105  }
106 }
107 
108 }