yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.7.2
Profile1D.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of YODA -- Yet more Objects for Data Analysis
4 // Copyright (C) 2008-2017 The YODA collaboration (see AUTHORS for details)
5 //
6 #ifndef YODA_Profile1D_h
7 #define YODA_Profile1D_h
8 
9 #include "YODA/AnalysisObject.h"
10 #include "YODA/ProfileBin1D.h"
11 #include "YODA/Scatter2D.h"
12 #include "YODA/Dbn2D.h"
13 #include "YODA/Axis1D.h"
14 #include "YODA/Exceptions.h"
15 #include <vector>
16 #include <string>
17 #include <map>
18 #include <tuple>
19 
20 namespace YODA {
21 
22 
23  // Forward declarations
24  class Histo1D;
25  class Scatter2D;
26 
27 
30 
31 
33  class Profile1D : public AnalysisObject {
34  public:
35 
37  typedef Profile1DAxis Axis;
38  typedef Axis::Bins Bins;
39  typedef ProfileBin1D Bin;
40 
41  typedef std::tuple<double, double> FillType;
42  typedef double BinType;
43  typedef std::shared_ptr<Profile1D> Ptr;
44 
45 
47 
48 
50  Profile1D(const std::string& path="", const std::string& title="")
51  : AnalysisObject("Profile1D", path, title),
52  _axis()
53  { }
54 
55 
57  Profile1D(size_t nxbins, double xlower, double xupper,
58  const std::string& path="", const std::string& title="")
59  : AnalysisObject("Profile1D", path, title),
60  _axis(nxbins, xlower, xupper)
61  { }
62 
63 
68  Profile1D(const std::vector<double>& xbinedges,
69  const std::string& path="", const std::string& title="")
70  : AnalysisObject("Profile1D", path, title),
71  _axis(xbinedges)
72  { }
73 
74 
77  Profile1D(const Profile1D& p, const std::string& path="");
78 
79 
82  Profile1D(const Scatter2D& s, const std::string& path="");
83 
84 
87  Profile1D(const Histo1D& h, const std::string& path="");
88 
89 
93  Profile1D(const std::vector<ProfileBin1D>& bins,
94  const Dbn2D& dbn_tot, const Dbn2D& dbn_uflow, const Dbn2D& dbn_oflow,
95  const std::string& path="", const std::string& title="")
96  : AnalysisObject("Profile1D", path, title),
97  _axis(bins, dbn_tot, dbn_uflow, dbn_oflow)
98  { }
99 
100 
103  AnalysisObject::operator = (p1); //< AO treatment of paths etc.
104  _axis = p1._axis;
105  return *this;
106  }
107 
109  Profile1D clone() const {
110  return Profile1D(*this);
111  }
112 
114  Profile1D* newclone() const {
115  return new Profile1D(*this);
116  }
117 
119 
120 
122  size_t dim() const { return 1; }
123 
124 
126 
127 
129  virtual void fill(double x, double y, double weight=1.0, double fraction=1.0);
130  void fill(const FillType & xs, double weight=1.0, double fraction=1.0) {
131  fill(std::get<0>(xs), std::get<1>(xs), weight, fraction);
132  }
133 
135  virtual void fillBin(size_t i, double y, double weight=1.0, double fraction=1.0);
136 
137 
141  void reset() {
142  _axis.reset();
143  }
144 
145 
147  void scaleW(double scalefactor) {
148  _axis.scaleW(scalefactor);
149  }
150 
151 
153  void scaleY(double scalefactor) {
154  _axis.totalDbn().scaleY(scalefactor);
155  _axis.overflow().scaleY(scalefactor);
156  _axis.underflow().scaleY(scalefactor);
157  for (size_t i = 0; i < bins().size(); ++i)
158  bin(i).scaleY(scalefactor);
159  }
160 
161 
163  void mergeBins(size_t from, size_t to) {
164  _axis.mergeBins(from, to);
165  }
166 
167 
169  void rebinBy(unsigned int n, size_t begin=0, size_t end=UINT_MAX) {
170  _axis.rebinBy(n, begin, end);
171  }
173  void rebin(unsigned int n, size_t begin=0, size_t end=UINT_MAX) {
174  rebinBy(n, begin, end);
175  }
176 
178  void rebinTo(const std::vector<double>& newedges) {
179  _axis.rebinTo(newedges);
180  }
182  void rebin(const std::vector<double>& newedges) {
183  rebinTo(newedges);
184  }
185 
186 
188  void addBin(double xlow, double xhigh) {
189  _axis.addBin(xlow, xhigh);
190  }
191 
193  void addBins(const std::vector<double> binedges) {
194  _axis.addBins(binedges);
195  }
196 
197  // /// Bin addition operator
198  // void addBins(const std::vector<std::pair<double,double> > edges) {
199  // _axis.addBins(edges);
200  // }
201 
203  void addBin(const ProfileBin1D& b) { _axis.addBin(b); }
204 
208  void addBins(const Bins& bins) {
209  _axis.addBins(bins);
210  }
211 
213 
214 
216 
217 
219  size_t numBins() const { return bins().size(); }
220 
222  double xMin() const { return _axis.xMin(); }
223 
225  double xMax() const { return _axis.xMax(); }
226 
231  const std::vector<double> xEdges() const { return _axis.xEdges(); }
232 
233 
235  std::vector<YODA::ProfileBin1D>& bins() { return _axis.bins(); }
236 
238  const std::vector<YODA::ProfileBin1D>& bins() const { return _axis.bins(); }
239 
240 
242  ProfileBin1D& bin(size_t index) { return _axis.bins()[index]; }
244  const ProfileBin1D& bin(size_t index) const { return _axis.bins()[index]; }
245 
247  int binIndexAt(double x) { return _axis.binIndexAt(x); }
248 
250  const ProfileBin1D& binAt(double x) const { return _axis.binAt(x); }
251 
252 
254  Dbn2D& totalDbn() { return _axis.totalDbn(); }
256  const Dbn2D& totalDbn() const { return _axis.totalDbn(); }
258  void setTotalDbn(const Dbn2D& dbn) { _axis.setTotalDbn(dbn); }
259 
260 
262  Dbn2D& underflow() { return _axis.underflow(); }
264  const Dbn2D& underflow() const { return _axis.underflow(); }
266  void setUnderflow(const Dbn2D& dbn) { _axis.setUnderflow(dbn); }
267 
268 
270  Dbn2D& overflow() { return _axis.overflow(); }
272  const Dbn2D& overflow() const { return _axis.overflow(); }
274  void setOverflow(const Dbn2D& dbn) { _axis.setOverflow(dbn); }
275 
277 
278 
280 
281 
283 
285  double numEntries(bool includeoverflows=true) const;
286 
288  double effNumEntries(bool includeoverflows=true) const;
289 
291  double sumW(bool includeoverflows=true) const;
292 
294  double sumW2(bool includeoverflows=true) const;
295 
297  double xMean(bool includeoverflows=true) const;
298 
300  double xVariance(bool includeoverflows=true) const;
301 
303  double xStdDev(bool includeoverflows=true) const {
304  return std::sqrt(xVariance(includeoverflows));
305  }
306 
308  double xStdErr(bool includeoverflows=true) const;
309 
311  double xRMS(bool includeoverflows=true) const;
312 
314 
315 
317 
318 
321  if (hasAnnotation("ScaledBy")) rmAnnotation("ScaledBy");
322  _axis += toAdd._axis;
323  return *this;
324  }
325 
327  Profile1D& operator -= (const Profile1D& toSubtract) {
328  if (hasAnnotation("ScaledBy")) rmAnnotation("ScaledBy");
329  _axis -= toSubtract._axis;
330  return *this;
331  }
332 
333  inline bool operator == (const Profile1D& other){
334  return _axis == other._axis;
335  }
336 
337  inline bool operator != (const Profile1D& other){
338  return ! operator == (other);
339  }
341 
342 
343  protected:
344 
346  ProfileBin1D& _binAt(double x) { return _axis.binAt(x); }
347 
348 
349  private:
350 
352 
353 
356 
358 
359  };
360 
361 
363  typedef Profile1D P1D;
364 
365 
367 
368 
369 
371  inline Profile1D add(const Profile1D& first, const Profile1D& second) {
372  Profile1D tmp = first;
373  if (first.path() != second.path()) tmp.setPath("");
374  tmp += second;
375  return tmp;
376  }
377 
378 
380  inline Profile1D operator + (const Profile1D& first, const Profile1D& second) {
381  return add(first, second);
382  }
383 
384 
386  inline Profile1D subtract(const Profile1D& first, const Profile1D& second) {
387  Profile1D tmp = first;
388  if (first.path() != second.path()) tmp.setPath("");
389  tmp -= second;
390  return tmp;
391  }
392 
393 
395  inline Profile1D operator - (const Profile1D& first, const Profile1D& second) {
396  return subtract(first, second);
397  }
398 
399 
401  Scatter2D divide(const Profile1D& numer, const Profile1D& denom);
402 
403 
405  inline Scatter2D operator / (const Profile1D& numer, const Profile1D& denom) {
406  return divide(numer, denom);
407  }
408 
410 
411 
412 }
413 
414 #endif
Profile1D & operator-=(const Profile1D &toSubtract)
Subtract another profile from this one.
Definition: Profile1D.h:327
Axis1D< ProfileBin1D, Dbn2D > Profile1DAxis
Convenience typedef.
Definition: Profile1D.h:25
double BinType
Definition: Profile1D.h:42
void rmAnnotation(const std::string &name)
Delete an annotation by name.
ProfileBin1D Bin
Definition: Profile1D.h:39
const Dbn2D & totalDbn() const
Access summary distribution, including gaps and overflows (const version)
Definition: Profile1D.h:256
Profile1D(const std::vector< double > &xbinedges, const std::string &path="", const std::string &title="")
Definition: Profile1D.h:68
Scatter1D divide(const Counter &numer, const Counter &denom)
Definition: Counter.cc:25
std::shared_ptr< Profile1D > Ptr
Definition: Profile1D.h:43
const std::string path() const
Get the AO path.
A very generic data type which is just a collection of 2D data points with errors.
Definition: Scatter2D.h:24
const ProfileBin1D & bin(size_t index) const
Access a bin by index (const version)
Definition: Profile1D.h:244
const ProfileBin1D & binAt(double x) const
Access a bin by x-coordinate (const version)
Definition: Profile1D.h:250
double xMean(bool includeoverflows=true) const
Get the mean x.
Definition: Profile1D.cc:83
size_t numBins() const
Number of bins on this axis (not counting under/overflow)
Definition: Profile1D.h:219
void setTotalDbn(const Dbn2D &dbn)
Set summary distribution, mainly for persistency: CAREFUL!
Definition: Profile1D.h:258
virtual void fillBin(size_t i, double y, double weight=1.0, double fraction=1.0)
Fill histo x bin i with the given y value and weight.
Definition: Profile1D.cc:41
void setUnderflow(const Dbn2D &dbn)
Set underflow distribution, mainly for persistency: CAREFUL!
Definition: Profile1D.h:266
void setPath(const std::string &path)
Axis1D< BIN1D, DBN > operator-(const Axis1D< BIN1D, DBN > &first, const Axis1D< BIN1D, DBN > &second)
Subtract the statistics on two axis.
Definition: Axis1D.h:597
const std::vector< double > xEdges() const
Definition: Profile1D.h:231
Profile1D * newclone() const
Make a copy on the heap, via &#39;new&#39;.
Definition: Profile1D.h:114
Dbn2D & overflow()
Access overflow (non-const version)
Definition: Profile1D.h:270
bool operator==(const Profile1D &other)
Definition: Profile1D.h:333
A one-dimensional histogram.
Definition: Histo1D.h:26
void addBins(const Bins &bins)
Bins addition operator.
Definition: Profile1D.h:208
void addBins(const std::vector< double > binedges)
Bin addition operator.
Definition: Profile1D.h:193
Counter add(const Counter &first, const Counter &second)
Add two counters.
Definition: Counter.h:236
double sumW2(bool includeoverflows=true) const
Get sum of squared weights in histo.
Definition: Profile1D.cc:73
Profile1D P1D
Convenience typedef.
Definition: Profile1D.h:363
A 2D distribution.
Definition: Dbn2D.h:16
const Dbn2D & overflow() const
Access overflow (const version)
Definition: Profile1D.h:272
void rebinBy(unsigned int n, size_t begin=0, size_t end=UINT_MAX)
Merge every group of n bins, starting from the LHS.
Definition: Profile1D.h:169
void fill(const FillType &xs, double weight=1.0, double fraction=1.0)
Definition: Profile1D.h:130
Dbn2D & totalDbn()
Access summary distribution, including gaps and overflows (non-const version)
Definition: Profile1D.h:254
double xStdErr(bool includeoverflows=true) const
Get the standard error on <x>
Definition: Profile1D.cc:99
void setOverflow(const Dbn2D &dbn)
Set overflow distribution, mainly for persistency: CAREFUL!
Definition: Profile1D.h:274
double effNumEntries(bool includeoverflows=true) const
Get the effective number of fills.
Definition: Profile1D.cc:57
void rebinTo(const std::vector< double > &newedges)
Rebin to the given list of bin edges.
Definition: Profile1D.h:178
Axis1D< BIN1D, DBN > operator+(const Axis1D< BIN1D, DBN > &first, const Axis1D< BIN1D, DBN > &second)
Add the statistics on two axes.
Definition: Axis1D.h:589
std::vector< YODA::ProfileBin1D > & bins()
Access the bin vector.
Definition: Profile1D.h:235
void scaleW(double scalefactor)
Rescale as if all fill weights had been different by factor scalefactor.
Definition: Profile1D.h:147
void addBin(double xlow, double xhigh)
Bin addition operator.
Definition: Profile1D.h:188
Profile1D & operator=(const Profile1D &p1)
Assignment operator.
Definition: Profile1D.h:102
void scaleY(double scalefactor)
Rescale as if all y values had been different by factor scalefactor.
Definition: Profile1D.h:153
Profile1D clone() const
Make a copy on the stack.
Definition: Profile1D.h:109
Counter subtract(const Counter &first, const Counter &second)
Subtract two counters.
Definition: Counter.h:249
Profile1D & operator+=(const Profile1D &toAdd)
Add another profile to this one.
Definition: Profile1D.h:320
void mergeBins(size_t from, size_t to)
Merge together the bin range with indices from from to to, inclusive.
Definition: Profile1D.h:163
void reset()
Reset the histogram.
Definition: Profile1D.h:141
Profile1DAxis Axis
Convenience typedefs.
Definition: Profile1D.h:37
void rebin(unsigned int n, size_t begin=0, size_t end=UINT_MAX)
Overloaded alias for rebinBy.
Definition: Profile1D.h:173
const std::string title() const
Get the AO title.
std::vector< Bin > Bins
A vector containing 1D bins. Not used for searching.
Definition: Axis1D.h:30
A Bin1D specialised for handling profile-type information.
Definition: ProfileBin1D.h:23
AnalysisObject is the base class for histograms and scatters.
bool hasAnnotation(const std::string &name) const
Check if an annotation is defined.
double xMax() const
High edge of this histo&#39;s axis.
Definition: Profile1D.h:225
double xVariance(bool includeoverflows=true) const
Get the variance in x.
Definition: Profile1D.cc:91
Scatter1D operator/(const Counter &numer, const Counter &denom)
Definition: Counter.h:267
size_t dim() const
Fill dimension of this data object.
Definition: Profile1D.h:122
void addBin(const ProfileBin1D &b)
Add a new bin, perhaps already populated: CAREFUL!
Definition: Profile1D.h:203
double numEntries(bool includeoverflows=true) const
Get the number of fills (fractional fills are possible)
Definition: Profile1D.cc:49
std::tuple< double, double > FillType
Definition: Profile1D.h:41
double xRMS(bool includeoverflows=true) const
Get the RMS in x.
Definition: Profile1D.cc:107
double xMin() const
Low edge of this histo&#39;s axis.
Definition: Profile1D.h:222
bool operator!=(const Profile1D &other)
Definition: Profile1D.h:337
Profile1D(const std::string &path="", const std::string &title="")
Default constructor.
Definition: Profile1D.h:50
Profile1D(size_t nxbins, double xlower, double xupper, const std::string &path="", const std::string &title="")
Constructor giving range and number of bins.
Definition: Profile1D.h:57
A one-dimensional profile histogram.
Definition: Profile1D.h:33
virtual void fill(double x, double y, double weight=1.0, double fraction=1.0)
Fill histo by value and weight.
Definition: Profile1D.cc:16
const std::vector< YODA::ProfileBin1D > & bins() const
Access the bin vector.
Definition: Profile1D.h:238
void scaleY(double ay)
Definition: ProfileBin1D.h:90
const Dbn2D & underflow() const
Access underflow (const version)
Definition: Profile1D.h:264
double sumW(bool includeoverflows=true) const
Get sum of weights in histo.
Definition: Profile1D.cc:65
double xStdDev(bool includeoverflows=true) const
Get the standard deviation in x.
Definition: Profile1D.h:303
Profile1D(const std::vector< ProfileBin1D > &bins, const Dbn2D &dbn_tot, const Dbn2D &dbn_uflow, const Dbn2D &dbn_oflow, const std::string &path="", const std::string &title="")
State-setting constructor.
Definition: Profile1D.h:93
ProfileBin1D & bin(size_t index)
Access a bin by index (non-const version)
Definition: Profile1D.h:242
int binIndexAt(double x)
Access a bin index by x-coordinate.
Definition: Profile1D.h:247
Dbn2D & underflow()
Access underflow (non-const version)
Definition: Profile1D.h:262
void rebin(const std::vector< double > &newedges)
Overloaded alias for rebinTo.
Definition: Profile1D.h:182
virtual AnalysisObject & operator=(const AnalysisObject &ao)
Default copy assignment operator.
Axis::Bins Bins
Definition: Profile1D.h:38
1D bin container
Definition: Axis1D.h:20