yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.9.0
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-2021 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/Fillable.h"
11 #include "YODA/Binned.h"
12 #include "YODA/ProfileBin1D.h"
13 #include "YODA/Scatter2D.h"
14 #include "YODA/Dbn2D.h"
15 #include "YODA/Axis1D.h"
16 #include "YODA/Exceptions.h"
17 #include <vector>
18 #include <string>
19 #include <map>
20 #include <tuple>
21 
22 namespace YODA {
23 
24 
25  // Forward declarations
26  class Histo1D;
27  class Scatter2D;
28 
29 
32 
33 
35  class Profile1D : public AnalysisObject, public Fillable, public Binned {
36  public:
37 
39  typedef Profile1DAxis Axis;
40  typedef Axis::Bins Bins;
41  typedef ProfileBin1D Bin;
42 
43  typedef std::tuple<double, double> FillType;
44  typedef double BinType;
45  typedef std::shared_ptr<Profile1D> Ptr;
46 
47 
50 
52  Profile1D(const std::string& path="", const std::string& title="")
53  : AnalysisObject("Profile1D", path, title),
54  _axis()
55  { }
56 
57 
59  Profile1D(size_t nxbins, double xlower, double xupper,
60  const std::string& path="", const std::string& title="")
61  : AnalysisObject("Profile1D", path, title),
62  _axis(nxbins, xlower, xupper)
63  { }
64 
65 
70  Profile1D(const std::vector<double>& xbinedges,
71  const std::string& path="", const std::string& title="")
72  : AnalysisObject("Profile1D", path, title),
73  _axis(xbinedges)
74  { }
75 
76 
79  Profile1D(const Profile1D& p, const std::string& path="");
80 
81 
84  Profile1D(const Scatter2D& s, const std::string& path="");
85 
86 
89  Profile1D(const Histo1D& h, const std::string& path="");
90 
91 
95  Profile1D(const std::vector<ProfileBin1D>& bins,
96  const Dbn2D& dbn_tot, const Dbn2D& dbn_uflow, const Dbn2D& dbn_oflow,
97  const std::string& path="", const std::string& title="")
98  : AnalysisObject("Profile1D", path, title),
99  _axis(bins, dbn_tot, dbn_uflow, dbn_oflow)
100  { }
101 
102 
105  AnalysisObject::operator = (p1); //< AO treatment of paths etc.
106  _axis = p1._axis;
107  return *this;
108  }
109 
111  Profile1D clone() const {
112  return Profile1D(*this);
113  }
114 
116  Profile1D* newclone() const {
117  return new Profile1D(*this);
118  }
119 
121 
122 
126  size_t dim() const { return 1; }
127 
129  size_t fillDim() const { return 1; }
130 
131 
134 
136  virtual void fill(double x, double y, double weight=1.0, double fraction=1.0);
137  void fill(const FillType & xs, double weight=1.0, double fraction=1.0) {
138  fill(std::get<0>(xs), std::get<1>(xs), weight, fraction);
139  }
140 
142  virtual void fillBin(size_t i, double y, double weight=1.0, double fraction=1.0);
143 
144 
148  void reset() {
149  _axis.reset();
150  }
151 
152 
154  void scaleW(double scalefactor) {
155  _axis.scaleW(scalefactor);
156  }
157 
158 
160  void scaleY(double scalefactor) {
161  _axis.totalDbn().scaleY(scalefactor);
162  _axis.overflow().scaleY(scalefactor);
163  _axis.underflow().scaleY(scalefactor);
164  for (size_t i = 0; i < bins().size(); ++i)
165  bin(i).scaleY(scalefactor);
166  }
167 
168 
170  void mergeBins(size_t from, size_t to) {
171  _axis.mergeBins(from, to);
172  }
173 
175  bool sameBinning(const Profile1D& p1) {
176  return _axis == p1._axis;
177  }
178 
180  void rebinBy(unsigned int n, size_t begin=0, size_t end=UINT_MAX) {
181  _axis.rebinBy(n, begin, end);
182  }
184  void rebin(unsigned int n, size_t begin=0, size_t end=UINT_MAX) {
185  rebinBy(n, begin, end);
186  }
187 
189  void rebinTo(const std::vector<double>& newedges) {
190  _axis.rebinTo(newedges);
191  }
193  void rebin(const std::vector<double>& newedges) {
194  rebinTo(newedges);
195  }
196 
198 
199 
202 
204  void addBin(double xlow, double xhigh) {
205  _axis.addBin(xlow, xhigh);
206  }
207 
209  void addBins(const std::vector<double> binedges) {
210  _axis.addBins(binedges);
211  }
212 
213  // /// Bin addition operator
214  // void addBins(const std::vector<std::pair<double,double> > edges) {
215  // _axis.addBins(edges);
216  // }
217 
219  void addBin(const ProfileBin1D& b) { _axis.addBin(b); }
220 
224  void addBins(const Bins& bins) {
225  _axis.addBins(bins);
226  }
227 
228  void rmBin(size_t index) {
229  _axis.eraseBin(index);
230  }
231 
233 
234 
237 
239  size_t numBins() const { return bins().size(); }
240 
242  size_t numBinsX() const { return numBins(); }
243 
245  double xMin() const { return _axis.xMin(); }
246 
248  double xMax() const { return _axis.xMax(); }
249 
254  const std::vector<double> xEdges() const { return _axis.xEdges(); }
255 
256 
258  std::vector<YODA::ProfileBin1D>& bins() { return _axis.bins(); }
259 
261  const std::vector<YODA::ProfileBin1D>& bins() const { return _axis.bins(); }
262 
263 
265  ProfileBin1D& bin(size_t index) { return _axis.bins()[index]; }
267  const ProfileBin1D& bin(size_t index) const { return _axis.bins()[index]; }
268 
270  int binIndexAt(double x) { return _axis.binIndexAt(x); }
271 
273  const ProfileBin1D& binAt(double x) const { return _axis.binAt(x); }
274 
275 
277  Dbn2D& totalDbn() { return _axis.totalDbn(); }
279  const Dbn2D& totalDbn() const { return _axis.totalDbn(); }
281  void setTotalDbn(const Dbn2D& dbn) { _axis.setTotalDbn(dbn); }
282 
283 
285  Dbn2D& underflow() { return _axis.underflow(); }
287  const Dbn2D& underflow() const { return _axis.underflow(); }
289  void setUnderflow(const Dbn2D& dbn) { _axis.setUnderflow(dbn); }
290 
291 
293  Dbn2D& overflow() { return _axis.overflow(); }
295  const Dbn2D& overflow() const { return _axis.overflow(); }
297  void setOverflow(const Dbn2D& dbn) { _axis.setOverflow(dbn); }
298 
300 
301 
304 
306 
308  double numEntries(bool includeoverflows=true) const;
309 
311  double effNumEntries(bool includeoverflows=true) const;
312 
314  double sumW(bool includeoverflows=true) const;
315 
317  double sumW2(bool includeoverflows=true) const;
318 
320  double xMean(bool includeoverflows=true) const;
321 
323  double xVariance(bool includeoverflows=true) const;
324 
326  double xStdDev(bool includeoverflows=true) const {
327  return std::sqrt(xVariance(includeoverflows));
328  }
329 
331  double xStdErr(bool includeoverflows=true) const;
332 
334  double xRMS(bool includeoverflows=true) const;
335 
337 
338 
341 
344  if (hasAnnotation("ScaledBy")) rmAnnotation("ScaledBy");
345  _axis += toAdd._axis;
346  return *this;
347  }
348 
350  Profile1D& operator -= (const Profile1D& toSubtract) {
351  if (hasAnnotation("ScaledBy")) rmAnnotation("ScaledBy");
352  _axis -= toSubtract._axis;
353  return *this;
354  }
355 
356  inline bool operator == (const Profile1D& other){
357  return _axis == other._axis;
358  }
359 
360  inline bool operator != (const Profile1D& other){
361  return ! operator == (other);
362  }
364 
365 
366  protected:
367 
369  ProfileBin1D& _binAt(double x) { return _axis.binAt(x); }
370 
371 
372  private:
373 
376 
379 
381 
382  };
383 
384 
386  typedef Profile1D P1D;
387 
388 
391 
392 
394  inline Profile1D add(const Profile1D& first, const Profile1D& second) {
395  Profile1D tmp = first;
396  if (first.path() != second.path()) tmp.setPath("");
397  tmp += second;
398  return tmp;
399  }
400 
401 
403  inline Profile1D operator + (const Profile1D& first, const Profile1D& second) {
404  return add(first, second);
405  }
406 
407 
409  inline Profile1D subtract(const Profile1D& first, const Profile1D& second) {
410  Profile1D tmp = first;
411  if (first.path() != second.path()) tmp.setPath("");
412  tmp -= second;
413  return tmp;
414  }
415 
416 
418  inline Profile1D operator - (const Profile1D& first, const Profile1D& second) {
419  return subtract(first, second);
420  }
421 
422 
424  Scatter2D divide(const Profile1D& numer, const Profile1D& denom);
425 
426 
428  inline Scatter2D operator / (const Profile1D& numer, const Profile1D& denom) {
429  return divide(numer, denom);
430  }
431 
433 
434 
435 }
436 
437 #endif
Profile1D & operator-=(const Profile1D &toSubtract)
Subtract another profile from this one.
Definition: Profile1D.h:350
Axis1D< ProfileBin1D, Dbn2D > Profile1DAxis
Convenience typedef.
Definition: Profile1D.h:27
double BinType
Definition: Profile1D.h:44
void rmAnnotation(const std::string &name)
Delete an annotation by name.
ProfileBin1D Bin
Definition: Profile1D.h:41
const Dbn2D & totalDbn() const
Access summary distribution, including gaps and overflows (const version)
Definition: Profile1D.h:279
Profile1D(const std::vector< double > &xbinedges, const std::string &path="", const std::string &title="")
Definition: Profile1D.h:70
void rmBin(size_t index)
Remove a bin.
Definition: Profile1D.h:228
Scatter1D divide(const Counter &numer, const Counter &denom)
Definition: Counter.cc:25
std::shared_ptr< Profile1D > Ptr
Definition: Profile1D.h:45
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:25
const ProfileBin1D & bin(size_t index) const
Access a bin by index (const version)
Definition: Profile1D.h:267
const ProfileBin1D & binAt(double x) const
Access a bin by x-coordinate (const version)
Definition: Profile1D.h:273
size_t numBinsX() const
Number of bins on the x-axis (not counting under/overflow)
Definition: Profile1D.h:242
double xMean(bool includeoverflows=true) const
Get the mean x.
Definition: Profile1D.cc:83
size_t numBins() const
Number of bins (not counting under/overflow)
Definition: Profile1D.h:239
void setTotalDbn(const Dbn2D &dbn)
Set summary distribution, mainly for persistency: CAREFUL!
Definition: Profile1D.h:281
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:289
void setPath(const std::string &path)
A base class for all fillable objects.
Definition: Fillable.h:16
Axis1D< BIN1D, DBN > operator-(const Axis1D< BIN1D, DBN > &first, const Axis1D< BIN1D, DBN > &second)
Subtract the statistics on two axis.
Definition: Axis1D.h:597
A base class for all binned objects.
Definition: Binned.h:16
const std::vector< double > xEdges() const
Definition: Profile1D.h:254
Profile1D * newclone() const
Make a copy on the heap, via &#39;new&#39;.
Definition: Profile1D.h:116
Dbn2D & overflow()
Access overflow (non-const version)
Definition: Profile1D.h:293
bool operator==(const Profile1D &other)
Definition: Profile1D.h:356
A one-dimensional histogram.
Definition: Histo1D.h:28
void addBins(const Bins &bins)
Bins addition operator.
Definition: Profile1D.h:224
void addBins(const std::vector< double > binedges)
Bin addition operator.
Definition: Profile1D.h:209
Counter add(const Counter &first, const Counter &second)
Add two counters.
Definition: Counter.h:247
double sumW2(bool includeoverflows=true) const
Get sum of squared weights in histo.
Definition: Profile1D.cc:73
Profile1D P1D
Convenience typedef.
Definition: Profile1D.h:386
A 2D distribution.
Definition: Dbn2D.h:16
const Dbn2D & overflow() const
Access overflow (const version)
Definition: Profile1D.h:295
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:180
void fill(const FillType &xs, double weight=1.0, double fraction=1.0)
Definition: Profile1D.h:137
Dbn2D & totalDbn()
Access summary distribution, including gaps and overflows (non-const version)
Definition: Profile1D.h:277
double xStdErr(bool includeoverflows=true) const
Get the standard error on the mean x.
Definition: Profile1D.cc:99
void setOverflow(const Dbn2D &dbn)
Set overflow distribution, mainly for persistency: CAREFUL!
Definition: Profile1D.h:297
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:189
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:258
void scaleW(double scalefactor)
Rescale as if all fill weights had been different by factor scalefactor.
Definition: Profile1D.h:154
void addBin(double xlow, double xhigh)
Bin addition operator.
Definition: Profile1D.h:204
Profile1D & operator=(const Profile1D &p1)
Assignment operator.
Definition: Profile1D.h:104
void scaleY(double scalefactor)
Rescale as if all y values had been different by factor scalefactor.
Definition: Profile1D.h:160
Profile1D clone() const
Make a copy on the stack.
Definition: Profile1D.h:111
Counter subtract(const Counter &first, const Counter &second)
Subtract two counters.
Definition: Counter.h:260
Profile1D & operator+=(const Profile1D &toAdd)
Add another profile to this one.
Definition: Profile1D.h:343
void mergeBins(size_t from, size_t to)
Merge together the bin range with indices from from to to, inclusive.
Definition: Profile1D.h:170
void reset()
Reset the histogram.
Definition: Profile1D.h:148
Profile1DAxis Axis
Convenience typedefs.
Definition: Profile1D.h:39
void rebin(unsigned int n, size_t begin=0, size_t end=UINT_MAX)
Overloaded alias for rebinBy.
Definition: Profile1D.h:184
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.
size_t fillDim() const
Fill dimension of this data object.
Definition: Profile1D.h:129
double xMax() const
High edge of this histo&#39;s axis.
Definition: Profile1D.h:248
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:278
size_t dim() const
Fill dimension of this data object.
Definition: Profile1D.h:126
void addBin(const ProfileBin1D &b)
Add a new bin, perhaps already populated: CAREFUL!
Definition: Profile1D.h:219
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:43
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:245
bool operator!=(const Profile1D &other)
Definition: Profile1D.h:360
Profile1D(const std::string &path="", const std::string &title="")
Default constructor.
Definition: Profile1D.h:52
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:59
A one-dimensional profile histogram.
Definition: Profile1D.h:35
bool sameBinning(const Profile1D &p1)
check if binning is the same as different Profile1D
Definition: Profile1D.h:175
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:261
void scaleY(double ay)
Definition: ProfileBin1D.h:90
const Dbn2D & underflow() const
Access underflow (const version)
Definition: Profile1D.h:287
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:326
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:95
ProfileBin1D & bin(size_t index)
Access a bin by index (non-const version)
Definition: Profile1D.h:265
int binIndexAt(double x)
Access a bin index by x-coordinate.
Definition: Profile1D.h:270
Dbn2D & underflow()
Access underflow (non-const version)
Definition: Profile1D.h:285
void rebin(const std::vector< double > &newedges)
Overloaded alias for rebinTo.
Definition: Profile1D.h:193
virtual AnalysisObject & operator=(const AnalysisObject &ao)
Default copy assignment operator.
Axis::Bins Bins
Definition: Profile1D.h:40
1D bin container
Definition: Axis1D.h:20