Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:24

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     : fNBins(0),
0058       fMinValue(0.),
0059       fMaxValue(0.),
0060       fEdges(edges)
0061       {}
0062 
0063   G4HnDimension() = default;
0064   G4HnDimension(const G4HnDimension& rhs) = default;
0065   G4HnDimension& operator=(const G4HnDimension& rhs) = default;
0066 
0067   void Print() const;
0068 
0069   G4int fNBins{0};
0070   G4double fMinValue{0.};
0071   G4double fMaxValue{0.};
0072   std::vector<G4double> fEdges;
0073 };
0074 
0075 // The additional histogram information per dimension
0076 struct G4HnDimensionInformation
0077 {
0078   G4HnDimensionInformation(
0079       G4String unitName,
0080       G4String fcnName,
0081       G4String binSchemeName = "linear")
0082     : fUnitName(std::move(unitName)),
0083       fFcnName(std::move(fcnName)),
0084       fBinSchemeName(std::move(binSchemeName)),
0085       fUnit(G4Analysis::GetUnitValue(fUnitName)),
0086       fFcn(G4Analysis::GetFunction(fFcnName)),
0087       fBinScheme(G4Analysis::GetBinScheme(fBinSchemeName))
0088       {}
0089 
0090   G4HnDimensionInformation()
0091     : G4HnDimensionInformation("none", "none", "linear") {}
0092   G4HnDimensionInformation(const G4HnDimensionInformation& rhs) = default;
0093   G4HnDimensionInformation& operator=(const G4HnDimensionInformation& rhs) = default;
0094 
0095   void Print() const;
0096 
0097   G4String fUnitName;
0098   G4String fFcnName;
0099   G4String fBinSchemeName;
0100   G4double fUnit;
0101   G4Fcn    fFcn;
0102   G4BinScheme fBinScheme;
0103 };
0104 
0105 // The additional histogram information
0106 class G4HnInformation
0107 {
0108   public:
0109     G4HnInformation(G4String name, G4int nofDimensions)
0110       : fName(std::move(name))
0111     { fHnDimensionInformations.reserve(nofDimensions); }
0112 
0113     // Deleted default constructor
0114     G4HnInformation() = delete;
0115 
0116     // Clear all data
0117     void Update(const G4HnInformation& other) {
0118       // Update all information except name and fHnDimensionInformations
0119       for (G4int i = 0; i < (G4int)fHnDimensionInformations.size(); ++i) {
0120         SetIsLogAxis(i, other.GetIsLogAxis(i));
0121       }
0122       fActivation = other.GetActivation();
0123       fAscii = other.GetAscii();
0124       fPlotting = other.GetPlotting();
0125       fFileName = other.GetFileName();
0126     }
0127 
0128     // Set methods
0129     void AddDimension(const G4HnDimensionInformation& hnDimensionInformation);
0130     void SetDimension(G4int dimension, const G4HnDimensionInformation& hnDimensionInformation);
0131 
0132     void SetIsLogAxis(G4int axis, G4bool isLog);
0133     void SetActivation(G4bool activation);
0134     void SetAscii(G4bool ascii);
0135     void SetPlotting(G4bool plotting);
0136     void SetDeleted(G4bool deleted, G4bool keepSetting);
0137     void SetFileName(const G4String& fileName);
0138 
0139     // Get methods
0140     G4String GetName() const;
0141     G4HnDimensionInformation* GetHnDimensionInformation(G4int dimension);
0142     const G4HnDimensionInformation& GetHnDimensionInformation(G4int dimension) const;
0143     G4bool  GetIsLogAxis(G4int axis) const;
0144     G4bool  GetActivation() const;
0145     G4bool  GetAscii() const;
0146     G4bool  GetPlotting() const;
0147     G4bool  GetDeleted() const;
0148     std::pair<G4bool, G4bool>  GetDeletedPair() const;
0149     G4String GetFileName() const;
0150 
0151   private:
0152     // Data members
0153     G4String fName;
0154     std::vector<G4HnDimensionInformation> fHnDimensionInformations;
0155     std::vector<G4bool> fIsLogAxis { false, false, false };
0156     G4bool   fActivation { true };
0157     G4bool   fAscii { false };
0158     G4bool   fPlotting { false };
0159     std::pair<G4bool, G4bool> fDeleted { false, false };
0160     G4String fFileName;
0161 };
0162 
0163 namespace G4Analysis
0164 {
0165 
0166 // Apply Hn information
0167 void Update(G4double& value, const G4HnDimensionInformation& hnInfo);
0168 void UpdateValues(G4HnDimension& bins, const G4HnDimensionInformation& hnInfo);
0169 void Update(G4HnDimension& bins, const G4HnDimensionInformation& hnInfo);
0170 void UpdateTitle(G4String& title, const G4HnDimensionInformation& hnInfo);
0171 
0172 // Paremeters check
0173 G4bool CheckMinMax(G4double min, G4double max);
0174 G4bool CheckDimension(unsigned int idim,
0175          const G4HnDimension& dimension, const G4HnDimensionInformation& info);
0176 
0177 template <unsigned int DIM>
0178 G4bool CheckDimensions(
0179          const std::array<G4HnDimension, DIM>& bins,
0180          const std::array<G4HnDimensionInformation, DIM>& hnInfo,
0181          G4bool isProfile = false);
0182 }
0183 
0184 // inline functions
0185 
0186 inline void G4HnInformation::AddDimension(
0187   const G4HnDimensionInformation& hnDimensionInformation)
0188 { fHnDimensionInformations.push_back(hnDimensionInformation); }
0189 
0190 inline void G4HnInformation::SetDimension(
0191   G4int dimension, const G4HnDimensionInformation& hnDimensionInformation)
0192 {
0193   auto info = GetHnDimensionInformation(dimension);
0194   (*info) = hnDimensionInformation;
0195 }
0196 
0197 inline void G4HnInformation::SetIsLogAxis(G4int axis, G4bool isLog)
0198 { fIsLogAxis[axis] = isLog; }
0199 
0200 inline void G4HnInformation::SetActivation(G4bool activation)
0201 { fActivation = activation; }
0202 
0203 inline void G4HnInformation::SetAscii(G4bool ascii)
0204 { fAscii = ascii; }
0205 
0206 inline void G4HnInformation::SetPlotting(G4bool plotting)
0207 { fPlotting = plotting; }
0208 
0209 inline void G4HnInformation::SetDeleted(G4bool deleted, G4bool keepSetting)
0210 { fDeleted = std::make_pair(deleted, keepSetting); }
0211 
0212 inline void G4HnInformation::SetFileName(const G4String& fileName)
0213 { fFileName = fileName; }
0214 
0215 inline G4String G4HnInformation::GetName() const
0216 { return fName; }
0217 
0218 inline G4HnDimensionInformation* G4HnInformation::GetHnDimensionInformation(G4int dimension)
0219 { return &(fHnDimensionInformations[dimension]); }
0220 
0221 inline const G4HnDimensionInformation& G4HnInformation::GetHnDimensionInformation(G4int dimension) const
0222 { return fHnDimensionInformations[dimension]; }
0223 
0224 inline G4bool  G4HnInformation::GetIsLogAxis(G4int axis) const
0225 { return fIsLogAxis[axis]; }
0226 
0227 inline G4bool  G4HnInformation::GetActivation() const
0228 { return fActivation; }
0229 
0230 inline G4bool  G4HnInformation::GetAscii() const
0231 { return fAscii; }
0232 
0233 inline G4bool  G4HnInformation::GetPlotting() const
0234 { return fPlotting; }
0235 
0236 inline G4bool G4HnInformation::GetDeleted() const
0237 { return fDeleted.first; }
0238 
0239 inline std::pair<G4bool, G4bool> G4HnInformation::GetDeletedPair() const
0240 { return fDeleted; }
0241 
0242 inline G4String G4HnInformation::GetFileName() const
0243 { return fFileName; }
0244 
0245 template <unsigned int DIM>
0246 inline G4bool G4Analysis::CheckDimensions(
0247          const std::array<G4HnDimension, DIM>& bins,
0248          const std::array<G4HnDimensionInformation, DIM>& hnInfo,
0249          G4bool isProfile)
0250 {
0251   G4bool result = true;
0252 
0253   // Check bins parameters
0254   // (the last dimension has special meaninh for profiles)
0255   auto dimToCheck = (isProfile) ? DIM -1 : DIM ;
0256   for (unsigned int idim = 0; idim < dimToCheck; ++idim) {
0257     result &= CheckDimension(idim, bins[idim], hnInfo[idim]);
0258   }
0259 
0260   // Check profile min/max value
0261   if (isProfile) {
0262     result &= CheckMinMax(bins[DIM-1].fMinValue, bins[DIM-1].fMaxValue);
0263   }
0264 
0265   return result;
0266 }
0267 
0268 #endif