Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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$
27 
28 // Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
29 
30 #ifndef G4VAnalysisManager_h
31 #define G4VAnalysisManager_h 1
32 
33 #include "G4AnalysisVerbose.hh"
34 #include "G4HnInformation.hh"
35 #include "globals.hh"
36 
37 #include <vector>
38 #include <fstream>
39 
41 
43 {
44  public:
45  // Supported object types
46  enum ObjectType { kH1, kH2, kNtuple };
47 
48  public:
49  G4VAnalysisManager(const G4String& type = "");
50  virtual ~G4VAnalysisManager();
51 
52  // Methods to manipulate files
53  virtual G4bool OpenFile();
54  virtual G4bool OpenFile(const G4String& fileName) = 0;
55  virtual G4bool Write() = 0;
56  virtual G4bool CloseFile() = 0;
57 
58  // Methods for handling files and directories names
59  virtual G4bool SetFileName(const G4String& fileName);
60  virtual G4bool SetHistoDirectoryName(const G4String& dirName);
61  virtual G4bool SetNtupleDirectoryName(const G4String& dirName);
62  virtual G4String GetFileName() const;
63  virtual G4String GetFullFileName() const;
64  virtual G4String GetHistoDirectoryName() const;
65  virtual G4String GetNtupleDirectoryName() const;
66 
67  // Methods for handling histogrammes
68  virtual G4int CreateH1(const G4String& name, const G4String& title,
69  G4int nbins, G4double xmin, G4double xmax,
70  const G4String& unitName = "none",
71  const G4String& fcnName = "none") = 0;
72  virtual G4int CreateH2(const G4String& name, const G4String& title,
73  G4int nxbins, G4double xmin, G4double xmax,
74  G4int nybins, G4double ymin, G4double ymax,
75  const G4String& xunitName = "none",
76  const G4String& yunitName = "none",
77  const G4String& xfcnName = "none",
78  const G4String& yfcnName = "none") = 0;
79 
80  virtual G4bool SetH1(G4int id,
81  G4int nbins, G4double xmin, G4double xmax,
82  const G4String& unitName = "none",
83  const G4String& fcnName = "none") = 0;
84  virtual G4bool SetH2(G4int id,
85  G4int nxbins, G4double xmin, G4double xmax,
86  G4int nybins, G4double ymin, G4double ymax,
87  const G4String& xunitName = "none",
88  const G4String& yunitName = "none",
89  const G4String& xfcnName = "none",
90  const G4String& yfcnName = "none") = 0;
91 
92  virtual G4bool ScaleH1(G4int id, G4double factor) = 0;
93  virtual G4bool ScaleH2(G4int id, G4double factor) = 0;
94 
95  // Methods for handling ntuples
96  virtual void CreateNtuple(const G4String& name, const G4String& title) = 0;
97  virtual G4int CreateNtupleIColumn(const G4String& name) = 0;
98  virtual G4int CreateNtupleFColumn(const G4String& name) = 0;
99  virtual G4int CreateNtupleDColumn(const G4String& name) = 0;
100  virtual void FinishNtuple() = 0;
101 
102  // The ids of histograms and ntuples are generated automatically
103  // starting from 0; with following functions it is possible to
104  // change the first Id to start from other value
105  virtual G4bool SetFirstHistoId(G4int firstId);
106  virtual G4bool SetFirstNtupleColumnId(G4int firstId);
107 
108  // Methods to fill histogrammes, ntuples
109  virtual G4bool FillH1(G4int id, G4double value, G4double weight = 1.0) = 0;
110  virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue,
111  G4double weight = 1.0) = 0;
112  virtual G4bool FillNtupleIColumn(G4int id, G4int value) = 0;
113  virtual G4bool FillNtupleFColumn(G4int id, G4float value) = 0;
114  virtual G4bool FillNtupleDColumn(G4int id, G4double value) = 0;
115  virtual G4bool AddNtupleRow() = 0;
116 
117  // Activation option
118 
119  // When this option is enabled, only the histograms marked as activated
120  // are returned, filled or saved on file.
121  // No warning is issued when Get or Fill is called on inactive histogram.
122  void SetActivation(G4bool activation);
123  G4bool GetActivation() const;
124 
125  // Return false if activation is enabled and there is no object activated,
126  // return true otherwise
127  G4bool IsActive() const;
128 
129  // ASCII option
130 
131  // Return false if there is no object selected for ASCII output,
132  // return true otherwise
133  G4bool IsAscii() const;
134 
135  // Access methods
136  virtual G4int GetNofH1s() const;
137  virtual G4int GetNofH2s() const;
138 
139  // Methods to manipulate additional information
140 
141  // Setters for additional information by fields
142  // (other fields are set by SetH1, SetH2 methods)
143  void SetActivation(ObjectType type, G4bool activation);
144  void SetActivation(ObjectType type, G4int id, G4bool activation);
145  void SetAscii(ObjectType type, G4int id, G4bool ascii);
146 
147  // Access to H1 parameters
148  virtual G4int GetH1Nbins(G4int id) const = 0;
149  virtual G4double GetH1Xmin(G4int id) const = 0;
150  virtual G4double GetH1Xmax(G4int id) const = 0;
151  virtual G4double GetH1Width(G4int id) const = 0;
152 
153  // Access to H2 parameters
154  virtual G4int GetH2Nxbins(G4int id) const = 0;
155  virtual G4double GetH2Xmin(G4int id) const = 0;
156  virtual G4double GetH2Xmax(G4int id) const = 0;
157  virtual G4double GetH2XWidth(G4int id) const = 0;
158  virtual G4int GetH2Nybins(G4int id) const = 0;
159  virtual G4double GetH2Ymin(G4int id) const = 0;
160  virtual G4double GetH2Ymax(G4int id) const = 0;
161  virtual G4double GetH2YWidth(G4int id) const = 0;
162 
163  // Access to H1 additional information
164  G4String GetH1Name(G4int id) const;
165  G4double GetH1Unit(G4int id) const;
166  G4bool GetH1Activation(G4int id) const;
167  G4bool GetH1Ascii(G4int id) const;
168 
169  // Access to H2 additional information
170  G4String GetH2Name(G4int id) const;
171  G4double GetH2XUnit(G4int id) const;
172  G4double GetH2YUnit(G4int id) const;
173  G4bool GetH2Activation(G4int id) const;
174  G4bool GetH2Ascii(G4int id) const;
175 
176  // Setters for attributes for plotting
177  virtual G4bool SetH1Title(G4int id, const G4String& title) = 0;
178  virtual G4bool SetH1XAxisTitle(G4int id, const G4String& title) = 0;
179  virtual G4bool SetH1YAxisTitle(G4int id, const G4String& title) = 0;
180  virtual G4bool SetH2Title(G4int id, const G4String& title) = 0;
181  virtual G4bool SetH2XAxisTitle(G4int id, const G4String& title) = 0;
182  virtual G4bool SetH2YAxisTitle(G4int id, const G4String& title) = 0;
183  virtual G4bool SetH2ZAxisTitle(G4int id, const G4String& title) = 0;
184 
185  // Access attributes for plotting
186  virtual G4String GetH1Title(G4int id) const = 0;
187  virtual G4String GetH1XAxisTitle(G4int id) const = 0;
188  virtual G4String GetH1YAxisTitle(G4int id) const = 0;
189  virtual G4String GetH2Title(G4int id) const = 0;
190  virtual G4String GetH2XAxisTitle(G4int id) const = 0;
191  virtual G4String GetH2YAxisTitle(G4int id) const = 0;
192  virtual G4String GetH2ZAxisTitle(G4int id) const = 0;
193 
194  // Verbosity
195  virtual G4int GetVerboseLevel() const;
196  virtual void SetVerboseLevel(G4int verboseLevel);
197 
198  // The manager type (starts with an uppercase letter)
199  G4String GetType() const;
200  // The manager file type (starts with a lowercase letter)
201  G4String GetFileType() const;
202 
203  protected:
204  // methods to manipulate additional information
205  void AddH1Information(const G4String& name,
206  const G4String& unitName,
207  const G4String& fcnName,
208  G4double unit,
209  G4Fcn fx);
210  void AddH2Information(const G4String& name,
211  const G4String& xunitName,
212  const G4String& yunitName,
213  const G4String& xfcnName,
214  const G4String& yfcnName,
215  G4double xunit, G4double yunit,
216  G4Fcn fx, G4Fcn fy);
217 
218  // Methods to access additional information
222 
223  // Access to additional information by fields
224  G4String GetName(ObjectType type, G4int id) const;
225  G4double GetXUnit(ObjectType type, G4int id) const;
226  G4double GetYUnit(ObjectType type, G4int id) const;
227  G4bool GetActivation(ObjectType type, G4int id) const;
228  G4bool GetAscii(ObjectType type, G4int id) const;
229 
230  G4bool WriteAscii();
231  virtual G4bool WriteOnAscii(std::ofstream& output) = 0;
232 
233  G4double GetUnitValue(const G4String& unit) const;
234  G4Fcn GetFunction(const G4String& fcnName) const;
235 
236  // data members
249 
250  // Additional histograms properties not included in tools
259 
260  private:
261  G4AnalysisMessenger* fMessenger;
262  G4int fNofActiveObjects;
263  G4int fNofAsciiObjects;
264 
265  // Additional histograms/ntuple properties not included in tools
266  std::vector<G4HnInformation*> fH1Informations;
267  std::vector<G4HnInformation*> fH2Informations;
268 };
269 
270 // inline functions
271 
273  return fFileName;
274 }
275 
277  return fHistoDirectoryName;
278 }
279 
281  return fNtupleDirectoryName;
282 }
283 
285  return fVerboseLevel;
286 }
287 
289  return fVerboseL1.GetType();
290 }
291 
292 inline void G4VAnalysisManager::SetActivation(G4bool activation) {
293  fActivation = activation;
294 }
295 
297  return fActivation;
298 }
299 
301  return fH1Informations.size();
302 }
303 
305  return fH2Informations.size();
306 }
307 
309  return GetName(kH1, id);
310 }
311 
313  return GetXUnit(kH1, id);
314 }
315 
317  return GetActivation(kH1, id);
318 }
319 
321  return GetAscii(kH1, id);
322 }
323 
325  return GetName(kH2, id);
326 }
327 
329  return GetXUnit(kH2, id);
330 }
331 
333  return GetYUnit(kH2, id);
334 }
335 
337  return GetActivation(kH2, id);
338 }
339 
341  return GetAscii(kH2, id);
342 }
343 
344 #endif
345