source: trunk/MagicSoft/Mars/mhist/MHCamera.h@ 3951

Last change on this file since 3951 was 3929, checked in by gaug, 21 years ago
*** empty log message ***
File size: 18.7 KB
Line 
1#ifndef MARS_MHCamera
2#define MARS_MHCamera
3
4#ifndef MARS_MAGIC
5#include "MAGIC.h"
6#endif
7#ifndef ROOT_TArrayC
8#include <TArrayC.h>
9#endif
10#ifndef ROOT_TArrayI
11#include <TArrayI.h>
12#endif
13#ifndef ROOT_TClonesArray
14#include <TClonesArray.h>
15#endif
16#ifndef ROOT_TH1
17#include <TH1.h>
18#endif
19
20class TPaveStats;
21class TProfile;
22
23class MGeomCam;
24class MCamEvent;
25class MRflEvtData;
26class MCerPhotEvt;
27class MImgCleanStd;
28
29class MHCamera : public TH1D
30{
31public:
32 enum {
33 kProfile = BIT(18), // FIXME: When changing change max/min!
34 kFreezed = BIT(19),
35 kNoLegend = BIT(20),
36 kVariance = BIT(21)
37 };
38private:
39 MGeomCam *fGeomCam; // pointer to camera geometry (y-axis)
40 TArrayC fUsed; // array containing flags
41
42 TArrayI fColors; //! Color conversion table
43 TList *fNotify; //!
44
45//#if ROOT_VERSION_CODE < ROOT_VERSION(4,00,03)
46 Bool_t fFreezed; //! Just a dummy!!!! ([Set,Is]Freezed)
47//#endif
48
49 void Init();
50
51 Stat_t Profile(Stat_t val) const
52 {
53 if (!TestBit(kProfile))
54 return val;
55
56 const Stat_t n = TH1D::GetEntries();
57 return n>0 ? val/n : val;
58 }
59
60 Int_t GetColor(Float_t val, Float_t min, Float_t max, Bool_t islog);
61
62 void PaintIndices(Int_t type);
63 void Update(Bool_t islog, Bool_t isbox, Bool_t iscol, Bool_t issame);
64 void UpdateLegend(Float_t min, Float_t max, Bool_t islog);
65 void SetRange();
66
67 TPaveStats *GetStatisticBox();
68
69 Int_t GetPixelIndex(Int_t px, Int_t py, Float_t conv=1) const;
70
71 void PaintAxisTitle();
72
73 enum {
74 kIsUsed = BIT(1)
75 };
76
77 void SetUsed(Int_t idx) { SETBIT(fUsed[idx], kIsUsed); }
78 void ResetUsed(Int_t idx) { CLRBIT(fUsed[idx], kIsUsed); }
79
80 Bool_t FindVal(const TArrayI &arr, Int_t val) const
81 {
82 const Int_t n = arr.GetSize();
83 if (n==0)
84 return kTRUE;
85
86 const Int_t *p = arr.GetArray();
87 const Int_t *end = p+n;
88 while (p<end)
89 if (val==*p++)
90 return kTRUE;
91
92 return kFALSE;
93 }
94 Bool_t MatchSector(Int_t idx, const TArrayI &sector, const TArrayI &aidx) const;
95
96 // This is a trick to remove TH1 entries from the context menu
97 TH1 *Rebin(Int_t ngroup=2, const char*newname="") { return this; }
98 void DrawPanel() {}
99
100 Int_t Fill(Axis_t x);
101 Int_t Fill(Axis_t x, Stat_t w);
102 Int_t Fill(const char *name, Stat_t w) { return -1; }
103 void FillN(Int_t ntimes, const Axis_t *x, const Double_t *w, Int_t stride=1) {}
104 void FillN(Int_t, const Axis_t *, const Axis_t *, const Double_t *, Int_t) {}
105
106public:
107 MHCamera();
108 MHCamera(const MGeomCam &geom, const char *name="", const char *title="");
109 ~MHCamera();
110
111 void SetGeometry(const MGeomCam &geom, const char *name="", const char *title="");
112 const MGeomCam* GetGeometry() const { return fGeomCam; }
113
114 Bool_t IsUsed(Int_t idx) const { return TESTBIT(const_cast<TArrayC&>(fUsed)[idx], kIsUsed); }
115
116 Int_t Fill(Axis_t x, Axis_t y, Stat_t w);
117
118 //void AddPixContent(Int_t idx) const { AddBinContent(idx+1); }
119 //void AddPixContent(Int_t idx, Stat_t w) const { AddBinContent(idx+1, w); }
120
121 // This is a trick to remove TH1 entries from the context menu
122 /*
123 void Add(const TH1 *h1, const TH1 *h2, Double_t c1=1, Double_t c2=1) { TH1::Add(h1, h2, c1, c2); }
124 void Add(TF1 *h1, Double_t c1=1) { TH1::Add(h1, c1); }
125 void Add(const TH1 *h1, Double_t c1=1) { TH1::Add(h1, c1); }
126 void Divide(TF1 *f1, Double_t c1=1) { TH1::Divide(f1, c1); }
127 void Divide(const TH1 *h1) { TH1::Divide(h1); }
128 void Divide(const TH1 *h1, const TH1 *h2, Double_t c1=1, Double_t c2=1, Option_t *option="") { TH1::Divide(h1, h2, c1, c2, option); }
129 void Multiply(TF1 *h1, Double_t c1=1) { TH1::Multiply(h1, c1); }
130 void Multiply(const TH1 *h1) { TH1::Multiply(h1); }
131 void Multiply(const TH1 *h1, const TH1 *h2, Double_t c1=1, Double_t c2=1, Option_t *option="") { TH1::Multiply(h1, h2, c1, c2, option); }
132 */
133
134 void FitPanel() { TH1::FitPanel(); }
135
136 virtual Double_t GetPixContent(Int_t idx) const { return GetBinContent(idx+1); }
137 virtual void AddCamContent(const MCamEvent &evt, Int_t type=0);
138 virtual void AddCamContent(const MHCamera &evt, Int_t type=0);
139 virtual void AddCamContent(const TArrayD &arr, const TArrayC *used=NULL);
140 virtual void SetCamContent(const MCamEvent &evt, Int_t type=0) { Reset(); AddCamContent(evt, type); }
141 virtual void SetCamContent(const TArrayD &evt, const TArrayC *used=NULL) { Reset(); AddCamContent(evt, used); }
142 virtual void SetCamContent(const MHCamera &d, Int_t type=0) { Reset(); AddCamContent(d, type); fEntries=d.fEntries; }
143
144 virtual void SetCamError(const MCamEvent &evt, Int_t type=0);
145 virtual void SetUsed(const TArrayC &arr);
146
147 virtual void CntCamContent(const MCamEvent &evt, Double_t threshold, Int_t type=0);
148 virtual void CntCamContent(const TArrayD &evt, Double_t threshold, Bool_t ispos=kTRUE);
149
150 Stat_t GetBinContent(Int_t bin) const { return Profile(TH1D::GetBinContent(bin)); }
151 Stat_t GetBinContent(Int_t binx, Int_t biny) const { return GetBinContent(binx); }
152 Stat_t GetBinContent(Int_t binx, Int_t biny, Int_t binz) const { return GetBinContent(binx); }
153 Stat_t GetBinError(Int_t bin) const;
154 Stat_t GetBinError(Int_t binx, Int_t biny) const { return GetBinError(binx); }
155 Stat_t GetBinError(Int_t binx, Int_t biny, Int_t binz) const { return GetBinError(binx); }
156
157 Double_t GetMinimum(Bool_t all) const { return GetMinimumSectors(TArrayI(), TArrayI(), all); }
158 Double_t GetMaximum(Bool_t all) const { return GetMaximumSectors(TArrayI(), TArrayI(), all); }
159
160 Double_t GetMinimum() const { return GetMinimumSectors(TArrayI(), TArrayI(), kFALSE); }
161 Double_t GetMaximum() const { return GetMaximumSectors(TArrayI(), TArrayI(), kFALSE); }
162
163 Double_t GetMinimumSector(Int_t sector, Int_t aidx, Bool_t all=kFALSE) const
164 {
165 return GetMinimumSectors(TArrayI(1, &sector), TArrayI(1, &aidx), all);
166 }
167 Double_t GetMaximumSector(Int_t sector, Int_t aidx, Bool_t all=kFALSE) const
168 {
169 return GetMaximumSectors(TArrayI(1, &sector), TArrayI(1, &aidx), all);
170 }
171 Double_t GetMinimumSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t all=kFALSE) const;
172 Double_t GetMaximumSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t all=kFALSE) const;
173
174 void SetLevels(const TArrayF &arr);
175
176 void FillRandom(const char *fname, Int_t ntimes=5000) { TH1::FillRandom(fname, ntimes); }
177 void FillRandom(TH1 *h, Int_t ntimes=5000) { TH1::FillRandom(h, ntimes); }
178 void FillRandom();
179
180 void PrintInfo() const { Print(""); } // *MENU*
181 void Reset(Option_t *);
182 void Reset() { Reset(""); } // *MENU*
183 TH1 *DrawCopy() const/* { gPad=NULL; return TH1D::DrawCopy(); }*/; // *MENU*
184 TH1 *DrawCopy(Option_t *o) const { return TH1D::DrawCopy(o); }
185
186 void Print(Option_t *) const;
187 void Paint(Option_t *option="");
188 void Draw(Option_t *option="");
189 TObject *DrawClone(Option_t *option="") const;
190 void DrawProjection (Int_t fit=0) const;
191 void DrawRadialProfile() const;
192
193 void SavePrimitive(ofstream &out, Option_t *);
194 Int_t DistancetoPrimitive(Int_t px, Int_t py);
195 char *GetObjectInfo(Int_t px, Int_t py) const;
196 void ExecuteEvent(Int_t event, Int_t px, Int_t py);
197
198 void SetPalette(Int_t ncolors, Int_t *colors);
199
200 void SetPrettyPalette(); // *MENU*
201 void SetDeepBlueSeaPalette(); // *MENU*
202 void SetInvDeepBlueSeaPalette(); // *MENU*
203
204 void SetAutoScale() { fMinimum = fMaximum = -1111; } // *MENU*
205 void DisplayAsHistogram() { SetDrawOption("histEP"); } // *MENU*
206 void DisplayAsCamera() { SetDrawOption(""); } // *MENU*
207
208 void SetFreezed(Bool_t f=kTRUE) { f ? SetBit(kFreezed) : ResetBit(kFreezed); } // *TOGGLE* *GETTER=IsFreezed
209 Bool_t IsFreezed() const { return TestBit(kFreezed); }
210 //void SetOptStat(Int_t os=-1) { fOptStat = os; } // *MENU*
211
212 void AddNotify(TObject *event);
213
214 Stat_t GetMean(Bool_t all) const { return GetMeanSectors(TArrayI(), TArrayI(), all); }
215 Stat_t GetRMS(Bool_t all) const { return GetRmsSectors(TArrayI(), TArrayI(), all); }
216
217 Stat_t GetMean(Int_t=0) const { return GetMeanSectors(TArrayI(), TArrayI(), kFALSE); }
218 Stat_t GetRMS(Int_t=0) const { return GetRmsSectors(TArrayI(), TArrayI(), kFALSE); }
219
220 Stat_t GetMeanSector(Int_t sector, Int_t aidx, Bool_t all=kFALSE) const
221 {
222 return GetMeanSectors(TArrayI(1, &sector), TArrayI(1, &aidx), all);
223 }
224 Stat_t GetRmsSector(Int_t sector, Int_t aidx, Bool_t all=kFALSE) const
225 {
226 return GetRmsSectors(TArrayI(1, &sector), TArrayI(1, &aidx), all);
227 }
228
229 Stat_t GetMeanSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t all=kFALSE) const;
230 Stat_t GetRmsSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t all=kFALSE) const;
231
232 UInt_t GetNumPixels() const;
233
234 TH1D *Projection(const char *name="_py") const { return ProjectionS(TArrayI(), TArrayI(), name); }
235 TH1D *ProjectionS(Int_t sector, Int_t aidx, const char *name="_py") const
236 {
237 return ProjectionS(TArrayI(1, &sector), TArrayI(1, &aidx), name);
238 }
239 TH1D *ProjectionS(const TArrayI &sector, const TArrayI &aidx, const char *name="_py") const;
240
241 TProfile *RadialProfile(const char *name="_rad") const { return RadialProfileS(TArrayI(), TArrayI(), name);}
242 TProfile *RadialProfileS(Int_t sector, Int_t aidx, const char *name="_rad", const Int_t nbins=25) const
243 {
244 return RadialProfileS(TArrayI(1, &sector), TArrayI(1, &aidx), name, nbins);
245 }
246 TProfile *RadialProfileS(const TArrayI &sector, const TArrayI &aidx, const char *name="_rad", const Int_t nbins=25) const;
247
248 const MGeomCam &GetGeomCam() const { return *fGeomCam; }
249
250 ClassDef(MHCamera, 1) // Displays the magic camera
251};
252
253#endif
254
255/* ------------ OK ---------------
256 virtual void Browse(TBrowser *b);
257 virtual void FillRandom(const char *fname, Int_t ntimes=5000);
258 virtual void FillRandom(TH1 *h, Int_t ntimes=5000);
259
260 virtual Int_t GetQuantiles(Int_t nprobSum, Double_t *q, const Double_t *probSum=0);
261 virtual Axis_t GetRandom();
262 virtual void GetStats(Stat_t *stats) const;
263 virtual Stat_t GetSumOfWeights() const;
264 virtual Int_t GetSumw2N() const {return fSumw2.fN;}
265 virtual Stat_t GetRMS(Int_t axis=1) const;
266
267 virtual Int_t GetNbinsX() const {return fXaxis.GetNbins();}
268 virtual Int_t GetNbinsY() const {return fYaxis.GetNbins();}
269 virtual Int_t GetNbinsZ() const {return fZaxis.GetNbins();}
270
271 // ------------- to check -------------------
272
273 virtual Double_t ComputeIntegral();
274 virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
275 virtual void Draw(Option_t *option="");
276 virtual TH1 *DrawCopy(Option_t *option="") const;
277 virtual TH1 *DrawNormalized(Option_t *option="", Double_t norm=1) const;
278 virtual Int_t BufferEmpty(Bool_t deleteBuffer=kFALSE);
279 virtual void Eval(TF1 *f1, Option_t *option="");
280 virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
281 virtual void FillN(Int_t ntimes, const Axis_t *x, const Double_t *w, Int_t stride=1);
282 virtual void FillN(Int_t, const Axis_t *, const Axis_t *, const Double_t *, Int_t) {;}
283 virtual Int_t FindBin(Axis_t x, Axis_t y=0, Axis_t z=0);
284 virtual TObject *FindObject(const char *name) const;
285 virtual TObject *FindObject(const TObject *obj) const;
286 virtual Int_t Fit(const char *formula ,Option_t *option="" ,Option_t *goption="", Axis_t xmin=0, Axis_t xmax=0); // *MENU*
287 virtual Int_t Fit(TF1 *f1 ,Option_t *option="" ,Option_t *goption="", Axis_t xmin=0, Axis_t xmax=0);
288 virtual void FitPanel(); // *MENU*
289 TH1 *GetAsymmetry(TH1* h2, Double_t c2=1, Double_t dc2=0);
290 Int_t GetBufferLength() const {return (Int_t)fBuffer[0];}
291 Int_t GetBufferSize () const {return fBufferSize;}
292 const Double_t *GetBuffer() const {return fBuffer;}
293 static Int_t GetDefaultBufferSize();
294 virtual Double_t *GetIntegral() {return fIntegral;}
295
296 TList *GetListOfFunctions() const { return fFunctions; }
297
298 virtual Int_t GetNdivisions(Option_t *axis="X") const;
299 virtual Color_t GetAxisColor(Option_t *axis="X") const;
300 virtual Color_t GetLabelColor(Option_t *axis="X") const;
301 virtual Style_t GetLabelFont(Option_t *axis="X") const;
302 virtual Float_t GetLabelOffset(Option_t *axis="X") const;
303 virtual Float_t GetLabelSize(Option_t *axis="X") const;
304 virtual Float_t GetTitleOffset(Option_t *axis="X") const;
305 virtual Float_t GetTitleSize(Option_t *axis="X") const;
306 virtual Float_t GetTickLength(Option_t *axis="X") const;
307 virtual Float_t GetBarOffset() const {return Float_t(0.001*Float_t(fBarOffset));}
308 virtual Float_t GetBarWidth() const {return Float_t(0.001*Float_t(fBarWidth));}
309 virtual Int_t GetContour(Double_t *levels=0);
310 virtual Double_t GetContourLevel(Int_t level) const;
311 virtual Double_t GetContourLevelPad(Int_t level) const;
312
313 virtual void GetCenter(Axis_t *center) const {fXaxis.GetCenter(center);}
314 TDirectory *GetDirectory() const {return fDirectory;}
315 virtual Stat_t GetEntries() const;
316 virtual TF1 *GetFunction(const char *name) const;
317 virtual Int_t GetDimension() const { return fDimension; }
318 virtual void GetLowEdge(Axis_t *edge) const {fXaxis.GetLowEdge(edge);}
319 virtual Double_t GetMaximum() const;
320 virtual Int_t GetMaximumBin() const;
321 virtual Int_t GetMaximumBin(Int_t &locmax, Int_t &locmay, Int_t &locmaz) const;
322 virtual Double_t GetMaximumStored() const {return fMaximum;}
323 virtual Double_t GetMinimum() const;
324 virtual Int_t GetMinimumBin() const;
325 virtual Int_t GetMinimumBin(Int_t &locmix, Int_t &locmiy, Int_t &locmiz) const;
326 virtual Double_t GetMinimumStored() const {return fMinimum;}
327 virtual Stat_t GetMean(Int_t axis=1) const;
328 virtual Double_t GetNormFactor() const {return fNormFactor;}
329 virtual char *GetObjectInfo(Int_t px, Int_t py) const;
330 Option_t *GetOption() const {return fOption.Data();}
331
332 TVirtualHistPainter *GetPainter();
333
334 TAxis *GetXaxis() const;
335 TAxis *GetYaxis() const;
336 TAxis *GetZaxis() const;
337 virtual Stat_t Integral(Option_t *option="") const;
338 virtual Stat_t Integral(Int_t binx1, Int_t binx2, Option_t *option="") const;
339 virtual Stat_t Integral(Int_t, Int_t, Int_t, Int_t, Option_t * ="") const {return 0;}
340 virtual Stat_t Integral(Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, Option_t * ="" ) const {return 0;}
341 virtual Double_t KolmogorovTest(TH1 *h2, Option_t *option="") const;
342 virtual void LabelsDeflate(Option_t *axis="X");
343 virtual void LabelsInflate(Option_t *axis="X");
344 virtual void LabelsOption(Option_t *option="h", Option_t *axis="X");
345 virtual Int_t Merge(TCollection *list);
346 virtual void Multiply(TF1 *h1, Double_t c1=1);
347 virtual void Multiply(const TH1 *h1);
348 virtual void Multiply(const TH1 *h1, const TH1 *h2, Double_t c1=1, Double_t c2=1, Option_t *option=""); // *MENU*
349 virtual void Paint(Option_t *option="");
350 virtual void Print(Option_t *option="") const;
351 virtual void PutStats(Stat_t *stats);
352 virtual TH1 *Rebin(Int_t ngroup=2, const char*newname=""); // *MENU*
353 virtual void RebinAxis(Axis_t x, Option_t *axis="X");
354 virtual void Rebuild(Option_t *option="");
355 virtual void RecursiveRemove(TObject *obj);
356 virtual void Reset(Option_t *option="");
357 virtual void SavePrimitive(ofstream &out, Option_t *option);
358 virtual void Scale(Double_t c1=1);
359 virtual void SetAxisColor(Color_t color=1, Option_t *axis="X");
360 virtual void SetAxisRange(Axis_t xmin, Axis_t xmax, Option_t *axis="X");
361 virtual void SetBarOffset(Float_t offset=0.25) {fBarOffset = Short_t(1000*offset);}
362 virtual void SetBarWidth(Float_t width=0.5) {fBarWidth = Short_t(1000*width);}
363 virtual void SetBinContent(Int_t bin, Stat_t content);
364 virtual void SetBinContent(Int_t binx, Int_t biny, Stat_t content);
365 virtual void SetBinContent(Int_t binx, Int_t biny, Int_t binz, Stat_t content);
366 virtual void SetBinError(Int_t bin, Stat_t error);
367 virtual void SetBinError(Int_t binx, Int_t biny, Stat_t error);
368 virtual void SetBinError(Int_t binx, Int_t biny, Int_t binz, Stat_t error);
369 virtual void SetBins(Int_t nx, Axis_t xmin, Axis_t xmax);
370 virtual void SetBins(Int_t nx, Axis_t xmin, Axis_t xmax, Int_t ny, Axis_t ymin, Axis_t ymax);
371 virtual void SetBins(Int_t nx, Axis_t xmin, Axis_t xmax, Int_t ny, Axis_t ymin, Axis_t ymax,
372 Int_t nz, Axis_t zmin, Axis_t zmax);
373 virtual void SetBinsLength(Int_t = -1) { } //refefined in derived classes
374 virtual void SetBuffer(Int_t buffersize, Option_t *option="");
375 virtual void SetCellContent(Int_t binx, Int_t biny, Stat_t content);
376 virtual void SetCellError(Int_t binx, Int_t biny, Stat_t content);
377 virtual void SetContent(const Stat_t *content);
378 virtual void SetContour(Int_t nlevels, const Double_t *levels=0);
379 virtual void SetContourLevel(Int_t level, Double_t value);
380 static void SetDefaultBufferSize(Int_t buffersize=1000);
381 virtual void SetDirectory(TDirectory *dir);
382 virtual void SetEntries(Stat_t n) {fEntries = n;};
383 virtual void SetError(const Stat_t *error);
384 virtual void SetLabelColor(Color_t color=1, Option_t *axis="X");
385 virtual void SetLabelFont(Style_t font=62, Option_t *axis="X");
386 virtual void SetLabelOffset(Float_t offset=0.005, Option_t *axis="X");
387 virtual void SetLabelSize(Float_t size=0.02, Option_t *axis="X");
388
389 virtual void SetMaximum(Double_t maximum=-1111); // *MENU*
390 virtual void SetMinimum(Double_t minimum=-1111); // *MENU*
391 virtual void SetName(const char *name); // *MENU*
392 virtual void SetNameTitle(const char *name, const char *title);
393 virtual void SetNdivisions(Int_t n=510, Option_t *axis="X");
394 virtual void SetNormFactor(Double_t factor=1) {fNormFactor = factor;}
395 virtual void SetStats(Bool_t stats=kTRUE);
396 virtual void SetOption(Option_t *option=" ") {fOption = option;}
397 virtual void SetTickLength(Float_t length=0.02, Option_t *axis="X");
398 virtual void SetTitleOffset(Float_t offset=1, Option_t *axis="X");
399 virtual void SetTitleSize(Float_t size=0.02, Option_t *axis="X");
400 virtual void SetTitle(const char *title);
401 virtual void SetXTitle(const char *title) {fXaxis.SetTitle(title);}
402 virtual void SetYTitle(const char *title) {fYaxis.SetTitle(title);}
403 virtual void SetZTitle(const char *title) {fZaxis.SetTitle(title);}
404 virtual void Smooth(Int_t ntimes=1); // *MENU*
405 static void SmoothArray(Int_t NN, Double_t *XX, Int_t ntimes=1);
406 static Double_t SmoothMedian(Int_t n, Double_t *a);
407 virtual void Sumw2();
408 void UseCurrentStyle();
409
410 ClassDef(TH1,4) //1-Dim histogram base class
411};
412
413*/
Note: See TracBrowser for help on using the repository browser.