Geant4  10.02.p01
ExG4HbookH1Manager.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 "ExG4HbookH1Manager.hh"
36 #include "ExG4HbookFileManager.hh"
37 #include "G4HnManager.hh"
39 #include "G4AnalysisUtilities.hh"
40 
41 #include <fstream>
42 
43 using namespace G4Analysis;
44 
45 //_____________________________________________________________________________
46 ExG4HbookH1Manager::ExG4HbookH1Manager(const G4AnalysisManagerState& state)
47  : G4VH1Manager(),
48  G4THnManager<tools::hbook::h1>(state, "H1"),
49  fBaseToolsManager("H1"),
50  fFileManager(0),
51  fH1HbookIdOffset(-1),
52  fH1Vector(),
53  fH1BookingVector(),
54  fH1NameIdMap()
55 {
56 }
57 
58 //_____________________________________________________________________________
59 ExG4HbookH1Manager::~ExG4HbookH1Manager()
60 {
61  // Delete h1
62  // Reset();
63 
64  // Delete h1 booking
65  std::vector<h1_booking*>::iterator it;
66  for ( it = fH1BookingVector.begin(); it != fH1BookingVector.end(); it++ ) {
67  delete *it;
68  }
69 }
70 
71 //
72 // utility functions
73 //
74 
75 namespace {
76 
77 //_____________________________________________________________________________
78 void ConvertToFloat(const std::vector<G4double>& doubleVector,
79  std::vector<float>& floatVector)
80 {
81  for (G4int i=0; i<G4int(doubleVector.size()); ++i)
82  floatVector.push_back((float)doubleVector[i]);
83 }
84 
85 //_____________________________________________________________________________
86 void UpdateH1Information(G4HnInformation* hnInformation,
87  const G4String& unitName,
88  const G4String& fcnName,
89  G4BinScheme binScheme)
90 {
91  hnInformation->SetDimension(kX, unitName, fcnName, binScheme);
92 }
93 
94 //_____________________________________________________________________________
95 h1_booking* CreateH1Booking(const G4String& title,
96  G4int nbins, G4double xmin, G4double xmax,
97  const G4String& unitName,
98  const G4String& fcnName,
99  G4BinScheme binScheme)
100 {
101  G4double unit = GetUnitValue(unitName);
102  G4Fcn fcn = GetFunction(fcnName);
103 
104  h1_booking* h1Booking = 0;
105  if ( binScheme != G4BinScheme::kLog ) {
106  if ( binScheme == G4BinScheme::kUser ) {
107  // This should never happen, but let's make sure about it
108  // by issuing a warning
109  G4ExceptionDescription description;
110  description
111  << " User binning scheme setting was ignored." << G4endl
112  << " Linear binning will be applied with given (nbins, xmin, xmax) values";
113  G4Exception("ExG4HbookH1Manager::CreateH1",
114  "Analysis_W013", JustWarning, description);
115  }
116  h1Booking = new h1_booking(nbins, fcn(xmin/unit), fcn(xmax/unit));
117  // h1_booking object is deleted in destructor
118  }
119  else {
120  // Compute edges
121  std::vector<G4double> edges;
122  ComputeEdges(nbins, xmin, xmax, unit, fcn, binScheme, edges);
123 
124  h1Booking = new h1_booking(edges);
125  // h1_booking object is deleted in destructor
126  }
127 
128  h1Booking->fTitle = title;
129  UpdateTitle(h1Booking->fTitle, unitName, fcnName);
130 
131  return h1Booking;
132 }
133 
134 //_____________________________________________________________________________
135 h1_booking* CreateH1Booking(const G4String& title,
136  const std::vector<G4double>& edges,
137  const G4String& unitName,
138  const G4String& fcnName)
139 {
140  G4double unit = GetUnitValue(unitName);
141  G4Fcn fcn = GetFunction(fcnName);
142 
143  // Apply function
144  std::vector<G4double> newEdges;
145  ComputeEdges(edges, unit, fcn, newEdges);
146 
147  h1_booking* h1Booking = new h1_booking(newEdges);
148  // h1_booking object is deleted in destructor
149 
150  h1Booking->fTitle = title;
151  UpdateTitle(h1Booking->fTitle, unitName, fcnName);
152 
153  return h1Booking;
154 }
155 
156 //_____________________________________________________________________________
157 void UpdateH1Booking(h1_booking* h1Booking,
158  G4int nbins, G4double xmin, G4double xmax,
159  const G4String& unitName,
160  const G4String& fcnName,
161  G4BinScheme binScheme)
162 {
163  G4double unit = GetUnitValue(unitName);
164  G4Fcn fcn = GetFunction(fcnName);
165 
166  if ( binScheme != G4BinScheme::kLog ) {
167  if ( binScheme == G4BinScheme::kUser ) {
168  // This should never happen, but let's make sure about it
169  // by issuing a warning
170  G4ExceptionDescription description;
171  description
172  << " User binning scheme setting was ignored." << G4endl
173  << " Linear binning will be applied with given (nbins, xmin, xmax) values";
174  G4Exception("ExG4HbookH1Manager::SetH1",
175  "Analysis_W013", JustWarning, description);
176  }
177  h1Booking->fNbins = nbins;
178  h1Booking->fXmin = fcn(xmin/unit);
179  h1Booking->fXmax = fcn(xmax/unit);
180  }
181  else {
182  // Compute edges
183  ComputeEdges(nbins, xmin, xmax, unit, fcn, binScheme, h1Booking->fEdges);
184  }
185 
186  UpdateTitle(h1Booking->fTitle, unitName, fcnName);
187 }
188 
189 //_____________________________________________________________________________
190 void UpdateH1Booking(h1_booking* h1Booking,
191  const std::vector<G4double>& edges,
192  const G4String& unitName,
193  const G4String& fcnName)
194 {
195  G4double unit = GetUnitValue(unitName);
196  G4Fcn fcn = GetFunction(fcnName);
197 
198  // Apply function
199  ComputeEdges(edges, unit, fcn, h1Booking->fEdges);
200 
201  UpdateTitle(h1Booking->fTitle, unitName, fcnName);
202 }
203 
204 //_____________________________________________________________________________
205 void ConfigureHbookH1(tools::hbook::h1* h1,
206  G4int nbins, G4double xmin, G4double xmax,
207  const G4String& unitName,
208  const G4String& fcnName,
209  G4BinScheme binScheme)
210 {
211  G4double unit = GetUnitValue(unitName);
212  G4Fcn fcn = GetFunction(fcnName);
213 
214  if ( binScheme != G4BinScheme::kLog ) {
215  if ( binScheme == G4BinScheme::kUser ) {
216  // This should never happen, but let's make sure about it
217  // by issuing a warning
218  G4ExceptionDescription description;
219  description
220  << " User binning scheme setting was ignored." << G4endl
221  << " Linear binning will be applied with given (nbins, xmin, xmax) values";
222  G4Exception("ExG4HbookH1Manager::SetH1",
223  "Analysis_W013", JustWarning, description);
224  }
225  G4cout << "configuring "
226  << h1 << ", " << fcn(xmin/unit) << ", " << fcn(xmax/unit) << G4endl;
227  h1->configure(nbins, fcn(xmin/unit), fcn(xmax/unit));
228  }
229  else {
230  // Compute bins
231  std::vector<G4double> edges;
232  ComputeEdges(nbins, xmin, xmax, unit, fcn, binScheme, edges);
233  // Convert to float
234  std::vector<float> fedges;
235  ConvertToFloat(edges, fedges);
236  h1->configure(fedges);
237  }
238 }
239 
240 //_____________________________________________________________________________
241 void ConfigureHbookH1(tools::hbook::h1* h1,
242  const std::vector<G4double>& edges,
243  const G4String& unitName,
244  const G4String& fcnName)
245 {
246  // Apply function to edges
247  G4double unit = GetUnitValue(unitName);
248  G4Fcn fcn = GetFunction(fcnName);
249  std::vector<G4double> newEdges;
250  ComputeEdges(edges, unit, fcn, newEdges);
251 
252  // Convert to float
253  std::vector<float> newFEdges;
254  ConvertToFloat(newEdges, newFEdges);
255 
256  h1->configure(newFEdges);
257 }
258 
259 }
260 
261 //
262 // private methods
263 //
264 
265 //_____________________________________________________________________________
266 void ExG4HbookH1Manager::SetH1HbookIdOffset()
267 {
268 // Set fH1HbookIdOffset if needed
269 
270  if ( fH1HbookIdOffset == -1 ) {
271  if ( fHnManager->GetFirstId() > 0 )
272  fH1HbookIdOffset = 0;
273  else
274  fH1HbookIdOffset = 1;
275 
276  //if ( fH1HbookIdOffset > 0 ) {
277  // G4ExceptionDescription description;
278  // description << "H1 will be defined in HBOOK with ID = G4_firstHistoId + 1";
279  // G4Exception("ExG4HbookH1Manager::SetH1HbookIdOffset()",
280  // "Analysis_W013", JustWarning, description);
281  //}
282  }
283 }
284 
285 //_____________________________________________________________________________
286 void ExG4HbookH1Manager::AddH1Information(const G4String& name,
287  const G4String& unitName,
288  const G4String& fcnName,
289  G4BinScheme binScheme) const
290 {
291  auto hnInformation = fHnManager->AddHnInformation(name, 1);
292  hnInformation->AddDimension(unitName, fcnName, binScheme);
293 }
294 
295 //_____________________________________________________________________________
296 G4int ExG4HbookH1Manager::CreateH1FromBooking(h1_booking* h1Booking,
297  G4bool chDir)
298 {
299 // Create h1 from h1_booking.
300 
301  if ( chDir ) {
302  // Go to histograms directory if defined
303  if ( fFileManager->GetHistoDirectoryName() != "" ) {
304  G4String histoPath = "//PAWC/LUN1/";
305  histoPath.append(fFileManager->GetHistoDirectoryName().data());
306  tools::hbook::CHCDIR(histoPath.data()," ");
307  }
308  }
309 
310  G4int index = fH1Vector.size();
311  G4int id = index + fHnManager->GetFirstId();
313  info = fHnManager->GetHnInformation(id, "CreateH1FromBooking");
314  // Hbook index
315  G4int hbookIndex = fH1HbookIdOffset + index + fHnManager->GetFirstId();
316 
317 #ifdef G4VERBOSE
318  if ( fState.GetVerboseL4() )
319  fState.GetVerboseL4()->Message("create from booking", "h1", info->GetName());
320 #endif
321 
322  // Create h1
323  tools::hbook::h1* h1 = 0;
324  if ( ! h1Booking->fEdges.size() ) {
325  h1 = new tools::hbook::h1(
326  hbookIndex, h1Booking->fTitle,
327  h1Booking->fNbins, h1Booking->fXmin, h1Booking->fXmax);
328  }
329  else {
330  // Convert to float
331  std::vector<float> newEdges;
332  ConvertToFloat(h1Booking->fEdges, newEdges);
333 
334  h1 = new tools::hbook::h1(hbookIndex, h1Booking->fTitle, newEdges);
335  }
336 
337  fH1Vector.push_back(h1);
338 
339  // Update axis titles
340  fBaseToolsManager.SetAxisTitle(*h1, ExG4HbookBaseHnManager::kX, h1Booking->fXAxisTitle);
341  fBaseToolsManager.SetAxisTitle(*h1, ExG4HbookBaseHnManager::kY, h1Booking->fYAxisTitle);
342 
343  if ( chDir ) {
344  if ( fFileManager->GetHistoDirectoryName() != "" ) {
345  // Return to //PAWC/LUN1 :
346  tools::hbook::CHCDIR("//PAWC/LUN1"," ");
347  }
348  }
349 
350 #ifdef G4VERBOSE
351  if ( fState.GetVerboseL3() ) {
352  G4ExceptionDescription description;
353  description << " name : " << info->GetName() << " hbook index : " << hbookIndex;
354  fState.GetVerboseL3()->Message("create from booking", "h1", description);
355  }
356 #endif
357 
358  return id;
359 }
360 
361 //_____________________________________________________________________________
362 G4int ExG4HbookH1Manager::RegisterH1Booking(const G4String& name,
363  h1_booking* h1Booking)
364 {
365  // Register h1
366  G4int index = fH1BookingVector.size();
367  fH1BookingVector.push_back(h1Booking);
368  fH1NameIdMap[name] = index + fHnManager->GetFirstId();
369 
370  return index + fHnManager->GetFirstId();
371 }
372 
373 //_____________________________________________________________________________
374 void ExG4HbookH1Manager::BeginCreateH1(const G4String& name)
375 {
376 #ifdef G4VERBOSE
377  if ( fState.GetVerboseL4() )
378  fState.GetVerboseL4()->Message("create", "H1", name);
379 #endif
380 
381  // Set fH1HbookIdOffset if needed
382  SetH1HbookIdOffset();
383 }
384 
385 //_____________________________________________________________________________
386 G4int ExG4HbookH1Manager::FinishCreateH1(
387  const G4String& name, h1_booking* h1Booking,
388  const G4String& unitName, const G4String& fcnName,
389  G4BinScheme binScheme)
390 {
391  // Register h1 booking
392  G4int id = RegisterH1Booking(name, h1Booking);
393 
394  // Save H1 information
395  AddH1Information(name, unitName, fcnName, binScheme);
396 
397  // Create h1 if the file is open
398  if ( fFileManager->IsFile() ) {
399  CreateH1FromBooking(h1Booking);
400  }
401 
402 #ifdef G4VERBOSE
403  if ( fState.GetVerboseL2() ) {
404  G4int hbookIndex = fH1HbookIdOffset + id;
405  G4ExceptionDescription description;
406  description << " name : " << name << " hbook index : " << hbookIndex;
407  fState.GetVerboseL2()->Message("create", "H1", description);
408  }
409 #endif
410 
411  return id;
412 }
413 
414 //_____________________________________________________________________________
415 G4bool ExG4HbookH1Manager::FinishSetH1(
416  G4int id,
417  G4HnInformation* info,
418  const G4String& unitName,
419  const G4String& fcnName,
420  G4BinScheme binScheme)
421 {
422  // Update information
423  UpdateH1Information(info, unitName, fcnName, binScheme);
424 
425  // Set activation
426  fHnManager->SetActivation(id, true);
427 
428  return true;
429 }
430 
431 
432 //_____________________________________________________________________________
433 void ExG4HbookH1Manager::CreateH1sFromBooking()
434 {
435 // Create all h1 from h1_booking.
436 
437  // Do nothing if any h1 histogram already exists
438  // or no h1 histograms are booked
439  if ( fH1Vector.size() || ( fH1BookingVector.size() == 0 ) ) return;
440 
441  // Go to histograms directory if defined
442  if ( fFileManager->GetHistoDirectoryName() != "" ) {
443  G4String histoPath = "//PAWC/LUN1/";
444  histoPath.append(fFileManager->GetHistoDirectoryName().data());
445  tools::hbook::CHCDIR(histoPath.data()," ");
446  }
447 
448  // Create histograms
449  std::vector<h1_booking*>::const_iterator it;
450  for ( it = fH1BookingVector.begin(); it != fH1BookingVector.end(); ++it) {
451  CreateH1FromBooking(*it, false);
452  }
453 
454  // Return backi from histograms directory if defined
455  if ( fFileManager->GetHistoDirectoryName() != "" ) {
456  // Return to //PAWC/LUN1 :
457  tools::hbook::CHCDIR("//PAWC/LUN1"," ");
458  }
459 }
460 
461 //_____________________________________________________________________________
462 void ExG4HbookH1Manager::Reset()
463 {
464 // Reset histograms and ntuple
465 
466  // Delete histograms (not needed as done by Hbook when closing file)
467  std::vector<tools::hbook::h1*>::iterator it;
468  for (it = fH1Vector.begin(); it != fH1Vector.end(); it++ ) {
469  delete *it;
470  }
471 
472  // Clear vectors
473  fH1Vector.clear();
474 }
475 
476 //_____________________________________________________________________________
477 h1_booking* ExG4HbookH1Manager::GetH1Booking(G4int id, G4bool warn) const
478 {
479  G4int index = id - fHnManager->GetFirstId();
480  if ( index < 0 || index >= G4int(fH1BookingVector.size()) ) {
481  if ( warn) {
482  G4ExceptionDescription description;
483  description << " " << "histo " << id << " does not exist.";
484  G4Exception("G4HbookH1Manager::GetH1Booking()",
485  "Analysis_W011", JustWarning, description);
486  }
487  return 0;
488  }
489 
490  return fH1BookingVector[index];
491 }
492 
493 //
494 // protected methods
495 //
496 
497 //_____________________________________________________________________________
498 G4bool ExG4HbookH1Manager::WriteOnAscii(std::ofstream& output)
499 {
500 // Write selected objects on ASCII file
501 // (Only H1 implemented by now)
502 // According to the implementation by Michel Maire, originally in
503 // extended examples.
504 
505  // h1 histograms
506  for ( G4int i=0; i<G4int(fH1Vector.size()); ++i ) {
507  G4int id = i + fHnManager->GetFirstId();
508  G4HnInformation* info
509  = fHnManager->GetHnInformation(id, "WriteOnAscii");
510  // skip writing if activation is enabled and H1 is inactivated
511  if ( ! info->GetAscii() ) continue;
512  tools::hbook::h1* h1 = fH1Vector[i];
513 
514 #ifdef G4VERBOSE
515  if ( fState.GetVerboseL3() )
516  fState.GetVerboseL3()->Message("write on ascii", "h1", info->GetName());
517 #endif
518 
519  output << "\n 1D histogram " << id << ": " << h1->title()
520  << "\n \n \t X \t\t Y" << G4endl;
521 
522  for (G4int j=0; j< G4int(h1->axis().bins()); ++j) {
523  output << " " << j << "\t"
524  << h1->axis().bin_center(j) << "\t"
525  << h1->bin_height(j) << G4endl;
526  }
527  }
528 
529  return true;
530 }
531 
532 //_____________________________________________________________________________
533 tools::hbook::h1* ExG4HbookH1Manager::GetH1InFunction(G4int id,
534  G4String functionName, G4bool warn,
535  G4bool onlyIfActive) const
536 {
537  G4int index = id - fHnManager->GetFirstId();
538  if ( index < 0 || index >= G4int(fH1Vector.size()) ) {
539  if ( warn) {
540  G4String inFunction = "ExG4HbookH1Manager::";
541  inFunction += functionName;
542  G4ExceptionDescription description;
543  description << " " << "histogram " << id << " does not exist.";
544  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
545  }
546  return 0;
547  }
548 
549  // Do not return histogram if inactive
550  if ( fState.GetIsActivation() && onlyIfActive && ( ! fHnManager->GetActivation(id) ) ) {
551  return 0;
552  }
553 
554  return fH1Vector[index];
555 }
556 
557 //
558 // public methods
559 //
560 
561 //_____________________________________________________________________________
562 G4int ExG4HbookH1Manager::CreateH1(
563  const G4String& name, const G4String& title,
564  G4int nbins, G4double xmin, G4double xmax,
565  const G4String& unitName, const G4String& fcnName,
566  const G4String& binSchemeName)
567 {
568  BeginCreateH1(name);
569 
570  G4BinScheme binScheme = GetBinScheme(binSchemeName);
571 
572  // Create h1 booking
573  h1_booking* h1Booking
574  = CreateH1Booking(title, nbins, xmin, xmax, unitName, fcnName, binScheme);
575 
576  return FinishCreateH1(name, h1Booking, unitName, fcnName, binScheme);
577 }
578 
579 //_____________________________________________________________________________
580 G4int ExG4HbookH1Manager::CreateH1(
581  const G4String& name, const G4String& title,
582  const std::vector<G4double>& edges,
583  const G4String& unitName,
584  const G4String& fcnName)
585 {
586  BeginCreateH1(name);
587 
588  // Create h1 booking
589  h1_booking* h1Booking
590  = CreateH1Booking(title, edges, unitName, fcnName);
591 
592  return FinishCreateH1(name, h1Booking, unitName, fcnName, G4BinScheme::kUser);
593 }
594 
595 
596 //_____________________________________________________________________________
597 G4bool ExG4HbookH1Manager::SetH1(G4int id,
598  G4int nbins, G4double xmin, G4double xmax,
599  const G4String& unitName,
600  const G4String& fcnName,
601  const G4String& binSchemeName)
602 {
603  h1_booking* h1Booking = GetH1Booking(id, false);
604  if ( ! h1Booking ) {
605  G4ExceptionDescription description;
606  description << " " << "histogram " << id << " does not exist.";
607  G4Exception("G4HbookH1Manager::SetH1()",
608  "Analysis_W011", JustWarning, description);
609  return false;
610  }
611 
612  G4HnInformation* info = fHnManager->GetHnInformation(id,"SetH1");
613 #ifdef G4VERBOSE
614  if ( fState.GetVerboseL4() )
615  fState.GetVerboseL4()->Message("configure", "H1", info->GetName());
616 #endif
617 
618  G4BinScheme binScheme = GetBinScheme(binSchemeName);
619 
620  // Update H1 booking
621  UpdateH1Booking(h1Booking,
622  nbins, xmin, xmax, unitName, fcnName, binScheme);
623 
624  // Re-configure histogram if it was already defined
625  if ( fH1Vector.size() ) {
626  tools::hbook::h1* h1 = GetH1(id);
627  ConfigureHbookH1(h1, nbins, xmin, xmax, unitName, fcnName, binScheme);
628  }
629 
630  return FinishSetH1(id, info, unitName, fcnName, binScheme);
631 }
632 
633 //_____________________________________________________________________________
634 G4bool ExG4HbookH1Manager::SetH1(G4int id,
635  const std::vector<G4double>& edges,
636  const G4String& unitName,
637  const G4String& fcnName)
638 {
639  h1_booking* h1Booking = GetH1Booking(id, false);
640  if ( ! h1Booking ) {
641  G4ExceptionDescription description;
642  description << " " << "histogram " << id << " does not exist.";
643  G4Exception("G4HbookH1Manager::SetH1()",
644  "Analysis_W011", JustWarning, description);
645  return false;
646  }
647 
648  G4HnInformation* info = fHnManager->GetHnInformation(id,"SetH1");
649 #ifdef G4VERBOSE
650  if ( fState.GetVerboseL4() )
651  fState.GetVerboseL4()->Message("configure", "H1", info->GetName());
652 #endif
653 
654  // Update H1 booking
655  UpdateH1Booking(h1Booking, edges, unitName, fcnName);
656 
657  // Re-configure histogram if it was already defined
658  if ( fH1Vector.size() ) {
659  tools::hbook::h1* h1 = GetH1(id);
660  ConfigureHbookH1(h1, edges, unitName, fcnName);
661  }
662 
663  return
664  FinishSetH1(id, info, unitName, fcnName, G4BinScheme::kUser);
665 }
666 
667 //_____________________________________________________________________________
668 G4bool ExG4HbookH1Manager::ScaleH1(G4int id, G4double factor)
669 {
670  tools::hbook::h1* h1 = GetH1InFunction(id, "ScaleH1", false, false);
671  if ( ! h1 ) return false;
672 
673  return h1->scale(factor);
674 }
675 
676 //_____________________________________________________________________________
677 G4bool ExG4HbookH1Manager::FillH1(G4int id, G4double value, G4double weight)
678 {
679  tools::hbook::h1* h1 = GetH1InFunction(id, "FillH1", true, false);
680  if ( ! h1 ) return false;
681 
682  if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(id) ) ) {
683  //G4cout << "Skipping FillH1 for " << id << G4endl;
684  return false;
685  }
686 
688  = fHnManager->GetHnDimensionInformation(id, kX, "FillH1");
689  h1->fill(info->fFcn(value/info->fUnit), weight);
690 #ifdef G4VERBOSE
691  if ( fState.GetVerboseL4() ) {
692  G4ExceptionDescription description;
693  description << " id " << id << " value " << value
694  << " fcn(value/unit) " << info->fFcn(value/info->fUnit)
695  << " weight " << weight;
696  fState.GetVerboseL4()->Message("fill", "H1", description);
697  }
698 #endif
699  return true;
700 }
701 
702 //_____________________________________________________________________________
703 tools::hbook::h1* ExG4HbookH1Manager::GetH1(G4int id, G4bool warn,
704  G4bool onlyIfActive) const
705 {
706  return GetH1InFunction(id, "GetH1", warn, onlyIfActive);
707 }
708 
709 //_____________________________________________________________________________
710 G4int ExG4HbookH1Manager::GetH1Id(const G4String& name, G4bool warn) const
711 {
712  std::map<G4String, G4int>::const_iterator it = fH1NameIdMap.find(name);
713  if ( it == fH1NameIdMap.end() ) {
714  if ( warn) {
715  G4String inFunction = "ExG4HbookH1Manager::GetH1Id";
716  G4ExceptionDescription description;
717  description << " " << "histogram " << name << " does not exist.";
718  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
719  }
720  return -1;
721  }
722  return it->second;
723 }
724 
725 //_____________________________________________________________________________
726 G4int ExG4HbookH1Manager::GetH1Nbins(G4int id) const
727 {
728  tools::hbook::h1* h1 = GetH1InFunction(id, "GetH1Nbins");
729  if ( ! h1 ) return 0;
730 
731  return fBaseToolsManager.GetNbins(h1->axis());
732 }
733 
734 //_____________________________________________________________________________
735 G4double ExG4HbookH1Manager::GetH1Xmin(G4int id) const
736 {
737 // Returns xmin value with applied unit and histogram function
738 
739  tools::hbook::h1* h1 = GetH1InFunction(id, "GetH1Xmin");
740  if ( ! h1 ) return 0;
741 
742  return fBaseToolsManager.GetMin(h1->axis());
743 }
744 
745 //_____________________________________________________________________________
746 G4double ExG4HbookH1Manager::GetH1Xmax(G4int id) const
747 {
748  tools::hbook::h1* h1 = GetH1InFunction(id, "GetH1Xmax");
749  if ( ! h1 ) return 0;
750 
751  return fBaseToolsManager.GetMax(h1->axis());
752 }
753 
754 //_____________________________________________________________________________
755 G4double ExG4HbookH1Manager::GetH1Width(G4int id) const
756 {
757  tools::hbook::h1* h1 = GetH1InFunction(id, "GetH1XWidth", true, false);
758  if ( ! h1 ) return 0;
759 
760  return fBaseToolsManager.GetWidth(h1->axis());
761 }
762 
763 //_____________________________________________________________________________
764 G4bool ExG4HbookH1Manager::SetH1Title(G4int id, const G4String& title)
765 {
766  h1_booking* h1Booking = GetH1Booking(id, false);
767  if ( ! h1Booking ) {
768  G4ExceptionDescription description;
769  description << " " << "histogram " << id << " does not exist.";
770  G4Exception("G4HbookH1Manager::SetH1Title()",
771  "Analysis_W011", JustWarning, description);
772  return false;
773  }
774 
775  h1Booking->fTitle = title;
776  return true;
777 }
778 
779 //_____________________________________________________________________________
780 G4bool ExG4HbookH1Manager::SetH1XAxisTitle(G4int id, const G4String& title)
781 {
782  h1_booking* h1Booking = GetH1Booking(id, false);
783  if ( ! h1Booking ) {
784  G4ExceptionDescription description;
785  description << " " << "histogram " << id << " does not exist.";
786  G4Exception("G4HbookH1Manager::SetH1XAxisTitle()",
787  "Analysis_W011", JustWarning, description);
788  return false;
789  }
790 
791  // set value to booking
792  h1Booking->fXAxisTitle = title;
793 
794  // update value in the histogram if it exists
795  tools::hbook::h1* h1 = GetH1InFunction(id, "SetH1XAxisTitle", false, false);
796  if ( ! h1 ) return true;
797 
798  return fBaseToolsManager.SetAxisTitle(*h1, ExG4HbookBaseHnManager::kX, title);
799 }
800 
801 //_____________________________________________________________________________
802 G4bool ExG4HbookH1Manager::SetH1YAxisTitle(G4int id, const G4String& title)
803 {
804  h1_booking* h1Booking = GetH1Booking(id, false);
805  if ( ! h1Booking ) {
806  G4ExceptionDescription description;
807  description << " " << "histogram " << id << " does not exist.";
808  G4Exception("G4HbookH1Manager::SetH1YAxisTitle()",
809  "Analysis_W011", JustWarning, description);
810  return false;
811  }
812 
813  // set value to booking
814  h1Booking->fYAxisTitle = title;
815 
816  // update value in the histogram if it exists
817  tools::hbook::h1* h1 = GetH1InFunction(id, "SetH1YAxisTitle", false, false);
818  if ( ! h1 ) return true;
819 
820  return fBaseToolsManager.SetAxisTitle(*h1, ExG4HbookBaseHnManager::kY, title);
821 }
822 
823 //_____________________________________________________________________________
824 G4String ExG4HbookH1Manager::GetH1Title(G4int id) const
825 {
826  h1_booking* h1Booking = GetH1Booking(id, false);
827  if ( ! h1Booking ) {
828  G4ExceptionDescription description;
829  description << " " << "histogram " << id << " does not exist.";
830  G4Exception("G4HbookH1Manager::GetH1Title()",
831  "Analysis_W011", JustWarning, description);
832  return "";
833  }
834 
835  return h1Booking->fTitle;
836 }
837 
838 
839 //_____________________________________________________________________________
840 G4String ExG4HbookH1Manager::GetH1XAxisTitle(G4int id) const
841 {
842  h1_booking* h1Booking = GetH1Booking(id, false);
843  if ( ! h1Booking ) {
844  G4ExceptionDescription description;
845  description << " " << "histogram " << id << " does not exist.";
846  G4Exception("G4HbookH1Manager::GetH1XAxisTitle()",
847  "Analysis_W011", JustWarning, description);
848  return "";
849  }
850 
851  return h1Booking->fXAxisTitle;
852 }
853 
854 //_____________________________________________________________________________
855 G4String ExG4HbookH1Manager::GetH1YAxisTitle(G4int id) const
856 {
857  h1_booking* h1Booking = GetH1Booking(id, false);
858  if ( ! h1Booking ) {
859  G4ExceptionDescription description;
860  description << " " << "histogram " << id << " does not exist.";
861  G4Exception("G4HbookH1Manager::GetH1YAxisTitle()",
862  "Analysis_W011", JustWarning, description);
863  return "";
864  }
865 
866  return h1Booking->fYAxisTitle;
867 }
868 
869 //_____________________________________________________________________________
870 G4bool ExG4HbookH1Manager::SetH1HbookIdOffset(G4int offset)
871 {
872  if ( fH1Vector.size() ) {
873  G4ExceptionDescription description;
874  description
875  << "Cannot set H1HbookIdOffset as some H1 histogramms already exist.";
876  G4Exception("G4HbookH1Manager::SetH1HbookIdOffset()",
877  "Analysis_W013", JustWarning, description);
878  return false;
879  }
880 
881  if ( fHnManager->GetFirstId() + offset < 1 ) {
882  G4ExceptionDescription description;
883  description << "The first histogram HBOOK id must be >= 1.";
884  G4Exception("G4HbookH1Manager::SetH1HbookIdOffset()",
885  "Analysis_W013", JustWarning, description);
886  return false;
887  }
888 
889  fH1HbookIdOffset = offset;
890  return true;
891 }
892 
893 #endif
G4double(*)(G4double) G4Fcn
Definition: G4Fcn.hh:36
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
void ComputeEdges(G4int nbins, G4double xmin, G4double xmax, G4double unit, G4Fcn fcn, G4BinScheme, std::vector< G4double > &edges)
Definition: G4BinScheme.cc:56
G4String name
Definition: TRTMaterials.hh:40
int G4int
Definition: G4Types.hh:78
void UpdateTitle(G4String &title, const G4String &unitName, const G4String &fcnName)
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
const G4int kX
G4double GetUnitValue(const G4String &unit)
Definition of the ExG4HbookH1Manager class.
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)
G4BinScheme GetBinScheme(const G4String &binSchemeName)
Definition: G4BinScheme.cc:36
G4bool GetAscii() const
#define G4endl
Definition: G4ios.hh:61
G4String GetName() const
G4BinScheme
Definition: G4BinScheme.hh:40
double G4double
Definition: G4Types.hh:76
void AddDimension(const G4String &unitName, const G4String &fcnName, G4BinScheme binScheme)
Definition of the ExG4HbookFileManager class.
void SetDimension(G4int dimension, const G4String &unitName, const G4String &fcnName, G4BinScheme binScheme)