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