source: trunk/Mars/mhbase/MH3.h@ 11589

Last change on this file since 11589 was 10234, checked in by tbretz, 14 years ago
Increased class version number to 7
File size: 6.3 KB
Line 
1#ifndef MARS_MH3
2#define MARS_MH3
3
4#ifndef ROOT_TH1
5#include <TH1.h>
6#endif
7#ifndef MARS_MH
8#include "MH.h"
9#endif
10#ifndef MARS_MObjLookup
11#include "MObjLookup.h"
12#endif
13
14class TH1;
15class MData;
16class MBinning;
17class TFormula;
18
19class MH3 : public MH
20{
21public:
22 enum Labels_t {
23 kNoLabels = 0,
24 kLabelsX = BIT(0),
25 kLabelsY = BIT(1),
26 kLabelsZ = BIT(2),
27 kLabelsXY = kLabelsX|kLabelsY,
28 kLabelsXZ = kLabelsX|kLabelsZ,
29 kLabelsYZ = kLabelsY|kLabelsZ,
30 kLabelsXYZ = kLabelsX|kLabelsY|kLabelsZ,
31 };
32
33 enum Type_t {
34 kHistogram = 0,
35 kProfile = 1,
36 kProfileSpread = kProfile | 2,
37 };
38
39 enum {
40 kDoNotReset = BIT(20)
41 };
42
43
44private:
45 static const TString gsDefName;
46 static const TString gsDefTitle;
47
48 // Helper for constructor
49 void Init();
50
51 // Helper for dealing with labeled histograms
52 MObjLookup *GetLabels(char axe);
53 void InitLabels(TAxis &x) const;
54 void DeflateLabels() const;
55 Labels_t GetLabels() const;
56 const char *GetLabel(Int_t axe, Double_t val) const;
57
58 // Get type
59 Type_t GetType() const;
60
61 // Helper for conversion
62 void Convert(TH1 &h) const;
63
64 MObjLookup fLabels[3]; //! Lookup table to conflate and name labels
65
66protected:
67 // Could be const but root < 3.02/06 doesn't like this...
68 Int_t fDimension; // Number of dimensions of histogram
69 TH1 *fHist; // Histogram to fill
70 MData *fData[4]; // Object from which the data is filled
71 MData *fWeight; // Additional weight
72 MBinning *fBins[3]; // Binning set omitting the parlist access
73 Double_t fScale[4]; // Scale for the three axis (eg unit)
74 Byte_t fStyleBits; // Set the range of a histogram automatically in Finalize
75
76 TFormula *fConversion; // Conversion function for displaying the histogram
77
78 void HandleLogAxis(TAxis &axe) const;
79
80 void StreamPrimitive(ostream &out) const;
81
82
83 enum {
84 kIsLogx = BIT(17),
85 kIsLogy = BIT(18),
86 kIsLogz = BIT(19)
87 };
88
89public:
90 MH3(const Int_t dim=0, Type_t type=MH3::kHistogram);
91 MH3(const TH1 &h1);
92 MH3(const char *memberx, Type_t type=MH3::kHistogram);
93 MH3(const char *memberx, const char *membery, Type_t type=MH3::kHistogram);
94 MH3(const char *memberx, const char *membery, const char *memberz, Type_t type=MH3::kHistogram);
95 MH3(const char *memberx, const char *membery, const char *memberz, const char *weight, Type_t type=MH3::kProfile);
96 ~MH3();
97
98 // Setter
99 void SetScaleX(Double_t scale) { fScale[0] = scale; }
100 void SetScaleY(Double_t scale) { fScale[1] = scale; }
101 void SetScaleZ(Double_t scale) { fScale[2] = scale; }
102 void SetScaleT(Double_t scale) { fScale[3] = scale; }
103 void SetScale(Double_t x, Double_t y=1, Double_t z=1, Double_t t=1) { SetScaleX(x); SetScaleY(y); SetScaleZ(z); SetScaleT(t); }
104
105 void SetLogx(Bool_t b=kTRUE) { b ? fHist->SetBit(kIsLogx) : fHist->ResetBit(kIsLogx); }
106 void SetLogy(Bool_t b=kTRUE) { b ? fHist->SetBit(kIsLogy) : fHist->ResetBit(kIsLogy); }
107 void SetLogz(Bool_t b=kTRUE) { b ? fHist->SetBit(kIsLogz) : fHist->ResetBit(kIsLogz); }
108 void SetLog(Bool_t x=kTRUE, Bool_t y=kTRUE, Bool_t z=kTRUE) { SetLogx(x); SetLogy(y); SetLogz(z); }
109
110 void SetAutoRangeX(Bool_t b=kTRUE) { b ? SETBIT(fStyleBits, 0) : CLRBIT(fStyleBits, 0); }
111 void SetAutoRangeY(Bool_t b=kTRUE) { b ? SETBIT(fStyleBits, 1) : CLRBIT(fStyleBits, 1); }
112 void SetAutoRangeZ(Bool_t b=kTRUE) { b ? SETBIT(fStyleBits, 2) : CLRBIT(fStyleBits, 2); }
113 void SetAutoRange(Bool_t x=kTRUE, Bool_t y=kTRUE, Bool_t z=kTRUE) { SetAutoRangeX(x); SetAutoRangeY(y); SetAutoRangeZ(z); }
114
115 void SetBinningX(MBinning *x) { fBins[0] = x; }
116 void SetBinningY(MBinning *y) { fBins[1] = y; }
117 void SetBinningZ(MBinning *z) { fBins[2] = z; }
118 void SetBinnings(MBinning *x=0, MBinning *y=0, MBinning *z=0) { SetBinningX(x); SetBinningY(y); SetBinningZ(z); }
119
120 void Sumw2() const { if (fHist) fHist->Sumw2(); }
121
122 void InitLabels(Labels_t labels) const;
123
124 void DefaultLabel(char axe, const char *name=0);
125 void DefaultLabelX(const char *name=0) { DefaultLabel('x', name); }
126 void DefaultLabelY(const char *name=0) { DefaultLabel('y', name); }
127 void DefaultLabelZ(const char *name=0) { DefaultLabel('z', name); }
128
129 void DefineLabel(char axe, Int_t label=0, const char *name=0);
130 void DefineLabelX(Int_t label, const char *name) { DefineLabel('x', label, name); }
131 void DefineLabelY(Int_t label, const char *name) { DefineLabel('y', label, name); }
132 void DefineLabelZ(Int_t label, const char *name) { DefineLabel('z', label, name); }
133
134 void DefineLabels(char axe, const TString &labels);
135 void DefineLabelsX(const TString &labels) { DefineLabels('x', labels); }
136 void DefineLabelsY(const TString &labels) { DefineLabels('y', labels); }
137 void DefineLabelsZ(const TString &labels) { DefineLabels('z', labels); }
138
139 void SetWeight(const char *phrase);
140
141 Bool_t SetConversion(const char *func="");
142
143 // Getter
144 Int_t GetDimension() const { return TMath::Abs(fDimension); }
145 Int_t GetNbins() const;
146 Int_t FindFixBin(Double_t x, Double_t y=0, Double_t z=0) const;
147
148 TH1 &GetHist() { return *fHist; }
149 const TH1 &GetHist() const { return *fHist; }
150
151 TString GetDataMember() const;
152 TString GetRule(const Char_t axis='x') const;
153
154 // MH
155 Bool_t SetupFill(const MParList *pList);
156 Int_t Fill(const MParContainer *par, const Stat_t w=1);
157 Bool_t Finalize();
158
159 TH1 *GetHistByName(const TString name="") const { return fHist; }
160 TObject *FindObject(const TObject *obj) const { return 0; }
161 TObject *FindObject(const char *name) const
162 {
163 return (TObject*)GetHistByName(name);
164 }
165
166 // MParContainer
167 MParContainer *New() const;
168
169 // TObject
170 void SetName(const char *name);
171 void SetTitle(const char *title);
172
173 const char *GetTitle() const { return fHist ? fHist->GetTitle() : static_cast<const char *>(fTitle); }
174 const TString &GetFullTitle() const { return fTitle; }
175
176 void Draw(Option_t *opt=NULL);
177 void Paint(Option_t *opt="");
178
179 void RecursiveRemove(TObject *obj);
180
181 ClassDef(MH3, 7) // Generalized 1/2/3D-histogram for Mars variables
182};
183
184#endif
Note: See TracBrowser for help on using the repository browser.