Geant4  10.00.p01
G4VAnalysisManager.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: G4VAnalysisManager.hh 71635 2013-06-19 13:48:28Z ihrivnac $
27 
28 // The nonvirtual public interface class to g4tools based analysis.
29 // It is defined as a composite of object manager base classes.
30 // Individual use of the component managers is disabled
31 // (except for file manager and Hn manager which are also used from
32 // other object managers).
33 // The functions which has to be implemented in concrete managers
34 // are declared as virtual protected.
35 
36 // Author: Ivana Hrivnacova, 09/07/2013 (ivana@ipno.in2p3.fr)
37 
38 #ifndef G4VAnalysisManager_h
39 #define G4VAnalysisManager_h 1
40 
42 #include "globals.hh"
43 
44 #include <vector>
45 #include <fstream>
46 
47 
49 class G4HnManager;
50 class G4VH1Manager;
51 class G4VH2Manager;
52 class G4VNtupleManager;
53 class G4VFileManager;
54 
56 {
57  public:
58  G4VAnalysisManager(const G4String& type, G4bool isMaster);
59  virtual ~G4VAnalysisManager();
60 
61  // Methods for handling files
62  G4bool OpenFile();
63  G4bool OpenFile(const G4String& fileName);
64  G4bool Write();
65  G4bool CloseFile();
66 
67  // Methods for handling files and directories names
68  G4bool SetFileName(const G4String& fileName);
69  G4bool SetHistoDirectoryName(const G4String& dirName);
70  G4bool SetNtupleDirectoryName(const G4String& dirName);
71  G4String GetFileName() const;
74 
75  // Methods for handling histogrammes
76  G4int CreateH1(const G4String& name, const G4String& title,
77  G4int nbins, G4double xmin, G4double xmax,
78  const G4String& unitName = "none",
79  const G4String& fcnName = "none",
80  const G4String& binSchemeName = "linear");
81 
82  G4int CreateH1(const G4String& name, const G4String& title,
83  const std::vector<G4double>& edges,
84  const G4String& unitName = "none",
85  const G4String& fcnName = "none");
86 
87  G4int CreateH2(const G4String& name, const G4String& title,
88  G4int nxbins, G4double xmin, G4double xmax,
89  G4int nybins, G4double ymin, G4double ymax,
90  const G4String& xunitName = "none",
91  const G4String& yunitName = "none",
92  const G4String& xfcnName = "none",
93  const G4String& yfcnName = "none",
94  const G4String& xbinScheme = "linear",
95  const G4String& ybinScheme = "linear");
96 
97  G4int CreateH2(const G4String& name, const G4String& title,
98  const std::vector<G4double>& xedges,
99  const std::vector<G4double>& yedges,
100  const G4String& xunitName = "none",
101  const G4String& yunitName = "none",
102  const G4String& xfcnName = "none",
103  const G4String& yfcnName = "none");
104 
105  G4bool SetH1(G4int id,
106  G4int nbins, G4double xmin, G4double xmax,
107  const G4String& unitName = "none",
108  const G4String& fcnName = "none",
109  const G4String& binSchemeName = "linear");
110 
111  G4bool SetH1(G4int id,
112  const std::vector<G4double>& edges,
113  const G4String& unitName = "none",
114  const G4String& fcnName = "none");
115 
116  G4bool SetH2(G4int id,
117  G4int nxbins, G4double xmin, G4double xmax,
118  G4int nybins, G4double ymin, G4double ymax,
119  const G4String& xunitName = "none",
120  const G4String& yunitName = "none",
121  const G4String& xfcnName = "none",
122  const G4String& yfcnName = "none",
123  const G4String& xbinSchemeName = "linear",
124  const G4String& ybinSchemeName = "linear");
125 
126  G4bool SetH2(G4int id,
127  const std::vector<G4double>& xedges,
128  const std::vector<G4double>& yedges,
129  const G4String& xunitName = "none",
130  const G4String& yunitName = "none",
131  const G4String& xfcnName = "none",
132  const G4String& yfcnName = "none");
133 
134  G4bool ScaleH1(G4int id, G4double factor);
135  G4bool ScaleH2(G4int id, G4double factor);
136 
137  // Methods for handling ntuples
138  G4int CreateNtuple(const G4String& name, const G4String& title);
139  // Create columns in the last created ntuple
140  G4int CreateNtupleIColumn(const G4String& name);
141  G4int CreateNtupleFColumn(const G4String& name);
142  G4int CreateNtupleDColumn(const G4String& name);
143  void FinishNtuple();
144  // Create columns in the ntuple with given id
145  G4int CreateNtupleIColumn(G4int ntupleId, const G4String& name);
146  G4int CreateNtupleFColumn(G4int ntupleId, const G4String& name);
147  G4int CreateNtupleDColumn(G4int ntupleId, const G4String& name);
148  void FinishNtuple(G4int ntupleId);
149 
150  // The ids of histograms and ntuples are generated automatically
151  // starting from 0; with following functions it is possible to
152  // change the first Id to start from other value
153  G4bool SetFirstHistoId(G4int firstId);
154  G4bool SetFirstH1Id(G4int firstId);
155  G4bool SetFirstH2Id(G4int firstId);
156  G4bool SetFirstNtupleId(G4int firstId);
158 
159  // Methods to fill histogrammes, ntuples
160  G4bool FillH1(G4int id, G4double value, G4double weight = 1.0);
161  G4bool FillH2(G4int id, G4double xvalue, G4double yvalue,
162  G4double weight = 1.0);
163  // Methods for ntuple with id = FirstNtupleId
164  G4bool FillNtupleIColumn(G4int id, G4int value);
168  // Methods for ntuple with id > FirstNtupleId (when more ntuples exist)
169  G4bool FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value);
170  G4bool FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value);
171  G4bool FillNtupleDColumn(G4int ntupleId, G4int columnId, G4double value);
172  G4bool AddNtupleRow(G4int ntupleId);
173 
174  // Activation option
175 
176  // When this option is enabled, only the histograms marked as activated
177  // are returned, filled or saved on file.
178  // No warning is issued when Get or Fill is called on inactive histogram.
179  void SetActivation(G4bool activation);
180  G4bool GetActivation() const;
181 
182  // Return false if activation is enabled and there is no object activated,
183  // return true otherwise
184  G4bool IsActive() const;
185 
186  // ASCII option
187 
188  // Return false if there is no object selected for ASCII output,
189  // return true otherwise
190  G4bool IsAscii() const;
191 
192  // Access methods
193  G4int GetNofH1s() const;
194  G4int GetNofH2s() const;
195  G4int GetNofNtuples() const;
196 
197  // Access methods via names
198  G4int GetH1Id(const G4String& name, G4bool warn = true) const;
199  G4int GetH2Id(const G4String& name, G4bool warn = true) const;
200 
201 
202  // Methods to manipulate additional information
203  void SetH1Activation(G4bool activation);
204  void SetH1Activation(G4int id, G4bool activation);
205  void SetH1Ascii(G4int id, G4bool ascii);
206  void SetH2Activation(G4bool activation);
207  void SetH2Activation(G4int id, G4bool activation);
208  void SetH2Ascii(G4int id, G4bool ascii);
209 
210  // Access to H1 parameters
211  G4int GetH1Nbins(G4int id) const;
212  G4double GetH1Xmin(G4int id) const;
213  G4double GetH1Xmax(G4int id) const;
214  G4double GetH1Width(G4int id) const;
215 
216  // Access to H2 parameters
217  G4int GetH2Nxbins(G4int id) const;
218  G4double GetH2Xmin(G4int id) const;
219  G4double GetH2Xmax(G4int id) const;
220  G4double GetH2XWidth(G4int id) const;
221  G4int GetH2Nybins(G4int id) const;
222  G4double GetH2Ymin(G4int id) const;
223  G4double GetH2Ymax(G4int id) const;
224  G4double GetH2YWidth(G4int id) const;
225 
226  // Access to H1 additional information
227  G4String GetH1Name(G4int id) const;
228  G4double GetH1Unit(G4int id) const;
229  G4bool GetH1Activation(G4int id) const;
230  G4bool GetH1Ascii(G4int id) const;
231 
232  // Access to H2 additional information
233  G4String GetH2Name(G4int id) const;
234  G4double GetH2XUnit(G4int id) const;
235  G4double GetH2YUnit(G4int id) const;
236  G4bool GetH2Activation(G4int id) const;
237  G4bool GetH2Ascii(G4int id) const;
238 
239  // Setters for attributes for plotting
240  G4bool SetH1Title(G4int id, const G4String& title);
241  G4bool SetH1XAxisTitle(G4int id, const G4String& title);
242  G4bool SetH1YAxisTitle(G4int id, const G4String& title);
243  G4bool SetH2Title(G4int id, const G4String& title);
244  G4bool SetH2XAxisTitle(G4int id, const G4String& title);
245  G4bool SetH2YAxisTitle(G4int id, const G4String& title);
246  G4bool SetH2ZAxisTitle(G4int id, const G4String& title);
247 
248  // Access attributes for plotting
249  G4String GetH1Title(G4int id) const;
250  G4String GetH1XAxisTitle(G4int id) const;
251  G4String GetH1YAxisTitle(G4int id) const;
252  G4String GetH2Title(G4int id) const;
253  G4String GetH2XAxisTitle(G4int id) const;
254  G4String GetH2YAxisTitle(G4int id) const;
255  G4String GetH2ZAxisTitle(G4int id) const;
256 
257  // Verbosity
258  void SetVerboseLevel(G4int verboseLevel);
259  G4int GetVerboseLevel() const;
260 
261  // The manager type (starts with an uppercase letter)
262  G4String GetType() const;
263  // The manager file type (starts with a lowercase letter)
264  G4String GetFileType() const;
265 
266  protected:
267  // virtual methods
268  virtual G4bool OpenFileImpl(const G4String& fileName) = 0;
269  virtual G4bool WriteImpl() = 0;
270  virtual G4bool CloseFileImpl() = 0;
271 
272  // methods
273  void SetH1Manager(G4VH1Manager* h1Manager);
274  void SetH2Manager(G4VH2Manager* h2Manager);
275  void SetNtupleManager(G4VNtupleManager* ntupleManager);
276  void SetFileManager(G4VFileManager* fileManager);
277 
278  // Methods to manipulate additional information
279  G4bool WriteAscii(const G4String& fileName);
280 
281  // data members
283 
284  private:
285  // data members
293 };
294 
295 // inline functions
296 
297 #include "G4VAnalysisManager.icc"
298 
299 #endif
300 
G4bool SetHistoDirectoryName(const G4String &dirName)
G4double GetH1Unit(G4int id) const
void SetH2Ascii(G4int id, G4bool ascii)
G4String GetNtupleDirectoryName() const
G4AnalysisMessenger * fMessenger
G4int CreateNtupleIColumn(const G4String &name)
G4bool SetFirstHistoId(G4int firstId)
G4VH2Manager * fVH2Manager
G4int CreateH1(const G4String &name, const G4String &title, G4int nbins, G4double xmin, G4double xmax, const G4String &unitName="none", const G4String &fcnName="none", const G4String &binSchemeName="linear")
G4double GetH2YUnit(G4int id) const
G4bool ScaleH1(G4int id, G4double factor)
G4bool ScaleH2(G4int id, G4double factor)
G4bool SetH2YAxisTitle(G4int id, const G4String &title)
void SetH1Manager(G4VH1Manager *h1Manager)
G4String name
Definition: TRTMaterials.hh:40
float G4float
Definition: G4Types.hh:77
virtual G4bool WriteImpl()=0
G4int GetH2Id(const G4String &name, G4bool warn=true) const
void SetVerboseLevel(G4int verboseLevel)
G4String GetH2ZAxisTitle(G4int id) const
G4double GetH2XWidth(G4int id) const
G4bool IsAscii() const
void SetH2Activation(G4bool activation)
G4int CreateNtuple(const G4String &name, const G4String &title)
G4VFileManager * fVFileManager
G4double GetH2Ymin(G4int id) const
G4VNtupleManager * fVNtupleManager
G4bool SetFileName(const G4String &fileName)
G4bool SetNtupleDirectoryName(const G4String &dirName)
int G4int
Definition: G4Types.hh:78
G4bool SetH2ZAxisTitle(G4int id, const G4String &title)
G4int GetNofH1s() const
G4bool FillNtupleFColumn(G4int id, G4float value)
G4bool SetFirstH1Id(G4int firstId)
G4double GetH2XUnit(G4int id) const
G4String GetH2Title(G4int id) const
G4VAnalysisManager(const G4String &type, G4bool isMaster)
G4double GetH2YWidth(G4int id) const
G4bool FillNtupleIColumn(G4int id, G4int value)
void SetH1Ascii(G4int id, G4bool ascii)
G4bool GetH2Ascii(G4int id) const
G4int GetNofNtuples() const
G4double GetH2Xmax(G4int id) const
G4double GetH1Xmax(G4int id) const
G4int GetVerboseLevel() const
G4VH1Manager * fVH1Manager
G4bool FillNtupleDColumn(G4int id, G4double value)
bool G4bool
Definition: G4Types.hh:79
virtual G4bool OpenFileImpl(const G4String &fileName)=0
G4String GetFileType() const
G4bool SetH1(G4int id, G4int nbins, G4double xmin, G4double xmax, const G4String &unitName="none", const G4String &fcnName="none", const G4String &binSchemeName="linear")
G4String GetFileName() const
G4bool IsActive() const
G4bool SetH1YAxisTitle(G4int id, const G4String &title)
void SetFileManager(G4VFileManager *fileManager)
G4String GetHistoDirectoryName() const
G4bool GetActivation() const
G4String GetH1XAxisTitle(G4int id) const
G4bool SetH2(G4int id, G4int nxbins, G4double xmin, G4double xmax, G4int nybins, G4double ymin, G4double ymax, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &xbinSchemeName="linear", const G4String &ybinSchemeName="linear")
void SetH2Manager(G4VH2Manager *h2Manager)
G4String GetType() const
G4HnManager * fH2HnManager
G4bool SetFirstNtupleId(G4int firstId)
G4bool SetH2Title(G4int id, const G4String &title)
G4int GetH1Nbins(G4int id) const
G4bool FillH2(G4int id, G4double xvalue, G4double yvalue, G4double weight=1.0)
void SetH1Activation(G4bool activation)
G4bool FillH1(G4int id, G4double value, G4double weight=1.0)
void SetActivation(G4bool activation)
G4int CreateNtupleFColumn(const G4String &name)
G4String GetH2YAxisTitle(G4int id) const
G4double GetH1Width(G4int id) const
G4double GetH1Xmin(G4int id) const
G4bool GetH1Activation(G4int id) const
G4HnManager * fH1HnManager
G4String GetH1Name(G4int id) const
G4bool SetFirstNtupleColumnId(G4int firstId)
G4bool SetFirstH2Id(G4int firstId)
G4String GetH2XAxisTitle(G4int id) const
G4double GetH2Xmin(G4int id) const
G4int CreateNtupleDColumn(const G4String &name)
G4String GetH2Name(G4int id) const
G4int GetH2Nxbins(G4int id) const
double G4double
Definition: G4Types.hh:76
G4bool GetH1Ascii(G4int id) const
G4String GetH1Title(G4int id) const
G4bool SetH1Title(G4int id, const G4String &title)
G4bool GetH2Activation(G4int id) const
G4AnalysisManagerState fState
G4double GetH2Ymax(G4int id) const
virtual G4bool CloseFileImpl()=0
G4bool SetH1XAxisTitle(G4int id, const G4String &title)
G4int GetH1Id(const G4String &name, G4bool warn=true) const
void SetNtupleManager(G4VNtupleManager *ntupleManager)
G4int GetNofH2s() const
G4String GetH1YAxisTitle(G4int id) const
G4bool SetH2XAxisTitle(G4int id, const G4String &title)
G4int GetH2Nybins(G4int id) const
G4bool WriteAscii(const G4String &fileName)
G4int CreateH2(const G4String &name, const G4String &title, G4int nxbins, G4double xmin, G4double xmax, G4int nybins, G4double ymin, G4double ymax, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &xbinScheme="linear", const G4String &ybinScheme="linear")