ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4H2ToolsManager.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4H2ToolsManager.hh
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 // Manager class for tools::histo::h2d.
28 // It implements functions specific to the H2 type
29 // (defined in g4tools).
30 //
31 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
32 
33 #ifndef G4H2ToolsManager_h
34 #define G4H2ToolsManager_h 1
35 
36 #include "G4VH2Manager.hh"
37 #include "G4THnManager.hh"
38 #include "G4HnManager.hh"
39 #include "globals.hh"
40 
41 #include <vector>
42 #include <map>
43 #include <memory>
44 
45 namespace tools {
46 namespace histo {
47 class h2d;
48 }
49 }
50 
52  public G4THnManager<tools::histo::h2d>
53 {
54  public:
55  explicit G4H2ToolsManager(const G4AnalysisManagerState& state);
56  virtual ~G4H2ToolsManager();
57 
58  // Method to add histograms read from a file
59  G4int AddH2(const G4String& name, tools::histo::h2d* h2d);
60  // Method for merge (MT)
61  void AddH2Vector(const std::vector<tools::histo::h2d*>& h2Vector);
62 
63  // Access methods
64  //
65  tools::histo::h2d* GetH2(G4int id, G4bool warn = true,
66  G4bool onlyIfActive = true) const;
67  // Iterators
68  std::vector<tools::histo::h2d*>::iterator BeginH2();
69  std::vector<tools::histo::h2d*>::iterator EndH2();
70  std::vector<tools::histo::h2d*>::const_iterator BeginConstH2() const;
71  std::vector<tools::histo::h2d*>::const_iterator EndConstH2() const;
72 
73  // Access to histogram vector (needed for Write())
74  const std::vector<tools::histo::h2d*>& GetH2Vector() const;
75  const std::vector<G4HnInformation*>& GetHnVector() const;
76 
77  protected:
78  // Virtual functions from base class
79  //
80 
81  // Methods to create histograms
82  //
83  virtual G4int CreateH2(const G4String& name, const G4String& title,
84  G4int nxbins, G4double xmin, G4double xmax,
85  G4int nybins, G4double ymin, G4double ymax,
86  const G4String& xunitName = "none",
87  const G4String& yunitName = "none",
88  const G4String& xfcnName = "none",
89  const G4String& yfcnName = "none",
90  const G4String& xbinScheme = "linear",
91  const G4String& ybinScheme = "linear") final;
92 
93  virtual G4int CreateH2(const G4String& name, const G4String& title,
94  const std::vector<G4double>& xedges,
95  const std::vector<G4double>& yedges,
96  const G4String& xunitName = "none",
97  const G4String& yunitName = "none",
98  const G4String& xfcnName = "none",
99  const G4String& yfcnName = "none") final;
100 
101  virtual G4bool SetH2(G4int id,
102  G4int nxbins, G4double xmin, G4double xmax,
103  G4int nybins, G4double ymin, G4double ymax,
104  const G4String& xunitName = "none",
105  const G4String& yunitName = "none",
106  const G4String& xfcnName = "none",
107  const G4String& yfcnName = "none",
108  const G4String& xbinScheme = "linear",
109  const G4String& ybinScheme = "linear") final;
110 
111  virtual G4bool SetH2(G4int id,
112  const std::vector<G4double>& xedges,
113  const std::vector<G4double>& yedges,
114  const G4String& xunitName = "none",
115  const G4String& yunitName = "none",
116  const G4String& xfcnName = "none",
117  const G4String& yfcnName = "none") final;
118 
119  virtual G4bool ScaleH2(G4int id, G4double factor) final;
120 
121  // Method to fill histograms
122  //
123  virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue,
124  G4double weight = 1.0) final;
125 
126 
127  // Methods to manipulate histograms
128  //
129 
130  // Access methods
131  virtual G4int GetH2Id(const G4String& name, G4bool warn = true) const final;
132 
133  // Access to H2 parameters
134  virtual G4int GetH2Nxbins(G4int id) const final;
135  virtual G4double GetH2Xmin(G4int id) const final;
136  virtual G4double GetH2Xmax(G4int id) const final;
137  virtual G4double GetH2XWidth(G4int id) const final;
138  virtual G4int GetH2Nybins(G4int id) const final;
139  virtual G4double GetH2Ymin(G4int id) const final;
140  virtual G4double GetH2Ymax(G4int id) const final;
141  virtual G4double GetH2YWidth(G4int id) const final;
142 
143  // Setters for attributes for plotting
144  virtual G4bool SetH2Title(G4int id, const G4String& title) final;
145  virtual G4bool SetH2XAxisTitle(G4int id, const G4String& title) final;
146  virtual G4bool SetH2YAxisTitle(G4int id, const G4String& title) final;
147  virtual G4bool SetH2ZAxisTitle(G4int id, const G4String& title) final;
148 
149  // Access attributes for plotting
150  virtual G4String GetH2Title(G4int id) const final;
151  virtual G4String GetH2XAxisTitle(G4int id) const final;
152  virtual G4String GetH2YAxisTitle(G4int id) const final;
153  virtual G4String GetH2ZAxisTitle(G4int id) const final;
154 
155  // Write data on ASCII file
156  virtual G4bool WriteOnAscii(std::ofstream& output) final;
157 
158  // Access to Hn manager
159  virtual std::shared_ptr<G4HnManager> GetHnManager() final;
160 
161  private:
162  void AddH2Information(const G4String& name,
163  const G4String& xunitName,
164  const G4String& yunitName,
165  const G4String& xfcnName,
166  const G4String& yfcnName,
167  G4BinScheme xbinScheme,
168  G4BinScheme ybinScheme) const;
169 
170  // data members
171  //
172  // static constexpr G4int kDimension = 2; // not yet supported on vc12
173  static const G4int kDimension;
174 };
175 // inline methods
176 
177 inline std::vector<tools::histo::h2d*>::iterator G4H2ToolsManager::BeginH2()
178 { return BeginT(); }
179 
180 inline std::vector<tools::histo::h2d*>::iterator G4H2ToolsManager::EndH2()
181 { return EndT(); }
182 
183 inline std::vector<tools::histo::h2d*>::const_iterator
185 { return BeginConstT(); }
186 
187 inline std::vector<tools::histo::h2d*>::const_iterator
189 { return EndConstT(); }
190 
191 inline const std::vector<tools::histo::h2d*>& G4H2ToolsManager::GetH2Vector() const
192 { return fTVector; }
193 
194 inline const std::vector<G4HnInformation*>& G4H2ToolsManager::GetHnVector() const
195 { return fHnManager->GetHnVector(); }
196 
197 inline std::shared_ptr<G4HnManager> G4H2ToolsManager::GetHnManager()
198 { return std::shared_ptr<G4HnManager>(fHnManager); }
199 
200 #endif
201