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

Last change on this file since 4928 was 4920, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 2.4 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 TH1 &h, const Char_t axis='x');
49 void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up);
50 void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up, const char *opt);
51 void SetEdgesLog(const Int_t nbins, const Axis_t lo, Axis_t up);
52 void SetEdgesCos(const Int_t nbins, const Axis_t lo, Axis_t up);
53
54 Int_t FindLoEdge(Double_t val) const
55 {
56 if (val<GetEdgeLo() || val>=GetEdgeHi())
57 return -1;
58
59 for (int i=1; i<fEdges.GetSize(); i++)
60 {
61 if (((TArrayD)fEdges)[i] >= val)
62 return i-1;
63 }
64 return -1;
65 }
66 Int_t FindHiEdge(Double_t val) const
67 {
68 const Int_t i = FindLoEdge(val);
69 return i<0 ? -1 : i+1;
70 }
71
72 // FIXME: ROOT workaround: "operator[] const" missing
73 Double_t GetEdgeLo() const { return ((TArrayD)fEdges)[0]; }
74 Double_t GetEdgeHi() const { return ((TArrayD)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
81 void AddEdge(Axis_t up);
82
83 Bool_t IsLinear() const { return fType==kIsLinear; }
84 Bool_t IsLogarithmic() const { return fType==kIsLogarithmic; }
85 Bool_t IsCosinic() const { return fType==kIsCosinic; }
86 Bool_t IsDefault() const { return fType==kIsDefault; }
87 Bool_t IsUserArray() const { return fType==kIsUserArray; }
88
89 Bool_t HasTitle() const { return gsDefTitle!=fTitle; }
90
91 void Apply(TH1 &) const;
92
93 ClassDef(MBinning, 1) //Container to store the binning of a histogram
94};
95
96#endif
97
Note: See TracBrowser for help on using the repository browser.