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