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

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