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

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