g4tools  5.4.0
Public Types | Public Member Functions | Public Attributes | List of all members
tools::histo::axis< TC, TO > Class Template Reference

Public Types

enum  { UNDERFLOW_BIN = axis_UNDERFLOW_BIN, OVERFLOW_BIN = axis_OVERFLOW_BIN }
 
typedef unsigned int bn_t
 

Public Member Functions

bool is_fixed_binning () const
 
TC lower_edge () const
 
TC upper_edge () const
 
bn_t bins () const
 
const std::vector< TC > & edges () const
 
TC bin_width (int a_bin) const
 
TC bin_lower_edge (int a_bin) const
 
TC bin_upper_edge (int a_bin) const
 
TC bin_center (int a_bin) const
 
int coord_to_index (TC a_value) const
 
bool coord_to_absolute_index (TC a_value, bn_t &a_index) const
 
bool in_range_to_absolute_index (int a_in, bn_t &a_out) const
 
bool configure (const std::vector< TC > &a_edges)
 
bool configure (bn_t aNumber, TC aMin, TC aMax)
 
bool is_compatible (const axis &a_axis) const
 
 axis ()
 
virtual ~axis ()
 
 axis (const axis &a_from)
 
axisoperator= (const axis &a_from)
 
bool equals (const axis &a_from) const
 
bool operator== (const axis &a_from) const
 
bool operator!= (const axis &a_from) const
 

Public Attributes

TO m_offset
 
bn_t m_number_of_bins
 
TC m_minimum_value
 
TC m_maximum_value
 
bool m_fixed
 
TC m_bin_width
 
std::vector< TC > m_edges
 

Detailed Description

template<class TC, class TO>
class tools::histo::axis< TC, TO >

Definition at line 19 of file axis.

Member Typedef Documentation

◆ bn_t

template<class TC , class TO >
typedef unsigned int tools::histo::axis< TC, TO >::bn_t

Definition at line 21 of file axis.

Member Enumeration Documentation

◆ anonymous enum

template<class TC , class TO >
anonymous enum
Enumerator
UNDERFLOW_BIN 
OVERFLOW_BIN 

Definition at line 23 of file axis.

Constructor & Destructor Documentation

◆ axis() [1/2]

template<class TC , class TO >
tools::histo::axis< TC, TO >::axis ( )
inline

Definition at line 215 of file axis.

216  :m_offset(0)
217  ,m_number_of_bins(0)
218  ,m_minimum_value(0)
219  ,m_maximum_value(0)
220  ,m_fixed(true)
221  ,m_bin_width(0)
222  {}

◆ ~axis()

template<class TC , class TO >
virtual tools::histo::axis< TC, TO >::~axis ( )
inlinevirtual

Definition at line 224 of file axis.

224 {}

◆ axis() [2/2]

template<class TC , class TO >
tools::histo::axis< TC, TO >::axis ( const axis< TC, TO > &  a_from)
inline

Definition at line 226 of file axis.

227  :m_offset(a_from.m_offset)
228  ,m_number_of_bins(a_from.m_number_of_bins)
229  ,m_minimum_value(a_from.m_minimum_value)
230  ,m_maximum_value(a_from.m_maximum_value)
231  ,m_fixed(a_from.m_fixed)
232  ,m_bin_width(a_from.m_bin_width)
233  ,m_edges(a_from.m_edges)
234  {}

Member Function Documentation

◆ bin_center()

template<class TC , class TO >
TC tools::histo::axis< TC, TO >::bin_center ( int  a_bin) const
inline

Definition at line 79 of file axis.

79  {
80  if(a_bin==UNDERFLOW_BIN) {
81  return 0; //FIXME : -INF
82  } else if(a_bin==OVERFLOW_BIN) {
83  return 0; //FIXME : +INF
84  } else if(a_bin<0) {
85  return 0; //FIXME : -INF
86  } else if(a_bin>=(int)m_number_of_bins) {
87  return 0; //FIXME : +INF
88  } else {
89  if(m_fixed) {
90  return (m_minimum_value + (a_bin + 0.5) * m_bin_width);
91  } else {
92  return (m_edges[a_bin] + m_edges[a_bin+1])/2.;
93  }
94  }
95  }

◆ bin_lower_edge()

template<class TC , class TO >
TC tools::histo::axis< TC, TO >::bin_lower_edge ( int  a_bin) const
inline

Definition at line 47 of file axis.

47  {
48  if(a_bin==UNDERFLOW_BIN) {
49  return 0; //FIXME return -DBL_MAX;
50  } else if(a_bin==OVERFLOW_BIN) {
51  return 0; //FIXME return bin_upper_edge(m_number_of_bins-1);
52  } else if((a_bin<0) ||(a_bin>=(int)m_number_of_bins)) {
53  return 0;
54  } else {
55  if(m_fixed) {
56  return (m_minimum_value + a_bin * m_bin_width);
57  } else {
58  return m_edges[a_bin];
59  }
60  }
61  }

◆ bin_upper_edge()

template<class TC , class TO >
TC tools::histo::axis< TC, TO >::bin_upper_edge ( int  a_bin) const
inline

Definition at line 63 of file axis.

63  {
64  if(a_bin==UNDERFLOW_BIN) {
65  return 0; //FIXME bin_lower_edge(0)
66  } else if(a_bin==OVERFLOW_BIN) {
67  return 0; //FIXME return DBL_MAX;
68  } else if((a_bin<0) ||(a_bin>=(int)m_number_of_bins)) {
69  return 0;
70  } else {
71  if(m_fixed) {
72  return (m_minimum_value + (a_bin + 1) * m_bin_width);
73  } else {
74  return m_edges[a_bin+1];
75  }
76  }
77  }

◆ bin_width()

template<class TC , class TO >
TC tools::histo::axis< TC, TO >::bin_width ( int  a_bin) const
inline

Definition at line 31 of file axis.

31  {
32  if(a_bin==UNDERFLOW_BIN) {
33  return 0; //FIXME return DBL_MAX;
34  } else if(a_bin==OVERFLOW_BIN) {
35  return 0; //FIXME return DBL_MAX;
36  } else if((a_bin<0) ||(a_bin>=(int)m_number_of_bins)) {
37  return 0;
38  } else {
39  if(m_fixed) {
40  return m_bin_width;
41  } else {
42  return (m_edges[a_bin+1]-m_edges[a_bin]);
43  }
44  }
45  }

◆ bins()

template<class TC , class TO >
bn_t tools::histo::axis< TC, TO >::bins ( ) const
inline

Definition at line 28 of file axis.

28 {return m_number_of_bins;}

◆ configure() [1/2]

template<class TC , class TO >
bool tools::histo::axis< TC, TO >::configure ( bn_t  aNumber,
TC  aMin,
TC  aMax 
)
inline

Definition at line 188 of file axis.

188  {
189  // init :
190  m_number_of_bins = 0;
191  m_minimum_value = 0;
192  m_maximum_value = 0;
193  m_fixed = true;
194  m_bin_width = 0;
195  m_edges.clear();
196  // setup :
197  if(aNumber<=0) return false;
198  if(aMax<=aMin) return false;
199  m_number_of_bins = aNumber;
200  m_minimum_value = aMin;
201  m_maximum_value = aMax;
202  m_bin_width = (aMax - aMin)/ aNumber;
203  m_fixed = true;
204  return true;
205  }

◆ configure() [2/2]

template<class TC , class TO >
bool tools::histo::axis< TC, TO >::configure ( const std::vector< TC > &  a_edges)
inline

Definition at line 164 of file axis.

164  {
165  // init :
166  m_number_of_bins = 0;
167  m_minimum_value = 0;
168  m_maximum_value = 0;
169  m_fixed = true;
170  m_bin_width = 0;
171  m_edges.clear();
172  // setup :
173  if(a_edges.size()<=1) return false;
174  bn_t number = (bn_t)a_edges.size()-1;
175  for(bn_t index=0;index<number;index++) {
176  if((a_edges[index]>=a_edges[index+1])) {
177  return false;
178  }
179  }
180  m_edges = a_edges;
181  m_number_of_bins = number;
182  m_minimum_value = a_edges[0];
184  m_fixed = false;
185  return true;
186  }

◆ coord_to_absolute_index()

template<class TC , class TO >
bool tools::histo::axis< TC, TO >::coord_to_absolute_index ( TC  a_value,
bn_t a_index 
) const
inline

Definition at line 117 of file axis.

117  {
118  if( a_value < m_minimum_value) {
119  a_index = 0;
120  return true;
121  } else if( a_value >= m_maximum_value) {
122  a_index = m_number_of_bins+1;
123  return true;
124  } else {
125  if(m_fixed) {
126  a_index = (bn_t)((a_value - m_minimum_value)/m_bin_width)+1;
127  return true;
128  } else {
129  for(bn_t index=0;index<m_number_of_bins;index++) {
130  if((m_edges[index]<=a_value)&&(a_value<m_edges[index+1])) {
131  a_index = index+1;
132  return true;
133  }
134  }
135  // Should never pass here...
136  a_index = 0;
137  return false;
138  }
139  }
140  }

◆ coord_to_index()

template<class TC , class TO >
int tools::histo::axis< TC, TO >::coord_to_index ( TC  a_value) const
inline

Definition at line 97 of file axis.

97  {
98  if( a_value < m_minimum_value) {
99  return UNDERFLOW_BIN;
100  } else if( a_value >= m_maximum_value) {
101  return OVERFLOW_BIN;
102  } else {
103  if(m_fixed) {
104  return (int)((a_value - m_minimum_value)/m_bin_width);
105  } else {
106  for(bn_t index=0;index<m_number_of_bins;index++) {
107  if((m_edges[index]<=a_value)&&(a_value<m_edges[index+1])) {
108  return index;
109  }
110  }
111  // Should never pass here...
112  return UNDERFLOW_BIN;
113  }
114  }
115  }

◆ edges()

template<class TC , class TO >
const std::vector<TC>& tools::histo::axis< TC, TO >::edges ( ) const
inline

Definition at line 29 of file axis.

29 {return m_edges;}

◆ equals()

template<class TC , class TO >
bool tools::histo::axis< TC, TO >::equals ( const axis< TC, TO > &  a_from) const
inline

Definition at line 248 of file axis.

248  {
249  if(&a_from==this) return true;
250  if(m_offset!=a_from.m_offset) return false;
251  if(m_number_of_bins!=a_from.m_number_of_bins) return false;
252  if(m_minimum_value!=a_from.m_minimum_value) return false;
253  if(m_maximum_value!=a_from.m_maximum_value) return false;
254  if(m_fixed!=a_from.m_fixed) return false;
255  if(m_bin_width!=a_from.m_bin_width) return false;
256  if(m_edges!=a_from.m_edges) return false;
257  return true;
258  }

◆ in_range_to_absolute_index()

template<class TC , class TO >
bool tools::histo::axis< TC, TO >::in_range_to_absolute_index ( int  a_in,
bn_t a_out 
) const
inline

Definition at line 142 of file axis.

142  {
143  // a_in is given in in-range indexing :
144  // - [0,n-1] for in-range bins
145  // - UNDERFLOW_BIN for the iaxis underflow bin
146  // - OVERFLOW_BIN for the iaxis overflow bin
147  // Return the absolute indexing in [0,n+1].
148  if(a_in==UNDERFLOW_BIN) {
149  a_out = 0;
150  return true;
151  } else if(a_in==OVERFLOW_BIN) {
152  a_out = m_number_of_bins+1;
153  return true;
154  } else if((a_in>=0)&&(a_in<(int)m_number_of_bins)){
155  a_out = a_in + 1;
156  return true;
157  } else {
158  return false;
159  }
160  }

◆ is_compatible()

template<class TC , class TO >
bool tools::histo::axis< TC, TO >::is_compatible ( const axis< TC, TO > &  a_axis) const
inline

Definition at line 207 of file axis.

207  {
208  if(m_number_of_bins!=a_axis.m_number_of_bins) return false;
209  if(m_minimum_value!=a_axis.m_minimum_value) return false;
210  if(m_maximum_value!=a_axis.m_maximum_value) return false;
211  return true;
212  }

◆ is_fixed_binning()

template<class TC , class TO >
bool tools::histo::axis< TC, TO >::is_fixed_binning ( ) const
inline

Definition at line 25 of file axis.

25 {return m_fixed;}

◆ lower_edge()

template<class TC , class TO >
TC tools::histo::axis< TC, TO >::lower_edge ( ) const
inline

Definition at line 26 of file axis.

26 {return m_minimum_value;}

◆ operator!=()

template<class TC , class TO >
bool tools::histo::axis< TC, TO >::operator!= ( const axis< TC, TO > &  a_from) const
inline

Definition at line 261 of file axis.

261 {return !equals(a_from);}

◆ operator=()

template<class TC , class TO >
axis& tools::histo::axis< TC, TO >::operator= ( const axis< TC, TO > &  a_from)
inline

Definition at line 236 of file axis.

236  {
237  if(&a_from==this) return *this;
238  m_offset = a_from.m_offset;
239  m_number_of_bins = a_from.m_number_of_bins;
240  m_minimum_value = a_from.m_minimum_value;
241  m_maximum_value = a_from.m_maximum_value;
242  m_fixed = a_from.m_fixed;
243  m_bin_width = a_from.m_bin_width;
244  m_edges = a_from.m_edges;
245  return *this;
246  }

◆ operator==()

template<class TC , class TO >
bool tools::histo::axis< TC, TO >::operator== ( const axis< TC, TO > &  a_from) const
inline

Definition at line 260 of file axis.

260 {return equals(a_from);}

◆ upper_edge()

template<class TC , class TO >
TC tools::histo::axis< TC, TO >::upper_edge ( ) const
inline

Definition at line 27 of file axis.

27 {return m_maximum_value;}

Member Data Documentation

◆ m_bin_width

template<class TC , class TO >
TC tools::histo::axis< TC, TO >::m_bin_width

Definition at line 270 of file axis.

◆ m_edges

template<class TC , class TO >
std::vector<TC> tools::histo::axis< TC, TO >::m_edges

Definition at line 272 of file axis.

◆ m_fixed

template<class TC , class TO >
bool tools::histo::axis< TC, TO >::m_fixed

Definition at line 268 of file axis.

◆ m_maximum_value

template<class TC , class TO >
TC tools::histo::axis< TC, TO >::m_maximum_value

Definition at line 267 of file axis.

◆ m_minimum_value

template<class TC , class TO >
TC tools::histo::axis< TC, TO >::m_minimum_value

Definition at line 266 of file axis.

◆ m_number_of_bins

template<class TC , class TO >
bn_t tools::histo::axis< TC, TO >::m_number_of_bins

Definition at line 265 of file axis.

◆ m_offset

template<class TC , class TO >
TO tools::histo::axis< TC, TO >::m_offset

Definition at line 264 of file axis.


The documentation for this class was generated from the following file:
tools::histo::axis::m_edges
std::vector< TC > m_edges
Definition: axis:272
tools::histo::axis::m_maximum_value
TC m_maximum_value
Definition: axis:267
tools::histo::axis::m_offset
TO m_offset
Definition: axis:264
tools::histo::axis_UNDERFLOW_BIN
@ axis_UNDERFLOW_BIN
Definition: axis:13
tools::histo::axis_OVERFLOW_BIN
@ axis_OVERFLOW_BIN
Definition: axis:13
tools::histo::axis::m_bin_width
TC m_bin_width
Definition: axis:270
tools::histo::axis::UNDERFLOW_BIN
@ UNDERFLOW_BIN
Definition: axis:23
tools::histo::axis::m_minimum_value
TC m_minimum_value
Definition: axis:266
tools::histo::axis::bn_t
unsigned int bn_t
Definition: axis:21
tools::histo::axis::m_number_of_bins
bn_t m_number_of_bins
Definition: axis:265
tools::histo::axis::OVERFLOW_BIN
@ OVERFLOW_BIN
Definition: axis:23
tools::histo::axis::equals
bool equals(const axis &a_from) const
Definition: axis:248
tools::histo::axis::m_fixed
bool m_fixed
Definition: axis:268