Geant4  10.01.p02
G4P2ToolsManager.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 "G4P2ToolsManager.hh"
31 #include "G4HnManager.hh"
33 #include "G4AnalysisUtilities.hh"
34 
35 #include "tools/histo/p2d"
36 
37 #include <fstream>
38 
39 using namespace G4Analysis;
40 
41 //_____________________________________________________________________________
43  : G4VP2Manager(state),
44  fBaseToolsManager("P2"),
45  fP2Vector(),
46  fP2NameIdMap()
47 {
48 }
49 
50 //_____________________________________________________________________________
52 {
53  std::vector<tools::histo::p2d*>::iterator it;
54  for (it = fP2Vector.begin(); it != fP2Vector.end(); it++ ) {
55  delete (*it);
56  }
57 }
58 
59 //
60 // Utility functions
61 //
62 
63 namespace {
64 
65 //_____________________________________________________________________________
66 void UpdateP2Information(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 {
76  G4double xunit = GetUnitValue(xunitName);
77  G4double yunit = GetUnitValue(yunitName);
78  G4double zunit = GetUnitValue(zunitName);
79  G4Fcn xfcn = GetFunction(xfcnName);
80  G4Fcn yfcn = GetFunction(yfcnName);
81  G4Fcn zfcn = GetFunction(zfcnName);
82 
83  G4HnDimensionInformation* xInformation
85  xInformation->fUnitName = xunitName;
86  xInformation->fFcnName = xfcnName;
87  xInformation->fUnit = xunit;
88  xInformation->fFcn = xfcn;
89  xInformation->fBinScheme = xbinScheme;
90 
91  G4HnDimensionInformation* yInformation
93  yInformation->fUnitName = yunitName;
94  yInformation->fFcnName = yfcnName;
95  yInformation->fUnit = yunit;
96  yInformation->fFcn = yfcn;
97  yInformation->fBinScheme = ybinScheme;
98 
99  G4HnDimensionInformation* zInformation
101  zInformation->fUnitName = zunitName;
102  zInformation->fFcnName = zfcnName;
103  zInformation->fUnit = zunit;
104  zInformation->fFcn = zfcn;
105  zInformation->fBinScheme = kLinearBinScheme;
106 }
107 
108 //_____________________________________________________________________________
109 void AddP2Annotation(tools::histo::p2d* p2d,
110  const G4String& xunitName,
111  const G4String& yunitName,
112  const G4String& zunitName,
113  const G4String& xfcnName,
114  const G4String& yfcnName,
115  const G4String& zfcnName)
116 {
117  G4String xaxisTitle;
118  G4String yaxisTitle;
119  G4String zaxisTitle;
120  UpdateTitle(xaxisTitle, xunitName, xfcnName);
121  UpdateTitle(yaxisTitle, yunitName, yfcnName);
122  UpdateTitle(zaxisTitle, zunitName, zfcnName);
123  p2d->add_annotation(tools::histo::key_axis_x_title(), xaxisTitle);
124  p2d->add_annotation(tools::histo::key_axis_y_title(), yaxisTitle);
125  p2d->add_annotation(tools::histo::key_axis_z_title(), zaxisTitle);
126 }
127 
128 //_____________________________________________________________________________
129 tools::histo::p2d* CreateToolsP2(
130  const G4String& title,
131  G4int nxbins, G4double xmin, G4double xmax,
132  G4int nybins, G4double ymin, G4double ymax,
133  G4double zmin, G4double zmax,
134  const G4String& xunitName,
135  const G4String& yunitName,
136  const G4String& zunitName,
137  const G4String& xfcnName,
138  const G4String& zfcnName,
139  const G4String& yfcnName,
140  const G4String& xbinSchemeName,
141  const G4String& ybinSchemeName)
142 {
143  G4double xunit = GetUnitValue(xunitName);
144  G4double yunit = GetUnitValue(yunitName);
145  G4double zunit = GetUnitValue(zunitName);
146  G4Fcn xfcn = GetFunction(xfcnName);
147  G4Fcn yfcn = GetFunction(yfcnName);
148  G4Fcn zfcn = GetFunction(zfcnName);
149  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
150  G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
151 
152  if ( xbinScheme != kLogBinScheme && ybinScheme != kLogBinScheme) {
153  if ( xbinScheme == kUserBinScheme || ybinScheme == kUserBinScheme ) {
154  // This should never happen, but let's make sure about it
155  // by issuing a warning
156  G4ExceptionDescription description;
157  description
158  << " User binning scheme setting was ignored." << G4endl
159  << " Linear binning will be applied with given (nbins, xmin, xmax) values";
160  G4Exception("G4P2ToolsManager::CreateP2",
161  "Analysis_W013", JustWarning, description);
162  }
163  return new tools::histo::p2d(title,
164  nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
165  nybins, yfcn(ymin/yunit), yfcn(ymax/yunit),
166  zfcn(zmin/zunit), zfcn(zmax/zunit));
167  // p2 objects are deleted in destructor and reset when
168  // closing a file.
169  }
170  else {
171  // Compute edges
172  std::vector<G4double> xedges;
173  ComputeEdges(nxbins, xmin, xmax, xunit, xfcn, xbinScheme, xedges);
174  std::vector<G4double> yedges;
175  ComputeEdges(nybins, ymin, ymax, yunit, yfcn, ybinScheme, yedges);
176  return new tools::histo::p2d(title, xedges, yedges,
177  zfcn(zmin/zunit), zfcn(zmax/zunit));
178  }
179 }
180 
181 //_____________________________________________________________________________
182 tools::histo::p2d* CreateToolsP2(
183  const G4String& title,
184  const std::vector<G4double>& xedges,
185  const std::vector<G4double>& yedges,
186  G4double zmin, G4double zmax,
187  const G4String& xunitName,
188  const G4String& yunitName,
189  const G4String& zunitName,
190  const G4String& xfcnName,
191  const G4String& yfcnName,
192  const G4String& zfcnName)
193 {
194  G4double xunit = GetUnitValue(xunitName);
195  G4double yunit = GetUnitValue(yunitName);
196  G4double zunit = GetUnitValue(zunitName);
197  G4Fcn xfcn = GetFunction(xfcnName);
198  G4Fcn yfcn = GetFunction(yfcnName);
199  G4Fcn zfcn = GetFunction(zfcnName);
200 
201  // Apply function
202  std::vector<G4double> xnewEdges;
203  ComputeEdges(xedges, xunit, xfcn, xnewEdges);
204  std::vector<G4double> ynewEdges;
205  ComputeEdges(yedges, yunit, yfcn, ynewEdges);
206 
207  return new tools::histo::p2d(title, xnewEdges, ynewEdges,
208  zfcn(zmin/zunit), zfcn(zmax/zunit));
209  // p2 objects are deleted in destructor and reset when
210  // closing a file.
211 }
212 
213 //_____________________________________________________________________________
214 void ConfigureToolsP2(tools::histo::p2d* p2d,
215  G4int nxbins, G4double xmin, G4double xmax,
216  G4int nybins, G4double ymin, G4double ymax,
217  G4double zmin, G4double zmax,
218  const G4String& xunitName,
219  const G4String& yunitName,
220  const G4String& zunitName,
221  const G4String& xfcnName,
222  const G4String& yfcnName,
223  const G4String& zfcnName,
224  const G4String& xbinSchemeName,
225  const G4String& ybinSchemeName)
226 {
227  G4double xunit = GetUnitValue(xunitName);
228  G4double yunit = GetUnitValue(yunitName);
229  G4double zunit = GetUnitValue(zunitName);
230  G4Fcn xfcn = GetFunction(xfcnName);
231  G4Fcn yfcn = GetFunction(yfcnName);
232  G4Fcn zfcn = GetFunction(zfcnName);
233  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
234  G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
235 
236  if ( xbinScheme != kLogBinScheme && ybinScheme != kLogBinScheme) {
237  if ( xbinScheme == kUserBinScheme || ybinScheme == kUserBinScheme) {
238  // This should never happen, but let's make sure about it
239  // by issuing a warning
240  G4ExceptionDescription description;
241  description
242  << " User binning scheme setting was ignored." << G4endl
243  << " Linear binning will be applied with given (nbins, xmin, xmax) values";
244  G4Exception("G4P2ToolsManager::CreateP2",
245  "Analysis_W013", JustWarning, description);
246  }
247  p2d->configure(nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
248  nybins, yfcn(ymin/yunit), yfcn(ymax/yunit),
249  zfcn(zmin/zunit), zfcn(zmax/zunit));
250  }
251  else {
252  // Compute bins
253  std::vector<G4double> xedges;
254  ComputeEdges(nxbins, xmin, xmax, xunit, xfcn, xbinScheme, xedges);
255  std::vector<G4double> yedges;
256  ComputeEdges(nybins, ymin, ymax, yunit, yfcn, ybinScheme, yedges);
257  p2d->configure(xedges, yedges, zfcn(zmin/zunit), zfcn(zmax/zunit));
258  }
259 }
260 
261 //_____________________________________________________________________________
262 void ConfigureToolsP2(tools::histo::p2d* p2d,
263  const std::vector<G4double>& xedges,
264  const std::vector<G4double>& yedges,
265  G4double zmin, G4double zmax,
266  const G4String& xunitName,
267  const G4String& yunitName,
268  const G4String& zunitName,
269  const G4String& xfcnName,
270  const G4String& yfcnName,
271  const G4String& zfcnName)
272 {
273  // Apply function to edges
274  G4double xunit = GetUnitValue(xunitName);
275  G4Fcn xfcn = GetFunction(xfcnName);
276  std::vector<G4double> xnewEdges;
277  ComputeEdges(xedges, xunit, xfcn, xnewEdges);
278 
279  G4double yunit = GetUnitValue(yunitName);
280  G4Fcn yfcn = GetFunction(yfcnName);
281  std::vector<G4double> ynewEdges;
282  ComputeEdges(yedges, yunit, yfcn, ynewEdges);
283 
284  G4double zunit = GetUnitValue(zunitName);
285  G4Fcn zfcn = GetFunction(zfcnName);
286  p2d->configure(xnewEdges, ynewEdges, zfcn(zmin/zunit), zfcn(zmax/zunit));
287 }
288 
289 }
290 
291 
292 //
293 // private methods
294 //
295 
296 //_____________________________________________________________________________
298  G4String functionName, G4bool warn,
299  G4bool onlyIfActive) const
300 {
301  G4int index = id - fFirstId;
302  if ( index < 0 || index >= G4int(fP2Vector.size()) ) {
303  if ( warn) {
304  G4String inFunction = "G4P2ToolsManager::";
305  inFunction += functionName;
306  G4ExceptionDescription description;
307  description << " " << "profile " << id << " does not exist.";
308  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
309  }
310  return 0;
311  }
312 
313  // Do not return profile if inactive
314  if ( fState.GetIsActivation() && onlyIfActive &&
315  ( ! fHnManager->GetActivation(id) ) ) {
316  return 0;
317  }
318 
319  return fP2Vector[index];
320 }
321 
322 
323 //_____________________________________________________________________________
325  const G4String& xunitName,
326  const G4String& yunitName,
327  const G4String& zunitName,
328  const G4String& xfcnName,
329  const G4String& yfcnName,
330  const G4String& zfcnName,
331  G4BinScheme xbinScheme,
332  G4BinScheme ybinScheme) const
333 {
334  G4double xunit = GetUnitValue(xunitName);
335  G4double yunit = GetUnitValue(yunitName);
336  G4double zunit = GetUnitValue(zunitName);
337  G4Fcn xfcn = GetFunction(xfcnName);
338  G4Fcn yfcn = GetFunction(yfcnName);
339  G4Fcn zfcn = GetFunction(zfcnName);
340  fHnManager
341  ->AddH3Information(name, xunitName, yunitName, zunitName,
342  xfcnName, yfcnName, zfcnName,
343  xunit, yunit, zunit, xfcn, yfcn, zfcn,
344  xbinScheme, ybinScheme, kLinearBinScheme);
345 }
346 
347 //_____________________________________________________________________________
348 G4int G4P2ToolsManager::RegisterToolsP2(tools::histo::p2d* p2d,
349  const G4String& name)
350 {
351  G4int index = fP2Vector.size();
352  fP2Vector.push_back(p2d);
353 
354  fLockFirstId = true;
355  fP2NameIdMap[name] = index + fFirstId;
356  return index + fFirstId;
357 }
358 
359 //
360 // protected methods
361 //
362 
363 //_____________________________________________________________________________
365  G4int nxbins, G4double xmin, G4double xmax,
366  G4int nybins, G4double ymin, G4double ymax,
367  G4double zmin, G4double zmax,
368  const G4String& xunitName, const G4String& yunitName,
369  const G4String& zunitName,
370  const G4String& xfcnName, const G4String& yfcnName,
371  const G4String& zfcnName,
372  const G4String& xbinSchemeName,
373  const G4String& ybinSchemeName)
374 
375 {
376 #ifdef G4VERBOSE
377  if ( fState.GetVerboseL4() )
378  fState.GetVerboseL4()->Message("create", "P2", name);
379 #endif
380  tools::histo::p2d* p2d
381  = CreateToolsP2(title,
382  nxbins, xmin, xmax, nybins, ymin, ymax, zmin, zmax,
383  xunitName, yunitName, zunitName,
384  xfcnName, yfcnName, zfcnName,
385  xbinSchemeName, ybinSchemeName);
386 
387  // Add annotation
388  AddP2Annotation(p2d, xunitName, yunitName, zunitName,
389  xfcnName, yfcnName, zfcnName);
390 
391  // Save P2 information
392  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
393  G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
395  name, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
396  xbinScheme, ybinScheme);
397 
398  // Register profile
399  G4int id = RegisterToolsP2(p2d, name);
400 
401 #ifdef G4VERBOSE
402  if ( fState.GetVerboseL2() )
403  fState.GetVerboseL2()->Message("create", "P2", name);
404 #endif
405 
406  return id;
407 }
408 
409 //_____________________________________________________________________________
411  const std::vector<G4double>& xedges,
412  const std::vector<G4double>& yedges,
413  G4double zmin, G4double zmax,
414  const G4String& xunitName, const G4String& yunitName,
415  const G4String& zunitName,
416  const G4String& xfcnName, const G4String& yfcnName,
417  const G4String& zfcnName)
418 
419 {
420 #ifdef G4VERBOSE
421  if ( fState.GetVerboseL4() )
422  fState.GetVerboseL4()->Message("create", "P2", name);
423 #endif
424  tools::histo::p2d* p2d
425  = CreateToolsP2(title, xedges, yedges, zmin, zmax,
426  xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName);
427 
428  // Add annotation
429  AddP2Annotation(
430  p2d, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName);
431 
432  // Save P2 information
434  name, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
436 
437  // Register profile
438  G4int id = RegisterToolsP2(p2d, name);
439 
440 #ifdef G4VERBOSE
441  if ( fState.GetVerboseL2() )
442  fState.GetVerboseL2()->Message("create", "P2", name);
443 #endif
444 
445  return id;
446 }
447 
448 //_____________________________________________________________________________
450  G4int nxbins, G4double xmin, G4double xmax,
451  G4int nybins, G4double ymin, G4double ymax,
452  G4double zmin, G4double zmax,
453  const G4String& xunitName, const G4String& yunitName,
454  const G4String& zunitName,
455  const G4String& xfcnName, const G4String& yfcnName,
456  const G4String& zfcnName,
457  const G4String& xbinSchemeName,
458  const G4String& ybinSchemeName)
459 {
460  tools::histo::p2d* p2d = GetP2InFunction(id, "SetP2", false, false);
461  if ( ! p2d ) return false;
462 
463  G4HnInformation* info = fHnManager->GetHnInformation(id, "SetP2");
464 #ifdef G4VERBOSE
465  if ( fState.GetVerboseL4() )
466  fState.GetVerboseL4()->Message("configure", "P2", info->GetName());
467 #endif
468 
469  // Configure tools p2
470  ConfigureToolsP2(
471  p2d, nxbins, xmin, xmax, nybins, ymin, ymax, zmin, zmax,
472  xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
473  xbinSchemeName, ybinSchemeName);
474 
475  // Add annotation
476  AddP2Annotation(p2d, xunitName, yunitName, zunitName,
477  xfcnName, yfcnName, zfcnName);
478 
479  // Update information
480  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
481  G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
482  UpdateP2Information(
483  info, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
484  xbinScheme, ybinScheme);
485 
486  // Set activation
487  fHnManager->SetActivation(id, true);
488 
489  return true;
490 }
491 
492 //_____________________________________________________________________________
494  const std::vector<G4double>& xedges,
495  const std::vector<G4double>& yedges,
496  G4double zmin, G4double zmax,
497  const G4String& xunitName, const G4String& yunitName,
498  const G4String& zunitName,
499  const G4String& xfcnName, const G4String& yfcnName,
500  const G4String& zfcnName)
501 {
502  tools::histo::p2d* p2d = GetP2InFunction(id, "SetP2", false, false);
503  if ( ! p2d ) return false;
504 
505  G4HnInformation* info = fHnManager->GetHnInformation(id, "SetP2");
506 #ifdef G4VERBOSE
507  if ( fState.GetVerboseL4() )
508  fState.GetVerboseL4()->Message("configure", "P2", info->GetName());
509 #endif
510 
511  // Configure tools p2
512  ConfigureToolsP2(p2d, xedges, yedges, zmin, zmax,
513  xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName);
514 
515  // Add annotation
516  AddP2Annotation(p2d, xunitName, yunitName, zunitName,
517  xfcnName, yfcnName, zfcnName);
518 
519  // Update information
520  UpdateP2Information(
521  info, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
523 
524  // Set activation
525  fHnManager->SetActivation(id, true);
526 
527  return true;
528 }
529 
530 //_____________________________________________________________________________
532 {
533  tools::histo::p2d* p2d = GetP2InFunction(id, "ScaleP2", false, false);
534  if ( ! p2d ) return false;
535 
536  return p2d->scale(factor);
537 }
538 
539 //_____________________________________________________________________________
541  G4double xvalue, G4double yvalue, G4double zvalue,
542  G4double weight)
543 {
544  tools::histo::p2d* p2d = GetP2InFunction(id, "FillP2", true, false);
545  if ( ! p2d ) return false;
546 
547  if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(id) ) ) {
548  return false;
549  }
550 
557 
558  p2d->fill(xInfo->fFcn(xvalue/xInfo->fUnit),
559  yInfo->fFcn(yvalue/yInfo->fUnit),
560  zInfo->fFcn(zvalue/zInfo->fUnit), weight);
561 #ifdef G4VERBOSE
562  if ( fState.GetVerboseL4() ) {
563  G4ExceptionDescription description;
564  //description << " id " << id
565  // << " xvalue " << xvalue << " yvalue " << yvalue << " zvalue " << zvalue;
566  description << " id " << id
567  << " xvalue " << xvalue
568  << " xfcn(xvalue/xunit) " << xInfo->fFcn(xvalue/xInfo->fUnit)
569  << " yvalue " << yvalue
570  << " yfcn(yvalue/yunit) " << yInfo->fFcn(yvalue/yInfo->fUnit)
571  << " zvalue " << zvalue
572  << " zfcn(zvalue/zunit) " << zInfo->fFcn(zvalue/zInfo->fUnit)
573  << " weight " << weight;
574  fState.GetVerboseL4()->Message("fill", "P2", description);
575  }
576 #endif
577  return true;
578 }
579 
580 //_____________________________________________________________________________
582 {
583  std::map<G4String, G4int>::const_iterator it = fP2NameIdMap.find(name);
584  if ( it == fP2NameIdMap.end() ) {
585  if ( warn) {
586  G4String inFunction = "G4P2ToolsManager::GetP2Id";
587  G4ExceptionDescription description;
588  description << " " << "profile " << name << " does not exist.";
589  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
590  }
591  return kInvalidId;
592  }
593  return it->second;
594 }
595 
596 //_____________________________________________________________________________
598 {
599  tools::histo::p2d* p2d = GetP2InFunction(id, "GetP2NXbins");
600  if ( ! p2d ) return 0;
601 
603 }
604 
605 //_____________________________________________________________________________
607 {
608 // Returns xmin value with applied unit and profile function
609 
610  tools::histo::p2d* p2d = GetP2InFunction(id, "GetP2Xmin");
611  if ( ! p2d ) return 0;
612 
614 }
615 
616 //_____________________________________________________________________________
618 {
619  tools::histo::p2d* p2d = GetP2InFunction(id, "GetP2Xmax");
620  if ( ! p2d ) return 0;
621 
623 }
624 
625 //_____________________________________________________________________________
627 {
628  tools::histo::p2d* p2d = GetP2InFunction(id, "GetP2XWidth", true, false);
629  if ( ! p2d ) return 0;
630 
632 }
633 
634 //_____________________________________________________________________________
636 {
637  tools::histo::p2d* p2d = GetP2InFunction(id, "GetP2NYbins");
638  if ( ! p2d ) return 0;
639 
641 }
642 
643 //_____________________________________________________________________________
645 {
646 // Returns xmin value with applied unit and profile function
647 
648  tools::histo::p2d* p2d = GetP2InFunction(id, "GetP2Ymin");
649  if ( ! p2d ) return 0;
650 
652 }
653 
654 //_____________________________________________________________________________
656 {
657  tools::histo::p2d* p2d = GetP2InFunction(id, "GetP2Ymax");
658  if ( ! p2d ) return 0;
659 
661 }
662 
663 //_____________________________________________________________________________
665 {
666  tools::histo::p2d* p2d = GetP2InFunction(id, "GetP2YWidth", true, false);
667  if ( ! p2d ) return 0;
668 
670 }
671 
672 //_____________________________________________________________________________
674 {
675 // Returns xmin value with applied unit and profile function
676 
677  tools::histo::p2d* p2d = GetP2InFunction(id, "GetP2Zmin");
678  if ( ! p2d ) return 0;
679 
681 }
682 
683 //_____________________________________________________________________________
685 {
686  tools::histo::p2d* p2d = GetP2InFunction(id, "GetP2Zmax");
687  if ( ! p2d ) return 0;
688 
690 }
691 
692 //_____________________________________________________________________________
694 {
695  tools::histo::p2d* p2d = GetP2InFunction(id, "SetP2Title");
696  if ( ! p2d ) return false;
697 
698  return fBaseToolsManager.SetTitle(*p2d, title);
699 }
700 
701 //_____________________________________________________________________________
703 {
704  tools::histo::p2d* p2d = GetP2InFunction(id, "SetP2XAxisTitle");
705  if ( ! p2d ) return false;
706 
708 }
709 
710 //_____________________________________________________________________________
712 {
713  tools::histo::p2d* p2d = GetP2InFunction(id, "SetP2YAxisTitle");
714  if ( ! p2d ) return false;
715 
717 }
718 
719 //_____________________________________________________________________________
721 {
722  tools::histo::p2d* p2d = GetP2InFunction(id, "SetP2ZAxisTitle");
723  if ( ! p2d ) return false;
724 
726 }
727 
728 //_____________________________________________________________________________
730 {
731  tools::histo::p2d* p2d = GetP2InFunction(id, "GetP2Title");
732  if ( ! p2d ) return "";
733 
734  return fBaseToolsManager.GetTitle(*p2d);
735 }
736 
737 //_____________________________________________________________________________
739 {
740  tools::histo::p2d* p2d = GetP2InFunction(id, "GetP2XAxisTitle");
741  if ( ! p2d ) return "";
742 
744 }
745 
746 //_____________________________________________________________________________
748 {
749  tools::histo::p2d* p2d = GetP2InFunction(id, "GetP2YAxisTitle");
750  if ( ! p2d ) return "";
751 
753 }
754 
755 //_____________________________________________________________________________
757 {
758  tools::histo::p2d* p2d = GetP2InFunction(id, "GetP2ZAxisTitle");
759  if ( ! p2d ) return "";
760 
762 }
763 
764 //_____________________________________________________________________________
765 G4bool G4P2ToolsManager::WriteOnAscii(std::ofstream& /*output*/)
766 {
767 // Write selected objects on ASCII file
768 // According to the implementation by Michel Maire, originally in
769 // extended examples.
770 // Not yet available for P2
771 
772  return ! fHnManager->IsAscii();
773 }
774 
775 //
776 // public methods
777 //
778 
779 //_____________________________________________________________________________
780 G4int G4P2ToolsManager::AddP2(const G4String& name, tools::histo::p2d* p2d)
781 {
782 #ifdef G4VERBOSE
783  if ( fState.GetVerboseL4() )
784  fState.GetVerboseL4()->Message("add", "P2", name);
785 #endif
786 
787  // Add annotation
788  AddP2Annotation(p2d, "none", "none", "none", "none", "none", "none");
789  // Add information
790  AddP2Information(name, "none", "none", "none", "none", "none", "none",
792 
793  // Register profile
794  G4int id = RegisterToolsP2(p2d, name);
795 
796 #ifdef G4VERBOSE
797  if ( fState.GetVerboseL2() )
798  fState.GetVerboseL2()->Message("add", "P2", name);
799 #endif
800  return id;
801 }
802 
803 //_____________________________________________________________________________
805  const std::vector<tools::histo::p2d*>& p2Vector)
806 {
807 #ifdef G4VERBOSE
808  if ( fState.GetVerboseL4() )
809  fState.GetVerboseL4()->Message("merge", "all p2", "");
810 #endif
811  std::vector<tools::histo::p2d*>::const_iterator itw = p2Vector.begin();
812  std::vector<tools::histo::p2d*>::iterator it;
813  for (it = fP2Vector.begin(); it != fP2Vector.end(); it++ ) {
814  (*it)->add(*(*itw++));
815  }
816 #ifdef G4VERBOSE
817  if ( fState.GetVerboseL1() )
818  fState.GetVerboseL1()->Message("merge", "all p2", "");
819 #endif
820 }
821 
822 //_____________________________________________________________________________
824 {
825 // Reset profiles and ntuple
826 
827  G4bool finalResult = true;
828 
829  std::vector<tools::histo::p2d*>::iterator it;
830  for (it = fP2Vector.begin(); it != fP2Vector.end(); it++ ) {
831  G4bool result = (*it)->reset();
832  if ( ! result ) finalResult = false;
833  }
834 
835  return finalResult;
836 }
837 
838 //_____________________________________________________________________________
840 {
841  return ! fP2Vector.size();
842 }
843 
844 //_____________________________________________________________________________
845 tools::histo::p2d* G4P2ToolsManager::GetP2(G4int id, G4bool warn,
846  G4bool onlyIfActive) const
847 {
848  return GetP2InFunction(id, "GetP2", warn, onlyIfActive);
849 }
850 
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
G4bool IsAscii() const
Definition: G4HnManager.cc:162
virtual tools::histo::p2d * GetP2InFunction(G4int id, G4String function, G4bool warn=true, G4bool onlyIfActive=true) const
G4bool IsEmpty() const
G4bool SetTitle(G4ToolsBaseHisto &baseHisto, const G4String &title)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
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 SetP2Title(G4int id, const G4String &title)
G4int RegisterToolsP2(tools::histo::p2d *p2d, const G4String &name)
std::vector< tools::histo::p2d * > fP2Vector
static const G4int kY
G4String name
Definition: TRTMaterials.hh:40
virtual G4String GetP2XAxisTitle(G4int id) const
virtual G4bool SetP2YAxisTitle(G4int id, const G4String &title)
G4double(* G4Fcn)(G4double)
Definition: G4Fcn.hh:36
virtual G4String GetP2ZAxisTitle(G4int id) const
virtual G4bool WriteOnAscii(std::ofstream &output)
virtual G4String GetP2Title(G4int id) const
virtual G4int GetP2Nybins(G4int id) const
static const G4int kZ
int G4int
Definition: G4Types.hh:78
G4int AddP2(const G4String &name, tools::histo::p2d *p2d)
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
std::map< G4String, G4int > fP2NameIdMap
void UpdateTitle(G4String &title, const G4String &unitName, const G4String &fcnName)
void AddP2Vector(const std::vector< tools::histo::p2d * > &p2Vector)
virtual G4String GetP2YAxisTitle(G4int id) const
virtual G4double GetP2Zmax(G4int id) const
G4int GetNbins(const G4ToolsBaseHisto &baseHisto, G4int dimension) const
tools::histo::p2d * GetP2(G4int id, G4bool warn=true, G4bool onlyIfActive=true) const
virtual G4bool SetP2ZAxisTitle(G4int id, const G4String &title)
const G4AnalysisVerbose * GetVerboseL4() const
virtual G4double GetP2Zmin(G4int id) const
bool G4bool
Definition: G4Types.hh:79
virtual G4int GetP2Id(const G4String &name, G4bool warn=true) const
virtual G4bool SetP2(G4int id, G4int nxbins, G4double xmin, G4double xmax, G4int nybins, G4double ymin, G4double ymax, G4double zmin=0, G4double zmax=0, 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")
G4double GetWidth(const G4ToolsBaseHisto &baseHisto, G4int dimension) const
virtual ~G4P2ToolsManager()
void AddP2Information(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) const
G4double GetUnitValue(const G4String &unit)
virtual G4bool ScaleP2(G4int id, G4double factor)
G4P2ToolsManager(const G4AnalysisManagerState &state)
virtual G4double GetP2Ymin(G4int id) const
G4HnManager * fHnManager
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
virtual G4double GetP2Xmax(G4int id) const
virtual G4bool FillP2(G4int id, G4double xvalue, G4double yvalue, G4double zvalue, G4double weight=1.0)
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
static const G4double factor
G4Fcn GetFunction(const G4String &fcnName)
Definition: G4Fcn.cc:36
G4double GetMax(const G4ToolsBaseHisto &baseHisto, G4int dimension) const
virtual G4double GetP2Ymax(G4int id) const
virtual G4bool SetP2XAxisTitle(G4int id, const G4String &title)
G4HnDimensionInformation * GetHnDimensionInformation(G4int dimension)
G4BinScheme GetBinScheme(const G4String &binSchemeName)
Definition: G4BinScheme.cc:36
virtual G4double GetP2XWidth(G4int id) const
virtual G4double GetP2YWidth(G4int id) const
#define G4endl
Definition: G4ios.hh:61
G4String GetName() const
G4BinScheme
Definition: G4BinScheme.hh:40
virtual G4double GetP2Xmin(G4int id) const
double G4double
Definition: G4Types.hh:76
G4double GetMin(const G4ToolsBaseHisto &baseHisto, G4int dimension) const
G4BaseToolsManager fBaseToolsManager
virtual G4int CreateP2(const G4String &name, const G4String &title, G4int nxbins, G4double xmin, G4double xmax, G4int nybins, G4double ymin, G4double ymax, G4double zmin=0, G4double zmax=0, 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")
virtual G4int GetP2Nxbins(G4int id) const
const G4int kInvalidId
const G4AnalysisVerbose * GetVerboseL1() const
void SetActivation(G4bool activation)
Definition: G4HnManager.cc:188
const G4AnalysisManagerState & fState
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