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