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