source: trunk/MagicSoft/Mars/mhist/MHCamera.cc@ 2273

Last change on this file since 2273 was 2265, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 27.3 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz, 05/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Harald Kornmayer, 1/2001
20!
21! Copyright: MAGIC Software Development, 2000-2003
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MHCamera
29//
30// Camera Display, based on a TH1D. Pleas be carefull using the
31// underlaying TH1D.
32//
33// To change the scale to a logarithmic scale SetLogy() of the Pad.
34//
35////////////////////////////////////////////////////////////////////////////
36#include "MHCamera.h"
37
38#include <fstream>
39#include <iostream>
40
41#include <TBox.h>
42#include <TArrow.h>
43#include <TLatex.h>
44#include <TStyle.h>
45#include <TCanvas.h>
46#include <TArrayF.h>
47#include <TRandom.h>
48#include <TPaveText.h>
49#include <TPaveStats.h>
50#include <TClonesArray.h>
51#include <THistPainter.h>
52
53#include "MLog.h"
54#include "MLogManip.h"
55
56#include "MH.h"
57#include "MHexagon.h"
58
59#include "MGeomPix.h"
60#include "MGeomCam.h"
61
62#include "MCerPhotPix.h"
63#include "MCerPhotEvt.h"
64
65#include "MPedestalPix.h"
66#include "MPedestalCam.h"
67
68#include "MCurrents.h"
69#include "MCamEvent.h"
70
71#include "MImgCleanStd.h"
72
73#define kItemsLegend 48 // see SetPalette(1,0)
74
75ClassImp(MHCamera);
76
77using namespace std;
78
79// ------------------------------------------------------------------------
80//
81// Default Constructor. To be used by the root system ONLY.
82//
83MHCamera::MHCamera() : TH1D(), fGeomCam(NULL), fColors(kItemsLegend), fOptStat(-1)
84{
85 SetDirectory(NULL);
86
87 fNotify = NULL;
88
89#if ROOT_VERSION_CODE < ROOT_VERSION(3,01,06)
90 SetPalette(1, 0);
91#else
92 SetPalette(51, 0);
93#endif
94}
95
96// ------------------------------------------------------------------------
97//
98// Constructor. Makes a clone of MGeomCam. Removed the TH1D from the
99// current directory. Calls Sumw2(). Set the histogram line color
100// (for error bars) to Green and the marker style to kFullDotMedium.
101//
102MHCamera::MHCamera(const MGeomCam &geom, const char *name, const char *title)
103: TH1D(name, title, geom.GetNumPixels(), -0.5, geom.GetNumPixels()-0.5),
104fUsed(geom.GetNumPixels()), fColors(kItemsLegend)
105{
106 fGeomCam = (MGeomCam*)geom.Clone();
107
108 SetDirectory(NULL);
109 Sumw2();
110
111 SetLineColor(kGreen);
112 SetMarkerStyle(kFullDotMedium);
113 SetXTitle("Pixel Index");
114
115 fNotify = new TList;
116
117 //
118 // create the hexagons of the display
119 //
120 // root 3.02
121 // * base/inc/TObject.h:
122 // register BIT(8) as kNoContextMenu. If an object has this bit set it will
123 // not get an automatic context menu when clicked with the right mouse button.
124
125 //
126 // Construct all hexagons. Use new-operator with placement
127 //
128 for (Int_t i=0; i<fNcells-2; i++)
129 ResetUsed(i);
130
131#if ROOT_VERSION_CODE < ROOT_VERSION(3,01,06)
132 SetPalette(1, 0);
133#else
134 SetPalette(51, 0);
135#endif
136}
137
138// ------------------------------------------------------------------------
139//
140// Destructor. Deletes the cloned fGeomCam and the notification list.
141//
142MHCamera::~MHCamera()
143{
144 if (fGeomCam)
145 delete fGeomCam;
146 if (fNotify)
147 delete fNotify;
148}
149
150// ------------------------------------------------------------------------
151//
152// Taken from TH1D::Fill(). Uses the argument directly as bin index.
153// Doesn't increment the number of entries.
154//
155// -*-*-*-*-*-*-*-*Increment bin with abscissa X by 1*-*-*-*-*-*-*-*-*-*-*
156// ==================================
157//
158// if x is less than the low-edge of the first bin, the Underflow bin is incremented
159// if x is greater than the upper edge of last bin, the Overflow bin is incremented
160//
161// If the storage of the sum of squares of weights has been triggered,
162// via the function Sumw2, then the sum of the squares of weights is incremented
163// by 1 in the bin corresponding to x.
164//
165// -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
166Int_t MHCamera::Fill(Axis_t x)
167{
168
169#if ROOT_VERSION_CODE > ROOT_VERSION(3,05,00)
170 if (fBuffer) return BufferFill(x,1);
171#endif
172 const Int_t bin = (Int_t)x+1;
173 AddBinContent(bin);
174 if (fSumw2.fN)
175 fSumw2.fArray[bin]++;
176
177 if (bin<=0 || bin>fNcells-2)
178 return -1;
179
180 fTsumw++;
181 fTsumw2++;
182 fTsumwx += x;
183 fTsumwx2 += x*x;
184 return bin;
185}
186
187// ------------------------------------------------------------------------
188//
189// Taken from TH1D::Fill(). Uses the argument directly as bin index.
190// Doesn't increment the number of entries.
191//
192// -*-*-*-*-*-*Increment bin with abscissa X with a weight w*-*-*-*-*-*-*-*
193// =============================================
194//
195// if x is less than the low-edge of the first bin, the Underflow bin is incremented
196// if x is greater than the upper edge of last bin, the Overflow bin is incremented
197//
198// If the storage of the sum of squares of weights has been triggered,
199// via the function Sumw2, then the sum of the squares of weights is incremented
200// by w^2 in the bin corresponding to x.
201//
202// -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
203Int_t MHCamera::Fill(Axis_t x, Stat_t w)
204{
205#if ROOT_VERSION_CODE > ROOT_VERSION(3,05,00)
206 if (fBuffer) return BufferFill(x,w);
207#endif
208 const Int_t bin = (Int_t)x+1;
209 AddBinContent(bin, w);
210 if (fSumw2.fN)
211 fSumw2.fArray[bin] += w*w;
212
213 if (bin<=0 || bin>fNcells-2)
214 return -1;
215
216 const Stat_t z = (w > 0 ? w : -w);
217 fTsumw += z;
218 fTsumw2 += z*z;
219 fTsumwx += z*x;
220 fTsumwx2 += z*x*x;
221 return bin;
222}
223
224Stat_t MHCamera::GetMean(Int_t axis) const
225{
226 Stat_t mean = 0;
227 for (int i=1; i<fNcells-1; i++)
228 mean += fArray[i];
229
230 return mean/(fNcells-2);
231}
232
233Stat_t MHCamera::GetRMS(Int_t axis) const
234{
235 const Int_t n = fNcells-2;
236
237 Stat_t sum = 0;
238 Stat_t sq = 0;
239 for (int i=1; i<n+1; i++)
240 {
241 sum += fArray[i];
242 sq += fArray[i]*fArray[i];
243 }
244
245 sum /= n;
246 sq /= n;
247
248 return sqrt(sq-sum*sum);
249}
250
251// ------------------------------------------------------------------------
252//
253// Return the minimum contents of all pixels (if all is set, otherwise
254// only of all 'used' pixels), fMinimum if fMinimum set
255//
256Double_t MHCamera::GetMinimum(Bool_t all) const
257{
258 if (fMinimum != -1111)
259 return fMinimum;
260
261 Double_t minimum=FLT_MAX;
262
263 if (all)
264 {
265 for (Int_t idx=0; idx<fNcells-2; idx++)
266 if (fArray[idx+1] < minimum)
267 minimum = fArray[idx+1];
268 }
269 else
270 {
271 for (Int_t idx=0; idx<fNcells-2; idx++)
272 if (IsUsed(idx) && fArray[idx+1] < minimum)
273 minimum = fArray[idx+1];
274 }
275 return minimum;
276}
277
278// ------------------------------------------------------------------------
279//
280// Return the maximum contents of all pixels (if all is set, otherwise
281// only of all 'used' pixels), fMaximum if fMaximum set
282//
283Double_t MHCamera::GetMaximum(Bool_t all) const
284{
285 if (fMaximum != -1111)
286 return fMaximum;
287
288 Double_t maximum=-FLT_MAX;
289 if (all)
290 {
291 for (Int_t idx=0; idx<fNcells-2; idx++)
292 if (fArray[idx+1] > maximum)
293 maximum = fArray[idx+1];
294 }
295 else
296 {
297 for (Int_t idx=0; idx<fNcells-2; idx++)
298 if (IsUsed(idx) && fArray[idx+1] > maximum)
299 maximum = fArray[idx+1];
300 }
301 return maximum;
302}
303
304// ------------------------------------------------------------------------
305//
306// Call this function to draw the camera layout into your canvas.
307// Setup a drawing canvas. Add this object and all child objects
308// (hexagons, etc) to the current pad. If no pad exists a new one is
309// created.
310//
311// To draw a camera into its own pad do something like:
312//
313// TCanvas *c = new TCanvas;
314// c->Divide(2,1);
315// MGeomCamMagic m;
316// MHCamera *d=new MHCamera(&m);
317// d->FillRandom();
318// c->cd(1);
319// gPad->SetBorderMode(0);
320// gPad->Divide(1,1);
321// gPad->cd(1);
322// d->Draw();
323// d->SetBit(kCanDelete);
324//
325void MHCamera::Draw(Option_t *option)
326{
327 // root 3.02:
328 // gPad->SetFixedAspectRatio()
329 Int_t col = 16;
330
331 if (gPad)
332 col = gPad->GetFillColor();
333
334 TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas("CamDisplay", "Mars Camera Display", 656, 600);
335 pad->SetBorderMode(0);
336 pad->SetFillColor(col);
337
338 AppendPad(option);
339}
340
341// ------------------------------------------------------------------------
342//
343// Resizes the current pad so that the camera is displayed in its
344// correct aspect ratio
345//
346void MHCamera::SetRange()
347{
348 const Float_t range = fGeomCam->GetMaxRadius()*1.05;
349
350 //
351 // Maintain aspect ratio
352 //
353 const float ratio = 1.15;
354
355 //
356 // Calculate width and height of the current pad in pixels
357 //
358 Float_t w = gPad->GetWw();
359 Float_t h = gPad->GetWh()*ratio;
360
361 //
362 // This prevents the pad from resizing itself wrongly
363 //
364 if (gPad->GetMother() != gPad)
365 {
366 w *= gPad->GetMother()->GetAbsWNDC();
367 h *= gPad->GetMother()->GetAbsHNDC();
368 }
369
370 //
371 // Set Range (coordinate system) of pad
372 //
373 gPad->Range(-range, -range, (2*ratio-1)*range, range);
374
375 //
376 // Resize Pad to given ratio
377 //
378 if (h<w)
379 gPad->SetPad((1.-h/w)/2, 0, (h/w+1.)/2, 1);
380 else
381 gPad->SetPad(0, (1.-w/h)/2, 1, (w/h+1.)/2);
382}
383
384// ------------------------------------------------------------------------
385//
386// Updates the pixel colors and paints the pixels
387//
388void MHCamera::Update(Bool_t islog, Bool_t isbox, Bool_t iscol)
389{
390 Double_t min = GetMinimum(kFALSE);
391 Double_t max = GetMaximum(kFALSE);
392 if (min==FLT_MAX)
393 {
394 min = 0;
395 max = 1;
396 }
397
398 if (min==max)
399 max += 1;
400
401 UpdateLegend(min, max, islog);
402
403 MHexagon hex;
404 for (Int_t i=0; i<fNcells-2; i++)
405 {
406 if (IsUsed(i) && iscol)
407 {
408 if (TMath::IsNaN(fArray[i+1]))
409 gLog << warn << "MHCamera::Update: " << GetName() << " <" << GetTitle() << "> - Pixel Index #" << i << " contents is NaN (Not a Number)..." << endl;
410
411 hex.SetFillColor(GetColor(fArray[i+1], min, max, islog));
412 }
413 else
414 hex.SetFillColor(10);
415
416 MGeomPix &pix = (*fGeomCam)[i];
417 if (!isbox)
418 hex.PaintHexagon(pix.GetX(), pix.GetY(), pix.GetD());
419 else
420 if (IsUsed(i) && !TMath::IsNaN(fArray[i+1]))
421 {
422 Float_t size = pix.GetD()*(fArray[i+1]-min)/(max-min);
423 if (size>pix.GetD())
424 size=pix.GetD();
425 hex.PaintHexagon(pix.GetX(), pix.GetY(), size);
426 }
427 }
428}
429
430// ------------------------------------------------------------------------
431//
432// Print minimum and maximum
433//
434void MHCamera::Print(Option_t *) const
435{
436 cout << "Minimum: " << GetMinimum();
437 if (fMinimum==-1111)
438 cout << " <autoscaled>";
439 cout << endl;
440 cout << "Maximum: " << GetMaximum();
441 if (fMaximum==-1111)
442 cout << " <autoscaled>";
443 cout << endl;
444}
445
446// ------------------------------------------------------------------------
447//
448// Paint the y-axis title
449//
450void MHCamera::PaintAxisTitle()
451{
452 const Float_t range = fGeomCam->GetMaxRadius()*1.05;
453 const Float_t w = (1 + 1.5/sqrt((float)(fNcells-2)))*range;
454
455 TLatex *ptitle = new TLatex(w, -.90*range, GetYaxis()->GetTitle());
456
457 ptitle->SetTextSize(0.05);
458 ptitle->SetTextAlign(21);
459
460 // box with the histogram title
461 ptitle->SetTextColor(gStyle->GetTitleTextColor());
462#if ROOT_VERSION_CODE > ROOT_VERSION(3,05,01)
463 ptitle->SetTextFont(gStyle->GetTitleFont(""));
464#endif
465 ptitle->Paint();
466}
467
468// ------------------------------------------------------------------------
469//
470// Paints the camera.
471//
472void MHCamera::Paint(Option_t *o)
473{
474 TString opt(o);
475 opt.ToLower();
476
477 if (opt.Contains("hist"))
478 {
479 opt.ReplaceAll("hist", "");
480 Int_t mode = gStyle->GetOptStat();
481 TVirtualPad *save = gPad;
482 gPad=NULL;
483 gStyle->SetOptStat(fOptStat<0 ? mode : fOptStat);
484 gPad=save;
485 TH1D::Paint(o);
486 gPad=NULL;
487 gStyle->SetOptStat(mode);
488 gPad=save;
489 return;
490 }
491
492 // Maintain aspect ratio
493 SetRange();
494
495 Bool_t isbox = opt.Contains("box");
496 Bool_t iscol = isbox ? !opt.Contains("nocol") : 1;
497
498 THistPainter paint;
499 if (!TestBit(TH1::kNoStats))
500 {
501 paint.SetHistogram(this);
502 paint.PaintStat(fOptStat<0?gStyle->GetOptStat():fOptStat, NULL);
503 }
504
505 // Update Contents of the pixels and paint legend
506 Update(gPad->GetLogy(), isbox, iscol);
507
508 // Paint primitives (pixels, color legend, photons, ...)
509 paint.PaintTitle();
510 PaintAxisTitle();
511}
512
513// ------------------------------------------------------------------------
514//
515// With this function you can change the color palette. For more
516// information see TStyle::SetPalette. Only palettes with 50 colors
517// are allowed.
518// In addition you can use SetPalette(52, 0) to create an inverse
519// deep blue sea palette
520//
521void MHCamera::SetPalette(Int_t ncolors, Int_t *colors)
522{
523 //
524 // If not enough colors are specified skip this.
525 //
526 if (ncolors>1 && ncolors<50)
527 {
528 cout << "MHCamera::SetPalette: Only default palettes with 50 colors are allowed... ignored." << endl;
529 return;
530 }
531
532 //
533 // If ncolors==52 create a reversed deep blue sea palette
534 //
535 if (ncolors==52)
536 {
537 gStyle->SetPalette(51, NULL);
538 TArrayI c(kItemsLegend);
539 for (int i=0; i<kItemsLegend; i++)
540 c[kItemsLegend-i-1] = gStyle->GetColorPalette(i);
541 gStyle->SetPalette(kItemsLegend, c.GetArray());
542 }
543 else
544 gStyle->SetPalette(ncolors, colors);
545
546 fColors.Set(kItemsLegend);
547 for (int i=0; i<kItemsLegend; i++)
548 fColors[i] = gStyle->GetColorPalette(i);
549}
550
551
552void MHCamera::SetPrettyPalette()
553{
554 if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
555 SetPalette(1, 0);
556}
557
558void MHCamera::SetDeepBlueSeaPalette()
559{
560 if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
561 SetPalette(51, 0);
562}
563
564void MHCamera::SetInvDeepBlueSeaPalette()
565{
566 if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
567 SetPalette(52, 0);
568}
569
570void MHCamera::DrawPixelIndices()
571{
572 // FIXME: Is this correct?
573 for (int i=0; i<kItemsLegend; i++)
574 fColors[i] = 16;
575
576 if (!gPad)
577 Draw();
578
579 TText txt;
580 txt.SetTextFont(122);
581 txt.SetTextAlign(22); // centered/centered
582
583 for (Int_t i=0; i<fNcells-2; i++)
584 {
585 TString num;
586 num += i;
587
588 const MGeomPix &h = (*fGeomCam)[i];
589 TText *nt = txt.DrawText(h.GetX(), h.GetY(), num);
590 nt->SetTextSize(0.3*h.GetD()/fGeomCam->GetMaxRadius()/1.05);
591 }
592}
593
594void MHCamera::DrawSectorIndices()
595{
596 for (int i=0; i<kItemsLegend; i++)
597 fColors[i] = 16;
598
599 if (!gPad)
600 Draw();
601
602 TText txt;
603 txt.SetTextFont(122);
604 txt.SetTextAlign(22); // centered/centered
605
606 for (Int_t i=0; i<fNcells-2; i++)
607 {
608 TString num;
609 num += (*fGeomCam)[i].GetSector();
610
611 const MGeomPix &h = (*fGeomCam)[i];
612 TText *nt = txt.DrawText(h.GetX(), h.GetY(), num);
613 nt->SetTextSize(0.3*h.GetD()/fGeomCam->GetMaxRadius()/1.05);
614 }
615}
616
617// ------------------------------------------------------------------------
618//
619// Call this function to add a MCamEvent on top of the present contents.
620// Only 'used' pixels are added.
621//
622void MHCamera::AddCamContent(const MCamEvent &event, Int_t type)
623{
624 // FIXME: Security check missing!
625 for (Int_t idx=0; idx<fNcells-2; idx++)
626 {
627 Double_t val=0;
628 if (event.GetPixelContent(val, idx, *fGeomCam, type) && !IsUsed(idx))
629 SetUsed(idx);
630
631 Fill(idx, val); // FIXME: Slow!
632 }
633 fEntries++;
634}
635
636// ------------------------------------------------------------------------
637//
638// Call this function to add a MHCamera on top of the present contents.
639// Only 'used' pixels are added.
640// Type:
641// 0) bin content
642// 1) errors
643// 2) rel. errors
644//
645void MHCamera::AddCamContent(const MHCamera &d, Int_t type)
646{
647 if (fNcells!=d.fNcells)
648 return;
649
650 // FIXME: Security check missing!
651 for (Int_t idx=0; idx<fNcells-2; idx++)
652 if (d.IsUsed(idx))
653 SetUsed(idx);
654
655 switch (type)
656 {
657 case 1:
658 for (Int_t idx=0; idx<fNcells-2; idx++)
659 Fill(idx, d.GetBinError(idx+1));
660 break;
661 case 2:
662 for (Int_t idx=0; idx<fNcells-2; idx++)
663 if (d.GetBinContent(idx+1)!=0)
664 Fill(idx, fabs(d.GetBinError(idx+1)/d.GetBinContent(idx+1)));
665 break;
666 default:
667 for (Int_t idx=0; idx<fNcells-2; idx++)
668 Fill(idx, d.GetBinContent(idx+1));
669 break;
670 }
671 fEntries++;
672}
673
674// ------------------------------------------------------------------------
675//
676// Call this function to add a TArrayD on top of the present contents.
677// Only 'used' pixels are added.
678//
679void MHCamera::AddCamContent(const TArrayD &event, const TArrayC *used)
680{
681 if (event.GetSize()!=fNcells-2)
682 return;
683
684 if (used && used->GetSize()!=fNcells-2)
685 return;
686
687 for (Int_t idx=0; idx<fNcells-2; idx++)
688 {
689 Fill(idx, const_cast<TArrayD&>(event)[idx]); // FIXME: Slow!
690
691 if (used && (*const_cast<TArrayC*>(used))[idx])
692 SetUsed(idx);
693 }
694 fEntries++;
695}
696
697// ------------------------------------------------------------------------
698//
699// Call this function to add a MCamEvent on top of the present contents.
700// 1 is added to each pixel if the contents of MCamEvent>threshold
701//
702void MHCamera::CntCamContent(const MCamEvent &event, Double_t threshold, Int_t type)
703{
704 // FIXME: Security check missing!
705 for (Int_t idx=0; idx<fNcells-2; idx++)
706 {
707 Double_t val=0;
708 if (event.GetPixelContent(val, idx, *fGeomCam, type) && !IsUsed(idx))
709 SetUsed(idx);
710
711 if (val>threshold)
712 Fill(idx);
713 }
714 fEntries++;
715}
716
717// ------------------------------------------------------------------------
718//
719// Call this function to add a TArrayD on top of the present contents.
720// 1 is added to each pixel if the contents of MCamEvent>threshold
721//
722void MHCamera::CntCamContent(const TArrayD &event, Double_t threshold, Bool_t ispos)
723{
724 if (event.GetSize()!=fNcells-2)
725 return;
726
727 for (Int_t idx=0; idx<fNcells-2; idx++)
728 {
729 if (const_cast<TArrayD&>(event)[idx]>threshold)
730 Fill(idx);
731
732 if (!ispos || fArray[idx+1]>0)
733 SetUsed(idx);
734 }
735 fEntries++;
736}
737
738// ------------------------------------------------------------------------
739//
740// Fill the pixels with random contents.
741//
742void MHCamera::FillRandom()
743{
744 Reset();
745
746 // FIXME: Security check missing!
747 for (Int_t idx=0; idx<fNcells-2; idx++)
748 {
749 Fill(idx, gRandom->Uniform()*fGeomCam->GetPixRatio(idx));
750 SetUsed(idx);
751 }
752 fEntries=1;
753}
754
755
756// ------------------------------------------------------------------------
757//
758// Fill the colors in respect to the cleaning levels
759//
760void MHCamera::FillLevels(const MCerPhotEvt &event, Float_t lvl1, Float_t lvl2)
761{
762 SetCamContent(event, 2);
763
764 for (Int_t i=0; i<fNcells-2; i++)
765 {
766 if (!IsUsed(i))
767 continue;
768
769 if (fArray[i+1]>lvl1)
770 fArray[i+1] = 0;
771 else
772 if (fArray[i+1]>lvl2)
773 fArray[i+1] = 1;
774 else
775 fArray[i+1] = 2;
776 }
777}
778
779// ------------------------------------------------------------------------
780//
781// Fill the colors in respect to the cleaning levels
782//
783void MHCamera::FillLevels(const MCerPhotEvt &event, const MImgCleanStd &clean)
784{
785 FillLevels(event, clean.GetCleanLvl1(), clean.GetCleanLvl2());
786}
787
788// ------------------------------------------------------------------------
789//
790// Reset the all pixel colors to a default value
791//
792void MHCamera::Reset(Option_t *opt)
793{
794 TH1::Reset(opt);
795
796 for (Int_t i=0; i<fNcells-2; i++)
797 {
798 fArray[i+1]=0;
799 ResetUsed(i);
800 }
801 fArray[0] = 0;
802 fArray[fNcells-1] = 0;
803}
804
805// ------------------------------------------------------------------------
806//
807// Here we calculate the color index for the current value.
808// The color index is defined with the class TStyle and the
809// Color palette inside. We use the command gStyle->SetPalette(1,0)
810// for the display. So we have to convert the value "wert" into
811// a color index that fits the color palette.
812// The range of the color palette is defined by the values fMinPhe
813// and fMaxRange. Between this values we have 50 color index, starting
814// with 0 up to 49.
815//
816Int_t MHCamera::GetColor(Float_t val, Float_t min, Float_t max, Bool_t islog)
817{
818 if (TMath::IsNaN(val)) // FIXME: gLog!
819 return 10;
820
821 //
822 // first treat the over- and under-flows
823 //
824 const Int_t maxcolidx = kItemsLegend-1;
825
826 if (val >= max)
827 return fColors[maxcolidx];
828
829 if (val <= min)
830 return fColors[0];
831
832 //
833 // calculate the color index
834 //
835 Float_t ratio;
836 if (islog && min>0)
837 ratio = log10(val/min) / log10(max/min);
838 else
839 ratio = (val-min) / (max-min);
840
841 const Int_t colidx = (Int_t)(ratio*maxcolidx + .5);
842 return fColors[colidx];
843}
844
845TPaveStats *MHCamera::GetStats()
846{
847 TObject *obj = 0;
848
849 TIter Next(fFunctions);
850 while ((obj = Next()))
851 if (obj->InheritsFrom(TPaveStats::Class()))
852 return static_cast<TPaveStats*>(obj);
853
854 return NULL;
855}
856
857// ------------------------------------------------------------------------
858//
859// Change the text on the legend according to the range of the Display
860//
861void MHCamera::UpdateLegend(Float_t min, Float_t max, Bool_t islog)
862{
863 TPaveStats *stats = GetStats();
864
865 const Float_t hndc = 0.92 - (stats ? stats->GetY1NDC() : 1);
866 const Float_t range = fGeomCam->GetMaxRadius()*1.05;
867 const Float_t H = (0.75-hndc)*range;
868 const Float_t offset = hndc*range;
869
870 const Float_t h = 2./kItemsLegend;
871 const Float_t w = range/sqrt((float)(fNcells-2));
872
873 TBox newbox;
874 TText newtxt;
875 newtxt.SetTextSize(0.03);
876 newtxt.SetTextAlign(12);
877#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
878 newtxt.SetBit(/*kNoContextMenu|*/kCannotPick);
879 newbox.SetBit(/*kNoContextMenu|*/kCannotPick);
880#endif
881
882 const Float_t step = (islog && min>0 ? log10(max/min) : max-min) / kItemsLegend;
883 const Int_t firsts = step*3 < 1e-8 ? 8 : (Int_t)floor(log10(step*3));
884 const TString opt = Form("%%.%if", firsts>0 ? 0 : abs(firsts));
885
886 for (Int_t i=0; i<kItemsLegend+1; i+=3)
887 {
888 Float_t val;
889 if (islog && min>0)
890 val = pow(10, step*i) * min;
891 else
892 val = min + step*i;
893
894 //const bool dispexp = max-min>1.5 && fabs(val)>0.1 && fabs(val)<1e6;
895 newtxt.PaintText(range+1.5*w, H*(i*h-1)-offset, Form(opt, val));
896 }
897
898 for (Int_t i=0; i<kItemsLegend; i++)
899 {
900 newbox.SetFillColor(fColors[i]);
901 newbox.PaintBox(range, H*(i*h-1)-offset, range+w, H*((i+1)*h-1)-offset);
902 }
903
904 TArrow arr;
905 arr.PaintArrow(-range*.9, -range*.9, -range*.6, -range*.9, 0.025);
906 arr.PaintArrow(-range*.9, -range*.9, -range*.9, -range*.6, 0.025);
907
908 TString text;
909 text += (int)(range*.3);
910 text += "mm";
911
912 TText newtxt2;
913 newtxt2.SetTextSize(0.04);
914 newtxt2.PaintText(-range*.85, -range*.85, text);
915
916 text = "";
917 text += (float)((int)(range*.3*fGeomCam->GetConvMm2Deg()*10))/10;
918 text += "\\circ";
919 text = text.Strip(TString::kLeading);
920
921 TLatex latex;
922 latex.PaintLatex(-range*.85, -range*.75, 0, 0.04, text);
923}
924
925// ------------------------------------------------------------------------
926//
927// Save primitive as a C++ statement(s) on output stream out
928//
929void MHCamera::SavePrimitive(ofstream &out, Option_t *opt)
930{
931 cout << "MHCamera::SavePrimitive: Must be rewritten!" << endl;
932 /*
933 if (!gROOT->ClassSaved(TCanvas::Class()))
934 fDrawingPad->SavePrimitive(out, opt);
935
936 out << " " << fDrawingPad->GetName() << "->SetWindowSize(";
937 out << fDrawingPad->GetWw() << "," << fDrawingPad->GetWh() << ");" << endl;
938 */
939}
940
941// ------------------------------------------------------------------------
942//
943// compute the distance of a point (px,py) to the Camera
944// this functions needed for graphical primitives, that
945// means without this function you are not able to interact
946// with the graphical primitive with the mouse!!!
947//
948// All calcutations are done in pixel coordinates
949//
950Int_t MHCamera::DistancetoPrimitive(Int_t px, Int_t py)
951{
952 if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
953 return TH1D::DistancetoPrimitive(px, py);
954
955 for (Int_t i=0; i<fNcells-2; i++)
956 {
957 MHexagon hex((*fGeomCam)[i]);
958 if (hex.DistancetoPrimitive(px, py)==0)
959 return 0;
960 }
961 return 999999;
962}
963
964// ------------------------------------------------------------------------
965//
966// Function introduced (31-01-03) WILL BE REMOVED IN THE FUTURE! DON'T
967// USE IT!
968//
969void MHCamera::SetPix(const Int_t idx, const Int_t color, Float_t min, Float_t max)
970{
971 fArray[idx+1] = color;
972 SetUsed(idx);
973}
974
975// ------------------------------------------------------------------------
976//
977// Function introduced (31-01-03) WILL BE REMOVED IN THE FUTURE! DON'T
978// USE IT!
979//
980Int_t MHCamera::GetPixelIndex(Int_t px, Int_t py) const
981{
982 Int_t i;
983 for (i=0; i<fNcells-2; i++)
984 {
985 MHexagon hex((*fGeomCam)[i]);
986 if (hex.DistancetoPrimitive(px, py)>0)
987 continue;
988
989 return i;
990 }
991 return -1;
992}
993
994// ------------------------------------------------------------------------
995//
996// Returns string containing info about the object at position (px,py).
997// Returned string will be re-used (lock in MT environment).
998//
999char *MHCamera::GetObjectInfo(Int_t px, Int_t py) const
1000{
1001 if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
1002 return TH1D::GetObjectInfo(px, py);
1003
1004 static char info[128];
1005
1006 const Int_t idx=GetPixelIndex(px, py);
1007
1008 if (idx<0)
1009 return TObject::GetObjectInfo(px, py);
1010
1011 sprintf(info, "Software Pixel Index: %d (Hardware Id=%d)", idx, idx+1);
1012 return info;
1013}
1014
1015// ------------------------------------------------------------------------
1016//
1017// Execute a mouse event on the camera
1018//
1019void MHCamera::ExecuteEvent(Int_t event, Int_t px, Int_t py)
1020{
1021 if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
1022 {
1023 TH1D::ExecuteEvent(event, px, py);
1024 return;
1025 }
1026 //if (event==kMouseMotion && fStatusBar)
1027 // fStatusBar->SetText(GetObjectInfo(px, py), 0);
1028 if (event!=kButton1Down)
1029 return;
1030
1031 const Int_t idx = GetPixelIndex(px, py);
1032 if (idx<0)
1033 return;
1034
1035 cout << GetTitle() << " <" << GetName() << ">" << endl;
1036 cout << "Software Pixel Index: " << idx << endl;
1037 cout << "Hardware Pixel Id: " << idx+1 << endl;
1038 cout << "Contents: " << fArray[idx+1] << " <";
1039 cout << (IsUsed(idx)?"on":"off");
1040 cout << ">" << endl;
1041
1042 if (fNotify && fNotify->GetSize()>0)
1043 new TCanvas;
1044 fNotify->ForEach(MCamEvent, DrawPixelContent)(idx);
1045}
Note: See TracBrowser for help on using the repository browser.