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[ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 // Common implementation for histograms managers.
 28 //
 29 // Author: Ivana Hrivnacova, 10/08/2022  (ivana@ipno.in2p3.fr)
 30 
 31 #ifndef G4THnToolsManager_h
 32 #define G4THnToolsManager_h 1
 33 
 34 #include "G4AnalysisUtilities.hh"
 35 #include "G4VTBaseHnManager.hh"
 36 #include "G4THnManager.hh"
 37 #include "globals.hh"
 38 
 39 #include <memory>
 40 #include <array>
 41 #include <string_view>
 42 
 43 class G4AnalysisManagerState;
 44 class G4HnManager;
 45 class G4UImessenger;
 46 
 47 template <unsigned int DIM, typename HT>
 48 class G4THnToolsManager : public G4VTBaseHnManager<DIM>,
 49                           public G4THnManager<HT>
 50 
 51 {
 52   // Disable using the object managers outside
 53   friend class G4VAnalysisManager;
 54   friend class G4VAnalysisReader;
 55 
 56   public:
 57     G4THnToolsManager(const G4AnalysisManagerState& state);
 58     ~G4THnToolsManager() override = default;
 59 
 60     // deleted copy constructor & assignment operator
 61     G4THnToolsManager(const G4THnToolsManager& rhs) = delete;
 62     G4THnToolsManager& operator=(const G4THnToolsManager& rhs) = delete;
 63 
 64     // Methods for handling histograms
 65     G4int Create(const G4String& name, const G4String& title,
 66                const std::array<G4HnDimension, DIM>& bins,
 67                const std::array<G4HnDimensionInformation, DIM>& hnInfo) override;
 68 
 69     G4bool Set(G4int id,
 70                const std::array<G4HnDimension, DIM>& bins,
 71                const std::array<G4HnDimensionInformation, DIM>& hnInfo) override;
 72 
 73     G4bool Scale(G4int id, G4double factor) override;
 74     G4int GetNofHns(G4bool onlyIfExist) const override;
 75 
 76     // Methods to fill histograms
 77     G4bool Fill(G4int id, std::array<G4double, DIM> value,
 78                 G4double weight = 1.0) override;
 79 
 80     // Access methods
 81     G4int GetId(const G4String &name, G4bool warn = true) const override;
 82 
 83     // Access to bins parameters
 84     G4int GetNbins(unsigned int idim, G4int id) const override;
 85     G4double GetMinValue(unsigned int idim, G4int id) const override;
 86     G4double GetMaxValue(unsigned int idim, G4int id) const override;
 87     G4double GetWidth(unsigned int idim, G4int id) const override;
 88 
 89     // Setters for attributes for plotting
 90     G4bool SetTitle(G4int id, const G4String &title) override;
 91     G4bool SetAxisTitle(unsigned int idim, G4int id,
 92                         const G4String &title) override;
 93 
 94     // Access attributes for plotting
 95     G4String GetTitle(G4int id) const override;
 96     G4String GetAxisTitle(unsigned int idim, G4int id) const override;
 97 
 98     // Methods to list/print histograms
 99     G4bool WriteOnAscii(std::ofstream &output) override;
100     // Function with specialization per histo type
101     G4bool List(std::ostream &output, G4bool onlyIfActive = true) override;
102 
103     // Methods to delete selected histograms
104     G4bool Delete(G4int id, G4bool keepSetting) override;
105 
106     // // Access to Hn manager
107     std::shared_ptr<G4HnManager> GetHnManager() override;
108     const std::shared_ptr<G4HnManager> GetHnManager() const override;
109 
110   protected:
111     // Functions from base class
112     using G4THnManager<HT>::RegisterT;
113     using G4THnManager<HT>::GetTHnInFunction;
114     using G4THnManager<HT>::GetTInFunction;
115     using G4THnManager<HT>::GetTId;
116     using G4THnManager<HT>::IsVerbose;
117     using G4THnManager<HT>::Message;
118 
119     static constexpr std::string_view fkClass { "G4THnToolsManager" };
120 
121   private:
122     void UpdateInformation(G4HnInformation* hnInformation,
123                            const std::array<G4HnDimensionInformation, DIM>& hnInfo);
124 
125     G4HnInformation* CreateInformation(const G4String& name,
126                        const std::array<G4HnDimensionInformation, DIM>& hnInfo);
127 
128     void AddAnnotation(HT* ht,
129                        const std::array<G4HnDimensionInformation, DIM>& hnInfo);
130 
131     G4bool CheckName(const G4String& name) const;
132 
133     // Functions with specialization per histo type
134 
135     HT* CreateToolsHT(const G4String& title,
136                       const std::array<G4HnDimension, DIM>& bins,
137                       const std::array<G4HnDimensionInformation, DIM>& hnInfo);
138 
139     void ConfigureToolsHT(HT* ht,
140                       const std::array<G4HnDimension, DIM>& bins,
141                       const std::array<G4HnDimensionInformation, DIM>& hnInfo);
142 
143     G4bool FillHT(HT* ht, const G4HnInformation& hnInformation,
144                      std::array<G4double, DIM>& value, 
145                      G4double weight = 1.0);
146 
147    // redefine tools::histo::key_axis_x_title() - not available via upper types
148    static const std::array<std::string, G4Analysis::kMaxDim> fkKeyAxisTitle;
149 
150    std::unique_ptr<G4UImessenger> fMessenger;
151 };
152 
153 // inline functions
154 
155 #include "G4THnMessenger.hh"
156 #include "G4THnToolsManager.icc"
157 #include "G4THnMessenger.icc"
158     // include messenger and its implementation here to avoid include recursion
159 
160 #endif
161