g4tools  5.4.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tools::histo::c1d Class Reference
Inheritance diagram for tools::histo::c1d:
Inheritance graph
[legend]
Collaboration diagram for tools::histo::c1d:
Collaboration graph
[legend]

Public Member Functions

bool set_title (const std::string &a_title)
 
unsigned int dimension () const
 
bool reset ()
 
unsigned int entries () const
 
double sum_of_weights () const
 
bool convert_to_histogram ()
 
bool is_converted () const
 
bool scale (double a_scale)
 
bool set_histogram (h1d *a_histo)
 
bool fill (double aX, double aW=1)
 
double lower_edge () const
 
double upper_edge () const
 
double value (unsigned int a_index) const
 
double weight (unsigned int a_index) const
 
double mean () const
 
double rms () const
 
bool convert (unsigned int a_bins, double a_lower_edge, double a_upper_edge)
 
bool convert (const std::vector< double > &a_edges)
 
const histo::h1dhistogram () const
 
template<class HISTO >
bool fill_histogram (HISTO &a_histo) const
 
bool set_conversion_parameters (unsigned int aCnvXnumber, double aCnvXmin, double aCnvXmax)
 
 c1d ()
 
 c1d (const std::string &a_title, int aLimit=base_cloud::UNLIMITED())
 
virtual ~c1d ()
 
 c1d (const c1d &a_from)
 
c1doperator= (const c1d &a_from)
 
double lowerEdge () const
 
double upperEdge () const
 
template<class HISTO >
bool fillHistogram (HISTO &a_histo) const
 
- Public Member Functions inherited from tools::histo::base_cloud
 base_cloud (const base_cloud &a_from)
 
base_cloudoperator= (const base_cloud &a_from)
 
const std::string & title () const
 
int max_entries () const
 

Static Public Member Functions

static const std::string & s_class ()
 

Protected Member Functions

void clear ()
 
- Protected Member Functions inherited from tools::histo::base_cloud
 base_cloud (int aLimit)
 
virtual ~base_cloud ()
 

Protected Attributes

std::vector< double > m_xs
 
double m_lower_x
 
double m_upper_x
 
double m_Sxw
 
double m_Sx2w
 
unsigned int m_cnv_x_num
 
double m_cnv_x_min
 
double m_cnv_x_max
 
histo::h1dm_histo
 
- Protected Attributes inherited from tools::histo::base_cloud
std::string m_title
 
int m_limit
 
double m_Sw
 
std::vector< double > m_ws
 

Additional Inherited Members

- Static Protected Member Functions inherited from tools::histo::base_cloud
static int UNLIMITED ()
 
static unsigned int BINS ()
 

Detailed Description

Definition at line 16 of file c1d.

Constructor & Destructor Documentation

◆ c1d() [1/3]

tools::histo::c1d::c1d ( )
inline

Definition at line 165 of file c1d.

167  ,m_lower_x(0),m_upper_x(0)
168  ,m_Sxw(0),m_Sx2w(0)
170  {}

◆ c1d() [2/3]

tools::histo::c1d::c1d ( const std::string &  a_title,
int  aLimit = base_cloud::UNLIMITED() 
)
inline

Definition at line 172 of file c1d.

173  :base_cloud(aLimit)
174  ,m_lower_x(0),m_upper_x(0)
175  ,m_Sxw(0),m_Sx2w(0)
177  {
178  set_title(a_title);
179  }

◆ ~c1d()

virtual tools::histo::c1d::~c1d ( )
inlinevirtual

Definition at line 181 of file c1d.

181 {delete m_histo;}

◆ c1d() [3/3]

tools::histo::c1d::c1d ( const c1d a_from)
inline

Definition at line 183 of file c1d.

184  :base_cloud(a_from)
185  ,m_xs(a_from.m_xs)
186  ,m_lower_x(a_from.m_lower_x)
187  ,m_upper_x(a_from.m_upper_x)
188  ,m_Sxw(a_from.m_Sxw)
189  ,m_Sx2w(a_from.m_Sx2w)
190  ,m_cnv_x_num(a_from.m_cnv_x_num)
191  ,m_cnv_x_min(a_from.m_cnv_x_min)
192  ,m_cnv_x_max(a_from.m_cnv_x_max)
193  ,m_histo(0)
194  {
195  if(a_from.m_histo) {
196  m_histo = new histo::h1d(*a_from.m_histo);
197  }
198  }

Member Function Documentation

◆ clear()

void tools::histo::c1d::clear ( )
inlineprotected

Definition at line 225 of file c1d.

225  {
226  m_lower_x = 0;
227  m_upper_x = 0;
228  m_Sw = 0;
229  m_Sxw = 0;
230  m_Sx2w = 0;
231  m_xs.clear();
232  m_ws.clear();
233  }

◆ convert() [1/2]

bool tools::histo::c1d::convert ( const std::vector< double > &  a_edges)
inline

Definition at line 135 of file c1d.

135  {
136  if(m_histo) return true;
137  m_histo = new histo::h1d(base_cloud::title(),a_edges);
138  if(!m_histo) return false;
139  bool status = fill_histogram(*m_histo);
140  clear();
141  return status;
142  }

◆ convert() [2/2]

bool tools::histo::c1d::convert ( unsigned int  a_bins,
double  a_lower_edge,
double  a_upper_edge 
)
inline

Definition at line 126 of file c1d.

126  {
127  if(m_histo) return true;
128  m_histo = new histo::h1d(base_cloud::title(),a_bins,a_lower_edge,a_upper_edge);
129  if(!m_histo) return false;
130  bool status = fill_histogram(*m_histo);
131  clear();
132  return status;
133  }

◆ convert_to_histogram()

bool tools::histo::c1d::convert_to_histogram ( )
inline

Definition at line 44 of file c1d.

44  {
45  if( (m_cnv_x_num<=0) || (m_cnv_x_max<=m_cnv_x_min) ) {
46  // Cloud min, max should be included in the histo.
47  double dx = 0.01 * (upper_edge() - lower_edge())/BINS();
48  return convert(BINS(),lower_edge(),upper_edge() + dx);
49  } else {
51  }
52  }

◆ dimension()

unsigned int tools::histo::c1d::dimension ( ) const
inline

Definition at line 29 of file c1d.

29 {return 1;}

◆ entries()

unsigned int tools::histo::c1d::entries ( ) const
inline

Definition at line 36 of file c1d.

36  {
37  return m_histo ? m_histo->all_entries() : (unsigned int)m_ws.size();
38  }

◆ fill()

bool tools::histo::c1d::fill ( double  aX,
double  aW = 1 
)
inline

Definition at line 75 of file c1d.

75  {
76  if(!m_histo && (m_limit!=UNLIMITED()) &&
77  ((int)m_xs.size()>=m_limit)){
79  }
80 
81  if(m_histo) {
82  return m_histo->fill(aX,aW);
83  } else {
84  if(m_xs.size()) {
85  m_lower_x = mn<double>(aX,m_lower_x);
86  m_upper_x = mx<double>(aX,m_upper_x);
87  } else {
88  m_lower_x = aX;
89  m_upper_x = aX;
90  }
91  m_xs.push_back(aX);
92  m_ws.push_back(aW);
93  m_Sw += aW;
94  double xw = aX * aW;
95  m_Sxw += xw;
96  m_Sx2w += aX * xw;
97  return true;
98  }
99  }

◆ fill_histogram()

template<class HISTO >
bool tools::histo::c1d::fill_histogram ( HISTO &  a_histo) const
inline

Definition at line 149 of file c1d.

149  {
150  size_t number = m_xs.size();
151  for(size_t index=0;index<number;index++) {
152  if(!a_histo.fill(m_xs[index],m_ws[index])) return false;
153  }
154  return true;
155  }

◆ fillHistogram()

template<class HISTO >
bool tools::histo::c1d::fillHistogram ( HISTO &  a_histo) const
inline

Definition at line 223 of file c1d.

223 {return fill_histogram<HISTO>(a_histo);}

◆ histogram()

const histo::h1d& tools::histo::c1d::histogram ( ) const
inline

Definition at line 144 of file c1d.

144  {
145  if(!m_histo) const_cast<c1d&>(*this).convert_to_histogram();
146  return *m_histo;
147  }

◆ is_converted()

bool tools::histo::c1d::is_converted ( ) const
inline

Definition at line 54 of file c1d.

54 {return m_histo ? true : false;}

◆ lower_edge()

double tools::histo::c1d::lower_edge ( ) const
inline

Definition at line 101 of file c1d.

101  {
102  return (m_histo ? m_histo->axis().lower_edge() : m_lower_x);
103  }

◆ lowerEdge()

double tools::histo::c1d::lowerEdge ( ) const
inline

Definition at line 220 of file c1d.

220 {return lower_edge();}

◆ mean()

double tools::histo::c1d::mean ( ) const
inline

Definition at line 109 of file c1d.

109  {
110  return (m_histo ? m_histo->mean() : (m_Sw?m_Sxw/m_Sw:0));
111  }

◆ operator=()

c1d& tools::histo::c1d::operator= ( const c1d a_from)
inline

Definition at line 200 of file c1d.

200  {
201  base_cloud::operator=(a_from);
202  if(&a_from==this) return *this;
203  m_xs = a_from.m_xs;
204  m_lower_x = a_from.m_lower_x;
205  m_upper_x = a_from.m_upper_x;
206  m_Sxw = a_from.m_Sxw;
207  m_Sx2w = a_from.m_Sx2w;
208  m_cnv_x_num = a_from.m_cnv_x_num;
209  m_cnv_x_min = a_from.m_cnv_x_min;
210  m_cnv_x_max = a_from.m_cnv_x_max;
211  delete m_histo;
212  m_histo = 0;
213  if(a_from.m_histo) {
214  m_histo = new histo::h1d(*a_from.m_histo);
215  }
216  return *this;
217  }

◆ reset()

bool tools::histo::c1d::reset ( )
inline

Definition at line 30 of file c1d.

30  {
31  clear();
32  delete m_histo;
33  m_histo = 0;
34  return true;
35  }

◆ rms()

double tools::histo::c1d::rms ( ) const
inline

Definition at line 112 of file c1d.

112  {
113  double _rms = 0; //FIXME nan.
114  if(m_histo) {
115  _rms = m_histo->rms();
116  } else {
117  if(m_Sw==0) {
118  } else {
119  double _mean = m_Sxw / m_Sw;
120  _rms = ::sqrt(::fabs( (m_Sx2w / m_Sw) - _mean * _mean));
121  }
122  }
123  return _rms;
124  }

◆ s_class()

static const std::string& tools::histo::c1d::s_class ( )
inlinestatic

Definition at line 18 of file c1d.

18  {
19  static const std::string s_v("tools::histo::c1d");
20  return s_v;
21  }

◆ scale()

bool tools::histo::c1d::scale ( double  a_scale)
inline

Definition at line 55 of file c1d.

55  {
56  if(m_histo) {
57  return m_histo->scale(a_scale);
58  } else {
59  size_t number = m_ws.size();
60  for(size_t index=0;index<number;index++) m_ws[index] *= a_scale;
61  m_Sw *= a_scale;
62  m_Sxw *= a_scale;
63  m_Sx2w *= a_scale;
64  return true;
65  }
66  }

◆ set_conversion_parameters()

bool tools::histo::c1d::set_conversion_parameters ( unsigned int  aCnvXnumber,
double  aCnvXmin,
double  aCnvXmax 
)
inline

Definition at line 156 of file c1d.

157  {
158  m_cnv_x_num = aCnvXnumber;
159  m_cnv_x_min = aCnvXmin;
160  m_cnv_x_max = aCnvXmax;
161  return true;
162  }

◆ set_histogram()

bool tools::histo::c1d::set_histogram ( h1d a_histo)
inline

Definition at line 68 of file c1d.

68  { //we take ownership of a_histo.
69  reset();
70  m_histo = a_histo;
71  return true;
72  }

◆ set_title()

bool tools::histo::c1d::set_title ( const std::string &  a_title)
inline

Definition at line 23 of file c1d.

23  {
24  m_title = a_title;
25  if(m_histo) m_histo->set_title(a_title);
26  return true;
27  }

◆ sum_of_weights()

double tools::histo::c1d::sum_of_weights ( ) const
inline

Definition at line 40 of file c1d.

40  {
41  return (m_histo ? m_histo->sum_bin_heights() : m_Sw);
42  }

◆ upper_edge()

double tools::histo::c1d::upper_edge ( ) const
inline

Definition at line 104 of file c1d.

104  {
105  return (m_histo ? m_histo->axis().upper_edge() : m_upper_x);
106  }

◆ upperEdge()

double tools::histo::c1d::upperEdge ( ) const
inline

Definition at line 221 of file c1d.

221 {return upper_edge();}

◆ value()

double tools::histo::c1d::value ( unsigned int  a_index) const
inline

Definition at line 107 of file c1d.

107 {return (m_histo ?0:m_xs[a_index]);}

◆ weight()

double tools::histo::c1d::weight ( unsigned int  a_index) const
inline

Definition at line 108 of file c1d.

108 {return (m_histo ?0:m_ws[a_index]);}

Member Data Documentation

◆ m_cnv_x_max

double tools::histo::c1d::m_cnv_x_max
protected

Definition at line 244 of file c1d.

◆ m_cnv_x_min

double tools::histo::c1d::m_cnv_x_min
protected

Definition at line 243 of file c1d.

◆ m_cnv_x_num

unsigned int tools::histo::c1d::m_cnv_x_num
protected

Definition at line 242 of file c1d.

◆ m_histo

histo::h1d* tools::histo::c1d::m_histo
protected

Definition at line 245 of file c1d.

◆ m_lower_x

double tools::histo::c1d::m_lower_x
protected

Definition at line 237 of file c1d.

◆ m_Sx2w

double tools::histo::c1d::m_Sx2w
protected

Definition at line 240 of file c1d.

◆ m_Sxw

double tools::histo::c1d::m_Sxw
protected

Definition at line 239 of file c1d.

◆ m_upper_x

double tools::histo::c1d::m_upper_x
protected

Definition at line 238 of file c1d.

◆ m_xs

std::vector<double> tools::histo::c1d::m_xs
protected

Definition at line 236 of file c1d.


The documentation for this class was generated from the following file:
tools::histo::c1d::m_xs
std::vector< double > m_xs
Definition: c1d:236
tools::histo::c1d::m_upper_x
double m_upper_x
Definition: c1d:238
tools::histo::base_cloud::operator=
base_cloud & operator=(const base_cloud &a_from)
Definition: base_cloud:48
tools::histo::base_cloud::title
const std::string & title() const
Definition: base_cloud:56
tools::histo::c1d::m_cnv_x_max
double m_cnv_x_max
Definition: c1d:244
tools::histo::c1d::m_cnv_x_num
unsigned int m_cnv_x_num
Definition: c1d:242
tools::histo::c1d::lower_edge
double lower_edge() const
Definition: c1d:101
tools::histo::c1d::m_lower_x
double m_lower_x
Definition: c1d:237
tools::histo::c1d::reset
bool reset()
Definition: c1d:30
tools::histo::c1d::m_Sx2w
double m_Sx2w
Definition: c1d:240
tools::histo::c1d::fill_histogram
bool fill_histogram(HISTO &a_histo) const
Definition: c1d:149
tools::histo::base_cloud::m_Sw
double m_Sw
Definition: base_cloud:64
tools::histo::axis::upper_edge
TC upper_edge() const
Definition: axis:27
tools::histo::base_cloud::m_limit
int m_limit
Definition: base_cloud:63
tools::histo::base_cloud::UNLIMITED
static int UNLIMITED()
Definition: base_cloud:59
tools::histo::base_cloud::m_title
std::string m_title
Definition: base_cloud:62
tools::histo::base_cloud::m_ws
std::vector< double > m_ws
Definition: base_cloud:65
tools::histo::c1d::clear
void clear()
Definition: c1d:225
tools::histo::c1d::convert
bool convert(unsigned int a_bins, double a_lower_edge, double a_upper_edge)
Definition: c1d:126
tools::histo::c1d::m_histo
histo::h1d * m_histo
Definition: c1d:245
tools::histo::b1::axis
const axis_t & axis() const
Definition: b1:103
tools::histo::b1::rms
TC rms() const
Definition: b1:37
tools::histo::c1d::set_title
bool set_title(const std::string &a_title)
Definition: c1d:23
tools::histo::base_histo::all_entries
TN all_entries() const
Definition: base_histo:95
tools::histo::c1d::c1d
c1d()
Definition: c1d:165
tools::histo::base_histo::set_title
bool set_title(const std::string &a_title)
Definition: base_histo:88
tools::histo::base_cloud::base_cloud
base_cloud(int aLimit)
Definition: base_cloud:23
tools::histo::h1::fill
bool fill(TC aX, TW aWeight=1)
Definition: h1:48
tools::histo::c1d::m_Sxw
double m_Sxw
Definition: c1d:239
tools::histo::c1d::m_cnv_x_min
double m_cnv_x_min
Definition: c1d:243
tools::histo::c1d::upper_edge
double upper_edge() const
Definition: c1d:104
tools::histo::c1d::convert_to_histogram
bool convert_to_histogram()
Definition: c1d:44
tools::histo::base_histo::sum_bin_heights
TH sum_bin_heights() const
Definition: base_histo:114
tools::histo::h1::scale
bool scale(TW a_factor)
Definition: h1:38
tools::histo::b1::mean
TC mean() const
Definition: b1:30
tools::histo::axis::lower_edge
TC lower_edge() const
Definition: axis:26
tools::histo::base_cloud::BINS
static unsigned int BINS()
Definition: base_cloud:60