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

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