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

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