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

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