Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4RootAnalysisManager.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$
27 
28 // Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
29 
30 #ifndef G4RootAnalysisManager_h
31 #define G4RootAnalysisManager_h 1
32 
33 #include "G4VAnalysisManager.hh"
34 #include "globals.hh"
35 
36 #include "tools/wroot/file"
37 #include "tools/wroot/to"
38 #include "tools/ntuple_booking"
39 #include "tools/wroot/ntuple"
40 #include "tools/histo/h1d"
41 #include "tools/histo/h2d"
42 
43 #include <vector>
44 #include <map>
45 
47 {
48  public:
50  virtual ~G4RootAnalysisManager();
51 
52  // static methods
54 
55  // Methods to manipulate files
57  virtual G4bool OpenFile(const G4String& fileName);
58  virtual G4bool Write();
59  virtual G4bool CloseFile();
60 
61  // Methods to create histogrammes, ntuples
62  virtual G4int CreateH1(const G4String& name, const G4String& title,
63  G4int nbins, G4double xmin, G4double xmax,
64  const G4String& unitName = "none",
65  const G4String& fcnName = "none");
66  virtual G4int CreateH2(const G4String& name, const G4String& title,
67  G4int nxbins, G4double xmin, G4double xmax,
68  G4int nybins, G4double ymin, G4double ymax,
69  const G4String& xunitName = "none",
70  const G4String& yunitName = "none",
71  const G4String& xfcnName = "none",
72  const G4String& yfcnName = "none");
73 
74  virtual G4bool SetH1(G4int id,
75  G4int nbins, G4double xmin, G4double xmax,
76  const G4String& unitName = "none",
77  const G4String& fcnName = "none");
78  virtual G4bool SetH2(G4int id,
79  G4int nxbins, G4double xmin, G4double xmax,
80  G4int nybins, G4double ymin, G4double ymax,
81  const G4String& xunitName = "none",
82  const G4String& yunitName = "none",
83  const G4String& xfcnName = "none",
84  const G4String& yfcnName = "none");
85 
86  virtual G4bool ScaleH1(G4int id, G4double factor);
87  virtual G4bool ScaleH2(G4int id, G4double factor);
88 
89  virtual void CreateNtuple(const G4String& name, const G4String& title);
90  virtual G4int CreateNtupleIColumn(const G4String& name);
91  virtual G4int CreateNtupleFColumn(const G4String& name);
92  virtual G4int CreateNtupleDColumn(const G4String& name);
93  virtual void FinishNtuple();
94 
95  // Methods to fill histogrammes, ntuples
96  virtual G4bool FillH1(G4int id, G4double value, G4double weight = 1.0);
97  virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue,
98  G4double weight = 1.0);
99  virtual G4bool FillNtupleIColumn(G4int id, G4int value);
100  virtual G4bool FillNtupleFColumn(G4int id, G4float value);
101  virtual G4bool FillNtupleDColumn(G4int id, G4double value);
102  virtual G4bool AddNtupleRow();
103 
104  // Access methods
105  virtual tools::histo::h1d* GetH1(G4int id, G4bool warn = true,
106  G4bool onlyIfActive = true) const;
107  virtual tools::histo::h2d* GetH2(G4int id, G4bool warn = true,
108  G4bool onlyIfActive = true) const;
109 
110  virtual tools::wroot::ntuple* GetNtuple() const;
111 
112  // Access methods via names
113  virtual G4int GetH1Id(const G4String& name, G4bool warn = true) const;
114  virtual G4int GetH2Id(const G4String& name, G4bool warn = true) const;
115 
116  // Access to H1 parameters
117  virtual G4int GetH1Nbins(G4int id) const;
118  virtual G4double GetH1Xmin(G4int id) const;
119  virtual G4double GetH1Xmax(G4int id) const;
120  virtual G4double GetH1Width(G4int id) const;
121 
122  // Access to H2 parameters
123  virtual G4int GetH2Nxbins(G4int id) const;
124  virtual G4double GetH2Xmin(G4int id) const;
125  virtual G4double GetH2Xmax(G4int id) const;
126  virtual G4double GetH2XWidth(G4int id) const;
127  virtual G4int GetH2Nybins(G4int id) const;
128  virtual G4double GetH2Ymin(G4int id) const;
129  virtual G4double GetH2Ymax(G4int id) const;
130  virtual G4double GetH2YWidth(G4int id) const;
131 
132  // Setters for attributes for plotting
133  virtual G4bool SetH1Title(G4int id, const G4String& title);
134  virtual G4bool SetH1XAxisTitle(G4int id, const G4String& title);
135  virtual G4bool SetH1YAxisTitle(G4int id, const G4String& title);
136  virtual G4bool SetH2Title(G4int id, const G4String& title);
137  virtual G4bool SetH2XAxisTitle(G4int id, const G4String& title);
138  virtual G4bool SetH2YAxisTitle(G4int id, const G4String& title);
139  virtual G4bool SetH2ZAxisTitle(G4int id, const G4String& title);
140 
141  // Access attributes for plotting
142  virtual G4String GetH1Title(G4int id) const;
143  virtual G4String GetH1XAxisTitle(G4int id) const;
144  virtual G4String GetH1YAxisTitle(G4int id) const;
145  virtual G4String GetH2Title(G4int id) const;
146  virtual G4String GetH2XAxisTitle(G4int id) const;
147  virtual G4String GetH2YAxisTitle(G4int id) const;
148  virtual G4String GetH2ZAxisTitle(G4int id) const;
149 
150  protected:
151  virtual G4bool WriteOnAscii(std::ofstream& output);
152 
153  private:
154  // static data members
155  //
156  static G4RootAnalysisManager* fgInstance;
157 
158  // methods
159  //
160  G4bool CreateHistoDirectory();
161  G4bool CreateNtupleDirectory();
162  void CreateNtupleFromBooking();
163  tools::wroot::ntuple::column<int>* GetNtupleIColumn(G4int id) const;
164  tools::wroot::ntuple::column<float>* GetNtupleFColumn(G4int id) const;
165  tools::wroot::ntuple::column<double>* GetNtupleDColumn(G4int id) const;
166  virtual G4bool Reset();
167  virtual tools::histo::h1d* GetH1InFunction(G4int id, G4String function,
168  G4bool warn = true,
169  G4bool onlyIfActive = true) const;
170  virtual tools::histo::h2d* GetH2InFunction(G4int id, G4String function,
171  G4bool warn = true,
172  G4bool onlyIfActive = true) const;
173  void UpdateTitle(G4String& title,
174  const G4String& unitName, const G4String& fcnName) const;
175 
176  // data members
177  //
178  tools::wroot::file* fFile;
179  tools::wroot::directory* fHistoDirectory;
180  tools::wroot::directory* fNtupleDirectory;
181 
182  std::vector<tools::histo::h1d*> fH1Vector;
183  std::vector<tools::histo::h2d*> fH2Vector;
184  std::map<G4String, G4int> fH1NameIdMap;
185  std::map<G4String, G4int> fH2NameIdMap;
186 
187  tools::wroot::ntuple* fNtuple;
188  tools::ntuple_booking* fNtupleBooking;
189  std::map<G4int, tools::wroot::ntuple::column<int>* > fNtupleIColumnMap;
190  std::map<G4int, tools::wroot::ntuple::column<float>* > fNtupleFColumnMap;
191  std::map<G4int, tools::wroot::ntuple::column<double>* > fNtupleDColumnMap;
192 };
193 
194 #endif
195