Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 26 27 // Author: Ivana Hrivnacova, 10/08/2022 (iva 27 // Author: Ivana Hrivnacova, 10/08/2022 (ivana@ipno.in2p3.fr) 28 28 29 #include "G4HnInformation.hh" 29 #include "G4HnInformation.hh" 30 #include "G4AnalysisUtilities.hh" 30 #include "G4AnalysisUtilities.hh" 31 31 32 32 33 //____________________________________________ 33 //_____________________________________________________________________________ 34 void G4HnDimension::Print() const 34 void G4HnDimension::Print() const 35 { 35 { 36 G4cout 36 G4cout 37 << "NBins: " << fNBins << " minValue: " << 37 << "NBins: " << fNBins << " minValue: " << fMinValue << " maxValue: " 38 << fMaxValue << ";" << " edges: "; 38 << fMaxValue << ";" << " edges: "; 39 for ( auto value : fEdges ) { 39 for ( auto value : fEdges ) { 40 G4cout << value << ", "; 40 G4cout << value << ", "; 41 } 41 } 42 G4cout << G4endl; 42 G4cout << G4endl; 43 } 43 } 44 44 45 //____________________________________________ 45 //_____________________________________________________________________________ 46 void G4HnDimensionInformation::Print() const 46 void G4HnDimensionInformation::Print() const 47 { 47 { 48 G4cout 48 G4cout 49 << "Unit name: " << fUnitName << " Fcn Nam 49 << "Unit name: " << fUnitName << " Fcn Name: " << fFcnName << " BinSchemeName: " 50 << fBinSchemeName << " Unit: " << fUnit << 50 << fBinSchemeName << " Unit: " << fUnit << " BinScheme: " << static_cast<int>(fBinScheme) 51 << G4endl; 51 << G4endl; 52 } 52 } 53 53 54 namespace G4Analysis 54 namespace G4Analysis 55 { 55 { 56 56 57 //____________________________________________ 57 //_____________________________________________________________________________ 58 void Update(G4double& value, const G4HnDimensi 58 void Update(G4double& value, const G4HnDimensionInformation& hnInfo) 59 { 59 { 60 // Apply hnInfo to a value 60 // Apply hnInfo to a value 61 61 62 auto unit = hnInfo.fUnit; 62 auto unit = hnInfo.fUnit; 63 auto fcn = hnInfo.fFcn; 63 auto fcn = hnInfo.fFcn; 64 64 65 if (unit == 0.) { 65 if (unit == 0.) { 66 // Should never happen 66 // Should never happen 67 Warn("Illegal unit value (0), 1. will be u 67 Warn("Illegal unit value (0), 1. will be used instead", 68 kNamespaceName, "UpdateBins"); 68 kNamespaceName, "UpdateBins"); 69 unit = 1.; 69 unit = 1.; 70 } 70 } 71 value = fcn(value/unit); 71 value = fcn(value/unit); 72 } 72 } 73 73 74 //____________________________________________ 74 //_____________________________________________________________________________ 75 void UpdateValues( 75 void UpdateValues( 76 G4HnDimension& bins, const G4HnDimensionInfo 76 G4HnDimension& bins, const G4HnDimensionInformation& hnInfo) 77 { 77 { 78 // Apply hnInfo to bins min and max value 78 // Apply hnInfo to bins min and max value 79 79 80 auto unit = hnInfo.fUnit; 80 auto unit = hnInfo.fUnit; 81 auto fcn = hnInfo.fFcn; 81 auto fcn = hnInfo.fFcn; 82 82 83 if (unit == 0.) { 83 if (unit == 0.) { 84 // Should never happen 84 // Should never happen 85 Warn("Illegal unit value (0), 1. will be u 85 Warn("Illegal unit value (0), 1. will be used instead", 86 kNamespaceName, "UpdateBins"); 86 kNamespaceName, "UpdateBins"); 87 unit = 1.; 87 unit = 1.; 88 } 88 } 89 // Update min/max values 89 // Update min/max values 90 bins.fMinValue = fcn(bins.fMinValue/unit); 90 bins.fMinValue = fcn(bins.fMinValue/unit); 91 bins.fMaxValue = fcn(bins.fMaxValue/unit); 91 bins.fMaxValue = fcn(bins.fMaxValue/unit); 92 } 92 } 93 93 94 //____________________________________________ 94 //_____________________________________________________________________________ 95 void Update( 95 void Update( 96 G4HnDimension& bins, const G4HnDimensionInfo 96 G4HnDimension& bins, const G4HnDimensionInformation& hnInfo) 97 { 97 { 98 // Apply hnInfo to bins, compute edges 98 // Apply hnInfo to bins, compute edges 99 99 100 auto unit = hnInfo.fUnit; 100 auto unit = hnInfo.fUnit; 101 auto fcn = hnInfo.fFcn; 101 auto fcn = hnInfo.fFcn; 102 auto binScheme = hnInfo.fBinScheme; 102 auto binScheme = hnInfo.fBinScheme; 103 103 104 if (binScheme == G4BinScheme::kLinear) { 104 if (binScheme == G4BinScheme::kLinear) { 105 // Compute edges, as they may be needed in 105 // Compute edges, as they may be needed in the context of 2D or 3D histograms 106 // with log binning in other dimension 106 // with log binning in other dimension 107 G4Analysis::ComputeEdges( 107 G4Analysis::ComputeEdges( 108 bins.fNBins, bins.fMinValue, bins.fMaxVa 108 bins.fNBins, bins.fMinValue, bins.fMaxValue, unit, fcn, binScheme, bins.fEdges); 109 109 110 // Update min/max Values 110 // Update min/max Values 111 UpdateValues(bins, hnInfo); 111 UpdateValues(bins, hnInfo); 112 112 113 return; 113 return; 114 } 114 } 115 115 116 if (binScheme == G4BinScheme::kLog) { 116 if (binScheme == G4BinScheme::kLog) { 117 // Logarithmic bin scheme 117 // Logarithmic bin scheme 118 // compute edges from parameters 118 // compute edges from parameters 119 G4Analysis::ComputeEdges( 119 G4Analysis::ComputeEdges( 120 bins.fNBins, bins.fMinValue, bins.fMaxVa 120 bins.fNBins, bins.fMinValue, bins.fMaxValue, unit, fcn, binScheme, bins.fEdges); 121 } 121 } 122 122 123 if (binScheme == G4BinScheme::kUser) { 123 if (binScheme == G4BinScheme::kUser) { 124 std::vector<G4double> edges = bins.fEdges; << 124 G4Analysis::ComputeEdges(bins.fEdges, unit, fcn, bins.fEdges); 125 bins.fEdges.clear(); << 126 G4Analysis::ComputeEdges(edges, unit, fcn, << 127 } 125 } 128 } 126 } 129 127 130 //____________________________________________ 128 //_____________________________________________________________________________ 131 void UpdateTitle(G4String& title, const G4HnDi 129 void UpdateTitle(G4String& title, const G4HnDimensionInformation& hnInfo) 132 { 130 { 133 if ( hnInfo.fFcnName != "none" ) { title += 131 if ( hnInfo.fFcnName != "none" ) { title += " "; title += hnInfo.fFcnName; title += "("; } 134 if ( hnInfo.fUnitName != "none" ) { title += 132 if ( hnInfo.fUnitName != "none" ) { title += " ["; title += hnInfo.fUnitName; title += "]";} 135 if ( hnInfo.fFcnName != "none" ) { title += 133 if ( hnInfo.fFcnName != "none" ) { title += ")"; } 136 } 134 } 137 135 138 //____________________________________________ 136 //_____________________________________________________________________________ 139 G4bool CheckMinMax(G4double minValue, G4double 137 G4bool CheckMinMax(G4double minValue, G4double maxValue) 140 { 138 { 141 auto result = true; 139 auto result = true; 142 140 143 // Do not check default values 141 // Do not check default values 144 if ( minValue == 0. && maxValue == 0. ) retu 142 if ( minValue == 0. && maxValue == 0. ) return result; 145 143 146 if ( maxValue <= minValue ) { 144 if ( maxValue <= minValue ) { 147 Warn("Illegal value of (minValue >= maxMax 145 Warn("Illegal value of (minValue >= maxMaxValue)", kNamespaceName, "CheckMinMax"); 148 result = false; 146 result = false; 149 } 147 } 150 148 151 return result; 149 return result; 152 } 150 } 153 151 154 //____________________________________________ 152 //_____________________________________________________________________________ 155 G4bool CheckDimension(unsigned int idim, 153 G4bool CheckDimension(unsigned int idim, 156 const G4HnDimension& dimension, const 154 const G4HnDimension& dimension, const G4HnDimensionInformation& info) 157 { 155 { 158 auto result = true; 156 auto result = true; 159 G4String xyz {"xyz"}; 157 G4String xyz {"xyz"}; 160 158 161 // Check nbins 159 // Check nbins 162 if ( (dimension.fNBins <= 0) && (info.fBinSc 160 if ( (dimension.fNBins <= 0) && (info.fBinScheme != G4BinScheme::kUser) ) { 163 Warn("Illegal value of number of " + xyz.s 161 Warn("Illegal value of number of " + xyz.substr(idim,1) + " bins: nbins <= 0.", 164 kNamespaceName, "CheckDimension"); 162 kNamespaceName, "CheckDimension"); 165 result = false; 163 result = false; 166 } 164 } 167 165 168 // Check min/max << 166 // Check edges 169 if ( (dimension.fMaxValue <= dimension.fMinV << 167 if ( dimension.fEdges.empty() && (info.fBinScheme == G4BinScheme::kUser) ) { 170 (info.fBinScheme != G4BinScheme::kUser) << 168 Warn("Illegal value of number of " + xyz.substr(idim,1) + " edges vector size", 171 Warn("Illegal value of " + xyz.substr(idim << 172 kNamespaceName, "CheckDimension"); 169 kNamespaceName, "CheckDimension"); 173 result = false; 170 result = false; 174 } 171 } 175 172 176 // Check edges << 173 // Check min/max 177 if (info.fBinScheme == G4BinScheme::kUser) { << 174 if ( dimension.fMaxValue <= dimension.fMinValue ) { 178 if ( dimension.fEdges.empty() ) { << 175 Warn("Illegal value of " + xyz.substr(idim,1) + " (min >= max)", 179 Warn(xyz.substr(idim,1) + " edges vector << 176 kNamespaceName, "CheckDimension"); 180 kNamespaceName, "CheckDimension"); << 177 result = false; 181 result = false; << 182 } << 183 // the edges values must be defined in inc << 184 for (size_t i = 1; i < dimension.fEdges.si << 185 if (dimension.fEdges[i-1] >= dimension.f << 186 Warn(xyz.substr(idim,1) + << 187 " edges vector values must be define << 188 kNamespaceName, "CheckDimension"); << 189 result = false; << 190 } << 191 } << 192 } 178 } 193 179 194 // Check function 180 // Check function 195 if ( ( info.fFcnName != "none" ) && ( info.f 181 if ( ( info.fFcnName != "none" ) && ( info.fBinScheme != G4BinScheme::kLinear ) ) { 196 Warn("Combining " + xyz.substr(idim,1) + 182 Warn("Combining " + xyz.substr(idim,1) + " Function and Binning scheme is not supported.", 197 kNamespaceName, "CheckDimension"); 183 kNamespaceName, "CheckDimension"); 198 result = false; 184 result = false; 199 } 185 } 200 186 201 // Check minValue if log binning or log func 187 // Check minValue if log binning or log function 202 if ( ( info.fBinScheme == G4BinScheme::kLog 188 if ( ( info.fBinScheme == G4BinScheme::kLog || 203 info.fFcnName == "log" || info.fFcnNa 189 info.fFcnName == "log" || info.fFcnName == "log10" ) && ( dimension.fMinValue == 0 ) ) { 204 Warn("Illegal value of " + xyz.substr(idim 190 Warn("Illegal value of " + xyz.substr(idim,1) + " (min = 0) with logarithmic function or binning", 205 kNamespaceName, "CheckDimension"); 191 kNamespaceName, "CheckDimension"); 206 result = false; 192 result = false; 207 } 193 } 208 194 209 return result; 195 return result; 210 } 196 } 211 197 212 } 198 } 213 199