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

Last change on this file since 5692 was 5692, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 2.7 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=0, const char *opt="", const char *title=NULL);
40 MBinning(const MBinning &bins) { SetEdges(bins); }
41
42 void Copy(TObject &named) const
43 {
44 MBinning &bins = (MBinning&)named;
45 bins.SetEdges(*this);
46 }
47
48 void SetEdges(const TArrayD &arr)
49 {
50 fEdges = arr;
51 fType = kIsUserArray;
52 }
53
54 void SetEdges(const TAxis &axe);
55 void SetEdges(const MBinning &bins) { SetEdges(bins.fEdges); fType = bins.fType; }
56 void SetEdges(const TH1 &h, const Char_t axis='x');
57 void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up);
58 void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up, const char *opt);
59 void SetEdgesLog(const Int_t nbins, const Axis_t lo, Axis_t up);
60 void SetEdgesCos(const Int_t nbins, const Axis_t lo, Axis_t up);
61
62 Int_t FindLoEdge(Double_t val) const
63 {
64 if (val<GetEdgeLo() || val>=GetEdgeHi())
65 return -1;
66
67 for (int i=1; i<fEdges.GetSize(); i++)
68 {
69 if (fEdges[i] >= val)
70 return i-1;
71 }
72 return -1;
73 }
74 Int_t FindHiEdge(Double_t val) const
75 {
76 const Int_t i = FindLoEdge(val);
77 return i<0 ? -1 : i+1;
78 }
79
80 Double_t GetEdgeLo() const { return fEdges[0]; }
81 Double_t GetEdgeHi() const { return fEdges[fEdges.GetSize()-1]; }
82
83 Int_t GetNumEdges() const { return fEdges.GetSize(); }
84 Int_t GetNumBins() const { return fEdges.GetSize()-1; }
85
86 Double_t *GetEdges() const { return (Double_t*)fEdges.GetArray(); }
87 const TArrayD &GetEdgesD() const { return fEdges; }
88
89 void AddEdge(Axis_t up);
90 void RemoveFirstEdge();
91 void RemoveLastEdge();
92
93 Bool_t IsLinear() const { return fType==kIsLinear; }
94 Bool_t IsLogarithmic() const { return fType==kIsLogarithmic; }
95 Bool_t IsCosinic() const { return fType==kIsCosinic; }
96 Bool_t IsDefault() const { return fType==kIsDefault; }
97 Bool_t IsUserArray() const { return fType==kIsUserArray; }
98
99 Bool_t HasTitle() const { return gsDefTitle!=fTitle; }
100
101 void Apply(TH1 &) const;
102
103 ClassDef(MBinning, 1) //Container to store the binning of a histogram
104};
105
106#endif
Note: See TracBrowser for help on using the repository browser.