Geant4  10.00.p03
ExG4HbookH2Manager.cc
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, 15/06/2011 (ivana@ipno.in2p3.fr)
32 
33 #ifdef G4_USE_HBOOK
34 
35 #include "ExG4HbookH2Manager.hh"
36 #include "ExG4HbookFileManager.hh"
37 #include "G4HnManager.hh"
39 #include "G4AnalysisUtilities.hh"
40 
41 #include <iostream>
42 
43 using namespace G4Analysis;
44 
45 const G4int ExG4HbookH2Manager::fgkDefaultH2HbookIdOffset = 100;
46 
47 //_____________________________________________________________________________
48 ExG4HbookH2Manager::ExG4HbookH2Manager(const G4AnalysisManagerState& state)
49  : G4VH2Manager(state),
50  fFileManager(0),
51  fH2HbookIdOffset(-1),
52  fH2Vector(),
53  fH2BookingVector(),
54  fH2NameIdMap()
55 {
56 }
57 
58 //_____________________________________________________________________________
59 ExG4HbookH2Manager::~ExG4HbookH2Manager()
60 {
61  // Delete h2
62  Reset();
63 
64  // Delete h2 booking
65  std::vector<h2_booking*>::iterator it2;
66  for ( it2 = fH2BookingVector.begin(); it2 != fH2BookingVector.end(); it2++ ) {
67  delete *it2;
68  }
69 }
70 
71 //
72 // private methods
73 //
74 
75 //_____________________________________________________________________________
76 void ExG4HbookH2Manager::SetH2HbookIdOffset()
77 {
78 // Set fH2HbookIdOffset if needed
79 
80  if ( fH2HbookIdOffset == -1 ) {
81  if ( fFirstId > 0 )
82  fH2HbookIdOffset = 0;
83  else
84  fH2HbookIdOffset = 1;
85 
86  if ( fH2HbookIdOffset > 0 ) {
87  G4ExceptionDescription description;
88  description << "H2 will be defined in HBOOK with ID = G4_firstHistoId + 1";
89  G4Exception("ExG4HbookH2Manager::SetH1HbookIdOffset",
90  "Analysis_W011", JustWarning, description);
91  }
92  }
93 }
94 
95 //_____________________________________________________________________________
96 void ExG4HbookH2Manager::CreateH2sFromBooking()
97 {
98 // Create h2 from h2_booking.
99 
100  // Do nothing if any h2 histogram already exists
101  // or no h2 histograms are booked
102  if ( fH2Vector.size() || ( fH2BookingVector.size() == 0 ) ) return;
103 
104  // Go to histograms directory
105  if ( fFileManager->GetHistoDirectoryName() != "" ) {
106  G4String histoPath = "//PAWC/LUN1/";
107  histoPath.append(fFileManager->GetHistoDirectoryName().data());
108  tools::hbook::CHCDIR(histoPath.data()," ");
109  }
110 
111  // Create histograms
112  G4int index = 0;
113  std::vector<h2_booking*>::const_iterator it;
114  for ( it = fH2BookingVector.begin(); it != fH2BookingVector.end(); ++it) {
115  // Get information
116  G4int id = index + fFirstId;
117  G4HnInformation* info = fHnManager->GetHnInformation(id, "CreateH2FromBooking");
118  // Hbook index
119  G4int hbookIndex = fH2HbookIdOffset + index + fFirstId;
120  ++index;
121 
122 #ifdef G4VERBOSE
123  if ( fState.GetVerboseL3() )
124  fState.GetVerboseL3()->Message("create from booking", "h2", info->fName);
125 #endif
126 
127  // Create h2
128  tools::hbook::h2* h2
129  = new tools::hbook::h2(hbookIndex, (*it)->fTitle,
130  (*it)->fNxbins, (*it)->fXmin, (*it)->fXmax,
131  (*it)->fNybins, (*it)->fYmin, (*it)->fYmax);
132  fH2Vector.push_back(h2);
133 
134 #ifdef G4VERBOSE
135  if ( fState.GetVerboseL3() ) {
136  G4ExceptionDescription description;
137  description << " name : " << info->fName << " hbook index : " << hbookIndex;
138  fState.GetVerboseL3()->Message("create from booking", "h2", description);
139  }
140 #endif
141  }
142 
143  if ( fFileManager->GetHistoDirectoryName() != "" ) {
144  // Return to //PAWC/LUN1 :
145  tools::hbook::CHCDIR("//PAWC/LUN1"," ");
146  }
147 }
148 
149 //_____________________________________________________________________________
150 void ExG4HbookH2Manager::Reset()
151 {
152 // Reset histograms and ntuple
153 
154  // Delete histograms
155  std::vector<tools::hbook::h2*>::iterator it2;
156  for (it2 = fH2Vector.begin(); it2 != fH2Vector.end(); it2++ ) {
157  delete *it2;
158  }
159 
160  // Clear vectors
161  fH2Vector.clear();
162 }
163 
164 //_____________________________________________________________________________
165 h2_booking* ExG4HbookH2Manager::GetH2Booking(G4int id, G4bool warn) const
166 {
167  G4int index = id - fFirstId;
168  if ( index < 0 || index >= G4int(fH2BookingVector.size()) ) {
169  if ( warn) {
170  G4ExceptionDescription description;
171  description << " " << "histo " << id << " does not exist.";
172  G4Exception("G4HbookAnalysisManager::GetH2Booking()",
173  "Analysis_W007", JustWarning, description);
174  }
175  return 0;
176  }
177 
178  return fH2BookingVector[index];
179 }
180 
181 //
182 // protected methods
183 //
184 
185 //_____________________________________________________________________________
186 G4bool ExG4HbookH2Manager::WriteOnAscii(std::ofstream& /*output*/)
187 {
188 // Write selected objects on ASCII file
189 // According to the implementation by Michel Maire, originally in
190 // extended examples.
191 // Not yet available for H2
192 
193  return false;
194 }
195 
196 //_____________________________________________________________________________
197 tools::hbook::h2* ExG4HbookH2Manager::GetH2InFunction(G4int id,
198  G4String functionName, G4bool warn,
199  G4bool onlyIfActive) const
200 {
201  G4int index = id - fFirstId;
202  if ( index < 0 || index >= G4int(fH2Vector.size()) ) {
203  if ( warn) {
204  G4String inFunction = "ExG4HbookH2Manager::";
205  inFunction += functionName;
206  G4ExceptionDescription description;
207  description << " " << "histogram " << id << " does not exist.";
208  G4Exception(inFunction, "Analysis_W007", JustWarning, description);
209  }
210  return 0;
211  }
212 
213  // Do not return histogram if inactive
214  if ( fState.GetIsActivation() && onlyIfActive && ( ! fHnManager->GetActivation(id) ) ) {
215  return 0;
216  }
217 
218  return fH2Vector[index];
219 }
220 
221 //
222 // public methods
223 //
224 
225 //_____________________________________________________________________________
226 G4int ExG4HbookH2Manager::CreateH2(const G4String& name, const G4String& title,
227  G4int nxbins, G4double xmin, G4double xmax,
228  G4int nybins, G4double ymin, G4double ymax,
229  const G4String& xunitName, const G4String& yunitName,
230  const G4String& xfcnName, const G4String& yfcnName,
231  const G4String& xbinSchemeName,
232  const G4String& ybinSchemeName)
233 
234 {
235  // HBook does not support user defined binning for H2
236  if ( xbinSchemeName != "linear" || ybinSchemeName != "linear" ) {
237  G4ExceptionDescription description;
238  description
239  << " "
240  << "Logarithimc binning is not supported for H2.";
241  G4Exception("ExG4HbookH2Manager::CreateH2",
242  "Analysis_F015", FatalException, description);
243  }
244 
245 #ifdef G4VERBOSE
246  if ( fState.GetVerboseL4() )
247  fState.GetVerboseL4()->Message("create", "H2", name);
248 #endif
249 
250  // Create h2 booking & information
251  G4int index = fH2BookingVector.size();
252  G4double xunit = GetUnitValue(xunitName);
253  G4double yunit = GetUnitValue(yunitName);
254  G4Fcn xfcn = GetFunction(xfcnName);
255  G4Fcn yfcn = GetFunction(yfcnName);
256  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
257  G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
258  G4String newTitle(title);
259  UpdateTitle(newTitle, xunitName, xfcnName);
260  UpdateTitle(newTitle, yunitName, yfcnName);
261 
262  h2_booking* h2Booking = new h2_booking(nxbins, xfcn(xmin), xfcn(xmax),
263  nybins, yfcn(ymin), yfcn(ymax));
264  // h2_booking object is deleted in destructor
265  h2Booking->fTitle = newTitle;
266  fH2BookingVector.push_back(h2Booking);
267  fHnManager
268  ->AddH2Information(name, xunitName, yunitName, xfcnName, yfcnName,
269  xunit, yunit, xfcn, yfcn, xbinScheme, ybinScheme);
270 
271  // Set fH1HbookIdOffset if needed
272  SetH2HbookIdOffset();
273 
274  // Hbook index
275  G4int hbookIndex = fH2HbookIdOffset + index + fFirstId;
276 
277  // Create h2 if the file is open
278  if ( fFileManager->IsFile() ) {
279  // Go to histograms directory
280  G4String histoPath = "//PAWC/LUN1/";
281  if ( fFileManager->GetHistoDirectoryName() != "" ) {
282  histoPath.append(fFileManager->GetHistoDirectoryName().data());
283  }
284  tools::hbook::CHCDIR(histoPath.data()," ");
285 
286  // Create histogram
287  tools::hbook::h2* h2
288  = new tools::hbook::h2(hbookIndex, title,
289  nxbins, xfcn(xmin), xfcn(xmax),
290  nybins, yfcn(ymin), yfcn(ymax));
291  // h2 objects are deleted when closing a file.
292  fH2Vector.push_back(h2);
293 
294  // Return to //PAWC/LUN1
295  if ( fFileManager->GetHistoDirectoryName() != "" ) {
296  tools::hbook::CHCDIR("//PAWC/LUN1"," ");
297  }
298  }
299 
300  fLockFirstId = true;
301 
302 #ifdef G4VERBOSE
303  if ( fState.GetVerboseL2() ) {
304  G4ExceptionDescription description;
305  description << " name : " << name << " hbook index : " << hbookIndex;
306  fState.GetVerboseL2()->Message("create", "H2", description);
307  }
308 #endif
309 
310  fH2NameIdMap[name] = index + fFirstId;
311  return index + fFirstId;
312 }
313 
314 //_____________________________________________________________________________
315 G4int ExG4HbookH2Manager::CreateH2(const G4String& /*name*/, const G4String& /*title*/,
316  const std::vector<G4double>& /*xedges*/,
317  const std::vector<G4double>& /*yedges*/,
318  const G4String& /*xunitName*/, const G4String& /*yunitName*/,
319  const G4String& /*xfcnName*/, const G4String& /*yfcnName*/)
320 {
321  // HBook does not support user defined binning for H2
322  G4ExceptionDescription description;
323  description
324  << " "
325  << "User defined binning is not supported for H2.";
326  G4Exception("ExG4HbookH2Manager::CreateH2",
327  "Analysis_F015", FatalException, description);
328  return 0;
329 }
330 
331 //_____________________________________________________________________________
332 G4bool ExG4HbookH2Manager::SetH2(G4int id,
333  G4int nxbins, G4double xmin, G4double xmax,
334  G4int nybins, G4double ymin, G4double ymax,
335  const G4String& xunitName, const G4String& yunitName,
336  const G4String& xfcnName, const G4String& yfcnName,
337  const G4String& xbinScheme, const G4String& ybinScheme)
338 {
339  // HBook does not support user defined binning for H2
340  if ( xbinScheme != "linear" || ybinScheme != "linear" ) {
341  G4ExceptionDescription description;
342  description
343  << " "
344  << "Logarithimc binning is not supported for H2.";
345  G4Exception("ExG4HbookH2Manager::CreateH2",
346  "Analysis_F015", FatalException, description);
347  }
348 
349  h2_booking* h2Booking = GetH2Booking(id, false);
350  if ( ! h2Booking ) {
351  G4ExceptionDescription description;
352  description << " " << "histogram " << id << " does not exist.";
353  G4Exception("G4HbookAnalysisManager::SetH2()",
354  "Analysis_W007", JustWarning, description);
355  return false;
356  }
357 
358  G4HnInformation* info = fHnManager->GetHnInformation(id, "SetH2");
359 #ifdef G4VERBOSE
360  if ( fState.GetVerboseL4() )
361  fState.GetVerboseL4()->Message("configure", "H2", info->fName);
362 #endif
363 
364  // Keep new parameters in booking & information
365  G4double xunit = GetUnitValue(xunitName);
366  G4double yunit = GetUnitValue(yunitName);
367  G4Fcn xfcn = GetFunction(xfcnName);
368  G4Fcn yfcn = GetFunction(yfcnName);
369 
370  h2Booking->fNxbins = nxbins;
371  h2Booking->fXmin = xfcn(xmin);
372  h2Booking->fXmax = xfcn(xmax);
373  h2Booking->fNybins = nybins;
374  h2Booking->fYmin = yfcn(ymin);
375  h2Booking->fYmax = yfcn(ymax);
376 
377  info->fXUnitName = xunitName;
378  info->fYUnitName = yunitName;
379  info->fXFcnName = xfcnName;
380  info->fYFcnName = yfcnName;
381  info->fXUnit = xunit;
382  info->fYUnit = yunit;
383  info->fXFcn = xfcn;
384  info->fYFcn = yfcn;
385  fHnManager->SetActivation(id, true);
386 
387  G4String newTitle(h2Booking->fTitle);
388  UpdateTitle(newTitle, xunitName, xfcnName);
389  UpdateTitle(newTitle, yunitName, yfcnName);
390  h2Booking->fTitle = newTitle;
391 
392  // Re-configure histogram if it was already defined
393  if ( fH2Vector.size() ) {
394  tools::hbook::h2* h2 = GetH2(id);
395  h2->configure(nxbins, xfcn(xmin), xfcn(xmax),
396  nybins, yfcn(ymin), yfcn(ymax));
397  }
398 
399  return true;
400 }
401 
402 //_____________________________________________________________________________
403 G4bool ExG4HbookH2Manager::SetH2(G4int /*id*/,
404  const std::vector<G4double>& /*xedges*/,
405  const std::vector<G4double>& /*yedges*/,
406  const G4String& /*xunitName*/, const G4String& /*yunitName*/,
407  const G4String& /*xfcnName*/, const G4String& /*yfcnName*/)
408 {
409  // HBook does not support user defined binning for H2
410  G4ExceptionDescription description;
411  description
412  << " "
413  << "User defined binning is not supported for H2.";
414  G4Exception("ExG4HbookH2Manager::CreateH2",
415  "Analysis_F015", FatalException, description);
416 
417  return false;
418 }
419 
420 //_____________________________________________________________________________
421 G4bool ExG4HbookH2Manager::ScaleH2(G4int id, G4double factor)
422 {
423  tools::hbook::h2* h2 = GetH2InFunction(id, "ScaleH2", false, false);
424  if ( ! h2 ) return false;
425 
426  return h2->scale(factor);
427 }
428 
429 //_____________________________________________________________________________
430 G4bool ExG4HbookH2Manager::FillH2(G4int id,
431  G4double xvalue, G4double yvalue,
432  G4double weight)
433 {
434  tools::hbook::h2* h2 = GetH2InFunction(id, "FillH2", true, false);
435  if ( ! h2 ) return false;
436 
437  if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(id) ) ) return false;
438 
439  G4HnInformation* info = fHnManager->GetHnInformation(id, "FillH2");
440  h2->fill(info->fXFcn(xvalue/info->fXUnit),
441  info->fYFcn(yvalue/info->fYUnit), weight);
442 #ifdef G4VERBOSE
443  if ( fState.GetVerboseL4() ) {
444  G4ExceptionDescription description;
445  description << " id " << id
446  << " xvalue " << xvalue << " yvalue " << yvalue;
447  fState.GetVerboseL4()->Message("fill", "H2", description);
448  }
449 #endif
450  return true;
451 }
452 
453 //_____________________________________________________________________________
454 tools::hbook::h2* ExG4HbookH2Manager::GetH2(G4int id, G4bool warn,
455  G4bool onlyIfActive) const
456 {
457  return GetH2InFunction(id, "GetH2", warn, onlyIfActive);
458 }
459 
460 //_____________________________________________________________________________
461 G4int ExG4HbookH2Manager::GetH2Id(const G4String& name, G4bool warn) const
462 {
463  std::map<G4String, G4int>::const_iterator it = fH2NameIdMap.find(name);
464  if ( it == fH2NameIdMap.end() ) {
465  if ( warn) {
466  G4String inFunction = "ExG4HbookH2Manager::GetH2Id";
467  G4ExceptionDescription description;
468  description << " " << "histogram " << name << " does not exist.";
469  G4Exception(inFunction, "Analysis_W007", JustWarning, description);
470  }
471  return -1;
472  }
473  return it->second;
474 }
475 
476 //_____________________________________________________________________________
477 G4int ExG4HbookH2Manager::GetH2Nxbins(G4int id) const
478 {
479  tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2NXbins");
480  if ( ! h2 ) return 0;
481 
482  return h2->axis_x().bins();
483 }
484 
485 //_____________________________________________________________________________
486 G4double ExG4HbookH2Manager::GetH2Xmin(G4int id) const
487 {
488 // Returns xmin value with applied unit and histogram function
489 
490  tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2Xmin");
491  if ( ! h2 ) return 0;
492 
493  G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2Xmin");
494  return info->fXFcn(h2->axis_x().lower_edge()*info->fXUnit);
495 }
496 
497 //_____________________________________________________________________________
498 G4double ExG4HbookH2Manager::GetH2Xmax(G4int id) const
499 {
500  tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2Xmax");
501  if ( ! h2 ) return 0;
502 
503  G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2Xmax");
504  return info->fXFcn(h2->axis_x().upper_edge()*info->fXUnit);
505 }
506 
507 //_____________________________________________________________________________
508 G4double ExG4HbookH2Manager::GetH2XWidth(G4int id) const
509 {
510  tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2XWidth", true, false);
511  if ( ! h2 ) return 0;
512 
513  G4int nbins = h2->axis_x().bins();
514  if ( ! nbins ) {
515  G4ExceptionDescription description;
516  description << " nbins = 0 (for h1 id = " << id << ").";
517  G4Exception("ExG4HbookH2Manager::GetH2Width",
518  "Analysis_W014", JustWarning, description);
519  return 0;
520  }
521 
522  G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2XWidth");
523  return ( info->fXFcn(h2->axis_x().upper_edge())
524  - info->fXFcn(h2->axis_x().lower_edge()))*info->fXUnit/nbins;
525 }
526 
527 //_____________________________________________________________________________
528 G4int ExG4HbookH2Manager::GetH2Nybins(G4int id) const
529 {
530  tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2NYbins");
531  if ( ! h2 ) return 0;
532 
533  return h2->axis_y().bins();
534 }
535 
536 //_____________________________________________________________________________
537 G4double ExG4HbookH2Manager::GetH2Ymin(G4int id) const
538 {
539 // Returns xmin value with applied unit and histogram function
540 
541  tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2Ymin");
542  if ( ! h2 ) return 0;
543 
544  G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2Ymin");
545  return info->fYFcn(h2->axis_y().lower_edge()*info->fYUnit);
546 }
547 
548 //_____________________________________________________________________________
549 G4double ExG4HbookH2Manager::GetH2Ymax(G4int id) const
550 {
551  tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2Ymax");
552  if ( ! h2 ) return 0;
553 
554  G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2Ymax");
555  return info->fYFcn(h2->axis_y().upper_edge()*info->fYUnit);
556 }
557 
558 //_____________________________________________________________________________
559 G4double ExG4HbookH2Manager::GetH2YWidth(G4int id) const
560 {
561  tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2YWidth", true, false);
562  if ( ! h2 ) return 0;
563 
564  G4int nbins = h2->axis_y().bins();
565  if ( ! nbins ) {
566  G4ExceptionDescription description;
567  description << " nbins = 0 (for h1 id = " << id << ").";
568  G4Exception("ExG4HbookH2Manager::GetH2Width",
569  "Analysis_W014", JustWarning, description);
570  return 0;
571  }
572 
573  G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2YWidth");
574  return ( info->fYFcn(h2->axis_y().upper_edge())
575  - info->fYFcn(h2->axis_y().lower_edge()))*info->fYUnit/nbins;
576 }
577 
578 //_____________________________________________________________________________
579 G4bool ExG4HbookH2Manager::SetH2Title(G4int id, const G4String& title)
580 {
581  h2_booking* h2Booking = GetH2Booking(id, false);
582  if ( ! h2Booking ) {
583  G4ExceptionDescription description;
584  description << " " << "histogram " << id << " does not exist.";
585  G4Exception("G4HbookAnalysisManager::SetH2Title()",
586  "Analysis_W007", JustWarning, description);
587  return false;
588  }
589 
590  h2Booking->fTitle = title;
591  return true;
592 }
593 
594 //_____________________________________________________________________________
595 G4bool ExG4HbookH2Manager::SetH2XAxisTitle(G4int id, const G4String& title)
596 {
597  tools::hbook::h2* h2 = GetH2InFunction(id, "SetH2XAxisTitle");
598  if ( ! h2 ) return false;
599 
600  h2->add_annotation(tools::hbook::key_axis_x_title(), title);
601  return true;
602 }
603 
604 //_____________________________________________________________________________
605 G4bool ExG4HbookH2Manager::SetH2YAxisTitle(G4int id, const G4String& title)
606 {
607  tools::hbook::h2* h2 = GetH2InFunction(id, "SetH2YAxisTitle");
608  if ( ! h2 ) return false;
609 
610  h2->add_annotation(tools::hbook::key_axis_x_title(), title);
611  return true;
612 }
613 
614 //_____________________________________________________________________________
615 G4bool ExG4HbookH2Manager::SetH2ZAxisTitle(G4int id, const G4String& title)
616 {
617  tools::hbook::h2* h2 = GetH2InFunction(id, "SetH2ZAxisTitle");
618  if ( ! h2 ) return false;
619 
620  h2->add_annotation(tools::hbook::key_axis_z_title(), title);
621  return true;
622 }
623 
624 //_____________________________________________________________________________
625 G4String ExG4HbookH2Manager::GetH2Title(G4int id) const
626 {
627  h2_booking* h2Booking = GetH2Booking(id, false);
628  if ( ! h2Booking ) {
629  G4ExceptionDescription description;
630  description << " " << "histogram " << id << " does not exist.";
631  G4Exception("G4HbookAnalysisManager::GetH2Title()",
632  "Analysis_W007", JustWarning, description);
633  return "";
634  }
635 
636  return h2Booking->fTitle;
637 }
638 
639 
640 //_____________________________________________________________________________
641 G4String ExG4HbookH2Manager::GetH2XAxisTitle(G4int id) const
642 {
643  tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2XAxisTitle");
644  if ( ! h2 ) return "";
645 
646  G4String title;
647  G4bool result = h2->annotation(tools::hbook::key_axis_x_title(), title);
648  if ( ! result ) {
649  G4ExceptionDescription description;
650  description << " Failed to get x_axis title for h2 id = " << id << ").";
651  G4Exception("ExG4HbookH2Manager::GetH2XAxisTitle",
652  "Analysis_W014", JustWarning, description);
653  return "";
654  }
655 
656  return title;
657 }
658 
659 //_____________________________________________________________________________
660 G4String ExG4HbookH2Manager::GetH2YAxisTitle(G4int id) const
661 {
662  tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2YAxisTitle");
663  if ( ! h2 ) return "";
664 
665  G4String title;
666  G4bool result = h2->annotation(tools::hbook::key_axis_y_title(), title);
667  if ( ! result ) {
668  G4ExceptionDescription description;
669  description << " Failed to get y_axis title for h2 id = " << id << ").";
670  G4Exception("ExG4HbookH2Manager::GetH2YAxisTitle",
671  "Analysis_W014", JustWarning, description);
672  return "";
673  }
674 
675  return title;
676 }
677 
678 //_____________________________________________________________________________
679 G4String ExG4HbookH2Manager::GetH2ZAxisTitle(G4int id) const
680 {
681  tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2ZAxisTitle");
682  if ( ! h2 ) return "";
683 
684  G4String title;
685  G4bool result = h2->annotation(tools::hbook::key_axis_z_title(), title);
686  if ( ! result ) {
687  G4ExceptionDescription description;
688  description << " Failed to get z_axis title for h2 id = " << id << ").";
689  G4Exception("ExG4HbookH2Manager::GetH2ZAxisTitle",
690  "Analysis_W014", JustWarning, description);
691  return "";
692  }
693 
694  return title;
695 }
696 
697 //_____________________________________________________________________________
698 G4bool ExG4HbookH2Manager::SetH2HbookIdOffset(G4int offset)
699 {
700  if ( fH2Vector.size() ) {
701  G4ExceptionDescription description;
702  description
703  << "Cannot set H2HbookIdOffset as some H2 histogramms already exist.";
704  G4Exception("G4HbookAnalysisManager::SetH2HbookIdOffset()",
705  "Analysis_W009", JustWarning, description);
706  return false;
707  }
708 
709  if ( fFirstId + offset < 1 ) {
710  G4ExceptionDescription description;
711  description << "The first histogram HBOOK id must be >= 1.";
712  G4Exception("G4HbookAnalysisManager::SetH1HbookIdOffset()",
713  "Analysis_W009", JustWarning, description);
714  return false;
715  }
716 
717  fH2HbookIdOffset = offset;
718  return true;
719 }
720 
721 #endif
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4String name
Definition: TRTMaterials.hh:40
G4double(* G4Fcn)(G4double)
Definition: G4Fcn.hh:36
int G4int
Definition: G4Types.hh:78
void UpdateTitle(G4String &title, const G4String &unitName, const G4String &fcnName)
bool G4bool
Definition: G4Types.hh:79
G4double GetUnitValue(const G4String &unit)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
const char * data() const
G4Fcn GetFunction(const G4String &fcnName)
Definition: G4Fcn.cc:36
G4String & append(const G4String &)
G4BinScheme GetBinScheme(const G4String &binSchemeName)
Definition: G4BinScheme.cc:36
Definition of the ExG4HbookH2Manager class.
G4BinScheme
Definition: G4BinScheme.hh:40
double G4double
Definition: G4Types.hh:76
Definition of the ExG4HbookFileManager class.