Geant4  10.01
G4H3ToolsManager.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 
28 // Author: Ivana Hrivnacova, 24/07/2014 (ivana@ipno.in2p3.fr)
29 
30 #include "G4H3ToolsManager.hh"
31 #include "G4HnManager.hh"
33 #include "G4AnalysisUtilities.hh"
34 
35 #include "tools/histo/h3d"
36 
37 #include <fstream>
38 
39 using namespace G4Analysis;
40 
41 //_____________________________________________________________________________
43  : G4VH3Manager(state),
44  fBaseToolsManager("H3"),
45  fH3Vector(),
46  fH3NameIdMap()
47 {
48 }
49 
50 //_____________________________________________________________________________
52 {
53  std::vector<tools::histo::h3d*>::iterator it;
54  for (it = fH3Vector.begin(); it != fH3Vector.end(); it++ ) {
55  delete (*it);
56  }
57 }
58 
59 //
60 // Utility functions
61 //
62 
63 namespace {
64 
65 //_____________________________________________________________________________
66 void UpdateH3Information(G4HnInformation* hnInformation,
67  const G4String& xunitName,
68  const G4String& yunitName,
69  const G4String& zunitName,
70  const G4String& xfcnName,
71  const G4String& yfcnName,
72  const G4String& zfcnName,
73  G4BinScheme xbinScheme,
74  G4BinScheme ybinScheme,
75  G4BinScheme zbinScheme)
76 {
77  G4double xunit = GetUnitValue(xunitName);
78  G4double yunit = GetUnitValue(yunitName);
79  G4double zunit = GetUnitValue(zunitName);
80  G4Fcn xfcn = GetFunction(xfcnName);
81  G4Fcn yfcn = GetFunction(yfcnName);
82  G4Fcn zfcn = GetFunction(zfcnName);
83 
84  G4HnDimensionInformation* xInformation
86  xInformation->fUnitName = xunitName;
87  xInformation->fFcnName = xfcnName;
88  xInformation->fUnit = xunit;
89  xInformation->fFcn = xfcn;
90  xInformation->fBinScheme = xbinScheme;
91 
92  G4HnDimensionInformation* yInformation
94  yInformation->fUnitName = yunitName;
95  yInformation->fFcnName = yfcnName;
96  yInformation->fUnit = yunit;
97  yInformation->fFcn = yfcn;
98  yInformation->fBinScheme = ybinScheme;
99 
100  G4HnDimensionInformation* zInformation
102  zInformation->fUnitName = zunitName;
103  zInformation->fFcnName = zfcnName;
104  zInformation->fUnit = zunit;
105  zInformation->fFcn = zfcn;
106  zInformation->fBinScheme = zbinScheme;
107 }
108 
109 //_____________________________________________________________________________
110 void AddH3Annotation(tools::histo::h3d* h3d,
111  const G4String& xunitName,
112  const G4String& yunitName,
113  const G4String& zunitName,
114  const G4String& xfcnName,
115  const G4String& yfcnName,
116  const G4String& zfcnName)
117 {
118  G4String xaxisTitle;
119  G4String yaxisTitle;
120  G4String zaxisTitle;
121  UpdateTitle(xaxisTitle, xunitName, xfcnName);
122  UpdateTitle(yaxisTitle, yunitName, yfcnName);
123  UpdateTitle(zaxisTitle, zunitName, zfcnName);
124  h3d->add_annotation(tools::histo::key_axis_x_title(), xaxisTitle);
125  h3d->add_annotation(tools::histo::key_axis_y_title(), yaxisTitle);
126  h3d->add_annotation(tools::histo::key_axis_z_title(), zaxisTitle);
127 }
128 
129 //_____________________________________________________________________________
130 tools::histo::h3d* CreateToolsH3(
131  const G4String& title,
132  G4int nxbins, G4double xmin, G4double xmax,
133  G4int nybins, G4double ymin, G4double ymax,
134  G4int nzbins, G4double zmin, G4double zmax,
135  const G4String& xunitName,
136  const G4String& yunitName,
137  const G4String& zunitName,
138  const G4String& xfcnName,
139  const G4String& zfcnName,
140  const G4String& yfcnName,
141  const G4String& xbinSchemeName,
142  const G4String& ybinSchemeName,
143  const G4String& zbinSchemeName)
144 {
145  G4double xunit = GetUnitValue(xunitName);
146  G4double yunit = GetUnitValue(yunitName);
147  G4double zunit = GetUnitValue(zunitName);
148  G4Fcn xfcn = GetFunction(xfcnName);
149  G4Fcn yfcn = GetFunction(yfcnName);
150  G4Fcn zfcn = GetFunction(zfcnName);
151  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
152  G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
153  G4BinScheme zbinScheme = GetBinScheme(zbinSchemeName);
154 
155  if ( xbinScheme != kLogBinScheme && ybinScheme != kLogBinScheme && zbinScheme != kLogBinScheme) {
156  if ( xbinScheme == kUserBinScheme || ybinScheme == kUserBinScheme || zbinScheme == kUserBinScheme) {
157  // This should never happen, but let's make sure about it
158  // by issuing a warning
159  G4ExceptionDescription description;
160  description
161  << " User binning scheme setting was ignored." << G4endl
162  << " Linear binning will be applied with given (nbins, xmin, xmax) values";
163  G4Exception("G4H3ToolsManager::CreateH3",
164  "Analysis_W013", JustWarning, description);
165  }
166  return new tools::histo::h3d(title,
167  nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
168  nybins, yfcn(ymin/yunit), yfcn(ymax/yunit),
169  nzbins, zfcn(zmin/zunit), zfcn(zmax/zunit));
170  // h3 objects are deleted in destructor and reset when
171  // closing a file.
172  }
173  else {
174  // Compute edges
175  std::vector<G4double> xedges;
176  ComputeEdges(nxbins, xmin, xmax, xunit, xfcn, xbinScheme, xedges);
177  std::vector<G4double> yedges;
178  ComputeEdges(nybins, ymin, ymax, yunit, yfcn, ybinScheme, yedges);
179  std::vector<G4double> zedges;
180  ComputeEdges(nzbins, zmin, zmax, zunit, zfcn, zbinScheme, zedges);
181  return new tools::histo::h3d(title, xedges, yedges, zedges);
182  }
183 }
184 
185 //_____________________________________________________________________________
186 tools::histo::h3d* CreateToolsH3(
187  const G4String& title,
188  const std::vector<G4double>& xedges,
189  const std::vector<G4double>& yedges,
190  const std::vector<G4double>& zedges,
191  const G4String& xunitName,
192  const G4String& yunitName,
193  const G4String& zunitName,
194  const G4String& xfcnName,
195  const G4String& yfcnName,
196  const G4String& zfcnName)
197 {
198  G4double xunit = GetUnitValue(xunitName);
199  G4double yunit = GetUnitValue(yunitName);
200  G4double zunit = GetUnitValue(zunitName);
201  G4Fcn xfcn = GetFunction(xfcnName);
202  G4Fcn yfcn = GetFunction(yfcnName);
203  G4Fcn zfcn = GetFunction(zfcnName);
204 
205  // Apply function
206  std::vector<G4double> xnewEdges;
207  ComputeEdges(xedges, xunit, xfcn, xnewEdges);
208  std::vector<G4double> ynewEdges;
209  ComputeEdges(yedges, yunit, yfcn, ynewEdges);
210  std::vector<G4double> znewEdges;
211  ComputeEdges(zedges, zunit, zfcn, znewEdges);
212 
213  return new tools::histo::h3d(title, xnewEdges, ynewEdges, znewEdges);
214  // h3 objects are deleted in destructor and reset when
215  // closing a file.
216 }
217 
218 //_____________________________________________________________________________
219 void ConfigureToolsH3(tools::histo::h3d* h3d,
220  G4int nxbins, G4double xmin, G4double xmax,
221  G4int nybins, G4double ymin, G4double ymax,
222  G4int nzbins, G4double zmin, G4double zmax,
223  const G4String& xunitName,
224  const G4String& yunitName,
225  const G4String& zunitName,
226  const G4String& xfcnName,
227  const G4String& yfcnName,
228  const G4String& zfcnName,
229  const G4String& xbinSchemeName,
230  const G4String& ybinSchemeName,
231  const G4String& zbinSchemeName)
232 {
233  G4double xunit = GetUnitValue(xunitName);
234  G4double yunit = GetUnitValue(yunitName);
235  G4double zunit = GetUnitValue(zunitName);
236  G4Fcn xfcn = GetFunction(xfcnName);
237  G4Fcn yfcn = GetFunction(yfcnName);
238  G4Fcn zfcn = GetFunction(zfcnName);
239  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
240  G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
241  G4BinScheme zbinScheme = GetBinScheme(zbinSchemeName);
242 
243  if ( xbinScheme != kLogBinScheme && ybinScheme != kLogBinScheme && zbinScheme != kLogBinScheme) {
244  if ( xbinScheme == kUserBinScheme || ybinScheme == kUserBinScheme || zbinScheme == kUserBinScheme) {
245  // This should never happen, but let's make sure about it
246  // by issuing a warning
247  G4ExceptionDescription description;
248  description
249  << " User binning scheme setting was ignored." << G4endl
250  << " Linear binning will be applied with given (nbins, xmin, xmax) values";
251  G4Exception("G4H3ToolsManager::CreateH3",
252  "Analysis_W013", JustWarning, description);
253  }
254  h3d->configure(nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
255  nybins, yfcn(ymin/yunit), yfcn(ymax/yunit),
256  nzbins, zfcn(zmin/zunit), zfcn(zmax/zunit));
257  }
258  else {
259  // Compute bins
260  std::vector<G4double> xedges;
261  ComputeEdges(nxbins, xmin, xmax, xunit, xfcn, xbinScheme, xedges);
262  std::vector<G4double> yedges;
263  ComputeEdges(nybins, ymin, ymax, yunit, yfcn, ybinScheme, yedges);
264  std::vector<G4double> zedges;
265  ComputeEdges(nzbins, zmin, zmax, zunit, zfcn, zbinScheme, zedges);
266  h3d->configure(xedges, yedges, zedges);
267  }
268 }
269 
270 //_____________________________________________________________________________
271 void ConfigureToolsH3(tools::histo::h3d* h3d,
272  const std::vector<G4double>& xedges,
273  const std::vector<G4double>& yedges,
274  const std::vector<G4double>& zedges,
275  const G4String& xunitName,
276  const G4String& yunitName,
277  const G4String& zunitName,
278  const G4String& xfcnName,
279  const G4String& yfcnName,
280  const G4String& zfcnName)
281 {
282  G4double xunit = GetUnitValue(xunitName);
283  G4Fcn xfcn = GetFunction(xfcnName);
284  std::vector<G4double> xnewEdges;
285  ComputeEdges(xedges, xunit, xfcn, xnewEdges);
286 
287  G4double yunit = GetUnitValue(yunitName);
288  G4Fcn yfcn = GetFunction(yfcnName);
289  std::vector<G4double> ynewEdges;
290  ComputeEdges(yedges, yunit, yfcn, ynewEdges);
291 
292  G4double zunit = GetUnitValue(zunitName);
293  G4Fcn zfcn = GetFunction(zfcnName);
294  std::vector<G4double> znewEdges;
295  ComputeEdges(zedges, zunit, zfcn, znewEdges);
296 
297  h3d->configure(xnewEdges, ynewEdges, znewEdges);
298 }
299 
300 }
301 
302 
303 //
304 // private methods
305 //
306 
307 //_____________________________________________________________________________
309  G4String functionName, G4bool warn,
310  G4bool onlyIfActive) const
311 {
312  G4int index = id - fFirstId;
313  if ( index < 0 || index >= G4int(fH3Vector.size()) ) {
314  if ( warn) {
315  G4String inFunction = "G4H3ToolsManager::";
316  inFunction += functionName;
317  G4ExceptionDescription description;
318  description << " " << "histogram " << id << " does not exist.";
319  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
320  }
321  return 0;
322  }
323 
324  // Do not return histogram if inactive
325  if ( fState.GetIsActivation() && onlyIfActive &&
326  ( ! fHnManager->GetActivation(id) ) ) {
327  return 0;
328  }
329 
330  return fH3Vector[index];
331 }
332 
333 
334 //_____________________________________________________________________________
336  const G4String& xunitName,
337  const G4String& yunitName,
338  const G4String& zunitName,
339  const G4String& xfcnName,
340  const G4String& yfcnName,
341  const G4String& zfcnName,
342  G4BinScheme xbinScheme,
343  G4BinScheme ybinScheme,
344  G4BinScheme zbinScheme) const
345 {
346  G4double xunit = GetUnitValue(xunitName);
347  G4double yunit = GetUnitValue(yunitName);
348  G4double zunit = GetUnitValue(zunitName);
349  G4Fcn xfcn = GetFunction(xfcnName);
350  G4Fcn yfcn = GetFunction(yfcnName);
351  G4Fcn zfcn = GetFunction(zfcnName);
352  fHnManager
353  ->AddH3Information(name, xunitName, yunitName, zunitName,
354  xfcnName, yfcnName, zfcnName,
355  xunit, yunit, zunit, xfcn, yfcn, zfcn,
356  xbinScheme, ybinScheme, zbinScheme);
357 }
358 
359 //_____________________________________________________________________________
360 G4int G4H3ToolsManager::RegisterToolsH3(tools::histo::h3d* h3d,
361  const G4String& name)
362 {
363  G4int index = fH3Vector.size();
364  fH3Vector.push_back(h3d);
365 
366  fLockFirstId = true;
367  fH3NameIdMap[name] = index + fFirstId;
368  return index + fFirstId;
369 }
370 
371 //
372 // protected methods
373 //
374 
375 //_____________________________________________________________________________
377  G4int nxbins, G4double xmin, G4double xmax,
378  G4int nybins, G4double ymin, G4double ymax,
379  G4int nzbins, G4double zmin, G4double zmax,
380  const G4String& xunitName, const G4String& yunitName,
381  const G4String& zunitName,
382  const G4String& xfcnName, const G4String& yfcnName,
383  const G4String& zfcnName,
384  const G4String& xbinSchemeName,
385  const G4String& ybinSchemeName,
386  const G4String& zbinSchemeName)
387 
388 {
389 #ifdef G4VERBOSE
390  if ( fState.GetVerboseL4() )
391  fState.GetVerboseL4()->Message("create", "H3", name);
392 #endif
393  tools::histo::h3d* h3d
394  = CreateToolsH3(title,
395  nxbins, xmin, xmax, nybins, ymin, ymax, nzbins, zmin, zmax,
396  xunitName, yunitName, zunitName,
397  xfcnName, yfcnName, zfcnName,
398  xbinSchemeName, ybinSchemeName, zbinSchemeName);
399 
400  // Add annotation
401  AddH3Annotation(h3d, xunitName, yunitName, zunitName,
402  xfcnName, yfcnName, zfcnName);
403 
404  // Save H3 information
405  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
406  G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
407  G4BinScheme zbinScheme = GetBinScheme(zbinSchemeName);
409  name, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
410  xbinScheme, ybinScheme, zbinScheme);
411 
412  // Register histogram
413  G4int id = RegisterToolsH3(h3d, name);
414 
415 #ifdef G4VERBOSE
416  if ( fState.GetVerboseL2() )
417  fState.GetVerboseL2()->Message("create", "H3", name);
418 #endif
419 
420  return id;
421 }
422 
423 //_____________________________________________________________________________
425  const std::vector<G4double>& xedges,
426  const std::vector<G4double>& yedges,
427  const std::vector<G4double>& zedges,
428  const G4String& xunitName, const G4String& yunitName,
429  const G4String& zunitName,
430  const G4String& xfcnName, const G4String& yfcnName,
431  const G4String& zfcnName)
432 
433 {
434 #ifdef G4VERBOSE
435  if ( fState.GetVerboseL4() )
436  fState.GetVerboseL4()->Message("create", "H3", name);
437 #endif
438  tools::histo::h3d* h3d
439  = CreateToolsH3(title, xedges, yedges, zedges,
440  xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName);
441 
442  // Add annotation
443  AddH3Annotation(h3d, xunitName, yunitName, zunitName,
444  xfcnName, yfcnName, zfcnName);
445 
446  // Save H3 information
448  name, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
450 
451  // Register histogram
452  G4int id = RegisterToolsH3(h3d, name);
453 
454 #ifdef G4VERBOSE
455  if ( fState.GetVerboseL2() )
456  fState.GetVerboseL2()->Message("create", "H3", name);
457 #endif
458 
459  return id;
460 }
461 
462 //_____________________________________________________________________________
464  G4int nxbins, G4double xmin, G4double xmax,
465  G4int nybins, G4double ymin, G4double ymax,
466  G4int nzbins, G4double zmin, G4double zmax,
467  const G4String& xunitName, const G4String& yunitName,
468  const G4String& zunitName,
469  const G4String& xfcnName, const G4String& yfcnName,
470  const G4String& zfcnName,
471  const G4String& xbinSchemeName,
472  const G4String& ybinSchemeName,
473  const G4String& zbinSchemeName)
474 {
475  tools::histo::h3d* h3d = GetH3InFunction(id, "SetH3", false, false);
476  if ( ! h3d ) return false;
477 
478  G4HnInformation* info = fHnManager->GetHnInformation(id, "SetH3");
479 #ifdef G4VERBOSE
480  if ( fState.GetVerboseL4() )
481  fState.GetVerboseL4()->Message("configure", "H3", info->GetName());
482 #endif
483 
484  // Configure tools h3
485  ConfigureToolsH3(
486  h3d, nxbins, xmin, xmax, nybins, ymin, ymax, nzbins, zmin, zmax,
487  xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
488  xbinSchemeName, ybinSchemeName, zbinSchemeName);
489 
490  // Add annotation
491  AddH3Annotation(h3d, xunitName, yunitName, zunitName,
492  xfcnName, yfcnName, zfcnName);
493 
494  // Update information
495  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
496  G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
497  G4BinScheme zbinScheme = GetBinScheme(zbinSchemeName);
498  UpdateH3Information(
499  info, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
500  xbinScheme, ybinScheme, zbinScheme);
501 
502  // Set activation
503  fHnManager->SetActivation(id, true);
504 
505  return true;
506 }
507 
508 //_____________________________________________________________________________
510  const std::vector<G4double>& xedges,
511  const std::vector<G4double>& yedges,
512  const std::vector<G4double>& zedges,
513  const G4String& xunitName, const G4String& yunitName,
514  const G4String& zunitName,
515  const G4String& xfcnName, const G4String& yfcnName,
516  const G4String& zfcnName)
517 {
518  tools::histo::h3d* h3d = GetH3InFunction(id, "SetH3", false, false);
519  if ( ! h3d ) return false;
520 
521  G4HnInformation* info = fHnManager->GetHnInformation(id, "SetH3");
522 #ifdef G4VERBOSE
523  if ( fState.GetVerboseL4() )
524  fState.GetVerboseL4()->Message("configure", "H3", info->GetName());
525 #endif
526 
527  // Configure tools h3
528  ConfigureToolsH3(h3d, xedges, yedges, zedges,
529  xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName);
530 
531  // Add annotation
532  AddH3Annotation(h3d, xunitName, yunitName, zunitName,
533  xfcnName, yfcnName, zfcnName);
534 
535  // Update information
536  UpdateH3Information(
537  info, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
539 
540  // Set activation
541  fHnManager->SetActivation(id, true);
542 
543  return true;
544 }
545 
546 //_____________________________________________________________________________
548 {
549  tools::histo::h3d* h3d = GetH3InFunction(id, "ScaleH3", false, false);
550  if ( ! h3d ) return false;
551 
552  return h3d->scale(factor);
553 }
554 
555 //_____________________________________________________________________________
557  G4double xvalue, G4double yvalue, G4double zvalue,
558  G4double weight)
559 {
560  tools::histo::h3d* h3d = GetH3InFunction(id, "FillH3", true, false);
561  if ( ! h3d ) return false;
562 
563  if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(id) ) ) {
564  return false;
565  }
566 
573 
574  h3d->fill(xInfo->fFcn(xvalue/xInfo->fUnit),
575  yInfo->fFcn(yvalue/yInfo->fUnit),
576  zInfo->fFcn(zvalue/zInfo->fUnit), weight);
577 #ifdef G4VERBOSE
578  if ( fState.GetVerboseL4() ) {
579  G4ExceptionDescription description;
580  description << " id " << id
581  << " xvalue " << xvalue
582  << " xfcn(xvalue/xunit) " << xInfo->fFcn(xvalue/xInfo->fUnit)
583  << " yvalue " << yvalue
584  << " yfcn(yvalue/yunit) " << yInfo->fFcn(yvalue/yInfo->fUnit)
585  << " zvalue " << zvalue
586  << " zfcn(zvalue/zunit) " << zInfo->fFcn(zvalue/zInfo->fUnit)
587  << " weight " << weight;
588  fState.GetVerboseL4()->Message("fill", "H3", description);
589  }
590 #endif
591  return true;
592 }
593 
594 //_____________________________________________________________________________
596 {
597  std::map<G4String, G4int>::const_iterator it = fH3NameIdMap.find(name);
598  if ( it == fH3NameIdMap.end() ) {
599  if ( warn) {
600  G4String inFunction = "G4H3ToolsManager::GetH3Id";
601  G4ExceptionDescription description;
602  description << " " << "histogram " << name << " does not exist.";
603  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
604  }
605  return kInvalidId;
606  }
607  return it->second;
608 }
609 
610 //_____________________________________________________________________________
612 {
613  tools::histo::h3d* h3d = GetH3InFunction(id, "GetH3NXbins");
614  if ( ! h3d ) return 0;
615 
617 }
618 
619 //_____________________________________________________________________________
621 {
622 // Returns xmin value with applied unit and histogram function
623 
624  tools::histo::h3d* h3d = GetH3InFunction(id, "GetH3Xmin");
625  if ( ! h3d ) return 0;
626 
628 }
629 
630 //_____________________________________________________________________________
632 {
633  tools::histo::h3d* h3d = GetH3InFunction(id, "GetH3Xmax");
634  if ( ! h3d ) return 0;
635 
637 }
638 
639 //_____________________________________________________________________________
641 {
642  tools::histo::h3d* h3d = GetH3InFunction(id, "GetH3XWidth", true, false);
643  if ( ! h3d ) return 0;
644 
646 }
647 
648 //_____________________________________________________________________________
650 {
651  tools::histo::h3d* h3d = GetH3InFunction(id, "GetH3NYbins");
652  if ( ! h3d ) return 0;
653 
655 }
656 
657 //_____________________________________________________________________________
659 {
660 // Returns xmin value with applied unit and histogram function
661 
662  tools::histo::h3d* h3d = GetH3InFunction(id, "GetH3Ymin");
663  if ( ! h3d ) return 0;
664 
666 }
667 
668 //_____________________________________________________________________________
670 {
671  tools::histo::h3d* h3d = GetH3InFunction(id, "GetH3Ymax");
672  if ( ! h3d ) return 0;
673 
675 }
676 
677 //_____________________________________________________________________________
679 {
680  tools::histo::h3d* h3d = GetH3InFunction(id, "GetH3YWidth", true, false);
681  if ( ! h3d ) return 0;
682 
684 }
685 
686 //_____________________________________________________________________________
688 {
689  tools::histo::h3d* h3d = GetH3InFunction(id, "GetH3NZbins");
690  if ( ! h3d ) return 0;
691 
693 }
694 
695 //_____________________________________________________________________________
697 {
698 // Returns xmin value with applied unit and histogram function
699 
700  tools::histo::h3d* h3d = GetH3InFunction(id, "GetH3Zmin");
701  if ( ! h3d ) return 0;
702 
704 }
705 
706 //_____________________________________________________________________________
708 {
709  tools::histo::h3d* h3d = GetH3InFunction(id, "GetH3Zmax");
710  if ( ! h3d ) return 0;
711 
713 }
714 
715 //_____________________________________________________________________________
717 {
718  tools::histo::h3d* h3d = GetH3InFunction(id, "GetH3ZWidth", true, false);
719  if ( ! h3d ) return 0;
720 
722 }
723 
724 //_____________________________________________________________________________
726 {
727  tools::histo::h3d* h3d = GetH3InFunction(id, "SetH3Title");
728  if ( ! h3d ) return false;
729 
730  return fBaseToolsManager.SetTitle(*h3d, title);
731 }
732 
733 //_____________________________________________________________________________
735 {
736  tools::histo::h3d* h3d = GetH3InFunction(id, "SetH3XAxisTitle");
737  if ( ! h3d ) return false;
738 
740 }
741 
742 //_____________________________________________________________________________
744 {
745  tools::histo::h3d* h3d = GetH3InFunction(id, "SetH3YAxisTitle");
746  if ( ! h3d ) return false;
747 
749 }
750 
751 //_____________________________________________________________________________
753 {
754  tools::histo::h3d* h3d = GetH3InFunction(id, "SetH3ZAxisTitle");
755  if ( ! h3d ) return false;
756 
758 }
759 
760 //_____________________________________________________________________________
762 {
763  tools::histo::h3d* h3d = GetH3InFunction(id, "GetH3Title");
764  if ( ! h3d ) return "";
765 
766  return fBaseToolsManager.GetTitle(*h3d);
767 }
768 
769 //_____________________________________________________________________________
771 {
772  tools::histo::h3d* h3d = GetH3InFunction(id, "GetH3XAxisTitle");
773  if ( ! h3d ) return "";
774 
776 }
777 
778 //_____________________________________________________________________________
780 {
781  tools::histo::h3d* h3d = GetH3InFunction(id, "GetH3YAxisTitle");
782  if ( ! h3d ) return "";
783 
785 }
786 
787 //_____________________________________________________________________________
789 {
790  tools::histo::h3d* h3d = GetH3InFunction(id, "GetH3ZAxisTitle");
791  if ( ! h3d ) return "";
792 
794 }
795 
796 //_____________________________________________________________________________
797 G4bool G4H3ToolsManager::WriteOnAscii(std::ofstream& /*output*/)
798 {
799 // Write selected objects on ASCII file
800 // According to the implementation by Michel Maire, originally in
801 // extended examples.
802 // Not yet available for H3
803 
804  return ! fHnManager->IsAscii();
805 }
806 
807 //
808 // public methods
809 //
810 
811 //_____________________________________________________________________________
812 G4int G4H3ToolsManager::AddH3(const G4String& name, tools::histo::h3d* h3d)
813 {
814 #ifdef G4VERBOSE
815  if ( fState.GetVerboseL4() )
816  fState.GetVerboseL4()->Message("add", "H3", name);
817 #endif
818 
819  // Add annotation
820  AddH3Annotation(h3d, "none", "none", "none", "none", "none", "none");
821  // Add information
822  AddH3Information(name, "none", "none", "none", "none", "none", "none",
824 
825  // Register histogram
826  G4int id = RegisterToolsH3(h3d, name);
827 
828 #ifdef G4VERBOSE
829  if ( fState.GetVerboseL2() )
830  fState.GetVerboseL2()->Message("add", "H3", name);
831 #endif
832  return id;
833 }
834 
835 //_____________________________________________________________________________
837  const std::vector<tools::histo::h3d*>& h3Vector)
838 {
839 #ifdef G4VERBOSE
840  if ( fState.GetVerboseL4() )
841  fState.GetVerboseL4()->Message("merge", "all h3", "");
842 #endif
843  std::vector<tools::histo::h3d*>::const_iterator itw = h3Vector.begin();
844  std::vector<tools::histo::h3d*>::iterator it;
845  for (it = fH3Vector.begin(); it != fH3Vector.end(); it++ ) {
846  (*it)->add(*(*itw++));
847  }
848 #ifdef G4VERBOSE
849  if ( fState.GetVerboseL1() )
850  fState.GetVerboseL1()->Message("merge", "all h3", "");
851 #endif
852 }
853 
854 //_____________________________________________________________________________
856 {
857 // Reset histograms and ntuple
858 
859  G4bool finalResult = true;
860 
861  std::vector<tools::histo::h3d*>::iterator it;
862  for (it = fH3Vector.begin(); it != fH3Vector.end(); it++ ) {
863  G4bool result = (*it)->reset();
864  if ( ! result ) finalResult = false;
865  }
866 
867  return finalResult;
868 }
869 
870 //_____________________________________________________________________________
872 {
873  return ! fH3Vector.size();
874 }
875 
876 //_____________________________________________________________________________
877 tools::histo::h3d* G4H3ToolsManager::GetH3(G4int id, G4bool warn,
878  G4bool onlyIfActive) const
879 {
880  return GetH3InFunction(id, "GetH3", warn, onlyIfActive);
881 }
882 
virtual G4double GetH3XWidth(G4int id) const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
G4bool IsAscii() const
Definition: G4HnManager.cc:162
void AddH3Vector(const std::vector< tools::histo::h3d * > &h3Vector)
virtual G4int GetH3Nzbins(G4int id) const
virtual tools::histo::h3d * GetH3InFunction(G4int id, G4String function, G4bool warn=true, G4bool onlyIfActive=true) const
G4int AddH3(const G4String &name, tools::histo::h3d *h3d)
virtual G4bool SetH3YAxisTitle(G4int id, const G4String &title)
G4bool SetTitle(G4ToolsBaseHisto &baseHisto, const G4String &title)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
virtual G4bool ScaleH3(G4int id, G4double factor)
G4String GetTitle(const G4ToolsBaseHisto &baseHisto) const
void ComputeEdges(G4int nbins, G4double xmin, G4double xmax, G4double unit, G4Fcn fcn, G4BinScheme, std::vector< G4double > &edges)
Definition: G4BinScheme.cc:56
virtual G4bool SetH3Title(G4int id, const G4String &title)
virtual G4int GetH3Nybins(G4int id) const
virtual G4int GetH3Id(const G4String &name, G4bool warn=true) const
static const G4int kY
G4String name
Definition: TRTMaterials.hh:40
virtual G4double GetH3Ymin(G4int id) const
std::map< G4String, G4int > fH3NameIdMap
G4double(* G4Fcn)(G4double)
Definition: G4Fcn.hh:36
G4bool IsEmpty() const
static const G4int kZ
int G4int
Definition: G4Types.hh:78
virtual G4int GetH3Nxbins(G4int id) const
G4String GetAxisTitle(const G4ToolsBaseHisto &baseHisto, G4int dimension) const
G4HnInformation * GetHnInformation(G4int id, G4String functionName="", G4bool warn=true) const
Definition: G4HnManager.cc:123
G4bool GetActivation(G4int id) const
Definition: G4HnManager.cc:270
const G4AnalysisVerbose * GetVerboseL2() const
void UpdateTitle(G4String &title, const G4String &unitName, const G4String &fcnName)
std::vector< tools::histo::h3d * > fH3Vector
G4HnManager * fHnManager
G4int RegisterToolsH3(tools::histo::h3d *h3d, const G4String &name)
void AddH3Information(const G4String &name, const G4String &xunitName, const G4String &yunitName, const G4String &zunitName, const G4String &xfcnName, const G4String &yfcnName, const G4String &zfcnName, G4BinScheme xbinScheme, G4BinScheme ybinScheme, G4BinScheme zbinScheme) const
G4int GetNbins(const G4ToolsBaseHisto &baseHisto, G4int dimension) const
virtual G4int CreateH3(const G4String &name, const G4String &title, G4int nxbins, G4double xmin, G4double xmax, G4int nybins, G4double ymin, G4double ymax, G4int nzbins, G4double zmin, G4double zmax, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &zunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &zfcnName="none", const G4String &xbinScheme="linear", const G4String &ybinScheme="linear", const G4String &zbinScheme="linear")
virtual G4double GetH3ZWidth(G4int id) const
const G4AnalysisVerbose * GetVerboseL4() const
virtual G4String GetH3XAxisTitle(G4int id) const
bool G4bool
Definition: G4Types.hh:79
G4double GetWidth(const G4ToolsBaseHisto &baseHisto, G4int dimension) const
virtual G4double GetH3Xmax(G4int id) const
virtual G4bool SetH3XAxisTitle(G4int id, const G4String &title)
virtual G4String GetH3Title(G4int id) const
G4double GetUnitValue(const G4String &unit)
virtual G4double GetH3Zmin(G4int id) const
virtual G4double GetH3Zmax(G4int id) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void AddH3Information(const G4String &name, const G4String &xunitName, const G4String &yunitName, const G4String &zunitName, const G4String &xfcnName, const G4String &yfcnName, const G4String &zfcnName, G4double xunit, G4double yunit, G4double zunit, G4Fcn fx, G4Fcn fy, G4Fcn fz, G4BinScheme xBinScheme, G4BinScheme yBinScheme, G4BinScheme zBinScheme)
Definition: G4HnManager.cc:95
virtual G4String GetH3YAxisTitle(G4int id) const
static const G4double factor
G4Fcn GetFunction(const G4String &fcnName)
Definition: G4Fcn.cc:36
virtual G4double GetH3YWidth(G4int id) const
virtual G4double GetH3Ymax(G4int id) const
virtual G4bool SetH3ZAxisTitle(G4int id, const G4String &title)
G4double GetMax(const G4ToolsBaseHisto &baseHisto, G4int dimension) const
G4HnDimensionInformation * GetHnDimensionInformation(G4int dimension)
G4BinScheme GetBinScheme(const G4String &binSchemeName)
Definition: G4BinScheme.cc:36
virtual G4bool SetH3(G4int id, G4int nxbins, G4double xmin, G4double xmax, G4int nybins, G4double ymin, G4double ymax, G4int nzbins, G4double zmin, G4double zmax, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &zunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &zfcnName="none", const G4String &xbinScheme="linear", const G4String &ybinScheme="linear", const G4String &zbinScheme="linear")
#define G4endl
Definition: G4ios.hh:61
G4String GetName() const
G4BinScheme
Definition: G4BinScheme.hh:40
virtual ~G4H3ToolsManager()
virtual G4bool WriteOnAscii(std::ofstream &output)
double G4double
Definition: G4Types.hh:76
G4double GetMin(const G4ToolsBaseHisto &baseHisto, G4int dimension) const
tools::histo::h3d * GetH3(G4int id, G4bool warn=true, G4bool onlyIfActive=true) const
const G4int kInvalidId
G4H3ToolsManager(const G4AnalysisManagerState &state)
virtual G4double GetH3Xmin(G4int id) const
const G4AnalysisVerbose * GetVerboseL1() const
void SetActivation(G4bool activation)
Definition: G4HnManager.cc:188
virtual G4bool FillH3(G4int id, G4double xvalue, G4double yvalue, G4double zvalue, G4double weight=1.0)
G4BaseToolsManager fBaseToolsManager
const G4AnalysisManagerState & fState
virtual G4String GetH3ZAxisTitle(G4int id) const
G4bool SetAxisTitle(G4ToolsBaseHisto &baseHisto, G4int dimension, const G4String &title)
static const G4int kX
G4HnDimensionInformation * GetHnDimensionInformation(G4int id, G4int dimension, G4String functionName="", G4bool warn=true) const
Definition: G4HnManager.cc:145