Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:58:36

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 
0027 // Data class for the added Hn/Pn information (not available in g4tools).
0028 //
0029 // Author: Ivana Hrivnacova, 04/07/2012  (ivana@ipno.in2p3.fr)
0030 
0031 #ifndef G4HnInformation_h
0032 #define G4HnInformation_h 1
0033 
0034 #include "G4AnalysisUtilities.hh"
0035 #include "G4BinScheme.hh"
0036 #include "G4Fcn.hh"
0037 #include "globals.hh"
0038 
0039 #include <utility>
0040 #include <vector>
0041 
0042 // The histogram input parameters per dimension
0043 struct G4HnDimension
0044 {
0045   G4HnDimension(
0046       G4int nbins,
0047       G4double minValue,
0048       G4double maxValue)
0049     : fNBins(nbins),
0050       fMinValue(minValue),
0051       fMaxValue(maxValue)
0052       {
0053         fEdges.clear();
0054       }
0055 
0056   G4HnDimension(const std::vector<G4double>& edges)
0057     : fEdges(edges) {}
0058   G4HnDimension() = default;
0059   G4HnDimension(const G4HnDimension& rhs) = default;
0060   G4HnDimension& operator=(const G4HnDimension& rhs) = default;
0061 
0062   void Print() const;
0063 
0064   G4int fNBins{0};
0065   G4double fMinValue{0.};
0066   G4double fMaxValue{0.};
0067   std::vector<G4double> fEdges;
0068 };
0069 
0070 // The additional histogram information per dimension
0071 struct G4HnDimensionInformation
0072 {
0073   G4HnDimensionInformation(
0074       G4String unitName,
0075       G4String fcnName,
0076       G4String binSchemeName = "linear")
0077     : fUnitName(std::move(unitName)),
0078       fFcnName(std::move(fcnName)),
0079       fBinSchemeName(std::move(binSchemeName)),
0080       fUnit(G4Analysis::GetUnitValue(fUnitName)),
0081       fFcn(G4Analysis::GetFunction(fFcnName)),
0082       fBinScheme(G4Analysis::GetBinScheme(fBinSchemeName))
0083       {}
0084 
0085   G4HnDimensionInformation()
0086     : G4HnDimensionInformation("none", "none", "linear") {}
0087   G4HnDimensionInformation(const G4HnDimensionInformation& rhs) = default;
0088   G4HnDimensionInformation& operator=(const G4HnDimensionInformation& rhs) = default;
0089 
0090   void Print() const;
0091 
0092   G4String fUnitName;
0093   G4String fFcnName;
0094   G4String fBinSchemeName;
0095   G4double fUnit;
0096   G4Fcn    fFcn;
0097   G4BinScheme fBinScheme;
0098 };
0099 
0100 // The additional histogram information
0101 class G4HnInformation
0102 {
0103   public:
0104     G4HnInformation(G4String name, G4int nofDimensions)
0105       : fName(std::move(name))
0106     { fHnDimensionInformations.reserve(nofDimensions); }
0107 
0108     // Deleted default constructor
0109     G4HnInformation() = delete;
0110 
0111     // Clear all data
0112     void Update(const G4HnInformation& other) {
0113       // Update all information except name and fHnDimensionInformations
0114       for (G4int i = 0; i < (G4int)fHnDimensionInformations.size(); ++i) {
0115         SetIsLogAxis(i, other.GetIsLogAxis(i));
0116       }
0117       fActivation = other.GetActivation();
0118       fAscii = other.GetAscii();
0119       fPlotting = other.GetPlotting();
0120       fFileName = other.GetFileName();
0121     }
0122 
0123     // Set methods
0124     void AddDimension(const G4HnDimensionInformation& hnDimensionInformation);
0125     void SetDimension(G4int dimension, const G4HnDimensionInformation& hnDimensionInformation);
0126 
0127     void SetIsLogAxis(G4int axis, G4bool isLog);
0128     void SetActivation(G4bool activation);
0129     void SetAscii(G4bool ascii);
0130     void SetPlotting(G4bool plotting);
0131     void SetDeleted(G4bool deleted, G4bool keepSetting);
0132     void SetFileName(const G4String& fileName);
0133 
0134     // Get methods
0135     G4String GetName() const;
0136     G4HnDimensionInformation* GetHnDimensionInformation(G4int dimension);
0137     const G4HnDimensionInformation& GetHnDimensionInformation(G4int dimension) const;
0138     G4bool  GetIsLogAxis(G4int axis) const;
0139     G4bool  GetActivation() const;
0140     G4bool  GetAscii() const;
0141     G4bool  GetPlotting() const;
0142     G4bool  GetDeleted() const;
0143     std::pair<G4bool, G4bool>  GetDeletedPair() const;
0144     G4String GetFileName() const;
0145 
0146   private:
0147     // Data members
0148     G4String fName;
0149     std::vector<G4HnDimensionInformation> fHnDimensionInformations;
0150     std::vector<G4bool> fIsLogAxis { false, false, false };
0151     G4bool   fActivation { true };
0152     G4bool   fAscii { false };
0153     G4bool   fPlotting { false };
0154     std::pair<G4bool, G4bool> fDeleted { false, false };
0155     G4String fFileName;
0156 };
0157 
0158 namespace G4Analysis
0159 {
0160 
0161 // Apply Hn information
0162 void Update(G4double& value, const G4HnDimensionInformation& hnInfo);
0163 void UpdateValues(G4HnDimension& bins, const G4HnDimensionInformation& hnInfo);
0164 void Update(G4HnDimension& bins, const G4HnDimensionInformation& hnInfo);
0165 void UpdateTitle(G4String& title, const G4HnDimensionInformation& hnInfo);
0166 
0167 // Paremeters check
0168 G4bool CheckMinMax(G4double min, G4double max);
0169 G4bool CheckDimension(unsigned int idim,
0170          const G4HnDimension& dimension, const G4HnDimensionInformation& info);
0171 
0172 template <unsigned int DIM>
0173 G4bool CheckDimensions(
0174          const std::array<G4HnDimension, DIM>& bins,
0175          const std::array<G4HnDimensionInformation, DIM>& hnInfo,
0176          G4bool isProfile = false);
0177 }
0178 
0179 // inline functions
0180 
0181 inline void G4HnInformation::AddDimension(
0182   const G4HnDimensionInformation& hnDimensionInformation)
0183 { fHnDimensionInformations.push_back(hnDimensionInformation); }
0184 
0185 inline void G4HnInformation::SetDimension(
0186   G4int dimension, const G4HnDimensionInformation& hnDimensionInformation)
0187 {
0188   auto info = GetHnDimensionInformation(dimension);
0189   (*info) = hnDimensionInformation;
0190 }
0191 
0192 inline void G4HnInformation::SetIsLogAxis(G4int axis, G4bool isLog)
0193 { fIsLogAxis[axis] = isLog; }
0194 
0195 inline void G4HnInformation::SetActivation(G4bool activation)
0196 { fActivation = activation; }
0197 
0198 inline void G4HnInformation::SetAscii(G4bool ascii)
0199 { fAscii = ascii; }
0200 
0201 inline void G4HnInformation::SetPlotting(G4bool plotting)
0202 { fPlotting = plotting; }
0203 
0204 inline void G4HnInformation::SetDeleted(G4bool deleted, G4bool keepSetting)
0205 { fDeleted = std::make_pair(deleted, keepSetting); }
0206 
0207 inline void G4HnInformation::SetFileName(const G4String& fileName)
0208 { fFileName = fileName; }
0209 
0210 inline G4String G4HnInformation::GetName() const
0211 { return fName; }
0212 
0213 inline G4HnDimensionInformation* G4HnInformation::GetHnDimensionInformation(G4int dimension)
0214 { return &(fHnDimensionInformations[dimension]); }
0215 
0216 inline const G4HnDimensionInformation& G4HnInformation::GetHnDimensionInformation(G4int dimension) const
0217 { return fHnDimensionInformations[dimension]; }
0218 
0219 inline G4bool  G4HnInformation::GetIsLogAxis(G4int axis) const
0220 { return fIsLogAxis[axis]; }
0221 
0222 inline G4bool  G4HnInformation::GetActivation() const
0223 { return fActivation; }
0224 
0225 inline G4bool  G4HnInformation::GetAscii() const
0226 { return fAscii; }
0227 
0228 inline G4bool  G4HnInformation::GetPlotting() const
0229 { return fPlotting; }
0230 
0231 inline G4bool G4HnInformation::GetDeleted() const
0232 { return fDeleted.first; }
0233 
0234 inline std::pair<G4bool, G4bool> G4HnInformation::GetDeletedPair() const
0235 { return fDeleted; }
0236 
0237 inline G4String G4HnInformation::GetFileName() const
0238 { return fFileName; }
0239 
0240 template <unsigned int DIM>
0241 inline G4bool G4Analysis::CheckDimensions(
0242          const std::array<G4HnDimension, DIM>& bins,
0243          const std::array<G4HnDimensionInformation, DIM>& hnInfo,
0244          G4bool isProfile)
0245 {
0246   G4bool result = true;
0247 
0248   // Check bins parameters
0249   // (the last dimension has special meaninh for profiles)
0250   auto dimToCheck = (isProfile) ? DIM -1 : DIM ;
0251   for (unsigned int idim = 0; idim < dimToCheck; ++idim) {
0252     result &= CheckDimension(idim, bins[idim], hnInfo[idim]);
0253   }
0254 
0255   // Check profile min/max value
0256   if (isProfile) {
0257     result &= CheckMinMax(bins[DIM-1].fMinValue, bins[DIM-1].fMaxValue);
0258   }
0259 
0260   return result;
0261 }
0262 
0263 #endif