Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4BaseHistoUtilities.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 "G4BaseHistoUtilities.hh"
31 #include "G4AnalysisUtilities.hh"
32 
33 #include "tools/histo/axis"
34 
35 namespace G4Analysis
36 {
37 
38 //_____________________________________________________________________________
39 G4int GetNbins(const G4ToolsBaseHisto& baseHisto, G4int dimension)
40 {
41  return baseHisto.get_axis(dimension).bins();
42 }
43 
44 //_____________________________________________________________________________
45 G4double GetMin(const G4ToolsBaseHisto& baseHisto, G4int dimension)
46 {
47 // Returns min data value
48 
49  return baseHisto.get_axis(dimension).lower_edge();
50 }
51 
52 //_____________________________________________________________________________
53 G4double GetMax(const G4ToolsBaseHisto& baseHisto, G4int dimension)
54 {
55 // Returns max data value
56 
57  return baseHisto.get_axis(dimension).upper_edge();
58 }
59 
60 //_____________________________________________________________________________
61 G4double GetWidth(const G4ToolsBaseHisto& baseHisto, G4int dimension,
62  const G4String& hnType)
63 {
64  auto nbins = baseHisto.get_axis(dimension).bins();
65  if ( ! nbins ) {
66  G4String functionName = "Get";
67  functionName += hnType;
68  functionName += "Width";
69  G4ExceptionDescription description;
70  description << " nbins = 0 (for " << hnType << ").";
71  G4Exception(functionName, "Analysis_W014", JustWarning, description);
72  return 0.;
73  }
74 
75  return ( baseHisto.get_axis(dimension).upper_edge()
76  - baseHisto.get_axis(dimension).lower_edge() )/nbins;
77 }
78 
79 //_____________________________________________________________________________
81 {
82  return baseHisto.set_title(title);
83 }
84 
85 //_____________________________________________________________________________
86 G4bool SetAxisTitle(G4ToolsBaseHisto& baseHisto, G4int dimension,
87  const G4String& title)
88 {
89  if ( dimension == kX ) {
90  baseHisto.add_annotation(tools::histo::key_axis_x_title(), title);
91  }
92  else if ( dimension == kY ) {
93  baseHisto.add_annotation(tools::histo::key_axis_y_title(), title);
94  }
95  else if ( dimension == kZ ) {
96  baseHisto.add_annotation(tools::histo::key_axis_z_title(), title);
97  }
98 
99  return true;
100 }
101 
102 //_____________________________________________________________________________
104 {
105  return baseHisto.title();
106 }
107 
108 
109 //_____________________________________________________________________________
110 G4String GetAxisTitle(const G4ToolsBaseHisto& baseHisto, G4int dimension,
111  const G4String& hnType)
112 {
113  G4String title;
114  G4bool result = false;
115  if ( dimension == kX ) {
116  result = baseHisto.annotation(tools::histo::key_axis_x_title(), title);
117  }
118  else if ( dimension == kY ) {
119  result = baseHisto.annotation(tools::histo::key_axis_y_title(), title);
120  }
121  else if ( dimension == kZ ) {
122  result = baseHisto.annotation(tools::histo::key_axis_z_title(), title);
123  }
124 
125  if ( ! result ) {
126  G4String axes("xyz");
127  G4String axis = axes(dimension, 1);
128  G4String functionName = "Get";
129  functionName += hnType;
130  functionName += axis;
131  functionName += "Title";
132  G4ExceptionDescription description;
133  description << " Failed to get " << axis << " axis " << hnType << " title.";
134  G4Exception(functionName, "Analysis_W014", JustWarning, description);
135  return "";
136  }
137 
138  return title;
139 }
140 
141 }
G4double G4ParticleHPJENDLHEData::G4double result
G4double GetWidth(const G4ToolsBaseHisto &baseHisto, G4int dimension, const G4String &hnType)
G4String GetTitle(const G4ToolsBaseHisto &baseHisto)
const G4int kZ
G4String GetAxisTitle(const G4ToolsBaseHisto &baseHisto, G4int dimension, const G4String &hnType)
G4double GetMin(const G4ToolsBaseHisto &baseHisto, G4int dimension)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4bool SetAxisTitle(G4ToolsBaseHisto &baseHisto, G4int dimension, const G4String &title)
tools::histo::base_histo< double, unsigned int, unsigned int, double, double > G4ToolsBaseHisto
int G4int
Definition: G4Types.hh:78
bool G4bool
Definition: G4Types.hh:79
const G4int kX
G4bool SetTitle(G4ToolsBaseHisto &baseHisto, const G4String &title)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4double GetMax(const G4ToolsBaseHisto &baseHisto, G4int dimension)
G4int GetNbins(const G4ToolsBaseHisto &baseHisto, G4int dimension)
double G4double
Definition: G4Types.hh:76
const G4int kY
subroutine title
Definition: hijing1.383.f:5980