source: trunk/Mars/mhbase/MBinning.h@ 15789

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