Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4BaseHistoUtilities.cc
이 파일의 문서화 페이지로 가기
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 //_____________________________________________________________________________
80 G4bool SetTitle(G4ToolsBaseHisto& baseHisto, const G4String& title)
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 GetMin(const G4ToolsBaseHisto &baseHisto, G4int dimension)
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
G4double GetMax(const G4ToolsBaseHisto &baseHisto, G4int dimension)
G4String GetAxisTitle(const G4ToolsBaseHisto &baseHisto, G4int dimension, const G4String &hnType)
const G4int kX
tools::histo::base_histo< double, unsigned int, unsigned int, double, double > G4ToolsBaseHisto
const G4int kY
G4double GetWidth(const G4ToolsBaseHisto &baseHisto, G4int dimension, const G4String &hnType)
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
G4int GetNbins(const G4ToolsBaseHisto &baseHisto, G4int dimension)
G4bool SetAxisTitle(G4ToolsBaseHisto &baseHisto, G4int dimension, const G4String &title)
G4double G4ParticleHPJENDLHEData::G4double result
const G4int kZ
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
int G4int
Definition: G4Types.hh:78
G4bool SetTitle(G4ToolsBaseHisto &baseHisto, const G4String &title)
G4String GetTitle(const G4ToolsBaseHisto &baseHisto)