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 // Data class for the added Hn/Pn information (not available in g4tools). 28 // 29 // Author: Ivana Hrivnacova, 04/07/2012 (ivana@ipno.in2p3.fr) 30 31 #ifndef G4HnInformation_h 32 #define G4HnInformation_h 1 33 34 #include "G4AnalysisUtilities.hh" 35 #include "G4BinScheme.hh" 36 #include "G4Fcn.hh" 37 #include "globals.hh" 38 39 #include <utility> 40 #include <vector> 41 42 // The histogram input parameters per dimension 43 struct G4HnDimension 44 { 45 G4HnDimension( 46 G4int nbins, 47 G4double minValue, 48 G4double maxValue) 49 : fNBins(nbins), 50 fMinValue(minValue), 51 fMaxValue(maxValue) 52 { 53 fEdges.clear(); 54 } 55 56 G4HnDimension(const std::vector<G4double>& edges) 57 : fEdges(edges) {} 58 G4HnDimension() = default; 59 G4HnDimension(const G4HnDimension& rhs) = default; 60 G4HnDimension& operator=(const G4HnDimension& rhs) = default; 61 62 void Print() const; 63 64 G4int fNBins{0}; 65 G4double fMinValue{0.}; 66 G4double fMaxValue{0.}; 67 std::vector<G4double> fEdges; 68 }; 69 70 // The additional histogram information per dimension 71 struct G4HnDimensionInformation 72 { 73 G4HnDimensionInformation( 74 G4String unitName, 75 G4String fcnName, 76 G4String binSchemeName = "linear") 77 : fUnitName(std::move(unitName)), 78 fFcnName(std::move(fcnName)), 79 fBinSchemeName(std::move(binSchemeName)), 80 fUnit(G4Analysis::GetUnitValue(fUnitName)), 81 fFcn(G4Analysis::GetFunction(fFcnName)), 82 fBinScheme(G4Analysis::GetBinScheme(fBinSchemeName)) 83 {} 84 85 G4HnDimensionInformation() 86 : G4HnDimensionInformation("none", "none", "linear") {} 87 G4HnDimensionInformation(const G4HnDimensionInformation& rhs) = default; 88 G4HnDimensionInformation& operator=(const G4HnDimensionInformation& rhs) = default; 89 90 void Print() const; 91 92 G4String fUnitName; 93 G4String fFcnName; 94 G4String fBinSchemeName; 95 G4double fUnit; 96 G4Fcn fFcn; 97 G4BinScheme fBinScheme; 98 }; 99 100 // The additional histogram information 101 class G4HnInformation 102 { 103 public: 104 G4HnInformation(G4String name, G4int nofDimensions) 105 : fName(std::move(name)) 106 { fHnDimensionInformations.reserve(nofDimensions); } 107 108 // Deleted default constructor 109 G4HnInformation() = delete; 110 111 // Clear all data 112 void Update(const G4HnInformation& other) { 113 // Update all information except name and fHnDimensionInformations 114 for (G4int i = 0; i < (G4int)fHnDimensionInformations.size(); ++i) { 115 SetIsLogAxis(i, other.GetIsLogAxis(i)); 116 } 117 fActivation = other.GetActivation(); 118 fAscii = other.GetAscii(); 119 fPlotting = other.GetPlotting(); 120 fFileName = other.GetFileName(); 121 } 122 123 // Set methods 124 void AddDimension(const G4HnDimensionInformation& hnDimensionInformation); 125 void SetDimension(G4int dimension, const G4HnDimensionInformation& hnDimensionInformation); 126 127 void SetIsLogAxis(G4int axis, G4bool isLog); 128 void SetActivation(G4bool activation); 129 void SetAscii(G4bool ascii); 130 void SetPlotting(G4bool plotting); 131 void SetDeleted(G4bool deleted, G4bool keepSetting); 132 void SetFileName(const G4String& fileName); 133 134 // Get methods 135 G4String GetName() const; 136 G4HnDimensionInformation* GetHnDimensionInformation(G4int dimension); 137 const G4HnDimensionInformation& GetHnDimensionInformation(G4int dimension) const; 138 G4bool GetIsLogAxis(G4int axis) const; 139 G4bool GetActivation() const; 140 G4bool GetAscii() const; 141 G4bool GetPlotting() const; 142 G4bool GetDeleted() const; 143 std::pair<G4bool, G4bool> GetDeletedPair() const; 144 G4String GetFileName() const; 145 146 private: 147 // Data members 148 G4String fName; 149 std::vector<G4HnDimensionInformation> fHnDimensionInformations; 150 std::vector<G4bool> fIsLogAxis { false, false, false }; 151 G4bool fActivation { true }; 152 G4bool fAscii { false }; 153 G4bool fPlotting { false }; 154 std::pair<G4bool, G4bool> fDeleted { false, false }; 155 G4String fFileName; 156 }; 157 158 namespace G4Analysis 159 { 160 161 // Apply Hn information 162 void Update(G4double& value, const G4HnDimensionInformation& hnInfo); 163 void UpdateValues(G4HnDimension& bins, const G4HnDimensionInformation& hnInfo); 164 void Update(G4HnDimension& bins, const G4HnDimensionInformation& hnInfo); 165 void UpdateTitle(G4String& title, const G4HnDimensionInformation& hnInfo); 166 167 // Paremeters check 168 G4bool CheckMinMax(G4double min, G4double max); 169 G4bool CheckDimension(unsigned int idim, 170 const G4HnDimension& dimension, const G4HnDimensionInformation& info); 171 172 template <unsigned int DIM> 173 G4bool CheckDimensions( 174 const std::array<G4HnDimension, DIM>& bins, 175 const std::array<G4HnDimensionInformation, DIM>& hnInfo, 176 G4bool isProfile = false); 177 } 178 179 // inline functions 180 181 inline void G4HnInformation::AddDimension( 182 const G4HnDimensionInformation& hnDimensionInformation) 183 { fHnDimensionInformations.push_back(hnDimensionInformation); } 184 185 inline void G4HnInformation::SetDimension( 186 G4int dimension, const G4HnDimensionInformation& hnDimensionInformation) 187 { 188 auto info = GetHnDimensionInformation(dimension); 189 (*info) = hnDimensionInformation; 190 } 191 192 inline void G4HnInformation::SetIsLogAxis(G4int axis, G4bool isLog) 193 { fIsLogAxis[axis] = isLog; } 194 195 inline void G4HnInformation::SetActivation(G4bool activation) 196 { fActivation = activation; } 197 198 inline void G4HnInformation::SetAscii(G4bool ascii) 199 { fAscii = ascii; } 200 201 inline void G4HnInformation::SetPlotting(G4bool plotting) 202 { fPlotting = plotting; } 203 204 inline void G4HnInformation::SetDeleted(G4bool deleted, G4bool keepSetting) 205 { fDeleted = std::make_pair(deleted, keepSetting); } 206 207 inline void G4HnInformation::SetFileName(const G4String& fileName) 208 { fFileName = fileName; } 209 210 inline G4String G4HnInformation::GetName() const 211 { return fName; } 212 213 inline G4HnDimensionInformation* G4HnInformation::GetHnDimensionInformation(G4int dimension) 214 { return &(fHnDimensionInformations[dimension]); } 215 216 inline const G4HnDimensionInformation& G4HnInformation::GetHnDimensionInformation(G4int dimension) const 217 { return fHnDimensionInformations[dimension]; } 218 219 inline G4bool G4HnInformation::GetIsLogAxis(G4int axis) const 220 { return fIsLogAxis[axis]; } 221 222 inline G4bool G4HnInformation::GetActivation() const 223 { return fActivation; } 224 225 inline G4bool G4HnInformation::GetAscii() const 226 { return fAscii; } 227 228 inline G4bool G4HnInformation::GetPlotting() const 229 { return fPlotting; } 230 231 inline G4bool G4HnInformation::GetDeleted() const 232 { return fDeleted.first; } 233 234 inline std::pair<G4bool, G4bool> G4HnInformation::GetDeletedPair() const 235 { return fDeleted; } 236 237 inline G4String G4HnInformation::GetFileName() const 238 { return fFileName; } 239 240 template <unsigned int DIM> 241 inline G4bool G4Analysis::CheckDimensions( 242 const std::array<G4HnDimension, DIM>& bins, 243 const std::array<G4HnDimensionInformation, DIM>& hnInfo, 244 G4bool isProfile) 245 { 246 G4bool result = true; 247 248 // Check bins parameters 249 // (the last dimension has special meaninh for profiles) 250 auto dimToCheck = (isProfile) ? DIM -1 : DIM ; 251 for (unsigned int idim = 0; idim < dimToCheck; ++idim) { 252 result &= CheckDimension(idim, bins[idim], hnInfo[idim]); 253 } 254 255 // Check profile min/max value 256 if (isProfile) { 257 result &= CheckMinMax(bins[DIM-1].fMinValue, bins[DIM-1].fMaxValue); 258 } 259 260 return result; 261 } 262 263 #endif 264