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 TH1;
|
---|
13 | class TAxis;
|
---|
14 |
|
---|
15 | class MParList;
|
---|
16 |
|
---|
17 | class MBinning : public MParContainer
|
---|
18 | {
|
---|
19 | public:
|
---|
20 | static const TString gsDefName;
|
---|
21 | static const TString gsDefTitle;
|
---|
22 |
|
---|
23 | private:
|
---|
24 |
|
---|
25 | TArrayD fEdges;
|
---|
26 |
|
---|
27 | Byte_t fType;
|
---|
28 |
|
---|
29 | void StreamPrimitive(ostream &out) const;
|
---|
30 |
|
---|
31 | enum {
|
---|
32 | kIsDefault,
|
---|
33 | kIsLinear,
|
---|
34 | kIsLogarithmic,
|
---|
35 | kIsCosinic,
|
---|
36 | kIsUserArray
|
---|
37 | };
|
---|
38 |
|
---|
39 | public:
|
---|
40 | MBinning(const char *name=NULL, const char *title=NULL);
|
---|
41 | MBinning(Int_t nbins, Axis_t lo, Axis_t hi, const char *name=0, const char *opt="", const char *title=NULL);
|
---|
42 | MBinning(const MBinning &bins, const char *name=NULL, const char *title=NULL);
|
---|
43 | MBinning(const TH1 &h, const Char_t axis='x', const char *name=0, const char *title=0);
|
---|
44 | MBinning(const TAxis &a, const char *name=0, const char *title=0);
|
---|
45 |
|
---|
46 | void Copy(TObject &named) const
|
---|
47 | {
|
---|
48 | MBinning &bins = (MBinning&)named;
|
---|
49 | bins.SetEdges(*this);
|
---|
50 | }
|
---|
51 |
|
---|
52 | void SetEdges(const TArrayD &arr)
|
---|
53 | {
|
---|
54 | fEdges = arr;
|
---|
55 | fType = kIsUserArray;
|
---|
56 | }
|
---|
57 |
|
---|
58 | Bool_t SetEdges(const MParList &list, const char *name=0);
|
---|
59 | Bool_t SetEdgesRaw(const char *txt);
|
---|
60 | //Bool_t SetEdges(const char *txt);
|
---|
61 | void SetEdges(const TAxis &axe);
|
---|
62 | void SetEdges(const MBinning &bins) { SetEdges(bins.fEdges); fType = bins.fType; fTitle = bins.fTitle; }
|
---|
63 | void SetEdges(const TH1 &h, const Char_t axis='x');
|
---|
64 | void SetEdges(Int_t nbins, const Axis_t lo, const Axis_t up) { SetEdgesLin(nbins, lo, up); }
|
---|
65 | void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up, const char *opt);
|
---|
66 | void SetEdgesLin(Int_t nbins, Axis_t lo, Axis_t up);
|
---|
67 | void SetEdgesLog(Int_t nbins, Axis_t lo, Axis_t up);
|
---|
68 | void SetEdgesCos(Int_t nbins, Axis_t lo, Axis_t up);
|
---|
69 | void SetEdgesASin(Int_t nbins, Axis_t lo, Axis_t up);
|
---|
70 |
|
---|
71 | Int_t FindLoEdge(Double_t val) const
|
---|
72 | {
|
---|
73 | if (val<GetEdgeLo() || val>=GetEdgeHi())
|
---|
74 | return -1;
|
---|
75 |
|
---|
76 | for (int i=1; i<fEdges.GetSize(); i++)
|
---|
77 | {
|
---|
78 | if (fEdges[i] >= val)
|
---|
79 | return i-1;
|
---|
80 | }
|
---|
81 | return -1;
|
---|
82 | }
|
---|
83 | Int_t FindHiEdge(Double_t val) const
|
---|
84 | {
|
---|
85 | const Int_t i = FindLoEdge(val);
|
---|
86 | return i<0 ? -1 : i+1;
|
---|
87 | }
|
---|
88 |
|
---|
89 | Double_t GetEdgeLo() const { return fEdges[0]; }
|
---|
90 | Double_t GetEdgeHi() const { return fEdges[fEdges.GetSize()-1]; }
|
---|
91 |
|
---|
92 | Int_t GetNumEdges() const { return fEdges.GetSize(); }
|
---|
93 | Int_t GetNumBins() const { return fEdges.GetSize()-1; }
|
---|
94 |
|
---|
95 | Double_t *GetEdges() const { return (Double_t*)fEdges.GetArray(); }
|
---|
96 | const TArrayD &GetEdgesD() const { return fEdges; }
|
---|
97 |
|
---|
98 | Double_t operator[](Int_t i) const { return fEdges[i]; }
|
---|
99 |
|
---|
100 | void AddEdge(Axis_t up);
|
---|
101 | void RemoveFirstEdge();
|
---|
102 | void RemoveLastEdge();
|
---|
103 |
|
---|
104 | Bool_t IsLinear() const { return fType==kIsLinear; }
|
---|
105 | Bool_t IsLogarithmic() const { return fType==kIsLogarithmic; }
|
---|
106 | Bool_t IsCosinic() const { return fType==kIsCosinic; }
|
---|
107 | Bool_t IsDefault() const { return fType==kIsDefault; }
|
---|
108 | Bool_t IsUserArray() const { return fType==kIsUserArray; }
|
---|
109 |
|
---|
110 | Bool_t HasTitle() const { return gsDefTitle!=fTitle; }
|
---|
111 |
|
---|
112 | void Apply(TH1 &) const;
|
---|
113 |
|
---|
114 | void Print(Option_t *o="") const; //*MENU*
|
---|
115 |
|
---|
116 | Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
|
---|
117 |
|
---|
118 | ClassDef(MBinning, 1) //Container to store the binning of a histogram
|
---|
119 | };
|
---|
120 |
|
---|
121 | #endif
|
---|