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

Last change on this file since 2236 was 2236, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 27.9 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 if (min==max)
367 max += 1;
368
369 UpdateLegend(min, max, islog);
370
371 MHexagon hex;
372 for (Int_t i=0; i<fNcells-2; i++)
373 {
374 if (IsUsed(i) && iscol)
375 hex.SetFillColor(GetColor(fArray[i+1], min, max, islog));
376 else
377 hex.SetFillColor(10);
378
379 MGeomPix &pix = (*fGeomCam)[i];
380 if (!isbox)
381 hex.PaintHexagon(pix.GetX(), pix.GetY(), pix.GetD());
382 else
383 if (IsUsed(i))
384 {
385 Float_t size = pix.GetD()*(fArray[i+1]-min)/(max-min);
386 if (size>pix.GetD())
387 size=pix.GetD();
388 hex.PaintHexagon(pix.GetX(), pix.GetY(), size);
389 }
390 }
391}
392
393// ------------------------------------------------------------------------
394//
395// Print minimum and maximum
396//
397void MHCamera::Print(Option_t *) const
398{
399 cout << "Minimum: " << GetMinimum();
400 if (fMinimum==-1111)
401 cout << " <autoscaled>";
402 cout << endl;
403 cout << "Maximum: " << GetMaximum();
404 if (fMaximum==-1111)
405 cout << " <autoscaled>";
406 cout << endl;
407}
408
409// ------------------------------------------------------------------------
410//
411// Paint the y-axis title
412//
413void MHCamera::PaintAxisTitle()
414{
415 Float_t fRange = fGeomCam->GetMaxRadius();
416
417 TLatex *ptitle = new TLatex(1.2*fRange, .97*fRange, GetYaxis()->GetTitle());
418
419 ptitle->SetTextSize(0.03);
420 ptitle->SetTextAlign(33);
421
422 // box with the histogram title
423 ptitle->SetTextColor(gStyle->GetTitleTextColor());
424#if ROOT_VERSION_CODE > ROOT_VERSION(3,05,00)
425 ptitle->SetTextFont(gStyle->GetTitleFont(""));
426#endif
427 ptitle->Paint();
428}
429
430// ------------------------------------------------------------------------
431//
432// Paint the histogram title
433//
434void MHCamera::PaintTitle()
435{
436// *-*-*-*-*-*-*-*-*-*Draw the histogram title*-*-*-*-*-*-*-*-*-*-*-*-*
437// ========================
438 //if (Hoption.Same) return;
439#if ROOT_VERSION_CODE > ROOT_VERSION(3,05,00)
440 if (TestBit(kNoTitle))
441 return;
442#endif
443
444 const Int_t nt = strlen(GetTitle());
445
446 TPaveText *title = (TPaveText*)gPad->FindObject("title");
447 if (nt == 0 || gStyle->GetOptTitle() <= 0)
448 {
449 if (title)
450 delete title;
451 return;
452 }
453
454 Double_t ht = gStyle->GetTitleH();
455 Double_t wt = gStyle->GetTitleW();
456
457 if (ht <= 0)
458 ht = 0.05;
459 if (wt <= 0)
460 {
461 TLatex l;
462 l.SetTextSize(ht);
463 l.SetTitle(GetTitle());
464 Double_t wndc = l.GetXsize()/(gPad->GetX2() - gPad->GetX1());
465 wt = TMath::Min(0.7, 0.02+wndc);
466 }
467 if (title)
468 {
469 TText *t0 = (TText*)title->GetLine(0);
470 if (t0)
471 {
472 if (!strcmp(t0->GetTitle(), GetTitle()))
473 return;
474
475 t0->SetTitle(GetTitle());
476 if (wt > 0)
477 title->SetX2NDC(title->GetX1NDC()+wt);
478 }
479 return;
480 }
481
482 TPaveText *ptitle = new TPaveText(
483 gStyle->GetTitleX(),
484 gStyle->GetTitleY()-ht,
485 gStyle->GetTitleX()+wt,
486 gStyle->GetTitleY(),"blNDC");
487
488 // box with the histogram title
489#if ROOT_VERSION_CODE > ROOT_VERSION(3,05,00)
490 ptitle->SetFillColor(gStyle->GetTitleFillColor());
491 ptitle->SetTextFont(gStyle->GetTitleFont(""));
492 if (gStyle->GetTitleFont("")%10 > 2)
493 ptitle->SetTextSize(gStyle->GetTitleFontSize());
494#endif
495 ptitle->SetFillStyle(gStyle->GetTitleStyle());
496 ptitle->SetName("title");
497 ptitle->SetBorderSize(gStyle->GetTitleBorderSize());
498 ptitle->SetTextColor(gStyle->GetTitleTextColor());
499 ptitle->AddText(GetTitle());
500 ptitle->SetBit(kCanDelete);
501 ptitle->Draw();
502 ptitle->Paint();
503}
504
505// ------------------------------------------------------------------------
506//
507// Paints the camera.
508//
509void MHCamera::Paint(Option_t *o)
510{
511 TString opt(o);
512 opt.ToLower();
513
514 if (opt.Contains("hist"))
515 {
516 opt.ReplaceAll("hist", "");
517
518 Int_t mode = gStyle->GetOptStat();
519 TVirtualPad *save = gPad;
520 gPad=NULL;
521 gStyle->SetOptStat(1000011);
522 gPad=save;
523 TH1D::Paint(o);
524 gPad=NULL;
525 gStyle->SetOptStat(mode);
526 gPad=save;
527 return;
528 }
529
530 // Maintain aspect ratio
531 SetRange();
532
533 Bool_t isbox = opt.Contains("box");
534 Bool_t iscol = isbox ? !opt.Contains("nocol") : 1;
535
536 // Update Contents of the pixels and paint legend
537 Update(gPad->GetLogy(), isbox, iscol);
538
539 // Paint primitives (pixels, color legend, photons, ...)
540 PaintTitle();
541 PaintAxisTitle();
542}
543
544// ------------------------------------------------------------------------
545//
546// With this function you can change the color palette. For more
547// information see TStyle::SetPalette. Only palettes with 50 colors
548// are allowed.
549// In addition you can use SetPalette(52, 0) to create an inverse
550// deep blue sea palette
551//
552void MHCamera::SetPalette(Int_t ncolors, Int_t *colors)
553{
554 //
555 // If not enough colors are specified skip this.
556 //
557 if (ncolors>1 && ncolors<50)
558 {
559 cout << "MHCamera::SetPalette: Only default palettes with 50 colors are allowed... ignored." << endl;
560 return;
561 }
562
563 //
564 // If ncolors==52 create a reversed deep blue sea palette
565 //
566 if (ncolors==52)
567 {
568 gStyle->SetPalette(51, NULL);
569 TArrayI c(kItemsLegend);
570 for (int i=0; i<kItemsLegend; i++)
571 c[kItemsLegend-i-1] = gStyle->GetColorPalette(i);
572 gStyle->SetPalette(kItemsLegend, c.GetArray());
573 }
574 else
575 gStyle->SetPalette(ncolors, colors);
576
577 fColors.Set(kItemsLegend);
578 for (int i=0; i<kItemsLegend; i++)
579 fColors[i] = gStyle->GetColorPalette(i);
580}
581
582
583void MHCamera::SetPrettyPalette()
584{
585 if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
586 SetPalette(1, 0);
587}
588
589void MHCamera::SetDeepBlueSeaPalette()
590{
591 if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
592 SetPalette(51, 0);
593}
594
595void MHCamera::SetInvDeepBlueSeaPalette()
596{
597 if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
598 SetPalette(52, 0);
599}
600
601void MHCamera::DrawPixelIndices()
602{
603 // FIXME: Is this correct?
604 for (int i=0; i<kItemsLegend; i++)
605 fColors[i] = 16;
606
607 if (!gPad)
608 Draw();
609
610 TText txt;
611 txt.SetTextFont(122);
612 txt.SetTextAlign(22); // centered/centered
613
614 for (Int_t i=0; i<fNcells-2; i++)
615 {
616 TString num;
617 num += i;
618
619 const MGeomPix &h = (*fGeomCam)[i];
620 TText *nt = txt.DrawText(h.GetX(), h.GetY(), num);
621 nt->SetTextSize(0.3*h.GetD()/fGeomCam->GetMaxRadius());
622 }
623}
624
625void MHCamera::DrawSectorIndices()
626{
627 for (int i=0; i<kItemsLegend; i++)
628 fColors[i] = 16;
629
630 if (!gPad)
631 Draw();
632
633 TText txt;
634 txt.SetTextFont(122);
635 txt.SetTextAlign(22); // centered/centered
636
637 for (Int_t i=0; i<fNcells-2; i++)
638 {
639 TString num;
640 num += (*fGeomCam)[i].GetSector();
641
642 const MGeomPix &h = (*fGeomCam)[i];
643 TText *nt = txt.DrawText(h.GetX(), h.GetY(), num);
644 nt->SetTextSize(0.3*h.GetD()/fGeomCam->GetMaxRadius());
645 }
646}
647
648// ------------------------------------------------------------------------
649//
650// Call this function to add a MCamEvent on top of the present contents.
651// Only 'used' pixels are added.
652//
653void MHCamera::AddCamContent(const MCamEvent &event, Int_t type)
654{
655 // FIXME: Security check missing!
656 for (Int_t idx=0; idx<fNcells-2; idx++)
657 {
658 Double_t val=0;
659 if (event.GetPixelContent(val, idx, *fGeomCam, type) && !IsUsed(idx))
660 SetUsed(idx);
661
662 Fill(idx, val); // FIXME: Slow!
663 }
664 fEntries++;
665}
666
667// ------------------------------------------------------------------------
668//
669// Call this function to add a MHCamera on top of the present contents.
670// Only 'used' pixels are added.
671// Type:
672// 0) bin content
673// 1) errors
674// 2) rel. errors
675//
676void MHCamera::AddCamContent(const MHCamera &d, Int_t type)
677{
678 if (fNcells!=d.fNcells)
679 return;
680
681 // FIXME: Security check missing!
682 for (Int_t idx=0; idx<fNcells-2; idx++)
683 if (d.IsUsed(idx))
684 SetUsed(idx);
685
686 switch (type)
687 {
688 case 1:
689 for (Int_t idx=0; idx<fNcells-2; idx++)
690 Fill(idx, d.GetBinError(idx+1));
691 break;
692 case 2:
693 for (Int_t idx=0; idx<fNcells-2; idx++)
694 if (d.GetBinContent(idx+1)!=0)
695 Fill(idx, fabs(d.GetBinError(idx+1)/d.GetBinContent(idx+1)));
696 break;
697 default:
698 for (Int_t idx=0; idx<fNcells-2; idx++)
699 Fill(idx, d.GetBinContent(idx+1));
700 break;
701 }
702 fEntries++;
703}
704
705// ------------------------------------------------------------------------
706//
707// Call this function to add a TArrayD on top of the present contents.
708// Only 'used' pixels are added.
709//
710void MHCamera::AddCamContent(const TArrayD &event, const TArrayC *used)
711{
712 if (event.GetSize()!=fNcells-2)
713 return;
714
715 if (used && used->GetSize()!=fNcells-2)
716 return;
717
718 for (Int_t idx=0; idx<fNcells-2; idx++)
719 {
720 Fill(idx, const_cast<TArrayD&>(event)[idx]); // FIXME: Slow!
721
722 if (used && (*used)[idx])
723 SetUsed(idx);
724 }
725 fEntries++;
726}
727
728// ------------------------------------------------------------------------
729//
730// Call this function to add a MCamEvent on top of the present contents.
731// 1 is added to each pixel if the contents of MCamEvent>threshold
732//
733void MHCamera::CntCamContent(const MCamEvent &event, Double_t threshold, Int_t type)
734{
735 // FIXME: Security check missing!
736 for (Int_t idx=0; idx<fNcells-2; idx++)
737 {
738 Double_t val=0;
739 if (event.GetPixelContent(val, idx, *fGeomCam, type) && !IsUsed(idx))
740 SetUsed(idx);
741
742 if (val>threshold)
743 Fill(idx);
744 }
745 fEntries++;
746}
747
748// ------------------------------------------------------------------------
749//
750// Call this function to add a TArrayD on top of the present contents.
751// 1 is added to each pixel if the contents of MCamEvent>threshold
752//
753void MHCamera::CntCamContent(const TArrayD &event, Double_t threshold, Bool_t ispos)
754{
755 if (event.GetSize()!=fNcells-2)
756 return;
757
758 for (Int_t idx=0; idx<fNcells-2; idx++)
759 {
760 if (const_cast<TArrayD&>(event)[idx]>threshold)
761 Fill(idx);
762
763 if (!ispos || fArray[idx+1]>0)
764 SetUsed(idx);
765 }
766 fEntries++;
767}
768
769// ------------------------------------------------------------------------
770//
771// Fill the pixels with random contents.
772//
773void MHCamera::FillRandom()
774{
775 Reset();
776
777 // FIXME: Security check missing!
778 for (Int_t idx=0; idx<fNcells-2; idx++)
779 {
780 Fill(idx, gRandom->Uniform()*fGeomCam->GetPixRatio(idx));
781 SetUsed(idx);
782 }
783 fEntries=1;
784}
785
786
787// ------------------------------------------------------------------------
788//
789// Fill the colors in respect to the cleaning levels
790//
791void MHCamera::FillLevels(const MCerPhotEvt &event, Float_t lvl1, Float_t lvl2)
792{
793 SetCamContent(event, 2);
794
795 for (Int_t i=0; i<fNcells-2; i++)
796 {
797 if (!IsUsed(i))
798 continue;
799
800 if (fArray[i+1]>lvl1)
801 fArray[i+1] = 0;
802 else
803 if (fArray[i+1]>lvl2)
804 fArray[i+1] = 1;
805 else
806 fArray[i+1] = 2;
807 }
808}
809
810// ------------------------------------------------------------------------
811//
812// Fill the colors in respect to the cleaning levels
813//
814void MHCamera::FillLevels(const MCerPhotEvt &event, const MImgCleanStd &clean)
815{
816 FillLevels(event, clean.GetCleanLvl1(), clean.GetCleanLvl2());
817}
818
819// ------------------------------------------------------------------------
820//
821// Reset the all pixel colors to a default value
822//
823void MHCamera::Reset(Option_t *opt)
824{
825 TH1::Reset(opt);
826
827 for (Int_t i=0; i<fNcells-2; i++)
828 {
829 fArray[i+1]=0;
830 ResetUsed(i);
831 }
832 fArray[0] = 0;
833 fArray[fNcells-1] = 0;
834}
835
836// ------------------------------------------------------------------------
837//
838// Here we calculate the color index for the current value.
839// The color index is defined with the class TStyle and the
840// Color palette inside. We use the command gStyle->SetPalette(1,0)
841// for the display. So we have to convert the value "wert" into
842// a color index that fits the color palette.
843// The range of the color palette is defined by the values fMinPhe
844// and fMaxRange. Between this values we have 50 color index, starting
845// with 0 up to 49.
846//
847Int_t MHCamera::GetColor(Float_t val, Float_t min, Float_t max, Bool_t islog)
848{
849 if (TMath::IsNaN(val)) // FIXME: gLog!
850 {
851 cout << "MHCamera::GetColor: " << GetName() << " <" << GetTitle() << "> - Color for val=NaN (Not a Number) requested... set val=min." << endl;
852 val = min;
853 }
854
855 //
856 // first treat the over- and under-flows
857 //
858 const Int_t maxcolidx = kItemsLegend-1;
859
860 if (val >= max)
861 return fColors[maxcolidx];
862
863 if (val <= min)
864 return fColors[0];
865
866 //
867 // calculate the color index
868 //
869 Float_t ratio;
870 if (islog && min>0)
871 ratio = log10(val/min) / log10(max/min);
872 else
873 ratio = (val-min) / (max-min);
874
875 const Int_t colidx = (Int_t)(ratio*maxcolidx + .5);
876 return fColors[colidx];
877}
878
879// ------------------------------------------------------------------------
880//
881// Change the text on the legend according to the range of the Display
882//
883void MHCamera::UpdateLegend(Float_t minphe, Float_t maxphe, Bool_t islog)
884{
885 const Float_t range = fGeomCam->GetMaxRadius();
886
887 const Float_t H = 0.9*range;
888 const Float_t h = 2./kItemsLegend;
889 const Float_t offset = 0.04*range;
890
891 const Float_t w = range/sqrt((float)(fNcells-2));
892
893 TBox newbox;
894 TText newtxt;
895 newtxt.SetTextSize(0.025);
896 newtxt.SetTextAlign(12);
897#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
898 newtxt.SetBit(/*kNoContextMenu|*/kCannotPick);
899 newbox.SetBit(/*kNoContextMenu|*/kCannotPick);
900#endif
901
902 for (Int_t i=0; i<kItemsLegend+1; i+=3)
903 {
904 const Float_t pos = (Float_t)i/kItemsLegend;
905
906 Float_t val;
907 if (islog && minphe>0)
908 val = pow(10, log10(maxphe/minphe)*pos) * minphe;
909 else
910 val = minphe + pos * (maxphe-minphe);
911
912 newtxt.PaintText(range+1.5*w, H*(i*h-1)-offset, Form(val<1e6?"%5.1f":"%5.1e", val));
913 }
914
915 for (Int_t i=0; i<kItemsLegend; i++)
916 {
917 newbox.SetFillColor(fColors[i]);
918 newbox.PaintBox(range, H*(i*h-1)-offset, range+w, H*((i+1)*h-1)-offset);
919 }
920
921 TArrow arr;
922 arr.PaintArrow(-range*.9, -range*.9, -range*.6, -range*.9, 0.025);
923 arr.PaintArrow(-range*.9, -range*.9, -range*.9, -range*.6, 0.025);
924
925 TString text;
926 text += (int)(range*.3);
927 text += "mm";
928
929 TText newtxt2;
930 newtxt2.SetTextSize(0.04);
931 newtxt2.PaintText(-range*.85, -range*.85, text);
932
933 text = "";
934 text += (float)((int)(range*.3*fGeomCam->GetConvMm2Deg()*10))/10;
935 text += "\\circ";
936 text = text.Strip(TString::kLeading);
937
938 TLatex latex;
939 latex.PaintLatex(-range*.85, -range*.75, 0, 0.04, text);
940}
941
942// ------------------------------------------------------------------------
943//
944// Save primitive as a C++ statement(s) on output stream out
945//
946void MHCamera::SavePrimitive(ofstream &out, Option_t *opt)
947{
948 cout << "MHCamera::SavePrimitive: Must be rewritten!" << endl;
949 /*
950 if (!gROOT->ClassSaved(TCanvas::Class()))
951 fDrawingPad->SavePrimitive(out, opt);
952
953 out << " " << fDrawingPad->GetName() << "->SetWindowSize(";
954 out << fDrawingPad->GetWw() << "," << fDrawingPad->GetWh() << ");" << endl;
955 */
956}
957
958// ------------------------------------------------------------------------
959//
960// compute the distance of a point (px,py) to the Camera
961// this functions needed for graphical primitives, that
962// means without this function you are not able to interact
963// with the graphical primitive with the mouse!!!
964//
965// All calcutations are done in pixel coordinates
966//
967Int_t MHCamera::DistancetoPrimitive(Int_t px, Int_t py)
968{
969 if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
970 return TH1D::DistancetoPrimitive(px, py);
971
972 for (Int_t i=0; i<fNcells-2; i++)
973 {
974 MHexagon hex((*fGeomCam)[i]);
975 if (hex.DistancetoPrimitive(px, py)==0)
976 return 0;
977 }
978 return 999999;
979}
980
981// ------------------------------------------------------------------------
982//
983// Function introduced (31-01-03) WILL BE REMOVED IN THE FUTURE! DON'T
984// USE IT!
985//
986void MHCamera::SetPix(const Int_t idx, const Int_t color, Float_t min, Float_t max)
987{
988 fArray[idx+1] = color;
989 SetUsed(idx);
990}
991
992// ------------------------------------------------------------------------
993//
994// Function introduced (31-01-03) WILL BE REMOVED IN THE FUTURE! DON'T
995// USE IT!
996//
997Int_t MHCamera::GetPixelIndex(Int_t px, Int_t py) const
998{
999 Int_t i;
1000 for (i=0; i<fNcells-2; i++)
1001 {
1002 MHexagon hex((*fGeomCam)[i]);
1003 if (hex.DistancetoPrimitive(px, py)>0)
1004 continue;
1005
1006 return i;
1007 }
1008 return -1;
1009}
1010
1011// ------------------------------------------------------------------------
1012//
1013// Returns string containing info about the object at position (px,py).
1014// Returned string will be re-used (lock in MT environment).
1015//
1016char *MHCamera::GetObjectInfo(Int_t px, Int_t py) const
1017{
1018 if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
1019 return TH1D::GetObjectInfo(px, py);
1020
1021 static char info[128];
1022
1023 const Int_t idx=GetPixelIndex(px, py);
1024
1025 if (idx<0)
1026 return TObject::GetObjectInfo(px, py);
1027
1028 sprintf(info, "Software Pixel Index: %d (Hardware Id=%d)", idx, idx+1);
1029 return info;
1030}
1031
1032// ------------------------------------------------------------------------
1033//
1034// Execute a mouse event on the camera
1035//
1036void MHCamera::ExecuteEvent(Int_t event, Int_t px, Int_t py)
1037{
1038 if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
1039 {
1040 TH1D::ExecuteEvent(event, px, py);
1041 return;
1042 }
1043 //if (event==kMouseMotion && fStatusBar)
1044 // fStatusBar->SetText(GetObjectInfo(px, py), 0);
1045 if (event!=kButton1Down)
1046 return;
1047
1048 const Int_t idx = GetPixelIndex(px, py);
1049 if (idx<0)
1050 return;
1051
1052 cout << GetTitle() << " <" << GetName() << ">" << endl;
1053 cout << "Software Pixel Index: " << idx << endl;
1054 cout << "Hardware Pixel Id: " << idx+1 << endl;
1055 cout << "Contents: " << fArray[idx+1] << " <";
1056 cout << (IsUsed(idx)?"on":"off");
1057 cout << ">" << endl;
1058
1059 if (fNotify && fNotify->GetSize()>0)
1060 new TCanvas;
1061 fNotify->ForEach(MCamEvent, DrawPixelContent)(idx);
1062}
Note: See TracBrowser for help on using the repository browser.