Geant4  10.00.p03
G4H2ToolsManager.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: G4H2ToolsManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
27 
28 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
29 
30 #include "G4H2ToolsManager.hh"
31 #include "G4HnManager.hh"
33 #include "G4AnalysisUtilities.hh"
34 
35 #include "tools/histo/h2d"
36 
37 #include <fstream>
38 
39 using namespace G4Analysis;
40 
41 //_____________________________________________________________________________
43  : G4VH2Manager(state),
44  fH2Vector(),
45  fH2NameIdMap()
46 {
47 }
48 
49 //_____________________________________________________________________________
51 {
52  std::vector<tools::histo::h2d*>::iterator it;
53  for (it = fH2Vector.begin(); it != fH2Vector.end(); it++ ) {
54  delete (*it);
55  }
56 }
57 
58 //
59 // Utility functions
60 //
61 
62 namespace {
63 
64 //_____________________________________________________________________________
65 void UpdateH2Information(G4HnInformation* information,
66  const G4String& xunitName,
67  const G4String& yunitName,
68  const G4String& xfcnName,
69  const G4String& yfcnName,
70  G4BinScheme xbinScheme,
71  G4BinScheme ybinScheme)
72 {
73  G4double xunit = GetUnitValue(xunitName);
74  G4double yunit = GetUnitValue(yunitName);
75  G4Fcn xfcn = GetFunction(xfcnName);
76  G4Fcn yfcn = GetFunction(yfcnName);
77  information->fXUnitName = xunitName;
78  information->fYUnitName = yunitName;
79  information->fXFcnName = xfcnName;
80  information->fYFcnName = yfcnName;
81  information->fXUnit = xunit;
82  information->fYUnit = yunit;
83  information->fXFcn = xfcn;
84  information->fYFcn = yfcn;
85  information->fXBinScheme = xbinScheme;
86  information->fYBinScheme = ybinScheme;
87 }
88 
89 //_____________________________________________________________________________
90 void AddH2Annotation(tools::histo::h2d* h2d,
91  const G4String& xunitName,
92  const G4String& yunitName,
93  const G4String& xfcnName,
94  const G4String& yfcnName)
95 {
96  G4String xaxisTitle;
97  G4String yaxisTitle;
98  UpdateTitle(xaxisTitle, xunitName, xfcnName);
99  UpdateTitle(yaxisTitle, yunitName, yfcnName);
100  h2d->add_annotation(tools::histo::key_axis_x_title(), xaxisTitle);
101  h2d->add_annotation(tools::histo::key_axis_y_title(), yaxisTitle);
102 }
103 
104 //_____________________________________________________________________________
105 tools::histo::h2d* CreateToolsH2(
106  const G4String& title,
107  G4int nxbins, G4double xmin, G4double xmax,
108  G4int nybins, G4double ymin, G4double ymax,
109  const G4String& xunitName,
110  const G4String& yunitName,
111  const G4String& xfcnName,
112  const G4String& yfcnName,
113  const G4String& xbinSchemeName,
114  const G4String& ybinSchemeName)
115 {
116  G4double xunit = GetUnitValue(xunitName);
117  G4double yunit = GetUnitValue(yunitName);
118  G4Fcn xfcn = GetFunction(xfcnName);
119  G4Fcn yfcn = GetFunction(yfcnName);
120  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
121  G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
122 
123  if ( xbinScheme != kLogBinScheme && ybinScheme != kLogBinScheme) {
124  if ( xbinScheme == kUserBinScheme || ybinScheme == kUserBinScheme) {
125  // This should never happen, but let's make sure about it
126  // by issuing a warning
127  G4ExceptionDescription description;
128  description
129  << " User binning scheme setting was ignored." << G4endl
130  << " Linear binning will be applied with given (nbins, xmin, xmax) values";
131  G4Exception("G4H2ToolsManager::CreateH2",
132  "Analysis_W013", JustWarning, description);
133  }
134  return new tools::histo::h2d(title,
135  nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
136  nybins, yfcn(ymin/yunit), yfcn(ymax/yunit));
137  // h2 objects are deleted in destructor and reset when
138  // closing a file.
139  }
140  else {
141  // Compute edges
142  std::vector<G4double> xedges;
143  ComputeEdges(nxbins, xmin, xmax, xunit, xfcn, xbinScheme, xedges);
144  std::vector<G4double> yedges;
145  ComputeEdges(nybins, ymin, ymax, yunit, yfcn, ybinScheme, yedges);
146  return new tools::histo::h2d(title, xedges, yedges);
147  }
148 }
149 
150 //_____________________________________________________________________________
151 tools::histo::h2d* CreateToolsH2(
152  const G4String& title,
153  const std::vector<G4double>& xedges,
154  const std::vector<G4double>& yedges,
155  const G4String& xunitName,
156  const G4String& yunitName,
157  const G4String& xfcnName,
158  const G4String& yfcnName)
159 {
160  G4double xunit = GetUnitValue(xunitName);
161  G4double yunit = GetUnitValue(yunitName);
162  G4Fcn xfcn = GetFunction(xfcnName);
163  G4Fcn yfcn = GetFunction(yfcnName);
164 
165  // Apply function
166  std::vector<G4double> xnewEdges;
167  ComputeEdges(xedges, xunit, xfcn, xnewEdges);
168  std::vector<G4double> ynewEdges;
169  ComputeEdges(yedges, yunit, yfcn, ynewEdges);
170 
171  return new tools::histo::h2d(title, xnewEdges, ynewEdges);
172  // h2 objects are deleted in destructor and reset when
173  // closing a file.
174 }
175 
176 //_____________________________________________________________________________
177 void ConfigureToolsH2(tools::histo::h2d* h2d,
178  G4int nxbins, G4double xmin, G4double xmax,
179  G4int nybins, G4double ymin, G4double ymax,
180  const G4String& xunitName,
181  const G4String& yunitName,
182  const G4String& xfcnName,
183  const G4String& yfcnName,
184  const G4String& xbinSchemeName,
185  const G4String& ybinSchemeName)
186 {
187  G4double xunit = GetUnitValue(xunitName);
188  G4double yunit = GetUnitValue(yunitName);
189  G4Fcn xfcn = GetFunction(xfcnName);
190  G4Fcn yfcn = GetFunction(yfcnName);
191  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
192  G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
193 
194  if ( xbinScheme != kLogBinScheme && ybinScheme != kLogBinScheme) {
195  if ( xbinScheme == kUserBinScheme || ybinScheme == kUserBinScheme) {
196  // This should never happen, but let's make sure about it
197  // by issuing a warning
198  G4ExceptionDescription description;
199  description
200  << " User binning scheme setting was ignored." << G4endl
201  << " Linear binning will be applied with given (nbins, xmin, xmax) values";
202  G4Exception("G4H2ToolsManager::CreateH2",
203  "Analysis_W013", JustWarning, description);
204  }
205  h2d->configure(nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
206  nybins, yfcn(ymin/yunit), yfcn(ymax/yunit));
207  }
208  else {
209  // Compute bins
210  std::vector<G4double> xedges;
211  ComputeEdges(nxbins, xmin, xmax, xunit, xfcn, xbinScheme, xedges);
212  std::vector<G4double> yedges;
213  ComputeEdges(nybins, ymin, ymax, yunit, yfcn, ybinScheme, yedges);
214  h2d->configure(xedges, yedges);
215  }
216 }
217 
218 //_____________________________________________________________________________
219 void ConfigureToolsH2(tools::histo::h2d* h2d,
220  const std::vector<G4double>& xedges,
221  const std::vector<G4double>& yedges,
222  const G4String& xunitName,
223  const G4String& yunitName,
224  const G4String& xfcnName,
225  const G4String& yfcnName)
226 {
227  G4double xunit = GetUnitValue(xunitName);
228  G4Fcn xfcn = GetFunction(xfcnName);
229  std::vector<G4double> xnewEdges;
230  ComputeEdges(xedges, xunit, xfcn, xnewEdges);
231 
232  G4double yunit = GetUnitValue(yunitName);
233  G4Fcn yfcn = GetFunction(yfcnName);
234  std::vector<G4double> ynewEdges;
235  ComputeEdges(yedges, yunit, yfcn, ynewEdges);
236 
237  h2d->configure(xnewEdges, ynewEdges);
238 }
239 
240 }
241 
242 
243 //
244 // private methods
245 //
246 
247 //_____________________________________________________________________________
249  G4String functionName, G4bool warn,
250  G4bool onlyIfActive) const
251 {
252  G4int index = id - fFirstId;
253  if ( index < 0 || index >= G4int(fH2Vector.size()) ) {
254  if ( warn) {
255  G4String inFunction = "G4H2ToolsManager::";
256  inFunction += functionName;
257  G4ExceptionDescription description;
258  description << " " << "histogram " << id << " does not exist.";
259  G4Exception(inFunction, "Analysis_W007", JustWarning, description);
260  }
261  return 0;
262  }
263 
264  // Do not return histogram if inactive
265  if ( fState.GetIsActivation() && onlyIfActive &&
266  ( ! fHnManager->GetActivation(id) ) ) {
267  return 0;
268  }
269 
270  return fH2Vector[index];
271 }
272 
273 
274 //_____________________________________________________________________________
276  const G4String& xunitName,
277  const G4String& yunitName,
278  const G4String& xfcnName,
279  const G4String& yfcnName,
280  G4BinScheme xbinScheme,
281  G4BinScheme ybinScheme) const
282 {
283  G4double xunit = GetUnitValue(xunitName);
284  G4double yunit = GetUnitValue(yunitName);
285  G4Fcn xfcn = GetFunction(xfcnName);
286  G4Fcn yfcn = GetFunction(yfcnName);
287  fHnManager
288  ->AddH2Information(name, xunitName, yunitName, xfcnName, yfcnName,
289  xunit, yunit, xfcn, yfcn,
290  xbinScheme, ybinScheme);
291 }
292 
293 //_____________________________________________________________________________
294 G4int G4H2ToolsManager::RegisterToolsH2(tools::histo::h2d* h2d,
295  const G4String& name)
296 {
297  G4int index = fH2Vector.size();
298  fH2Vector.push_back(h2d);
299 
300  fLockFirstId = true;
301  fH2NameIdMap[name] = index + fFirstId;
302  return index + fFirstId;
303 }
304 
305 //
306 // protected methods
307 //
308 
309 //_____________________________________________________________________________
311  G4int nxbins, G4double xmin, G4double xmax,
312  G4int nybins, G4double ymin, G4double ymax,
313  const G4String& xunitName, const G4String& yunitName,
314  const G4String& xfcnName, const G4String& yfcnName,
315  const G4String& xbinSchemeName,
316  const G4String& ybinSchemeName)
317 
318 {
319 #ifdef G4VERBOSE
320  if ( fState.GetVerboseL4() )
321  fState.GetVerboseL4()->Message("create", "H2", name);
322 #endif
323  tools::histo::h2d* h2d
324  = CreateToolsH2(title, nxbins, xmin, xmax, nybins, ymin, ymax,
325  xunitName, yunitName, xfcnName, yfcnName,
326  xbinSchemeName, ybinSchemeName);
327 
328  // Add annotation
329  AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
330 
331  // Save H2 information
332  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
333  G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
335  name, xunitName, yunitName, xfcnName, yfcnName, xbinScheme, ybinScheme);
336 
337  // Register histogram
338  G4int id = RegisterToolsH2(h2d, name);
339 
340 #ifdef G4VERBOSE
341  if ( fState.GetVerboseL2() )
342  fState.GetVerboseL2()->Message("create", "H2", name);
343 #endif
344 
345  return id;
346 }
347 
348 //_____________________________________________________________________________
350  const std::vector<G4double>& xedges,
351  const std::vector<G4double>& yedges,
352  const G4String& xunitName, const G4String& yunitName,
353  const G4String& xfcnName, const G4String& yfcnName)
354 
355 {
356 #ifdef G4VERBOSE
357  if ( fState.GetVerboseL4() )
358  fState.GetVerboseL4()->Message("create", "H2", name);
359 #endif
360  tools::histo::h2d* h2d
361  = CreateToolsH2(title, xedges, yedges,
362  xunitName, yunitName, xfcnName, yfcnName);
363 
364  // Add annotation
365  AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
366 
367  // Save H2 information
369  name, xunitName, yunitName, xfcnName, yfcnName, kUserBinScheme, kUserBinScheme);
370 
371  // Register histogram
372  G4int id = RegisterToolsH2(h2d, name);
373 
374 #ifdef G4VERBOSE
375  if ( fState.GetVerboseL2() )
376  fState.GetVerboseL2()->Message("create", "H2", name);
377 #endif
378 
379  return id;
380 }
381 
382 //_____________________________________________________________________________
384  G4int nxbins, G4double xmin, G4double xmax,
385  G4int nybins, G4double ymin, G4double ymax,
386  const G4String& xunitName, const G4String& yunitName,
387  const G4String& xfcnName, const G4String& yfcnName,
388  const G4String& xbinSchemeName,
389  const G4String& ybinSchemeName)
390 {
391  tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2", false, false);
392  if ( ! h2d ) return false;
393 
394  G4HnInformation* info = fHnManager->GetHnInformation(id, "SetH2");
395 #ifdef G4VERBOSE
396  if ( fState.GetVerboseL4() )
397  fState.GetVerboseL4()->Message("configure", "H2", info->fName);
398 #endif
399 
400  // Configure tools h2
401  ConfigureToolsH2(
402  h2d, nxbins, xmin, xmax, nybins, ymin, ymax,
403  xunitName, yunitName, xfcnName, yfcnName, xbinSchemeName, ybinSchemeName);
404 
405  // Add annotation
406  AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
407 
408  // Update information
409  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
410  G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
411  UpdateH2Information(
412  info, xunitName, yunitName, xfcnName, yfcnName, xbinScheme, ybinScheme);
413 
414  // Set activation
415  fHnManager->SetActivation(id, true);
416 
417  return true;
418 }
419 
420 //_____________________________________________________________________________
422  const std::vector<G4double>& xedges,
423  const std::vector<G4double>& yedges,
424  const G4String& xunitName, const G4String& yunitName,
425  const G4String& xfcnName, const G4String& yfcnName)
426 {
427  tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2", false, false);
428  if ( ! h2d ) return false;
429 
430  G4HnInformation* info = fHnManager->GetHnInformation(id, "SetH2");
431 #ifdef G4VERBOSE
432  if ( fState.GetVerboseL4() )
433  fState.GetVerboseL4()->Message("configure", "H2", info->fName);
434 #endif
435 
436  // Configure tools h2
437  ConfigureToolsH2(h2d, xedges, yedges, xunitName, yunitName, xfcnName, yfcnName);
438 
439  // Add annotation
440  AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
441 
442  // Update information
443  UpdateH2Information(
444  info, xunitName, yunitName, xfcnName, yfcnName, kUserBinScheme, kUserBinScheme);
445 
446  // Set activation
447  fHnManager->SetActivation(id, true);
448 
449  return true;
450 }
451 
452 //_____________________________________________________________________________
454 {
455  tools::histo::h2d* h2d = GetH2InFunction(id, "ScaleH2", false, false);
456  if ( ! h2d ) return false;
457 
458  return h2d->scale(factor);
459 }
460 
461 //_____________________________________________________________________________
463  G4double xvalue, G4double yvalue,
464  G4double weight)
465 {
466  tools::histo::h2d* h2d = GetH2InFunction(id, "FillH2", true, false);
467  if ( ! h2d ) return false;
468 
469  if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(id) ) ) {
470  return false;
471  }
472 
473  G4HnInformation* info = fHnManager->GetHnInformation(id, "FillH2");
474  h2d->fill(info->fXFcn(xvalue/info->fXUnit),
475  info->fYFcn(yvalue/info->fYUnit), weight);
476 #ifdef G4VERBOSE
477  if ( fState.GetVerboseL4() ) {
478  G4ExceptionDescription description;
479  description << " id " << id
480  << " xvalue " << xvalue << " yvalue " << yvalue;
481  fState.GetVerboseL4()->Message("fill", "H2", description);
482  }
483 #endif
484  return true;
485 }
486 
487 //_____________________________________________________________________________
489 {
490  std::map<G4String, G4int>::const_iterator it = fH2NameIdMap.find(name);
491  if ( it == fH2NameIdMap.end() ) {
492  if ( warn) {
493  G4String inFunction = "G4H2ToolsManager::GetH2Id";
494  G4ExceptionDescription description;
495  description << " " << "histogram " << name << " does not exist.";
496  G4Exception(inFunction, "Analysis_W007", JustWarning, description);
497  }
498  return -1;
499  }
500  return it->second;
501 }
502 
503 //_____________________________________________________________________________
505 {
506  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2NXbins");
507  if ( ! h2d ) return 0;
508 
509  return h2d->axis_x().bins();
510 }
511 
512 //_____________________________________________________________________________
514 {
515 // Returns xmin value with applied unit and histogram function
516 
517  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Xmin");
518  if ( ! h2d ) return 0;
519 
520  return h2d->axis_x().lower_edge();
521 }
522 
523 //_____________________________________________________________________________
525 {
526  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Xmax");
527  if ( ! h2d ) return 0;
528 
529  return h2d->axis_x().upper_edge();
530 }
531 
532 //_____________________________________________________________________________
534 {
535  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2XWidth", true, false);
536  if ( ! h2d ) return 0;
537 
538  G4int nbins = h2d->axis_x().bins();
539  if ( ! nbins ) {
540  G4ExceptionDescription description;
541  description << " nbins = 0 (for h2 id = " << id << ").";
542  G4Exception("G4H2ToolsManager::GetH2Width",
543  "Analysis_W014", JustWarning, description);
544  return 0;
545  }
546 
547  return ( h2d->axis_x().upper_edge() - h2d->axis_x().lower_edge())/nbins;
548 }
549 
550 //_____________________________________________________________________________
552 {
553  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2NYbins");
554  if ( ! h2d ) return 0;
555 
556  return h2d->axis_y().bins();
557 }
558 
559 //_____________________________________________________________________________
561 {
562 // Returns xmin value with applied unit and histogram function
563 
564  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Ymin");
565  if ( ! h2d ) return 0;
566 
567  return h2d->axis_y().lower_edge();
568 }
569 
570 //_____________________________________________________________________________
572 {
573  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Ymax");
574  if ( ! h2d ) return 0;
575 
576  return h2d->axis_y().upper_edge();
577 }
578 
579 //_____________________________________________________________________________
581 {
582  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2YWidth", true, false);
583  if ( ! h2d ) return 0;
584 
585  G4int nbins = h2d->axis_y().bins();
586  if ( ! nbins ) {
587  G4ExceptionDescription description;
588  description << " nbins = 0 (for h2 id = " << id << ").";
589  G4Exception("G4H2ToolsManager::GetH2Width",
590  "Analysis_W014", JustWarning, description);
591  return 0;
592  }
593 
594  return ( h2d->axis_y().upper_edge() - h2d->axis_y().lower_edge())/nbins;
595 }
596 
597 //_____________________________________________________________________________
599 {
600  tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2Title");
601  if ( ! h2d ) return false;
602 
603  return h2d->set_title(title);
604 }
605 
606 //_____________________________________________________________________________
608 {
609  tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2XAxisTitle");
610  if ( ! h2d ) return false;
611 
612  h2d->add_annotation(tools::histo::key_axis_x_title(), title);
613  return true;
614 }
615 
616 //_____________________________________________________________________________
618 {
619  tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2YAxisTitle");
620  if ( ! h2d ) return false;
621 
622  h2d->add_annotation(tools::histo::key_axis_y_title(), title);
623  return true;
624 }
625 
626 //_____________________________________________________________________________
628 {
629  tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2ZAxisTitle");
630  if ( ! h2d ) return false;
631 
632  h2d->add_annotation(tools::histo::key_axis_z_title(), title);
633  return true;
634 }
635 
636 //_____________________________________________________________________________
638 {
639  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Title");
640  if ( ! h2d ) return "";
641 
642  return h2d->title();
643 }
644 
645 //_____________________________________________________________________________
647 {
648  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2XAxisTitle");
649  if ( ! h2d ) return "";
650 
651  G4String title;
652  G4bool result = h2d->annotation(tools::histo::key_axis_x_title(), title);
653  if ( ! result ) {
654  G4ExceptionDescription description;
655  description << " Failed to get x_axis title for h2 id = " << id << ").";
656  G4Exception("G4H2ToolsManager::GetH2XAxisTitle",
657  "Analysis_W014", JustWarning, description);
658  return "";
659  }
660 
661  return title;
662 }
663 
664 //_____________________________________________________________________________
666 {
667  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2YAxisTitle");
668  if ( ! h2d ) return "";
669 
670  G4String title;
671  G4bool result = h2d->annotation(tools::histo::key_axis_y_title(), title);
672  if ( ! result ) {
673  G4ExceptionDescription description;
674  description << " Failed to get y_axis title for h2 id = " << id << ").";
675  G4Exception("G4H2ToolsManager::GetH2YAxisTitle",
676  "Analysis_W014", JustWarning, description);
677  return "";
678  }
679 
680  return title;
681 }
682 
683 //_____________________________________________________________________________
685 {
686  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2ZAxisTitle");
687  if ( ! h2d ) return "";
688 
689  G4String title;
690  G4bool result = h2d->annotation(tools::histo::key_axis_z_title(), title);
691  if ( ! result ) {
692  G4ExceptionDescription description;
693  description << " Failed to get z_axis title for h2 id = " << id << ").";
694  G4Exception("G4H2ToolsManager::GetH2ZAxisTitle",
695  "Analysis_W014", JustWarning, description);
696  return "";
697  }
698 
699  return title;
700 }
701 
702 //_____________________________________________________________________________
703 G4bool G4H2ToolsManager::WriteOnAscii(std::ofstream& /*output*/)
704 {
705 // Write selected objects on ASCII file
706 // According to the implementation by Michel Maire, originally in
707 // extended examples.
708 // Not yet available for H2
709 
710  return ! fHnManager->IsAscii();
711 }
712 
713 //
714 // public methods
715 //
716 
717 //_____________________________________________________________________________
719  const std::vector<tools::histo::h2d*>& h2Vector)
720 {
721 #ifdef G4VERBOSE
722  if ( fState.GetVerboseL4() )
723  fState.GetVerboseL4()->Message("merge", "all h2", "");
724 #endif
725  std::vector<tools::histo::h2d*>::const_iterator itw = h2Vector.begin();
726  std::vector<tools::histo::h2d*>::iterator it;
727  for (it = fH2Vector.begin(); it != fH2Vector.end(); it++ ) {
728  (*it)->add(*(*itw++));
729  }
730 #ifdef G4VERBOSE
731  if ( fState.GetVerboseL1() )
732  fState.GetVerboseL1()->Message("merge", "all h2", "");
733 #endif
734 }
735 
736 //_____________________________________________________________________________
738 {
739 // Reset histograms and ntuple
740 
741  G4bool finalResult = true;
742 
743  std::vector<tools::histo::h2d*>::iterator it;
744  for (it = fH2Vector.begin(); it != fH2Vector.end(); it++ ) {
745  G4bool result = (*it)->reset();
746  if ( ! result ) finalResult = false;
747  }
748 
749  return finalResult;
750 }
751 
752 //_____________________________________________________________________________
754 {
755  return ! fH2Vector.size();
756 }
757 
758 //_____________________________________________________________________________
759 tools::histo::h2d* G4H2ToolsManager::GetH2(G4int id, G4bool warn,
760  G4bool onlyIfActive) const
761 {
762  return GetH2InFunction(id, "GetH2", warn, onlyIfActive);
763 }
764 
virtual G4int GetH2Nybins(G4int id) const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
G4bool IsAscii() const
Definition: G4HnManager.cc:114
G4HnManager * fHnManager
virtual G4String GetH2YAxisTitle(G4int id) const
virtual G4bool SetH2YAxisTitle(G4int id, const G4String &title)
virtual G4String GetH2XAxisTitle(G4int id) const
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
void AddH2Information(const G4String &name, const G4String &xunitName, const G4String &yunitName, const G4String &xfcnName, const G4String &yfcnName, G4BinScheme xbinScheme, G4BinScheme ybinScheme) const
virtual ~G4H2ToolsManager()
virtual G4double GetH2Ymax(G4int id) const
G4String name
Definition: TRTMaterials.hh:40
G4double(* G4Fcn)(G4double)
Definition: G4Fcn.hh:36
G4bool IsEmpty() const
virtual G4double GetH2Xmin(G4int id) const
virtual tools::histo::h2d * GetH2InFunction(G4int id, G4String function, G4bool warn=true, G4bool onlyIfActive=true) const
virtual G4int GetH2Nxbins(G4int id) const
virtual G4bool SetH2ZAxisTitle(G4int id, const G4String &title)
int G4int
Definition: G4Types.hh:78
G4int RegisterToolsH2(tools::histo::h2d *h2d, const G4String &name)
virtual G4String GetH2Title(G4int id) const
G4HnInformation * GetHnInformation(G4int id, G4String functionName="", G4bool warn=true) const
Definition: G4HnManager.cc:86
G4bool GetActivation(G4int id) const
Definition: G4HnManager.cc:209
const G4AnalysisVerbose * GetVerboseL2() const
void UpdateTitle(G4String &title, const G4String &unitName, const G4String &fcnName)
std::vector< tools::histo::h2d * > fH2Vector
void AddH2Vector(const std::vector< tools::histo::h2d * > &h2Vector)
virtual G4double GetH2YWidth(G4int id) const
virtual G4bool WriteOnAscii(std::ofstream &output)
const G4AnalysisVerbose * GetVerboseL4() const
bool G4bool
Definition: G4Types.hh:79
virtual G4bool SetH2(G4int id, G4int nxbins, G4double xmin, G4double xmax, G4int nybins, G4double ymin, G4double ymax, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &xbinScheme="linear", const G4String &ybinScheme="linear")
virtual G4bool SetH2XAxisTitle(G4int id, const G4String &title)
G4double GetUnitValue(const G4String &unit)
G4BinScheme fXBinScheme
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
tools::histo::h2d * GetH2(G4int id, G4bool warn=true, G4bool onlyIfActive=true) const
virtual G4String GetH2ZAxisTitle(G4int id) const
G4BinScheme fYBinScheme
G4Fcn GetFunction(const G4String &fcnName)
Definition: G4Fcn.cc:36
virtual G4double GetH2Ymin(G4int id) const
virtual G4int CreateH2(const G4String &name, const G4String &title, G4int nxbins, G4double xmin, G4double xmax, G4int nybins, G4double ymin, G4double ymax, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &xbinScheme="linear", const G4String &ybinScheme="linear")
virtual G4double GetH2Xmax(G4int id) const
virtual G4double GetH2XWidth(G4int id) const
G4BinScheme GetBinScheme(const G4String &binSchemeName)
Definition: G4BinScheme.cc:36
virtual G4int GetH2Id(const G4String &name, G4bool warn=true) const
#define G4endl
Definition: G4ios.hh:61
G4BinScheme
Definition: G4BinScheme.hh:40
void AddH2Information(const G4String &name, const G4String &xunitName, const G4String &yunitName, const G4String &xfcnName, const G4String &yfcnName, G4double xunit, G4double yunit, G4Fcn fx, G4Fcn fy, G4BinScheme xBinScheme, G4BinScheme yBinScheme)
Definition: G4HnManager.cc:70
std::map< G4String, G4int > fH2NameIdMap
double G4double
Definition: G4Types.hh:76
virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue, G4double weight=1.0)
virtual G4bool SetH2Title(G4int id, const G4String &title)
virtual G4bool ScaleH2(G4int id, G4double factor)
const G4AnalysisVerbose * GetVerboseL1() const
void SetActivation(G4bool activation)
Definition: G4HnManager.cc:140
const G4AnalysisManagerState & fState
G4H2ToolsManager(const G4AnalysisManagerState &state)