source: trunk/Mars/mhbase/MBinning.h@ 20095

Last change on this file since 20095 was 20095, checked in by tbretz, 4 years ago
Oh great master of the root universe, thanks for you namepace polution.
File size: 3.6 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(std::ostream &out) const;
30
31#pragma GCC diagnostic push
32#pragma GCC diagnostic ignored "-Wshadow"
33 enum {
34 kIsDefault,
35 kIsLinear,
36 kIsLogarithmic,
37 kIsCosinic,
38 kIsUserArray
39 };
40#pragma GCC diagnostic pop
41
42public:
43 MBinning(const char *name=NULL, const char *title=NULL);
44 MBinning(Int_t nbins, Axis_t lo, Axis_t hi, const char *name=0, const char *opt="", const char *title=NULL);
45 MBinning(const MBinning &bins, const char *name=NULL, const char *title=NULL);
46 MBinning(const TH1 &h, const Char_t axis='x', const char *name=0, const char *title=0);
47 MBinning(const TAxis &a, const char *name=0, const char *title=0);
48 MBinning(const TArrayD &a, const char *name=0, const char *title=0);
49
50 void Copy(TObject &named) const
51 {
52 MBinning &bins = (MBinning&)named;
53 bins.SetEdges(*this);
54 }
55
56 void SetEdges(const TArrayD &arr)
57 {
58 fEdges = arr;
59 fType = kIsUserArray;
60 }
61
62 Bool_t SetEdges(const MParList &list, const char *name=0);
63 Bool_t SetEdgesRaw(const char *txt);
64 //Bool_t SetEdges(const char *txt);
65 void SetEdges(const TAxis &axe);
66 void SetEdges(const MBinning &bins) { SetEdges(bins.fEdges); fType = bins.fType; fTitle = bins.fTitle; }
67 void SetEdges(const TH1 &h, const Char_t axis='x');
68 void SetEdges(Int_t nbins, const Axis_t lo, const Axis_t up) { SetEdgesLin(nbins, lo, up); }
69 void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up, const char *opt);
70 void SetEdgesLin(Int_t nbins, Axis_t lo, Axis_t up);
71 void SetEdgesLog(Int_t nbins, Axis_t lo, Axis_t up);
72 void SetEdgesCos(Int_t nbins, Axis_t lo, Axis_t up);
73 void SetEdgesASin(Int_t nbins, Axis_t lo, Axis_t up);
74
75 Int_t FindLoEdge(Double_t val) const
76 {
77 if (val<GetEdgeLo() || val>=GetEdgeHi())
78 return -1;
79
80 for (int i=1; i<fEdges.GetSize(); i++)
81 {
82 if (fEdges[i] >= val)
83 return i-1;
84 }
85 return -1;
86 }
87 Int_t FindHiEdge(Double_t val) const
88 {
89 const Int_t i = FindLoEdge(val);
90 return i<0 ? -1 : i+1;
91 }
92
93 Double_t GetEdgeLo() const { return fEdges[0]; }
94 Double_t GetEdgeHi() const { return fEdges[fEdges.GetSize()-1]; }
95
96 Int_t GetNumEdges() const { return fEdges.GetSize(); }
97 Int_t GetNumBins() const { return fEdges.GetSize()-1; }
98
99 const Double_t *GetEdges() const { return fEdges.GetArray(); }
100 const TArrayD &GetEdgesD() const { return fEdges; }
101
102 Double_t operator[](Int_t i) const { return fEdges[i]; }
103
104 void AddEdge(Axis_t up);
105 void RemoveFirstEdge();
106 void RemoveLastEdge();
107
108 Bool_t IsLinear() const { return fType==kIsLinear; }
109 Bool_t IsLogarithmic() const { return fType==kIsLogarithmic; }
110 Bool_t IsCosinic() const { return fType==kIsCosinic; }
111 Bool_t IsDefault() const { return fType==kIsDefault; }
112 Bool_t IsUserArray() const { return fType==kIsUserArray; }
113
114 Bool_t HasTitle() const { return gsDefTitle!=fTitle; }
115
116 void Apply(TH1 &) const;
117
118 void Print(Option_t *o="") const; //*MENU*
119
120 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
121
122 ClassDef(MBinning, 1) //Container to store the binning of a histogram
123};
124
125#endif
Note: See TracBrowser for help on using the repository browser.