Geant4  10.01.p03
G4H1ToolsManager.hh
Go to the documentation of this file.
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 // $Id: G4H1ToolsManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
27 
28 // Manager class for tools::histo::h1d.
29 // It implements functions specific to the H1 type
30 // (defined in g4tools).
31 //
32 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
33 
34 #ifndef G4H1ToolsManager_h
35 #define G4H1ToolsManager_h 1
36 
37 #include "G4VH1Manager.hh"
38 #include "G4BaseToolsManager.hh"
39 #include "G4HnManager.hh"
40 #include "G4BinScheme.hh"
41 #include "globals.hh"
42 
43 #include <vector>
44 #include <map>
45 
46 namespace tools {
47 namespace histo {
48 class h1d;
49 }
50 }
51 
53 {
54  public:
56  virtual ~G4H1ToolsManager();
57 
58  // Method to add histograms read from a file
59  G4int AddH1(const G4String& name, tools::histo::h1d* h1d);
60  // Method for merge (MT)
61  void AddH1Vector(const std::vector<tools::histo::h1d*>& h1Vector);
62  // Reset data
63  G4bool Reset();
64  // Return true if the H1 vector is empty
65  G4bool IsEmpty() const;
66 
67  // Access methods
68  //
69  tools::histo::h1d* GetH1(G4int id, G4bool warn = true,
70  G4bool onlyIfActive = true) const;
71 
72  // Iterators
73  std::vector<tools::histo::h1d*>::iterator BeginH1();
74  std::vector<tools::histo::h1d*>::iterator EndH1();
75  std::vector<tools::histo::h1d*>::const_iterator BeginConstH1() const;
76  std::vector<tools::histo::h1d*>::const_iterator EndConstH1() const;
77 
78  // Access to histogram vector (needed for Write())
79  const std::vector<tools::histo::h1d*>& GetH1Vector() const;
80  const std::vector<G4HnInformation*>& GetHnVector() const;
81 
82  protected:
83  // Virtual functions from base class
84  //
85 
86  // Methods to create histograms
87  //
88  virtual G4int CreateH1(const G4String& name, const G4String& title,
89  G4int nbins, G4double xmin, G4double xmax,
90  const G4String& unitName = "none",
91  const G4String& fcnName = "none",
92  const G4String& binScheme = "linear");
93  virtual G4int CreateH1(const G4String& name, const G4String& title,
94  const std::vector<G4double>& edges,
95  const G4String& unitName = "none",
96  const G4String& fcnName = "none");
97 
98  virtual G4bool SetH1(G4int id,
99  G4int nbins, G4double xmin, G4double xmax,
100  const G4String& unitName = "none",
101  const G4String& fcnName = "none",
102  const G4String& binSchemeName = "linear");
103  virtual G4bool SetH1(G4int id,
104  const std::vector<G4double>& edges,
105  const G4String& unitName = "none",
106  const G4String& fcnName = "none");
107  virtual G4bool ScaleH1(G4int id, G4double factor);
108 
109  // Method to fill histograms
110  //
111  virtual G4bool FillH1(G4int id, G4double value, G4double weight = 1.0);
112 
113  // Access methods
114  //
115  virtual G4int GetH1Id(const G4String& name, G4bool warn = true) const;
116 
117  // Access to H1 parameters
118  virtual G4int GetH1Nbins(G4int id) const;
119  virtual G4double GetH1Xmin(G4int id) const;
120  virtual G4double GetH1Xmax(G4int id) const;
121  virtual G4double GetH1Width(G4int id) const;
122 
123  // Attributes for plotting
124  //
125 
126  // Setters
127  virtual G4bool SetH1Title(G4int id, const G4String& title);
128  virtual G4bool SetH1XAxisTitle(G4int id, const G4String& title);
129  virtual G4bool SetH1YAxisTitle(G4int id, const G4String& title);
130 
131  // Accessors
132  virtual G4String GetH1Title(G4int id) const;
133  virtual G4String GetH1XAxisTitle(G4int id) const;
134  virtual G4String GetH1YAxisTitle(G4int id) const;
135 
136  // Write data on ASCII file
137  virtual G4bool WriteOnAscii(std::ofstream& output);
138 
139  private:
140  // methods
141  //
142  virtual tools::histo::h1d* GetH1InFunction(G4int id,
143  G4String functionName,
144  G4bool warn = true,
145  G4bool onlyIfActive = true) const;
146 
147  void AddH1Information(const G4String& name,
148  const G4String& unitName,
149  const G4String& fcnName,
150  G4BinScheme binScheme) const;
151 
152  G4int RegisterToolsH1(tools::histo::h1d* h1d,
153  const G4String& name);
154 
155  // data members
156  //
158  std::vector<tools::histo::h1d*> fH1Vector;
159  std::map<G4String, G4int> fH1NameIdMap;
160 };
161 
162 // inline methods
163 
164 inline std::vector<tools::histo::h1d*>::iterator G4H1ToolsManager::BeginH1()
165 { return fH1Vector.begin(); }
166 
167 inline std::vector<tools::histo::h1d*>::iterator G4H1ToolsManager::EndH1()
168 { return fH1Vector.end(); }
169 
170 inline std::vector<tools::histo::h1d*>::const_iterator
172 { return fH1Vector.begin(); }
173 
174 inline std::vector<tools::histo::h1d*>::const_iterator
176 { return fH1Vector.end(); }
177 
178 inline const std::vector<tools::histo::h1d*>& G4H1ToolsManager::GetH1Vector() const
179 { return fH1Vector; }
180 
181 inline const std::vector<G4HnInformation*>& G4H1ToolsManager::GetHnVector() const
182 { return fHnManager->GetHnVector(); }
183 
184 #endif
185 
virtual G4bool SetH1YAxisTitle(G4int id, const G4String &title)
G4BaseToolsManager fBaseToolsManager
virtual G4bool SetH1XAxisTitle(G4int id, const G4String &title)
std::vector< tools::histo::h1d * >::iterator EndH1()
virtual ~G4H1ToolsManager()
virtual G4bool SetH1(G4int id, G4int nbins, G4double xmin, G4double xmax, const G4String &unitName="none", const G4String &fcnName="none", const G4String &binSchemeName="linear")
const std::vector< tools::histo::h1d * > & GetH1Vector() const
G4String name
Definition: TRTMaterials.hh:40
virtual G4double GetH1Xmin(G4int id) const
tools::histo::h1d * GetH1(G4int id, G4bool warn=true, G4bool onlyIfActive=true) const
virtual G4bool SetH1Title(G4int id, const G4String &title)
int G4int
Definition: G4Types.hh:78
std::vector< tools::histo::h1d * > fH1Vector
virtual G4String GetH1XAxisTitle(G4int id) const
void AddH1Information(const G4String &name, const G4String &unitName, const G4String &fcnName, G4BinScheme binScheme) const
virtual G4int GetH1Nbins(G4int id) const
std::vector< tools::histo::h1d * >::const_iterator EndConstH1() const
bool G4bool
Definition: G4Types.hh:79
const std::vector< G4HnInformation * > & GetHnVector() const
virtual G4int GetH1Id(const G4String &name, G4bool warn=true) const
virtual G4bool WriteOnAscii(std::ofstream &output)
virtual tools::histo::h1d * GetH1InFunction(G4int id, G4String functionName, G4bool warn=true, G4bool onlyIfActive=true) const
virtual G4int CreateH1(const G4String &name, const G4String &title, G4int nbins, G4double xmin, G4double xmax, const G4String &unitName="none", const G4String &fcnName="none", const G4String &binScheme="linear")
std::map< G4String, G4int > fH1NameIdMap
G4HnManager * fHnManager
static const G4double factor
virtual G4double GetH1Width(G4int id) const
virtual G4String GetH1YAxisTitle(G4int id) const
G4int AddH1(const G4String &name, tools::histo::h1d *h1d)
G4H1ToolsManager(const G4AnalysisManagerState &state)
const std::vector< G4HnInformation * > & GetHnVector() const
Definition: G4HnManager.hh:134
G4BinScheme
Definition: G4BinScheme.hh:40
void AddH1Vector(const std::vector< tools::histo::h1d * > &h1Vector)
std::vector< tools::histo::h1d * >::const_iterator BeginConstH1() const
virtual G4double GetH1Xmax(G4int id) const
G4int RegisterToolsH1(tools::histo::h1d *h1d, const G4String &name)
double G4double
Definition: G4Types.hh:76
virtual G4bool ScaleH1(G4int id, G4double factor)
std::vector< tools::histo::h1d * >::iterator BeginH1()
virtual G4String GetH1Title(G4int id) const
virtual G4bool FillH1(G4int id, G4double value, G4double weight=1.0)
G4bool IsEmpty() const