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

Last change on this file since 10009 was 9858, checked in by tbretz, 14 years ago
Implemented TProfile3D in MH3 and MHn and the possibility to skip the reset of the histograms in the SetupFill.
File size: 6.2 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[3]; // 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 SetScale(Double_t x, Double_t y=1, Double_t z=2) { SetScaleX(x); SetScaleY(y); SetScaleZ(z); }
103
104 void SetLogx(Bool_t b=kTRUE) { b ? fHist->SetBit(kIsLogx) : fHist->ResetBit(kIsLogx); }
105 void SetLogy(Bool_t b=kTRUE) { b ? fHist->SetBit(kIsLogy) : fHist->ResetBit(kIsLogy); }
106 void SetLogz(Bool_t b=kTRUE) { b ? fHist->SetBit(kIsLogz) : fHist->ResetBit(kIsLogz); }
107 void SetLog(Bool_t x=kTRUE, Bool_t y=kTRUE, Bool_t z=kTRUE) { SetLogx(x); SetLogy(y); SetLogz(z); }
108
109 void SetAutoRangeX(Bool_t b=kTRUE) { b ? SETBIT(fStyleBits, 0) : CLRBIT(fStyleBits, 0); }
110 void SetAutoRangeY(Bool_t b=kTRUE) { b ? SETBIT(fStyleBits, 1) : CLRBIT(fStyleBits, 1); }
111 void SetAutoRangeZ(Bool_t b=kTRUE) { b ? SETBIT(fStyleBits, 2) : CLRBIT(fStyleBits, 2); }
112 void SetAutoRange(Bool_t x=kTRUE, Bool_t y=kTRUE, Bool_t z=kTRUE) { SetAutoRangeX(x); SetAutoRangeY(y); SetAutoRangeZ(z); }
113
114 void SetBinningX(MBinning *x) { fBins[0] = x; }
115 void SetBinningY(MBinning *y) { fBins[1] = y; }
116 void SetBinningZ(MBinning *z) { fBins[2] = z; }
117 void SetBinnings(MBinning *x=0, MBinning *y=0, MBinning *z=0) { SetBinningX(x); SetBinningY(y); SetBinningZ(z); }
118
119 void Sumw2() const { if (fHist) fHist->Sumw2(); }
120
121 void InitLabels(Labels_t labels) const;
122
123 void DefaultLabel(char axe, const char *name=0);
124 void DefaultLabelX(const char *name=0) { DefaultLabel('x', name); }
125 void DefaultLabelY(const char *name=0) { DefaultLabel('y', name); }
126 void DefaultLabelZ(const char *name=0) { DefaultLabel('z', name); }
127
128 void DefineLabel(char axe, Int_t label=0, const char *name=0);
129 void DefineLabelX(Int_t label, const char *name) { DefineLabel('x', label, name); }
130 void DefineLabelY(Int_t label, const char *name) { DefineLabel('y', label, name); }
131 void DefineLabelZ(Int_t label, const char *name) { DefineLabel('z', label, name); }
132
133 void DefineLabels(char axe, const TString &labels);
134 void DefineLabelsX(const TString &labels) { DefineLabels('x', labels); }
135 void DefineLabelsY(const TString &labels) { DefineLabels('y', labels); }
136 void DefineLabelsZ(const TString &labels) { DefineLabels('z', labels); }
137
138 void SetWeight(const char *phrase);
139
140 Bool_t SetConversion(const char *func="");
141
142 // Getter
143 Int_t GetDimension() const { return TMath::Abs(fDimension); }
144 Int_t GetNbins() const;
145 Int_t FindFixBin(Double_t x, Double_t y=0, Double_t z=0) const;
146
147 TH1 &GetHist() { return *fHist; }
148 const TH1 &GetHist() const { return *fHist; }
149
150 TString GetDataMember() const;
151 TString GetRule(const Char_t axis='x') const;
152
153 // MH
154 Bool_t SetupFill(const MParList *pList);
155 Int_t Fill(const MParContainer *par, const Stat_t w=1);
156 Bool_t Finalize();
157
158 TH1 *GetHistByName(const TString name="") const { return fHist; }
159 TObject *FindObject(const TObject *obj) const { return 0; }
160 TObject *FindObject(const char *name) const
161 {
162 return (TObject*)GetHistByName(name);
163 }
164
165 // MParContainer
166 MParContainer *New() const;
167
168 // TObject
169 void SetName(const char *name);
170 void SetTitle(const char *title);
171
172 const char *GetTitle() const { return fHist ? fHist->GetTitle() : static_cast<const char *>(fTitle); }
173 const TString &GetFullTitle() const { return fTitle; }
174
175 void Draw(Option_t *opt=NULL);
176 void Paint(Option_t *opt="");
177
178 void RecursiveRemove(TObject *obj);
179
180 ClassDef(MH3, 6) // Generalized 1/2/3D-histogram for Mars variables
181};
182
183#endif
Note: See TracBrowser for help on using the repository browser.