Geant4 Cross Reference |
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