source: trunk/MagicSoft/Mars/mhbase/MH3.h@ 9271

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