Geant4 Cross Reference |
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" 30 #include "G4AnalysisUtilities.hh" 31 32 33 //_____________________________________________________________________________ 34 void G4HnDimension::Print() const 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 //_____________________________________________________________________________ 46 void G4HnDimensionInformation::Print() const 47 { 48 G4cout 49 << "Unit name: " << fUnitName << " Fcn Name: " << fFcnName << " BinSchemeName: " 50 << fBinSchemeName << " Unit: " << fUnit << " BinScheme: " << static_cast<int>(fBinScheme) 51 << G4endl; 52 } 53 54 namespace G4Analysis 55 { 56 57 //_____________________________________________________________________________ 58 void 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 //_____________________________________________________________________________ 75 void UpdateValues( 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 //_____________________________________________________________________________ 95 void 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 107 G4Analysis::ComputeEdges( 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 119 G4Analysis::ComputeEdges( 120 bins.fNBins, bins.fMinValue, bins.fMaxValue, unit, fcn, binScheme, bins.fEdges); 121 } 122 123 if (binScheme == G4BinScheme::kUser) { 124 std::vector<G4double> edges = bins.fEdges; 125 bins.fEdges.clear(); 126 G4Analysis::ComputeEdges(edges, unit, fcn, bins.fEdges); 127 } 128 } 129 130 //_____________________________________________________________________________ 131 void UpdateTitle(G4String& title, const G4HnDimensionInformation& hnInfo) 132 { 133 if ( hnInfo.fFcnName != "none" ) { title += " "; title += hnInfo.fFcnName; title += "("; } 134 if ( hnInfo.fUnitName != "none" ) { title += " ["; title += hnInfo.fUnitName; title += "]";} 135 if ( hnInfo.fFcnName != "none" ) { title += ")"; } 136 } 137 138 //_____________________________________________________________________________ 139 G4bool CheckMinMax(G4double minValue, G4double maxValue) 140 { 141 auto result = true; 142 143 // Do not check default values 144 if ( minValue == 0. && maxValue == 0. ) return result; 145 146 if ( maxValue <= minValue ) { 147 Warn("Illegal value of (minValue >= maxMaxValue)", kNamespaceName, "CheckMinMax"); 148 result = false; 149 } 150 151 return result; 152 } 153 154 //_____________________________________________________________________________ 155 G4bool CheckDimension(unsigned int idim, 156 const G4HnDimension& dimension, const G4HnDimensionInformation& info) 157 { 158 auto result = true; 159 G4String xyz {"xyz"}; 160 161 // Check nbins 162 if ( (dimension.fNBins <= 0) && (info.fBinScheme != G4BinScheme::kUser) ) { 163 Warn("Illegal value of number of " + xyz.substr(idim,1) + " bins: nbins <= 0.", 164 kNamespaceName, "CheckDimension"); 165 result = false; 166 } 167 168 // Check min/max 169 if ( (dimension.fMaxValue <= dimension.fMinValue) && 170 (info.fBinScheme != G4BinScheme::kUser) ) { 171 Warn("Illegal value of " + xyz.substr(idim,1) + " (min >= max)", 172 kNamespaceName, "CheckDimension"); 173 result = false; 174 } 175 176 // Check edges 177 if (info.fBinScheme == G4BinScheme::kUser) { 178 if ( dimension.fEdges.empty() ) { 179 Warn(xyz.substr(idim,1) + " edges vector is empty.", 180 kNamespaceName, "CheckDimension"); 181 result = false; 182 } 183 // the edges values must be defined in increasing order 184 for (size_t i = 1; i < dimension.fEdges.size(); ++i){ 185 if (dimension.fEdges[i-1] >= dimension.fEdges[i]) { 186 Warn(xyz.substr(idim,1) + 187 " edges vector values must be defined in increasing order.", 188 kNamespaceName, "CheckDimension"); 189 result = false; 190 } 191 } 192 } 193 194 // Check function 195 if ( ( info.fFcnName != "none" ) && ( info.fBinScheme != G4BinScheme::kLinear ) ) { 196 Warn("Combining " + xyz.substr(idim,1) + " Function and Binning scheme is not supported.", 197 kNamespaceName, "CheckDimension"); 198 result = false; 199 } 200 201 // Check minValue if log binning or log function 202 if ( ( info.fBinScheme == G4BinScheme::kLog || 203 info.fFcnName == "log" || info.fFcnName == "log10" ) && ( dimension.fMinValue == 0 ) ) { 204 Warn("Illegal value of " + xyz.substr(idim,1) + " (min = 0) with logarithmic function or binning", 205 kNamespaceName, "CheckDimension"); 206 result = false; 207 } 208 209 return result; 210 } 211 212 } 213