Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:11

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     virtual ~G4THnToolsManager() = 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     virtual G4bool Scale(G4int id, G4double factor) override;
0074     virtual G4int  GetNofHns(G4bool onlyIfExist) const override;
0075 
0076     // Methods to fill histograms
0077     virtual G4bool Fill(G4int id, std::array<G4double, DIM> value, G4double weight = 1.0) override;
0078 
0079     // Access methods
0080     virtual G4int  GetId(const G4String& name, G4bool warn = true) const  override;
0081 
0082     // Access to bins parameters
0083     virtual G4int    GetNbins(unsigned int idim, G4int id) const  override;
0084     virtual G4double GetMinValue(unsigned int idim, G4int id) const override;
0085     virtual G4double GetMaxValue(unsigned int idim, G4int id) const override;
0086     virtual G4double GetWidth(unsigned int idim, G4int id) const override;
0087 
0088     // Setters for attributes for plotting
0089     virtual G4bool SetTitle(G4int id, const G4String& title) override;
0090     virtual G4bool SetAxisTitle(unsigned int idim, G4int id, const G4String& title)  override;
0091 
0092     // Access attributes for plotting
0093     virtual G4String GetTitle(G4int id) const  override;
0094     virtual G4String GetAxisTitle(unsigned int idim, G4int id) const override;
0095 
0096     // Methods to list/print histograms
0097     virtual G4bool WriteOnAscii(std::ofstream& output) override;
0098             // Function with specialization per histo type
0099     virtual G4bool List(std::ostream& output, G4bool onlyIfActive = true) override;
0100 
0101     // Methods to delete selected histograms
0102     virtual G4bool Delete(G4int id, G4bool keepSetting) override;
0103 
0104     // // Access to Hn manager
0105     virtual std::shared_ptr<G4HnManager> GetHnManager() override;
0106     virtual const std::shared_ptr<G4HnManager> GetHnManager() const override;
0107 
0108   protected:
0109     // Functions from base class
0110     using G4THnManager<HT>::RegisterT;
0111     using G4THnManager<HT>::GetTHnInFunction;
0112     using G4THnManager<HT>::GetTInFunction;
0113     using G4THnManager<HT>::GetTId;
0114     using G4THnManager<HT>::IsVerbose;
0115     using G4THnManager<HT>::Message;
0116 
0117     static constexpr std::string_view fkClass { "G4THnToolsManager" };
0118 
0119   private:
0120     void UpdateInformation(G4HnInformation* hnInformation,
0121                            const std::array<G4HnDimensionInformation, DIM>& hnInfo);
0122 
0123     G4HnInformation* CreateInformation(const G4String& name,
0124                        const std::array<G4HnDimensionInformation, DIM>& hnInfo);
0125 
0126     void AddAnnotation(HT* ht,
0127                        const std::array<G4HnDimensionInformation, DIM>& hnInfo);
0128 
0129     G4bool CheckName(const G4String& name) const;
0130 
0131     // Functions with specialization per histo type
0132 
0133     HT* CreateToolsHT(const G4String& title,
0134                       const std::array<G4HnDimension, DIM>& bins,
0135                       const std::array<G4HnDimensionInformation, DIM>& hnInfo);
0136 
0137     void ConfigureToolsHT(HT* ht,
0138                       const std::array<G4HnDimension, DIM>& bins,
0139                       const std::array<G4HnDimensionInformation, DIM>& hnInfo);
0140 
0141     G4bool FillHT(HT* ht, const G4HnInformation& hnInformation,
0142                      std::array<G4double, DIM>& value, 
0143                      G4double weight = 1.0);
0144 
0145    // redefine tools::histo::key_axis_x_title() - not available via upper types
0146    static const std::array<std::string, G4Analysis::kMaxDim> fkKeyAxisTitle;
0147 
0148    std::unique_ptr<G4UImessenger> fMessenger;
0149 };
0150 
0151 // inline functions
0152 
0153 #include "G4THnMessenger.hh"
0154 #include "G4THnToolsManager.icc"
0155 #include "G4THnMessenger.icc"
0156     // include messenger and its implementation here to avoid include recursion
0157 
0158 #endif