Geant4  10.01.p01
ExG4HbookP1Manager.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 //
30 
31 // Author: Ivana Hrivnacova, 03/11/2014 (ivana@ipno.in2p3.fr)
32 
33 #ifdef G4_USE_HBOOK
34 
35 #ifndef ExG4HbookP1Manager_h
36 #define ExG4HbookP1Manager_h 1
37 
38 #include "G4VP1Manager.hh"
39 #include "G4HnInformation.hh"
41 #include "globals.hh"
42 
43 #include <tools/hbook/p1>
44 
45 #include <vector>
46 #include <map>
47 
48 class ExG4HbookFileManager;
49 
50 struct p1_booking {
51  p1_booking(G4int nbins, G4double xmin, G4double xmax,
52  G4double ymin, G4double ymax)
53  : fTitle(""),
54  fNbins(nbins),
55  fXmin(xmin),
56  fXmax(xmax),
57  fYmin(ymin),
58  fYmax(ymax),
59  fEdges() {}
60  p1_booking(const std::vector<G4double>& edges,
61  G4double ymin, G4double ymax)
62  : fTitle(""),
63  fNbins(0),
64  fXmin(0),
65  fXmax(0),
66  fYmin(ymin),
67  fYmax(ymax),
68  fEdges() {
69  for (G4int i=0; i<=G4int(edges.size()); ++i) fEdges.push_back(edges[i]);
70  }
71  G4String fTitle;
72  G4int fNbins;
73  G4double fXmin;
74  G4double fXmax;
75  G4double fYmin;
76  G4double fYmax;
77  std::vector<G4double> fEdges;
78 };
79 
85 
86 class ExG4HbookP1Manager : public G4VP1Manager
87 {
88  friend class ExG4HbookAnalysisManager;
89 
90  protected:
91  ExG4HbookP1Manager(const G4AnalysisManagerState& state);
92  virtual ~ExG4HbookP1Manager();
93 
94  // Functions specific to the output type
95  //
96 
97  // HBOOK does not allow IDs the same IDs for P1 and H2,
98  // and also IDs starting from 0; thats why there is defined an offset
99  // with respect to the G4AnalysisManager generic Ids.
100  // The default values of these offsets can be changed by the user.
101  //
102  // Set the offset of HBOOK ID for P1
103  // ( default value = firstHistoID if firstHistoID > 0; otherwise = 1)
104  G4bool SetP1HbookIdOffset(G4int offset);
105  G4int GetP1HbookIdOffset() const;
106 
107  // Set methods
108  void SetFileManager(ExG4HbookFileManager* fileManager);
109 
110  // Access methods
111  //
112  tools::hbook::p1* GetP1(G4int id, G4bool warn = true,
113  G4bool onlyIfActive = true) const;
114 
115  // Iterators
116  std::vector<tools::hbook::p1*>::iterator BeginP1();
117  std::vector<tools::hbook::p1*>::iterator EndP1();
118  std::vector<tools::hbook::p1*>::const_iterator BeginConstP1() const;
119  std::vector<tools::hbook::p1*>::const_iterator EndConstP1() const;
120 
121  // Virtual functions from base class
122  //
123 
124  // Methods to create profiles
125  virtual G4int CreateP1(const G4String& name, const G4String& title,
126  G4int nbins, G4double xmin, G4double xmax,
127  G4double ymin = 0, G4double ymax = 0,
128  const G4String& xunitName = "none",
129  const G4String& yunitName = "none",
130  const G4String& xfcnName = "none",
131  const G4String& yfcnName = "none",
132  const G4String& xbinScheme = "linear");
133  virtual G4int CreateP1(const G4String& name, const G4String& title,
134  const std::vector<G4double>& edges,
135  G4double ymin = 0, G4double ymax = 0,
136  const G4String& xunitName = "none",
137  const G4String& yunitName = "none",
138  const G4String& xfcnName = "none",
139  const G4String& yfcnName = "none");
140 
141  virtual G4bool SetP1(G4int id,
142  G4int nbins, G4double xmin, G4double xmax,
143  G4double ymin = 0, G4double ymax = 0,
144  const G4String& xunitName = "none",
145  const G4String& yunitName = "none",
146  const G4String& xfcnName = "none",
147  const G4String& yfcnName = "none",
148  const G4String& xbinScheme = "linear");
149  virtual G4bool SetP1(G4int id,
150  const std::vector<G4double>& edges,
151  G4double ymin = 0, G4double ymax = 0,
152  const G4String& xunitName = "none",
153  const G4String& yunitName = "none",
154  const G4String& xfcnName = "none",
155  const G4String& yfcnName = "none");
156 
157  virtual G4bool ScaleP1(G4int id, G4double factor);
158 
159 
160  // Methods to fill profiles
161  virtual G4bool FillP1(G4int id, G4double value, G4double yvalue,
162  G4double weight = 1.0);
163 
164  // Access methods
165  //
166  virtual G4int GetP1Id(const G4String& name, G4bool warn = true) const;
167 
168  // Access to P1 parameters
169  virtual G4int GetP1Nbins(G4int id) const;
170  virtual G4double GetP1Xmin(G4int id) const;
171  virtual G4double GetP1Xmax(G4int id) const;
172  virtual G4double GetP1XWidth(G4int id) const;
173  virtual G4double GetP1Ymin(G4int id) const;
174  virtual G4double GetP1Ymax(G4int id) const;
175 
176  // Setters for attributes for plotting
177  virtual G4bool SetP1Title(G4int id, const G4String& title);
178  virtual G4bool SetP1XAxisTitle(G4int id, const G4String& title);
179  virtual G4bool SetP1YAxisTitle(G4int id, const G4String& title);
180 
181  // Access attributes for plotting
182  virtual G4String GetP1Title(G4int id) const;
183  virtual G4String GetP1XAxisTitle(G4int id) const;
184  virtual G4String GetP1YAxisTitle(G4int id) const;
185 
186  // Write data on ASCII file
187  // virtual G4bool WriteOnAscii(std::ofstream& output);
188 
189  private:
190  // methods
191  //
192  void SetP1HbookIdOffset();
193  void AddP1Information(const G4String& name,
194  const G4String& xunitName,
195  const G4String& yunitName,
196  const G4String& xfcnName,
197  const G4String& yfcnName,
198  G4BinScheme xbinScheme) const;
199 
200  G4int CreateP1FromBooking(p1_booking* p1Booking,
201  G4bool chDir = true);
202  G4int RegisterP1Booking(const G4String& name,
203  p1_booking* p1Booking);
204 
205  void BeginCreateP1(const G4String& name);
206  G4int FinishCreateP1(const G4String& name, p1_booking* p1Booking,
207  const G4String& xunitName,
208  const G4String& yunitName,
209  const G4String& xfcnName,
210  const G4String& yfcnName,
211  G4BinScheme xbinScheme) ;
212 
213  G4bool BeginSetP1(G4int id,
214  p1_booking* p1Booking,
215  G4HnInformation* info);
216  G4bool FinishSetP1(G4int id,
217  G4HnInformation* info,
218  const G4String& xunitName,
219  const G4String& yunitName,
220  const G4String& xfcnName,
221  const G4String& yfcnName,
222  G4BinScheme xbinScheme) ;
223 
224  void CreateP1sFromBooking();
225  void Reset();
226  virtual p1_booking* GetP1Booking(G4int id, G4bool warn = true) const;
227 
228  virtual tools::hbook::p1* GetP1InFunction(G4int id, G4String function,
229  G4bool warn = true,
230  G4bool onlyIfActive = true) const;
231 
232  // data members
233  //
234  ExG4HbookBaseHnManager fBaseToolsManager;
235  ExG4HbookFileManager* fFileManager;
236  G4int fP1HbookIdOffset;
237  std::vector<tools::hbook::p1*> fP1Vector;
238  std::vector<p1_booking*> fP1BookingVector;
239  std::map<G4String, G4int> fP1NameIdMap;
240 };
241 
242 // inline functions
243 
244 inline void ExG4HbookP1Manager::SetFileManager(ExG4HbookFileManager* fileManager)
245 { fFileManager = fileManager; }
246 
247 inline G4int ExG4HbookP1Manager::GetP1HbookIdOffset() const
248 { return fP1HbookIdOffset; }
249 
250 inline std::vector<tools::hbook::p1*>::iterator ExG4HbookP1Manager::BeginP1()
251 { return fP1Vector.begin(); }
252 
253 inline std::vector<tools::hbook::p1*>::iterator ExG4HbookP1Manager::EndP1()
254 { return fP1Vector.end(); }
255 
256 inline std::vector<tools::hbook::p1*>::const_iterator
257 ExG4HbookP1Manager::BeginConstP1() const
258 { return fP1Vector.begin(); }
259 
260 inline std::vector<tools::hbook::p1*>::const_iterator
261 ExG4HbookP1Manager::EndConstP1() const
262 { return fP1Vector.end(); }
263 
264 
265 #endif
266 
267 #endif
virtual G4int GetP1Nbins(G4int id) const =0
virtual G4bool SetP1XAxisTitle(G4int id, const G4String &title)=0
G4String name
Definition: TRTMaterials.hh:40
int G4int
Definition: G4Types.hh:78
virtual G4String GetP1Title(G4int id) const =0
virtual G4bool SetP1Title(G4int id, const G4String &title)=0
virtual G4String GetP1XAxisTitle(G4int id) const =0
virtual G4bool SetP1YAxisTitle(G4int id, const G4String &title)=0
bool G4bool
Definition: G4Types.hh:79
virtual G4double GetP1Xmin(G4int id) const =0
virtual G4bool ScaleP1(G4int id, G4double factor)=0
Manager class for tools::hbook::base_histo functions.
Definition of the ExG4HbookBaseHnManager class.
virtual G4double GetP1Ymax(G4int id) const =0
static const G4double factor
virtual G4double GetP1Ymin(G4int id) const =0
virtual G4int CreateP1(const G4String &name, const G4String &title, G4int nbins, G4double xmin, G4double xmax, G4double ymin=0, G4double ymax=0, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &xbinScheme="linear")=0
G4BinScheme
Definition: G4BinScheme.hh:40
virtual G4bool FillP1(G4int id, G4double xvalue, G4double yvalue, G4double weight=1.0)=0
double G4double
Definition: G4Types.hh:76
virtual G4bool SetP1(G4int id, G4int nbins, G4double xmin, G4double xmax, G4double ymin=0, G4double ymax=0, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &xbinScheme="linear")=0
virtual G4String GetP1YAxisTitle(G4int id) const =0
virtual G4double GetP1XWidth(G4int id) const =0
virtual G4double GetP1Xmax(G4int id) const =0
virtual G4int GetP1Id(const G4String &name, G4bool warn=true) const =0