Geant4  10.00.p01
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& xfcnName,
110  const G4String& yfcnName,
111  const G4String& xbinSchemeName,
112  const G4String& ybinSchemeName)
113 {
114  G4Fcn xfcn = GetFunction(xfcnName);
115  G4Fcn yfcn = GetFunction(yfcnName);
116  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
117  G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
118 
119  if ( xbinScheme != kLogBinScheme && ybinScheme != kLogBinScheme) {
120  if ( xbinScheme == kUserBinScheme || ybinScheme == kUserBinScheme) {
121  // This should never happen, but let's make sure about it
122  // by issuing a warning
123  G4ExceptionDescription description;
124  description
125  << " User binning scheme setting was ignored." << G4endl
126  << " Linear binning will be applied with given (nbins, xmin, xmax) values";
127  G4Exception("G4H2ToolsManager::CreateH2",
128  "Analysis_W013", JustWarning, description);
129  }
130  return new tools::histo::h2d(title,
131  nxbins, xfcn(xmin), xfcn(xmax),
132  nybins, yfcn(ymin), yfcn(ymax));
133  // h2 objects are deleted in destructor and reset when
134  // closing a file.
135  }
136  else {
137  // Compute edges
138  std::vector<G4double> xedges;
139  ComputeEdges(nxbins, xmin, xmax, xfcn, xbinScheme, xedges);
140  std::vector<G4double> yedges;
141  ComputeEdges(nybins, ymin, ymax, yfcn, ybinScheme, yedges);
142  return new tools::histo::h2d(title, xedges, yedges);
143  }
144 }
145 
146 //_____________________________________________________________________________
147 tools::histo::h2d* CreateToolsH2(
148  const G4String& title,
149  const std::vector<G4double>& xedges,
150  const std::vector<G4double>& yedges,
151  const G4String& xfcnName,
152  const G4String& yfcnName)
153 {
154  G4Fcn xfcn = GetFunction(xfcnName);
155  G4Fcn yfcn = GetFunction(yfcnName);
156 
157  // Apply function
158  std::vector<G4double> xnewEdges;
159  ComputeEdges(xedges, xfcn, xnewEdges);
160  std::vector<G4double> ynewEdges;
161  ComputeEdges(yedges, yfcn, ynewEdges);
162 
163  return new tools::histo::h2d(title, xnewEdges, ynewEdges);
164  // h2 objects are deleted in destructor and reset when
165  // closing a file.
166 }
167 
168 //_____________________________________________________________________________
169 void ConfigureToolsH2(tools::histo::h2d* h2d,
170  G4int nxbins, G4double xmin, G4double xmax,
171  G4int nybins, G4double ymin, G4double ymax,
172  const G4String& xfcnName,
173  const G4String& yfcnName,
174  const G4String& xbinSchemeName,
175  const G4String& ybinSchemeName)
176 {
177  G4Fcn xfcn = GetFunction(xfcnName);
178  G4Fcn yfcn = GetFunction(yfcnName);
179  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
180  G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
181 
182  if ( xbinScheme != kLogBinScheme && ybinScheme != kLogBinScheme) {
183  if ( xbinScheme == kUserBinScheme || ybinScheme == kUserBinScheme) {
184  // This should never happen, but let's make sure about it
185  // by issuing a warning
186  G4ExceptionDescription description;
187  description
188  << " User binning scheme setting was ignored." << G4endl
189  << " Linear binning will be applied with given (nbins, xmin, xmax) values";
190  G4Exception("G4H2ToolsManager::CreateH2",
191  "Analysis_W013", JustWarning, description);
192  }
193  h2d->configure(nxbins, xfcn(xmin), xfcn(xmax),
194  nybins, yfcn(ymin), yfcn(ymax));
195  }
196  else {
197  // Compute bins
198  std::vector<G4double> xedges;
199  ComputeEdges(nxbins, xmin, xmax, xfcn, xbinScheme, xedges);
200  std::vector<G4double> yedges;
201  ComputeEdges(nybins, ymin, ymax, yfcn, ybinScheme, yedges);
202  h2d->configure(xedges, yedges);
203  }
204 }
205 
206 //_____________________________________________________________________________
207 void ConfigureToolsH2(tools::histo::h2d* h2d,
208  const std::vector<G4double>& xedges,
209  const std::vector<G4double>& yedges,
210  const G4String& xfcnName,
211  const G4String& yfcnName)
212 {
213  G4Fcn xfcn = GetFunction(xfcnName);
214  std::vector<G4double> xnewEdges;
215  ComputeEdges(xedges, xfcn, xnewEdges);
216 
217  G4Fcn yfcn = GetFunction(yfcnName);
218  std::vector<G4double> ynewEdges;
219  ComputeEdges(yedges, yfcn, ynewEdges);
220 
221  h2d->configure(xnewEdges, ynewEdges);
222 }
223 
224 }
225 
226 
227 //
228 // private methods
229 //
230 
231 //_____________________________________________________________________________
233  G4String functionName, G4bool warn,
234  G4bool onlyIfActive) const
235 {
236  G4int index = id - fFirstId;
237  if ( index < 0 || index >= G4int(fH2Vector.size()) ) {
238  if ( warn) {
239  G4String inFunction = "G4H2ToolsManager::";
240  inFunction += functionName;
241  G4ExceptionDescription description;
242  description << " " << "histogram " << id << " does not exist.";
243  G4Exception(inFunction, "Analysis_W007", JustWarning, description);
244  }
245  return 0;
246  }
247 
248  // Do not return histogram if inactive
249  if ( fState.GetIsActivation() && onlyIfActive &&
250  ( ! fHnManager->GetActivation(id) ) ) {
251  return 0;
252  }
253 
254  return fH2Vector[index];
255 }
256 
257 
258 //_____________________________________________________________________________
260  const G4String& xunitName,
261  const G4String& yunitName,
262  const G4String& xfcnName,
263  const G4String& yfcnName,
264  G4BinScheme xbinScheme,
265  G4BinScheme ybinScheme) const
266 {
267  G4double xunit = GetUnitValue(xunitName);
268  G4double yunit = GetUnitValue(yunitName);
269  G4Fcn xfcn = GetFunction(xfcnName);
270  G4Fcn yfcn = GetFunction(yfcnName);
271  fHnManager
272  ->AddH2Information(name, xunitName, yunitName, xfcnName, yfcnName,
273  xunit, yunit, xfcn, yfcn,
274  xbinScheme, ybinScheme);
275 }
276 
277 //_____________________________________________________________________________
278 G4int G4H2ToolsManager::RegisterToolsH2(tools::histo::h2d* h2d,
279  const G4String& name)
280 {
281  G4int index = fH2Vector.size();
282  fH2Vector.push_back(h2d);
283 
284  fLockFirstId = true;
285  fH2NameIdMap[name] = index + fFirstId;
286  return index + fFirstId;
287 }
288 
289 //
290 // protected methods
291 //
292 
293 //_____________________________________________________________________________
295  G4int nxbins, G4double xmin, G4double xmax,
296  G4int nybins, G4double ymin, G4double ymax,
297  const G4String& xunitName, const G4String& yunitName,
298  const G4String& xfcnName, const G4String& yfcnName,
299  const G4String& xbinSchemeName,
300  const G4String& ybinSchemeName)
301 
302 {
303 #ifdef G4VERBOSE
304  if ( fState.GetVerboseL4() )
305  fState.GetVerboseL4()->Message("create", "H2", name);
306 #endif
307  tools::histo::h2d* h2d
308  = CreateToolsH2(title, nxbins, xmin, xmax, nybins, ymin, ymax,
309  xfcnName, yfcnName, xbinSchemeName, ybinSchemeName);
310 
311  // Add annotation
312  AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
313 
314  // Save H2 information
315  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
316  G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
318  name, xunitName, yunitName, xfcnName, yfcnName, xbinScheme, ybinScheme);
319 
320  // Register histogram
321  G4int id = RegisterToolsH2(h2d, name);
322 
323 #ifdef G4VERBOSE
324  if ( fState.GetVerboseL2() )
325  fState.GetVerboseL2()->Message("create", "H2", name);
326 #endif
327 
328  return id;
329 }
330 
331 //_____________________________________________________________________________
333  const std::vector<G4double>& xedges,
334  const std::vector<G4double>& yedges,
335  const G4String& xunitName, const G4String& yunitName,
336  const G4String& xfcnName, const G4String& yfcnName)
337 
338 {
339 #ifdef G4VERBOSE
340  if ( fState.GetVerboseL4() )
341  fState.GetVerboseL4()->Message("create", "H2", name);
342 #endif
343  tools::histo::h2d* h2d
344  = CreateToolsH2(title, xedges, yedges, xfcnName, yfcnName);
345 
346  // Add annotation
347  AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
348 
349  // Save H2 information
351  name, xunitName, yunitName, xfcnName, yfcnName, kUserBinScheme, kUserBinScheme);
352 
353  // Register histogram
354  G4int id = RegisterToolsH2(h2d, name);
355 
356 #ifdef G4VERBOSE
357  if ( fState.GetVerboseL2() )
358  fState.GetVerboseL2()->Message("create", "H2", name);
359 #endif
360 
361  return id;
362 }
363 
364 //_____________________________________________________________________________
366  G4int nxbins, G4double xmin, G4double xmax,
367  G4int nybins, G4double ymin, G4double ymax,
368  const G4String& xunitName, const G4String& yunitName,
369  const G4String& xfcnName, const G4String& yfcnName,
370  const G4String& xbinSchemeName,
371  const G4String& ybinSchemeName)
372 {
373  tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2", false, false);
374  if ( ! h2d ) return false;
375 
376  G4HnInformation* info = fHnManager->GetHnInformation(id, "SetH2");
377 #ifdef G4VERBOSE
378  if ( fState.GetVerboseL4() )
379  fState.GetVerboseL4()->Message("configure", "H2", info->fName);
380 #endif
381 
382  // Configure tools h2
383  ConfigureToolsH2(
384  h2d, nxbins, xmin, xmax, nybins, ymin, ymax, xfcnName, yfcnName,
385  xbinSchemeName, xbinSchemeName);
386 
387  // Add annotation
388  AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
389 
390  // Update information
391  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
392  G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
393  UpdateH2Information(
394  info, xunitName, yunitName, xfcnName, yfcnName, xbinScheme, ybinScheme);
395 
396  // Set activation
397  fHnManager->SetActivation(id, true);
398 
399  return true;
400 }
401 
402 //_____________________________________________________________________________
404  const std::vector<G4double>& xedges,
405  const std::vector<G4double>& yedges,
406  const G4String& xunitName, const G4String& yunitName,
407  const G4String& xfcnName, const G4String& yfcnName)
408 {
409  tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2", false, false);
410  if ( ! h2d ) return false;
411 
412  G4HnInformation* info = fHnManager->GetHnInformation(id, "SetH2");
413 #ifdef G4VERBOSE
414  if ( fState.GetVerboseL4() )
415  fState.GetVerboseL4()->Message("configure", "H2", info->fName);
416 #endif
417 
418  // Configure tools h2
419  ConfigureToolsH2(h2d, xedges, yedges, xfcnName, yfcnName);
420 
421  // Add annotation
422  AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
423 
424  // Update information
425  UpdateH2Information(
426  info, xunitName, yunitName, xfcnName, yfcnName, kUserBinScheme, kUserBinScheme);
427 
428  // Set activation
429  fHnManager->SetActivation(id, true);
430 
431  return true;
432 }
433 
434 //_____________________________________________________________________________
436 {
437  tools::histo::h2d* h2d = GetH2InFunction(id, "ScaleH2", false, false);
438  if ( ! h2d ) return false;
439 
440  return h2d->scale(factor);
441 }
442 
443 //_____________________________________________________________________________
445  G4double xvalue, G4double yvalue,
446  G4double weight)
447 {
448  tools::histo::h2d* h2d = GetH2InFunction(id, "FillH2", true, false);
449  if ( ! h2d ) return false;
450 
451  if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(id) ) ) {
452  return false;
453  }
454 
455  G4HnInformation* info = fHnManager->GetHnInformation(id, "FillH2");
456  h2d->fill(info->fXFcn(xvalue/info->fXUnit),
457  info->fYFcn(yvalue/info->fYUnit), weight);
458 #ifdef G4VERBOSE
459  if ( fState.GetVerboseL4() ) {
460  G4ExceptionDescription description;
461  description << " id " << id
462  << " xvalue " << xvalue << " yvalue " << yvalue;
463  fState.GetVerboseL4()->Message("fill", "H2", description);
464  }
465 #endif
466  return true;
467 }
468 
469 //_____________________________________________________________________________
471 {
472  std::map<G4String, G4int>::const_iterator it = fH2NameIdMap.find(name);
473  if ( it == fH2NameIdMap.end() ) {
474  if ( warn) {
475  G4String inFunction = "G4H2ToolsManager::GetH2Id";
476  G4ExceptionDescription description;
477  description << " " << "histogram " << name << " does not exist.";
478  G4Exception(inFunction, "Analysis_W007", JustWarning, description);
479  }
480  return -1;
481  }
482  return it->second;
483 }
484 
485 //_____________________________________________________________________________
487 {
488  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2NXbins");
489  if ( ! h2d ) return 0;
490 
491  return h2d->axis_x().bins();
492 }
493 
494 //_____________________________________________________________________________
496 {
497 // Returns xmin value with applied unit and histogram function
498 
499  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Xmin");
500  if ( ! h2d ) return 0;
501 
502  G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2Xmin");
503  return info->fXFcn(h2d->axis_x().lower_edge()*info->fXUnit);
504 }
505 
506 //_____________________________________________________________________________
508 {
509  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Xmax");
510  if ( ! h2d ) return 0;
511 
512  G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2Xmax");
513  return info->fXFcn(h2d->axis_x().upper_edge()*info->fXUnit);
514 }
515 
516 //_____________________________________________________________________________
518 {
519  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2XWidth", true, false);
520  if ( ! h2d ) return 0;
521 
522  G4int nbins = h2d->axis_x().bins();
523  if ( ! nbins ) {
524  G4ExceptionDescription description;
525  description << " nbins = 0 (for h2 id = " << id << ").";
526  G4Exception("G4H2ToolsManager::GetH2Width",
527  "Analysis_W014", JustWarning, description);
528  return 0;
529  }
530 
531  G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2XWidth");
532  return ( info->fXFcn(h2d->axis_x().upper_edge())
533  - info->fXFcn(h2d->axis_x().lower_edge()))*info->fXUnit/nbins;
534 }
535 
536 //_____________________________________________________________________________
538 {
539  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2NYbins");
540  if ( ! h2d ) return 0;
541 
542  return h2d->axis_y().bins();
543 }
544 
545 //_____________________________________________________________________________
547 {
548 // Returns xmin value with applied unit and histogram function
549 
550  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Ymin");
551  if ( ! h2d ) return 0;
552 
553  G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2Ymin");
554  return info->fYFcn(h2d->axis_y().lower_edge()*info->fYUnit);
555 }
556 
557 //_____________________________________________________________________________
559 {
560  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Ymax");
561  if ( ! h2d ) return 0;
562 
563  G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2Ymax");
564  return info->fYFcn(h2d->axis_y().upper_edge()*info->fYUnit);
565 }
566 
567 //_____________________________________________________________________________
569 {
570  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2YWidth", true, false);
571  if ( ! h2d ) return 0;
572 
573  G4int nbins = h2d->axis_y().bins();
574  if ( ! nbins ) {
575  G4ExceptionDescription description;
576  description << " nbins = 0 (for h2 id = " << id << ").";
577  G4Exception("G4H2ToolsManager::GetH2Width",
578  "Analysis_W014", JustWarning, description);
579  return 0;
580  }
581 
582  G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2YWidth");
583  return ( info->fYFcn(h2d->axis_y().upper_edge())
584  - info->fYFcn(h2d->axis_y().lower_edge()))*info->fYUnit/nbins;
585 }
586 
587 //_____________________________________________________________________________
589 {
590  tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2Title");
591  if ( ! h2d ) return false;
592 
593  return h2d->set_title(title);
594 }
595 
596 //_____________________________________________________________________________
598 {
599  tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2XAxisTitle");
600  if ( ! h2d ) return false;
601 
602  h2d->add_annotation(tools::histo::key_axis_x_title(), title);
603  return true;
604 }
605 
606 //_____________________________________________________________________________
608 {
609  tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2YAxisTitle");
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, "SetH2ZAxisTitle");
620  if ( ! h2d ) return false;
621 
622  h2d->add_annotation(tools::histo::key_axis_z_title(), title);
623  return true;
624 }
625 
626 //_____________________________________________________________________________
628 {
629  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Title");
630  if ( ! h2d ) return "";
631 
632  return h2d->title();
633 }
634 
635 //_____________________________________________________________________________
637 {
638  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2XAxisTitle");
639  if ( ! h2d ) return "";
640 
641  G4String title;
642  G4bool result = h2d->annotation(tools::histo::key_axis_x_title(), title);
643  if ( ! result ) {
644  G4ExceptionDescription description;
645  description << " Failed to get x_axis title for h2 id = " << id << ").";
646  G4Exception("G4H2ToolsManager::GetH2XAxisTitle",
647  "Analysis_W014", JustWarning, description);
648  return "";
649  }
650 
651  return title;
652 }
653 
654 //_____________________________________________________________________________
656 {
657  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2YAxisTitle");
658  if ( ! h2d ) return "";
659 
660  G4String title;
661  G4bool result = h2d->annotation(tools::histo::key_axis_y_title(), title);
662  if ( ! result ) {
663  G4ExceptionDescription description;
664  description << " Failed to get y_axis title for h2 id = " << id << ").";
665  G4Exception("G4H2ToolsManager::GetH2YAxisTitle",
666  "Analysis_W014", JustWarning, description);
667  return "";
668  }
669 
670  return title;
671 }
672 
673 //_____________________________________________________________________________
675 {
676  tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2ZAxisTitle");
677  if ( ! h2d ) return "";
678 
679  G4String title;
680  G4bool result = h2d->annotation(tools::histo::key_axis_z_title(), title);
681  if ( ! result ) {
682  G4ExceptionDescription description;
683  description << " Failed to get z_axis title for h2 id = " << id << ").";
684  G4Exception("G4H2ToolsManager::GetH2ZAxisTitle",
685  "Analysis_W014", JustWarning, description);
686  return "";
687  }
688 
689  return title;
690 }
691 
692 //_____________________________________________________________________________
693 G4bool G4H2ToolsManager::WriteOnAscii(std::ofstream& /*output*/)
694 {
695 // Write selected objects on ASCII file
696 // According to the implementation by Michel Maire, originally in
697 // extended examples.
698 // Not yet available for H2
699 
700  return false;
701 }
702 
703 //
704 // public methods
705 //
706 
707 //_____________________________________________________________________________
709  const std::vector<tools::histo::h2d*>& h2Vector)
710 {
711 #ifdef G4VERBOSE
712  if ( fState.GetVerboseL4() )
713  fState.GetVerboseL4()->Message("merge", "all h2", "");
714 #endif
715  std::vector<tools::histo::h2d*>::const_iterator itw = h2Vector.begin();
716  std::vector<tools::histo::h2d*>::iterator it;
717  for (it = fH2Vector.begin(); it != fH2Vector.end(); it++ ) {
718  (*it)->add(*(*itw++));
719  }
720 #ifdef G4VERBOSE
721  if ( fState.GetVerboseL1() )
722  fState.GetVerboseL1()->Message("merge", "all h2", "");
723 #endif
724 }
725 
726 //_____________________________________________________________________________
728 {
729 // Reset histograms and ntuple
730 
731  G4bool finalResult = true;
732 
733  std::vector<tools::histo::h2d*>::iterator it;
734  for (it = fH2Vector.begin(); it != fH2Vector.end(); it++ ) {
735  G4bool result = (*it)->reset();
736  if ( ! result ) finalResult = false;
737  }
738 
739  return finalResult;
740 }
741 
742 //_____________________________________________________________________________
744 {
745  return ! fH2Vector.size();
746 }
747 
748 //_____________________________________________________________________________
749 tools::histo::h2d* G4H2ToolsManager::GetH2(G4int id, G4bool warn,
750  G4bool onlyIfActive) const
751 {
752  return GetH2InFunction(id, "GetH2", warn, onlyIfActive);
753 }
754 
virtual G4int GetH2Nybins(G4int id) const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
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 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
void ComputeEdges(G4int nbins, G4double xmin, G4double xmax, G4Fcn fcn, G4BinScheme, std::vector< G4double > &edges)
Definition: G4BinScheme.cc:56
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)