source: trunk/MagicSoft/Mars/mhist/MBinning.h@ 2230

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