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

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