source: trunk/MagicSoft/Mars/mhbase/MBinning.h@ 5133

Last change on this file since 5133 was 4966, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 2.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 MBinning : public MParContainer
16{
17public:
18 static const TString gsDefName;
19 static const TString gsDefTitle;
20
21private:
22
23 TArrayD fEdges;
24
25 Byte_t fType;
26
27 void StreamPrimitive(ofstream &out) const;
28
29 enum {
30 kIsDefault,
31 kIsLinear,
32 kIsLogarithmic,
33 kIsCosinic,
34 kIsUserArray
35 };
36
37public:
38 MBinning(const char *name=NULL, const char *title=NULL);
39 MBinning(Int_t nbins, Axis_t lo, Axis_t hi, const char *name, const char *opt="", const char *title=NULL);
40
41 void SetEdges(const TArrayD &arr)
42 {
43 fEdges = arr;
44 fType = kIsUserArray;
45 }
46
47 void SetEdges(const TAxis &axe);
48 void SetEdges(const MBinning &bins) { SetEdges(fEdges); }
49 void SetEdges(const TH1 &h, const Char_t axis='x');
50 void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up);
51 void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up, const char *opt);
52 void SetEdgesLog(const Int_t nbins, const Axis_t lo, Axis_t up);
53 void SetEdgesCos(const Int_t nbins, const Axis_t lo, Axis_t up);
54
55 Int_t FindLoEdge(Double_t val) const
56 {
57 if (val<GetEdgeLo() || val>=GetEdgeHi())
58 return -1;
59
60 for (int i=1; i<fEdges.GetSize(); i++)
61 {
62 if (fEdges[i] >= val)
63 return i-1;
64 }
65 return -1;
66 }
67 Int_t FindHiEdge(Double_t val) const
68 {
69 const Int_t i = FindLoEdge(val);
70 return i<0 ? -1 : i+1;
71 }
72
73 Double_t GetEdgeLo() const { return fEdges[0]; }
74 Double_t GetEdgeHi() const { return fEdges[fEdges.GetSize()-1]; }
75
76 Int_t GetNumEdges() const { return fEdges.GetSize(); }
77 Int_t GetNumBins() const { return fEdges.GetSize()-1; }
78
79 Double_t *GetEdges() const { return (Double_t*)fEdges.GetArray(); }
80 const TArrayD &GetEdgesD() const { return fEdges; }
81
82 void AddEdge(Axis_t up);
83 void RemoveFirstEdge();
84 void RemoveLastEdge();
85
86 Bool_t IsLinear() const { return fType==kIsLinear; }
87 Bool_t IsLogarithmic() const { return fType==kIsLogarithmic; }
88 Bool_t IsCosinic() const { return fType==kIsCosinic; }
89 Bool_t IsDefault() const { return fType==kIsDefault; }
90 Bool_t IsUserArray() const { return fType==kIsUserArray; }
91
92 Bool_t HasTitle() const { return gsDefTitle!=fTitle; }
93
94 void Apply(TH1 &) const;
95
96 ClassDef(MBinning, 1) //Container to store the binning of a histogram
97};
98
99#endif
Note: See TracBrowser for help on using the repository browser.