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 std::vector<G4double> edges = bins.fEdges; 125 bins.fEdges.clear(); 125 bins.fEdges.clear(); 126 G4Analysis::ComputeEdges(edges, unit, fcn, 126 G4Analysis::ComputeEdges(edges, unit, fcn, bins.fEdges); 127 } 127 } 128 } 128 } 129 129 130 //____________________________________________ 130 //_____________________________________________________________________________ 131 void UpdateTitle(G4String& title, const G4HnDi 131 void UpdateTitle(G4String& title, const G4HnDimensionInformation& hnInfo) 132 { 132 { 133 if ( hnInfo.fFcnName != "none" ) { title += 133 if ( hnInfo.fFcnName != "none" ) { title += " "; title += hnInfo.fFcnName; title += "("; } 134 if ( hnInfo.fUnitName != "none" ) { title += 134 if ( hnInfo.fUnitName != "none" ) { title += " ["; title += hnInfo.fUnitName; title += "]";} 135 if ( hnInfo.fFcnName != "none" ) { title += 135 if ( hnInfo.fFcnName != "none" ) { title += ")"; } 136 } 136 } 137 137 138 //____________________________________________ 138 //_____________________________________________________________________________ 139 G4bool CheckMinMax(G4double minValue, G4double 139 G4bool CheckMinMax(G4double minValue, G4double maxValue) 140 { 140 { 141 auto result = true; 141 auto result = true; 142 142 143 // Do not check default values 143 // Do not check default values 144 if ( minValue == 0. && maxValue == 0. ) retu 144 if ( minValue == 0. && maxValue == 0. ) return result; 145 145 146 if ( maxValue <= minValue ) { 146 if ( maxValue <= minValue ) { 147 Warn("Illegal value of (minValue >= maxMax 147 Warn("Illegal value of (minValue >= maxMaxValue)", kNamespaceName, "CheckMinMax"); 148 result = false; 148 result = false; 149 } 149 } 150 150 151 return result; 151 return result; 152 } 152 } 153 153 154 //____________________________________________ 154 //_____________________________________________________________________________ 155 G4bool CheckDimension(unsigned int idim, 155 G4bool CheckDimension(unsigned int idim, 156 const G4HnDimension& dimension, const 156 const G4HnDimension& dimension, const G4HnDimensionInformation& info) 157 { 157 { 158 auto result = true; 158 auto result = true; 159 G4String xyz {"xyz"}; 159 G4String xyz {"xyz"}; 160 160 161 // Check nbins 161 // Check nbins 162 if ( (dimension.fNBins <= 0) && (info.fBinSc 162 if ( (dimension.fNBins <= 0) && (info.fBinScheme != G4BinScheme::kUser) ) { 163 Warn("Illegal value of number of " + xyz.s 163 Warn("Illegal value of number of " + xyz.substr(idim,1) + " bins: nbins <= 0.", 164 kNamespaceName, "CheckDimension"); 164 kNamespaceName, "CheckDimension"); 165 result = false; 165 result = false; 166 } 166 } 167 167 168 // Check min/max 168 // Check min/max 169 if ( (dimension.fMaxValue <= dimension.fMinV 169 if ( (dimension.fMaxValue <= dimension.fMinValue) && 170 (info.fBinScheme != G4BinScheme::kUser) 170 (info.fBinScheme != G4BinScheme::kUser) ) { 171 Warn("Illegal value of " + xyz.substr(idim 171 Warn("Illegal value of " + xyz.substr(idim,1) + " (min >= max)", 172 kNamespaceName, "CheckDimension"); 172 kNamespaceName, "CheckDimension"); 173 result = false; 173 result = false; 174 } 174 } 175 175 176 // Check edges 176 // Check edges 177 if (info.fBinScheme == G4BinScheme::kUser) { 177 if (info.fBinScheme == G4BinScheme::kUser) { 178 if ( dimension.fEdges.empty() ) { 178 if ( dimension.fEdges.empty() ) { 179 Warn(xyz.substr(idim,1) + " edges vector 179 Warn(xyz.substr(idim,1) + " edges vector is empty.", 180 kNamespaceName, "CheckDimension"); 180 kNamespaceName, "CheckDimension"); 181 result = false; 181 result = false; 182 } 182 } 183 // the edges values must be defined in inc 183 // the edges values must be defined in increasing order 184 for (size_t i = 1; i < dimension.fEdges.si 184 for (size_t i = 1; i < dimension.fEdges.size(); ++i){ 185 if (dimension.fEdges[i-1] >= dimension.f 185 if (dimension.fEdges[i-1] >= dimension.fEdges[i]) { 186 Warn(xyz.substr(idim,1) + 186 Warn(xyz.substr(idim,1) + 187 " edges vector values must be define 187 " edges vector values must be defined in increasing order.", 188 kNamespaceName, "CheckDimension"); 188 kNamespaceName, "CheckDimension"); 189 result = false; 189 result = false; 190 } 190 } 191 } 191 } 192 } 192 } 193 193 194 // Check function 194 // Check function 195 if ( ( info.fFcnName != "none" ) && ( info.f 195 if ( ( info.fFcnName != "none" ) && ( info.fBinScheme != G4BinScheme::kLinear ) ) { 196 Warn("Combining " + xyz.substr(idim,1) + 196 Warn("Combining " + xyz.substr(idim,1) + " Function and Binning scheme is not supported.", 197 kNamespaceName, "CheckDimension"); 197 kNamespaceName, "CheckDimension"); 198 result = false; 198 result = false; 199 } 199 } 200 200 201 // Check minValue if log binning or log func 201 // Check minValue if log binning or log function 202 if ( ( info.fBinScheme == G4BinScheme::kLog 202 if ( ( info.fBinScheme == G4BinScheme::kLog || 203 info.fFcnName == "log" || info.fFcnNa 203 info.fFcnName == "log" || info.fFcnName == "log10" ) && ( dimension.fMinValue == 0 ) ) { 204 Warn("Illegal value of " + xyz.substr(idim 204 Warn("Illegal value of " + xyz.substr(idim,1) + " (min = 0) with logarithmic function or binning", 205 kNamespaceName, "CheckDimension"); 205 kNamespaceName, "CheckDimension"); 206 result = false; 206 result = false; 207 } 207 } 208 208 209 return result; 209 return result; 210 } 210 } 211 211 212 } 212 } 213 213