1 | #ifndef MARS_MBinning
|
---|
2 | #define MARS_MBinning
|
---|
3 |
|
---|
4 | #ifndef MARS_MParContainer
|
---|
5 | #include "MParContainer.h"
|
---|
6 | #endif
|
---|
7 |
|
---|
8 | #ifndef ROOT_TArrayD
|
---|
9 | #include "TArrayD.h"
|
---|
10 | #endif
|
---|
11 |
|
---|
12 | class MBinning : public MParContainer
|
---|
13 | {
|
---|
14 | private:
|
---|
15 | TArrayD fEdges;
|
---|
16 |
|
---|
17 | public:
|
---|
18 | MBinning(const char *name=NULL, const char *title=NULL);
|
---|
19 |
|
---|
20 | void SetEdges(const TArrayD &arr)
|
---|
21 | {
|
---|
22 | const Int_t nbins = arr.GetSize();
|
---|
23 | fEdges.Set(nbins);
|
---|
24 | for (int i=0; i<=nbins; i++)
|
---|
25 | fEdges[i] = (*(TArrayD*)(&arr))[i];
|
---|
26 | }
|
---|
27 |
|
---|
28 | void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up)
|
---|
29 | {
|
---|
30 | const Double_t binsize = (up-lo)/nbins;
|
---|
31 | fEdges.Set(nbins+1);
|
---|
32 | for (int i=0; i<=nbins; i++)
|
---|
33 | fEdges[i] = binsize*i + lo;
|
---|
34 | }
|
---|
35 |
|
---|
36 | void SetEdgesLog(const Int_t nbins, const Axis_t lo, Axis_t up)
|
---|
37 | {
|
---|
38 | const Double_t binsize = (log10(up)-log10(lo))/nbins;
|
---|
39 | fEdges.Set(nbins+1);
|
---|
40 | for (int i=0; i<=nbins; i++)
|
---|
41 | fEdges[i] = pow(10, binsize*i) * lo;
|
---|
42 | }
|
---|
43 |
|
---|
44 | // ROOT workaround: "operator[] const" missing
|
---|
45 | Double_t GetEdgeLo() const { return (*(TArrayD*)(&fEdges))[0]; }
|
---|
46 | Double_t GetEdgeHi() const { return (*(TArrayD*)(&fEdges))[fEdges.GetSize()-1]; }
|
---|
47 |
|
---|
48 | Int_t GetNumEdges() const { return fEdges.GetSize(); }
|
---|
49 | Int_t GetNumBins() const { return fEdges.GetSize()-1; }
|
---|
50 |
|
---|
51 | Double_t *GetEdges() const { return fEdges.GetArray(); }
|
---|
52 |
|
---|
53 | ClassDef(MBinning, 1) //Container to store the binning of a histogram
|
---|
54 | };
|
---|
55 |
|
---|
56 | #endif
|
---|
57 |
|
---|