Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:59:32

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 // Common implementation for histograms managers.
0028 //
0029 // Author: Ivana Hrivnacova, 10/08/2022  (ivana@ipno.in2p3.fr)
0030 
0031 #ifndef G4THnToolsManager_h
0032 #define G4THnToolsManager_h 1
0033 
0034 #include "G4AnalysisUtilities.hh"
0035 #include "G4VTBaseHnManager.hh"
0036 #include "G4THnManager.hh"
0037 #include "globals.hh"
0038 
0039 #include <memory>
0040 #include <array>
0041 #include <string_view>
0042 
0043 class G4AnalysisManagerState;
0044 class G4HnManager;
0045 class G4UImessenger;
0046 
0047 template <unsigned int DIM, typename HT>
0048 class G4THnToolsManager : public G4VTBaseHnManager<DIM>,
0049                           public G4THnManager<HT>
0050 
0051 {
0052   // Disable using the object managers outside
0053   friend class G4VAnalysisManager;
0054   friend class G4VAnalysisReader;
0055 
0056   public:
0057     G4THnToolsManager(const G4AnalysisManagerState& state);
0058     ~G4THnToolsManager() override = default;
0059 
0060     // deleted copy constructor & assignment operator
0061     G4THnToolsManager(const G4THnToolsManager& rhs) = delete;
0062     G4THnToolsManager& operator=(const G4THnToolsManager& rhs) = delete;
0063 
0064     // Methods for handling histograms
0065     G4int Create(const G4String& name, const G4String& title,
0066                const std::array<G4HnDimension, DIM>& bins,
0067                const std::array<G4HnDimensionInformation, DIM>& hnInfo) override;
0068 
0069     G4bool Set(G4int id,
0070                const std::array<G4HnDimension, DIM>& bins,
0071                const std::array<G4HnDimensionInformation, DIM>& hnInfo) override;
0072 
0073     G4bool Scale(G4int id, G4double factor) override;
0074     G4int GetNofHns(G4bool onlyIfExist) const override;
0075 
0076     // Methods to fill histograms
0077     G4bool Fill(G4int id, std::array<G4double, DIM> value,
0078                 G4double weight = 1.0) override;
0079 
0080     // Access methods
0081     G4int GetId(const G4String &name, G4bool warn = true) const override;
0082 
0083     // Access to bins parameters
0084     G4int GetNbins(unsigned int idim, G4int id) const override;
0085     G4double GetMinValue(unsigned int idim, G4int id) const override;
0086     G4double GetMaxValue(unsigned int idim, G4int id) const override;
0087     G4double GetWidth(unsigned int idim, G4int id) const override;
0088 
0089     // Setters for attributes for plotting
0090     G4bool SetTitle(G4int id, const G4String &title) override;
0091     G4bool SetAxisTitle(unsigned int idim, G4int id,
0092                         const G4String &title) override;
0093 
0094     // Access attributes for plotting
0095     G4String GetTitle(G4int id) const override;
0096     G4String GetAxisTitle(unsigned int idim, G4int id) const override;
0097 
0098     // Methods to list/print histograms
0099     G4bool WriteOnAscii(std::ofstream &output) override;
0100     // Function with specialization per histo type
0101     G4bool List(std::ostream &output, G4bool onlyIfActive = true) override;
0102 
0103     // Methods to delete selected histograms
0104     G4bool Delete(G4int id, G4bool keepSetting) override;
0105 
0106     // // Access to Hn manager
0107     std::shared_ptr<G4HnManager> GetHnManager() override;
0108     const std::shared_ptr<G4HnManager> GetHnManager() const override;
0109 
0110   protected:
0111     // Functions from base class
0112     using G4THnManager<HT>::RegisterT;
0113     using G4THnManager<HT>::GetTHnInFunction;
0114     using G4THnManager<HT>::GetTInFunction;
0115     using G4THnManager<HT>::GetTId;
0116     using G4THnManager<HT>::IsVerbose;
0117     using G4THnManager<HT>::Message;
0118 
0119     static constexpr std::string_view fkClass { "G4THnToolsManager" };
0120 
0121   private:
0122     void UpdateInformation(G4HnInformation* hnInformation,
0123                            const std::array<G4HnDimensionInformation, DIM>& hnInfo);
0124 
0125     G4HnInformation* CreateInformation(const G4String& name,
0126                        const std::array<G4HnDimensionInformation, DIM>& hnInfo);
0127 
0128     void AddAnnotation(HT* ht,
0129                        const std::array<G4HnDimensionInformation, DIM>& hnInfo);
0130 
0131     G4bool CheckName(const G4String& name) const;
0132 
0133     // Functions with specialization per histo type
0134 
0135     HT* CreateToolsHT(const G4String& title,
0136                       const std::array<G4HnDimension, DIM>& bins,
0137                       const std::array<G4HnDimensionInformation, DIM>& hnInfo);
0138 
0139     void ConfigureToolsHT(HT* ht,
0140                       const std::array<G4HnDimension, DIM>& bins,
0141                       const std::array<G4HnDimensionInformation, DIM>& hnInfo);
0142 
0143     G4bool FillHT(HT* ht, const G4HnInformation& hnInformation,
0144                      std::array<G4double, DIM>& value, 
0145                      G4double weight = 1.0);
0146 
0147    // redefine tools::histo::key_axis_x_title() - not available via upper types
0148    static const std::array<std::string, G4Analysis::kMaxDim> fkKeyAxisTitle;
0149 
0150    std::unique_ptr<G4UImessenger> fMessenger;
0151 };
0152 
0153 // inline functions
0154 
0155 #include "G4THnMessenger.hh"
0156 #include "G4THnToolsManager.icc"
0157 #include "G4THnMessenger.icc"
0158     // include messenger and its implementation here to avoid include recursion
0159 
0160 #endif