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