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

Last change on this file since 3823 was 3798, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 42.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! Author(s): Markus Gaug, 03/2004 <mailto:markus@ifae.es>
21!
22! Copyright: MAGIC Software Development, 2000-2004
23!
24!
25\* ======================================================================== */
26
27/////////////////////////////////////////////////////////////////////////////
28//
29// MHCamera
30//
31// Camera Display, based on a TH1D. Pleas be carefull using the
32// underlaying TH1D.
33//
34// To change the scale to a logarithmic scale SetLogy() of the Pad.
35//
36// Be carefull: Entries in this context means Entries/bin or Events
37//
38// FIXME? Maybe MHCamera can take the fLog object from MGeomCam?
39//
40////////////////////////////////////////////////////////////////////////////
41#include "MHCamera.h"
42
43#include <fstream>
44#include <iostream>
45
46#include <TBox.h>
47#include <TArrow.h>
48#include <TLatex.h>
49#include <TStyle.h>
50#include <TCanvas.h>
51#include <TArrayF.h>
52#include <TRandom.h>
53#include <TPaveText.h>
54#include <TPaveStats.h>
55#include <TClonesArray.h>
56#include <THistPainter.h>
57#include <THLimitsFinder.h>
58#include <TProfile.h>
59
60#include "MLog.h"
61#include "MLogManip.h"
62
63#include "MH.h"
64#include "MHexagon.h"
65
66#include "MGeomPix.h"
67#include "MGeomCam.h"
68
69#include "MCamEvent.h"
70
71
72#define kItemsLegend 48 // see SetPalette(1,0)
73
74ClassImp(MHCamera);
75
76using namespace std;
77
78void MHCamera::Init()
79{
80 UseCurrentStyle();
81
82 SetDirectory(NULL);
83
84 SetLineColor(kGreen);
85 SetMarkerStyle(kFullDotMedium);
86 SetXTitle("Pixel Index");
87
88 fNotify = new TList;
89 fNotify->SetBit(kMustCleanup);
90 gROOT->GetListOfCleanups()->Add(fNotify);
91
92#if ROOT_VERSION_CODE < ROOT_VERSION(3,01,06)
93 SetPalette(1, 0);
94#else
95 SetInvDeepBlueSeaPalette();
96#endif
97}
98
99// ------------------------------------------------------------------------
100//
101// Default Constructor. To be used by the root system ONLY.
102//
103MHCamera::MHCamera() : TH1D(), fGeomCam(NULL), fColors(kItemsLegend)
104{
105 Init();
106}
107
108// ------------------------------------------------------------------------
109//
110// Constructor. Makes a clone of MGeomCam. Removed the TH1D from the
111// current directory. Calls Sumw2(). Set the histogram line color
112// (for error bars) to Green and the marker style to kFullDotMedium.
113//
114MHCamera::MHCamera(const MGeomCam &geom, const char *name, const char *title)
115: fGeomCam(NULL), fColors(kItemsLegend)
116{
117 //fGeomCam = (MGeomCam*)geom.Clone();
118 SetGeometry(geom, name, title);
119 Init();
120
121 //
122 // root 3.02
123 // * base/inc/TObject.h:
124 // register BIT(8) as kNoContextMenu. If an object has this bit set it will
125 // not get an automatic context menu when clicked with the right mouse button.
126}
127
128void MHCamera::SetGeometry(const MGeomCam &geom, const char *name, const char *title)
129{
130 SetNameTitle(name, title);
131
132 TAxis &x = *GetXaxis();
133
134 SetBins(geom.GetNumPixels(), 0, 1);
135 x.Set(geom.GetNumPixels(), -0.5, geom.GetNumPixels()-0.5);
136
137 //SetBins(geom.GetNumPixels(), -0.5, geom.GetNumPixels()-0.5);
138 //Rebuild();
139
140 Sumw2(); // necessary?
141
142 if (fGeomCam)
143 delete fGeomCam;
144 fGeomCam = (MGeomCam*)geom.Clone();
145
146 fUsed.Set(geom.GetNumPixels());
147 for (Int_t i=0; i<fNcells-2; i++)
148 ResetUsed(i);
149}
150
151// ------------------------------------------------------------------------
152//
153// Destructor. Deletes the cloned fGeomCam and the notification list.
154//
155MHCamera::~MHCamera()
156{
157 if (fGeomCam)
158 delete fGeomCam;
159 if (fNotify)
160 delete fNotify;
161}
162
163// ------------------------------------------------------------------------
164//
165// Return kTRUE for sector<0. Otherwise return kTRUE only if the specified
166// sector idx matches the sector of the pixel with index idx.
167//
168Bool_t MHCamera::MatchSector(Int_t idx, const TArrayI &sector, const TArrayI &aidx) const
169{
170 const MGeomPix &pix = (*fGeomCam)[idx];
171 return FindVal(sector, pix.GetSector()) && FindVal(aidx, pix.GetAidx());
172}
173
174// ------------------------------------------------------------------------
175//
176// Taken from TH1D::Fill(). Uses the argument directly as bin index.
177// Doesn't increment the number of entries.
178//
179// -*-*-*-*-*-*-*-*Increment bin with abscissa X by 1*-*-*-*-*-*-*-*-*-*-*
180// ==================================
181//
182// if x is less than the low-edge of the first bin, the Underflow bin is incremented
183// if x is greater than the upper edge of last bin, the Overflow bin is incremented
184//
185// If the storage of the sum of squares of weights has been triggered,
186// via the function Sumw2, then the sum of the squares of weights is incremented
187// by 1 in the bin corresponding to x.
188//
189// -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
190Int_t MHCamera::Fill(Axis_t x)
191{
192#if ROOT_VERSION_CODE > ROOT_VERSION(3,05,00)
193 if (fBuffer) return BufferFill(x,1);
194#endif
195 const Int_t bin = (Int_t)x+1;
196 AddBinContent(bin);
197 if (fSumw2.fN)
198 fSumw2.fArray[bin]++;
199
200 if (bin<=0 || bin>fNcells-2)
201 return -1;
202
203 fTsumw++;
204 fTsumw2++;
205 fTsumwx += x;
206 fTsumwx2 += x*x;
207 return bin;
208}
209
210// ------------------------------------------------------------------------
211//
212// Taken from TH1D::Fill(). Uses the argument directly as bin index.
213// Doesn't increment the number of entries.
214//
215// -*-*-*-*-*-*Increment bin with abscissa X with a weight w*-*-*-*-*-*-*-*
216// =============================================
217//
218// if x is less than the low-edge of the first bin, the Underflow bin is incremented
219// if x is greater than the upper edge of last bin, the Overflow bin is incremented
220//
221// If the storage of the sum of squares of weights has been triggered,
222// via the function Sumw2, then the sum of the squares of weights is incremented
223// by w^2 in the bin corresponding to x.
224//
225// -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
226Int_t MHCamera::Fill(Axis_t x, Stat_t w)
227{
228#if ROOT_VERSION_CODE > ROOT_VERSION(3,05,00)
229 if (fBuffer) return BufferFill(x,w);
230#endif
231 const Int_t bin = (Int_t)x+1;
232 AddBinContent(bin, w);
233 if (fSumw2.fN)
234 fSumw2.fArray[bin] += w*w;
235
236 if (bin<=0 || bin>fNcells-2)
237 return -1;
238
239 const Stat_t z = (w > 0 ? w : -w);
240 fTsumw += z;
241 fTsumw2 += z*z;
242 fTsumwx += z*x;
243 fTsumwx2 += z*x*x;
244 return bin;
245}
246
247// ------------------------------------------------------------------------
248//
249// Use x and y in millimeters
250//
251Int_t MHCamera::Fill(Axis_t x, Axis_t y, Stat_t w)
252{
253 if (fNcells<=1 || IsFreezed())
254 return -1;
255
256 for (Int_t idx=0; idx<fNcells-2; idx++)
257 {
258 MHexagon hex((*fGeomCam)[idx]);
259 if (hex.DistanceToPrimitive(x, y)>0)
260 continue;
261
262 SetUsed(idx);
263 return Fill(idx, w);
264 }
265 return -1;
266}
267
268// ------------------------------------------------------------------------
269//
270// Call this if you want to change the display status (displayed or not)
271// for all pixels. val==0 means that the pixel is not displayed.
272//
273void MHCamera::SetUsed(const TArrayC &arr)
274{
275 if (fNcells-2 != arr.GetSize())
276 {
277 gLog << warn << "WARNING - MHCamera::SetUsed: array size mismatch... ignored." << endl;
278 return;
279 }
280
281 for (Int_t idx=0; idx<fNcells-2; idx++)
282 arr[idx] ? SetUsed(idx) : ResetUsed(idx);
283}
284
285// ------------------------------------------------------------------------
286//
287// Return the mean value of all entries which are used if all=kFALSE and
288// of all entries if all=kTRUE if sector<0. If sector>=0 only
289// entries with match the given sector are taken into account.
290//
291Stat_t MHCamera::GetMeanSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t all) const
292{
293 if (fNcells<=1)
294 return 0;
295
296 Int_t n=0;
297
298 Stat_t mean = 0;
299 for (int i=0; i<fNcells-2; i++)
300 {
301 if ((all || IsUsed(i)) && MatchSector(i, sector, aidx))
302 {
303 mean += fArray[i+1];
304 n++;
305 }
306 }
307
308 return n==0 ? 0 : Profile(mean/n);
309}
310
311// ------------------------------------------------------------------------
312//
313// Return the variance of all entries which are used if all=kFALSE and
314// of all entries if all=kTRUE if sector<0. If sector>=0 only
315// entries with match the given sector are taken into account.
316//
317Stat_t MHCamera::GetRmsSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t all) const
318{
319 if (fNcells<=1)
320 return -1;
321
322 Int_t n=0;
323
324 Stat_t sum = 0;
325 Stat_t sq = 0;
326 for (int i=0; i<fNcells-2; i++)
327 {
328 if ((all || IsUsed(i)) && MatchSector(i, sector, aidx))
329 {
330 sum += fArray[i+1];
331 sq += fArray[i+1]*fArray[i+1];
332 n++;
333 }
334 }
335
336 if (n==0)
337 return 0;
338
339 sum /= n;
340 sq /= n;
341
342 return Profile(TMath::Sqrt(sq-sum*sum));
343}
344
345// ------------------------------------------------------------------------
346//
347// Return the minimum contents of all pixels (if all is set, otherwise
348// only of all 'used' pixels), fMinimum if fMinimum set. If sector>=0
349// only pixels with matching sector number are taken into account.
350//
351Double_t MHCamera::GetMinimumSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t all) const
352{
353 if (fMinimum != -1111)
354 return fMinimum;
355
356 if (fNcells<=1)
357 return 0;
358
359 Double_t minimum=FLT_MAX;
360
361 for (Int_t idx=0; idx<fNcells-2; idx++)
362 if (MatchSector(idx, sector, aidx) && (all || IsUsed(idx)) && fArray[idx+1]<minimum)
363 minimum = fArray[idx+1];
364
365 return Profile(minimum);
366}
367
368// ------------------------------------------------------------------------
369//
370// Return the maximum contents of all pixels (if all is set, otherwise
371// only of all 'used' pixels), fMaximum if fMaximum set. If sector>=0
372// only pixels with matching sector number are taken into account.
373//
374Double_t MHCamera::GetMaximumSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t all) const
375{
376 if (fMaximum!=-1111)
377 return fMaximum;
378
379 if (fNcells<=1)
380 return 1;
381
382 Double_t maximum=-FLT_MAX;
383 for (Int_t idx=0; idx<fNcells-2; idx++)
384 if (MatchSector(idx, sector, aidx) && (all || IsUsed(idx)) && fArray[idx+1]>maximum)
385 maximum = fArray[idx+1];
386
387 return Profile(maximum);
388}
389
390// ------------------------------------------------------------------------
391//
392// Call this function to draw the camera layout into your canvas.
393// Setup a drawing canvas. Add this object and all child objects
394// (hexagons, etc) to the current pad. If no pad exists a new one is
395// created. (To access the 'real' pad containing the camera you have
396// to do a cd(1) in the current layer.
397//
398// To draw a camera into its own pad do something like:
399//
400// MGeomCamMagic m;
401// MHCamera *d=new MHCamera(m);
402//
403// TCanvas *c = new TCanvas;
404// c->Divide(2,1);
405// c->cd(1);
406//
407// d->FillRandom();
408// d->Draw();
409// d->SetBit(kCanDelete);
410//
411// There are several drawing options:
412// 'hist' Draw as a standard TH1 histogram (value vs. pixel index)
413// 'box' Draw hexagons which size is in respect to its contents
414// 'nocol' Leave the 'boxed' hexagons empty
415// 'pixelindex' Display the pixel index in each pixel
416// 'sectorindex' Display the sector index in each pixel
417// 'content' Display the relative content aligned to GetMaximum() and
418// GeMinimum() ((val-min)/(max-min))
419// 'proj' Display the y-projection of the histogram
420// 'same' Draw trandparent pixels on top of an existing pad. This
421// makes it possible to draw the camera image on top of an
422// existing TH2, but also allows for distorted camera images
423//
424void MHCamera::Draw(Option_t *option)
425{
426 const Bool_t hassame = TString(option).Contains("same", TString::kIgnoreCase) && gPad;
427
428 // root 3.02:
429 // gPad->SetFixedAspectRatio()
430 const Color_t col = gPad ? gPad->GetFillColor() : 16;
431 TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas("CamDisplay", "Mars Camera Display", 656, 600);
432
433 if (!hassame)
434 {
435 pad->SetBorderMode(0);
436 pad->SetFillColor(col);
437
438 //
439 // Create an own pad for the MHCamera-Object which can be
440 // resized in paint to keep the correct aspect ratio
441 //
442 pad->Divide(1, 1, 0, 0, col);
443 pad->cd(1);
444 gPad->SetBorderMode(0);
445 }
446
447 AppendPad(option);
448 //fGeomCam->AppendPad();
449
450 //
451 // Do not change gPad. The user should not see, that Draw
452 // changes gPad...
453 //
454 if (!hassame)
455 pad->cd();
456}
457
458// ------------------------------------------------------------------------
459//
460// This is TObject::DrawClone but completely ignores
461// gROOT->GetSelectedPad(). tbretz had trouble with this in the past.
462// If this makes trouble please write a bug report.
463//
464TObject *MHCamera::DrawClone(Option_t *option) const
465{
466 // Draw a clone of this object in the current pad
467
468 //TVirtualPad *pad = gROOT->GetSelectedPad();
469 TVirtualPad *padsav = gPad;
470 //if (pad) pad->cd();
471
472 TObject *newobj = Clone();
473
474 if (!newobj)
475 return 0;
476
477 /*
478 if (pad) {
479 if (strlen(option)) pad->GetListOfPrimitives()->Add(newobj,option);
480 else pad->GetListOfPrimitives()->Add(newobj,GetDrawOption());
481 pad->Modified(kTRUE);
482 pad->Update();
483 if (padsav) padsav->cd();
484 return newobj;
485 }
486 */
487
488 TString opt(option);
489 opt.ToLower();
490
491 newobj->Draw(opt.IsNull() ? GetDrawOption() : option);
492
493 if (padsav)
494 padsav->cd();
495
496 return newobj;
497}
498
499// ------------------------------------------------------------------------
500//
501// Creates a TH1D which contains the projection of the contents of the
502// MHCamera onto the y-axis. The maximum and minimum are calculated
503// such that a slighly wider range than (GetMinimum(), GetMaximum()) is
504// displayed using THLimitsFinder::OptimizeLimits.
505//
506// If no name is given the newly allocated histogram is removed from
507// the current directory calling SetDirectory(0) in any other case
508// the newly created histogram is removed from the current directory
509// and added to gROOT such the gROOT->FindObject can find the histogram.
510//
511// If the standard name "_py" is given "_py" is appended to the name
512// of the MHCamera and the corresponding histogram is searched using
513// gROOT->FindObject and updated with the present projection.
514//
515// It is the responsibility of the user to make sure, that the newly
516// created histogram is freed correctly.
517//
518// Currently the new histogram is restrictred to 50 bins.
519// Maybe a optimal number can be calulated from the number of
520// bins on the x-axis of the MHCamera?
521//
522// The code was taken mainly from TH2::ProjectX such the interface
523// is more or less the same than to TH2-projections.
524//
525// If sector>=0 only entries with matching sector index are taken
526// into account.
527//
528TH1D *MHCamera::ProjectionS(const TArrayI &sector, const TArrayI &aidx, const char *name) const
529{
530 Int_t nbins = 50;
531
532 // Create the projection histogram
533 TString pname(name);
534 if (name=="_py")
535 {
536 pname.Prepend(GetName());
537 if (sector.GetSize()>0)
538 {
539 pname += ";";
540 for (int i=0; i<sector.GetSize(); i++)
541 pname += sector[i];
542 }
543 if (aidx.GetSize()>0)
544 {
545 pname += ";";
546 for (int i=0; i<aidx.GetSize(); i++)
547 pname += aidx[i];
548 }
549 }
550
551 TH1D *h1=0;
552
553 //check if histogram with identical name exist
554 TObject *h1obj = gROOT->FindObject(pname);
555 if (h1obj && h1obj->InheritsFrom("TH1D")) {
556 h1 = (TH1D*)h1obj;
557 h1->Reset();
558 }
559
560 if (!h1)
561 {
562 Double_t min = GetMinimumSectors(sector, aidx);
563 Double_t max = GetMaximumSectors(sector, aidx);
564
565 Int_t newbins=0;
566
567 THLimitsFinder::OptimizeLimits(nbins, newbins, min, max, kFALSE);
568
569 h1 = new TH1D(pname, GetTitle(), nbins, min, max);
570 h1->SetDirectory(pname.IsNull() ? NULL : gROOT);
571 h1->SetXTitle(GetYaxis()->GetTitle());
572 h1->SetYTitle("Counts");
573 //h1->Sumw2();
574 }
575
576 // Fill the projected histogram
577 for (Int_t idx=0; idx<fNcells-2; idx++)
578 if (IsUsed(idx) && MatchSector(idx, sector, aidx))
579 h1->Fill(GetBinContent(idx+1));
580
581 return h1;
582}
583
584// ------------------------------------------------------------------------
585//
586// Creates a TH1D which contains the projection of the contents of the
587// MHCamera onto the radius from the camera center.
588// The maximum and minimum are calculated
589// such that a slighly wider range than (GetMinimum(), GetMaximum()) is
590// displayed using THLimitsFinder::OptimizeLimits.
591//
592// If no name is given the newly allocated histogram is removed from
593// the current directory calling SetDirectory(0) in any other case
594// the newly created histogram is removed from the current directory
595// and added to gROOT such the gROOT->FindObject can find the histogram.
596//
597// If the standard name "_rad" is given "_rad" is appended to the name
598// of the MHCamera and the corresponding histogram is searched using
599// gROOT->FindObject and updated with the present projection.
600//
601// It is the responsibility of the user to make sure, that the newly
602// created histogram is freed correctly.
603//
604// Currently the new histogram is restrictred to 50 bins.
605// Maybe a optimal number can be calulated from the number of
606// bins on the x-axis of the MHCamera?
607//
608// The code was taken mainly from TH2::ProjectX such the interface
609// is more or less the same than to TH2-projections.
610//
611// If sector>=0 only entries with matching sector index are taken
612// into account.
613//
614TProfile *MHCamera::RadialProfileS(const TArrayI &sector, const TArrayI &aidx, const char *name, const Int_t nbins) const
615{
616
617 // Create the projection histogram
618 TString pname(name);
619 if (name=="_rad")
620 {
621 pname.Prepend(GetName());
622 if (sector.GetSize()>0)
623 {
624 pname += ";";
625 for (int i=0; i<sector.GetSize(); i++)
626 pname += sector[i];
627 }
628 if (aidx.GetSize()>0)
629 {
630 pname += ";";
631 for (int i=0; i<aidx.GetSize(); i++)
632 pname += aidx[i];
633 }
634 }
635
636 TProfile *h1=0;
637
638 //check if histogram with identical name exist
639 TObject *h1obj = gROOT->FindObject(pname);
640 if (h1obj && h1obj->InheritsFrom("TProfile")) {
641 h1 = (TProfile*)h1obj;
642 h1->Reset();
643 }
644
645 if (!h1)
646 {
647
648 Double_t min = 0.;
649 Double_t max = fGeomCam->GetMaxRadius();
650
651 Int_t newbins=0;
652
653 THLimitsFinder::OptimizeLimits(nbins, newbins, min, max, kFALSE);
654
655 h1 = new TProfile(pname, GetTitle(), nbins, min, max);
656 h1->SetDirectory(pname.IsNull() ? NULL : gROOT);
657 h1->SetXTitle("Radius from camera center [mm]");
658 h1->SetYTitle(GetYaxis()->GetTitle());
659 }
660
661 // Fill the projected histogram
662 for (Int_t idx=0; idx<fNcells-2; idx++)
663 if (IsUsed(idx) && MatchSector(idx, sector, aidx))
664 h1->Fill(TMath::Hypot((*fGeomCam)[idx].GetX(),(*fGeomCam)[idx].GetY()),
665 GetBinContent(idx+1));
666 return h1;
667}
668
669
670// ------------------------------------------------------------------------
671//
672// Resizes the current pad so that the camera is displayed in its
673// correct aspect ratio
674//
675void MHCamera::SetRange()
676{
677 const Float_t range = fGeomCam->GetMaxRadius()*1.05;
678
679 //
680 // Maintain aspect ratio
681 //
682 const float ratio = TestBit(kNoLegend) ? 1 : 1.15;
683
684 //
685 // Calculate width and height of the current pad in pixels
686 //
687 Float_t w = gPad->GetWw();
688 Float_t h = gPad->GetWh()*ratio;
689
690 //
691 // This prevents the pad from resizing itself wrongly
692 //
693 if (gPad->GetMother() != gPad)
694 {
695 w *= gPad->GetMother()->GetAbsWNDC();
696 h *= gPad->GetMother()->GetAbsHNDC();
697 }
698
699 //
700 // Set Range (coordinate system) of pad
701 //
702 gPad->Range(-range, -range, (2*ratio-1)*range, range);
703
704 //
705 // Resize Pad to given ratio
706 //
707 if (h<w)
708 gPad->SetPad((1.-h/w)/2, 0, (h/w+1.)/2, 1);
709 else
710 gPad->SetPad(0, (1.-w/h)/2, 1, (w/h+1.)/2);
711}
712
713// ------------------------------------------------------------------------
714//
715// Updates the pixel colors and paints the pixels
716//
717void MHCamera::Update(Bool_t islog, Bool_t isbox, Bool_t iscol, Bool_t issame)
718{
719 Double_t min = GetMinimum(kFALSE);
720 Double_t max = GetMaximum(kFALSE);
721 if (min==FLT_MAX)
722 {
723 min = 0;
724 max = 1;
725 }
726
727 if (min==max)
728 max += 1;
729
730 if (!issame)
731 UpdateLegend(min, max, islog);
732
733 // Try to estimate the units of the current display. This is only
734 // necessary for 'same' option and allows distorted images of the camera!
735 const Float_t maxr = (1-fGeomCam->GetConvMm2Deg())*fGeomCam->GetMaxRadius()/2;
736 const Float_t conv = !issame ||
737 gPad->GetX1()<-maxr || gPad->GetY1()<-maxr ||
738 gPad->GetX2()> maxr || gPad->GetY2()>maxr ? 1 : fGeomCam->GetConvMm2Deg();
739
740 MHexagon hex;
741 for (Int_t i=0; i<fNcells-2; i++)
742 {
743 hex.SetFillStyle(issame ? 0 : 1001);
744
745 if (!issame)
746 {
747 if (IsUsed(i) && iscol)
748 {
749 if (TMath::IsNaN(fArray[i+1]))
750 gLog << warn << "MHCamera::Update: " << GetName() << " <" << GetTitle() << "> - Pixel Index #" << i << " contents is NaN (Not a Number)..." << endl;
751
752 hex.SetFillColor(GetColor(GetBinContent(i+1), min, max, islog));
753 }
754 else
755 hex.SetFillColor(10);
756 }
757
758 const MGeomPix &pix = (*fGeomCam)[i];
759
760 const Float_t x = pix.GetX()*conv;
761 const Float_t y = pix.GetY()*conv;
762 const Float_t d = pix.GetD()*conv;
763
764 if (!isbox)
765 hex.PaintHexagon(x, y, d);
766 else
767 if (IsUsed(i) && !TMath::IsNaN(fArray[i+1]))
768 {
769 Float_t size = d*(GetBinContent(i+1)-min)/(max-min);
770 if (size>d)
771 size=d;
772 hex.PaintHexagon(x, y, size);
773 }
774 }
775}
776
777// ------------------------------------------------------------------------
778//
779// Print minimum and maximum
780//
781void MHCamera::Print(Option_t *) const
782{
783 gLog << all << "Minimum: " << GetMinimum();
784 if (fMinimum==-1111)
785 gLog << " <autoscaled>";
786 gLog << endl;
787 gLog << "Maximum: " << GetMaximum();
788 if (fMaximum==-1111)
789 gLog << " <autoscaled>";
790 gLog << endl;
791}
792
793// ------------------------------------------------------------------------
794//
795// Paint the y-axis title
796//
797void MHCamera::PaintAxisTitle()
798{
799 const Float_t range = fGeomCam->GetMaxRadius()*1.05;
800 const Float_t w = (1 + 1.5/sqrt((float)(fNcells-2)))*range;
801
802 TLatex *ptitle = new TLatex(w, -.90*range, GetYaxis()->GetTitle());
803
804 ptitle->SetTextSize(0.05);
805 ptitle->SetTextAlign(21);
806
807 // box with the histogram title
808 ptitle->SetTextColor(gStyle->GetTitleTextColor());
809#if ROOT_VERSION_CODE > ROOT_VERSION(3,05,01)
810 ptitle->SetTextFont(gStyle->GetTitleFont(""));
811#endif
812 ptitle->Paint();
813}
814
815// ------------------------------------------------------------------------
816//
817// Paints the camera.
818//
819void MHCamera::Paint(Option_t *o)
820{
821 if (fNcells<=1)
822 return;
823
824 TString opt(o);
825 opt.ToLower();
826
827 if (opt.Contains("hist"))
828 {
829 opt.ReplaceAll("hist", "");
830 TH1D::Paint(opt);
831 return;
832 }
833
834 if (opt.Contains("proj"))
835 {
836 opt.ReplaceAll("proj", "");
837 Projection(GetName())->Paint(opt);
838 return;
839 }
840
841 const Bool_t hassame = opt.Contains("same");
842 const Bool_t hasbox = opt.Contains("box");
843 const Bool_t hascol = hasbox ? !opt.Contains("nocol") : kTRUE;
844
845 if (!hassame)
846 {
847 gPad->Clear();
848
849 // Maintain aspect ratio
850 SetRange();
851
852 if (GetPainter())
853 {
854 // Paint statistics
855 if (!TestBit(TH1::kNoStats))
856 fPainter->PaintStat(gStyle->GetOptStat(), NULL);
857
858 // Paint primitives (pixels, color legend, photons, ...)
859 if (fPainter->InheritsFrom(THistPainter::Class()))
860 {
861 static_cast<THistPainter*>(fPainter)->MakeChopt("");
862 static_cast<THistPainter*>(fPainter)->PaintTitle();
863 }
864 }
865 }
866
867 // Update Contents of the pixels and paint legend
868 Update(gPad->GetLogy(), hasbox, hascol, hassame);
869
870 if (!hassame)
871 PaintAxisTitle();
872
873 if (opt.Contains("pixelindex"))
874 PaintIndices(0);
875 if (opt.Contains("sectorindex"))
876 PaintIndices(1);
877 if (opt.Contains("content"))
878 PaintIndices(2);
879}
880
881// ------------------------------------------------------------------------
882//
883// With this function you can change the color palette. For more
884// information see TStyle::SetPalette. Only palettes with 50 colors
885// are allowed.
886// In addition you can use SetPalette(52, 0) to create an inverse
887// deep blue sea palette
888//
889void MHCamera::SetPalette(Int_t ncolors, Int_t *colors)
890{
891 //
892 // If not enough colors are specified skip this.
893 //
894 if (ncolors>1 && ncolors<50)
895 {
896 gLog << err << "MHCamera::SetPalette: Only default palettes with 50 colors are allowed... ignored." << endl;
897 return;
898 }
899
900 //
901 // If ncolors==52 create a reversed deep blue sea palette
902 //
903 if (ncolors==52)
904 {
905 gStyle->SetPalette(51, NULL);
906 TArrayI c(kItemsLegend);
907 for (int i=0; i<kItemsLegend; i++)
908 c[kItemsLegend-i-1] = gStyle->GetColorPalette(i);
909 gStyle->SetPalette(kItemsLegend, c.GetArray());
910 }
911 else
912 gStyle->SetPalette(ncolors, colors);
913
914 fColors.Set(kItemsLegend);
915 for (int i=0; i<kItemsLegend; i++)
916 fColors[i] = gStyle->GetColorPalette(i);
917}
918
919
920void MHCamera::SetPrettyPalette()
921{
922 if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
923 SetPalette(1, 0);
924}
925
926void MHCamera::SetDeepBlueSeaPalette()
927{
928 if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
929 SetPalette(51, 0);
930}
931
932void MHCamera::SetInvDeepBlueSeaPalette()
933{
934 if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
935 SetPalette(52, 0);
936}
937
938void MHCamera::PaintIndices(Int_t type)
939{
940 if (fNcells<=1)
941 return;
942
943 const Double_t min = GetMinimum();
944 const Double_t max = GetMaximum();
945
946 if (type==2 && max==min)
947 return;
948
949 TText txt;
950 txt.SetTextFont(122);
951 txt.SetTextAlign(22); // centered/centered
952
953 for (Int_t i=0; i<fNcells-2; i++)
954 {
955 const MGeomPix &h = (*fGeomCam)[i];
956
957 TString num;
958 switch (type)
959 {
960 case 0: num += i; break;
961 case 1: num += h.GetSector(); break;
962 case 2: num += (Int_t)((fArray[i+1]-min)/(max-min)); break;
963 }
964
965 // FIXME: Should depend on the color of the pixel...
966 //(GetColor(GetBinContent(i+1), min, max, 0));
967 txt.SetTextColor(kRed);
968 txt.SetTextSize(0.3*h.GetD()/fGeomCam->GetMaxRadius()/1.05);
969 txt.PaintText(h.GetX(), h.GetY(), num);
970 }
971}
972
973// ------------------------------------------------------------------------
974//
975// Call this function to add a MCamEvent on top of the present contents.
976//
977void MHCamera::AddCamContent(const MCamEvent &event, Int_t type)
978{
979 if (fNcells<=1 || IsFreezed())
980 return;
981
982 // FIXME: Security check missing!
983 for (Int_t idx=0; idx<fNcells-2; idx++)
984 {
985 Double_t val=0;
986 if (event.GetPixelContent(val, idx, *fGeomCam, type)/* && !IsUsed(idx)*/)
987 SetUsed(idx);
988
989 Fill(idx, val); // FIXME: Slow!
990 }
991 fEntries++;
992}
993
994// ------------------------------------------------------------------------
995//
996// Call this function to add a MCamEvent on top of the present contents.
997//
998void MHCamera::SetCamError(const MCamEvent &evt, Int_t type)
999{
1000
1001 if (fNcells<=1 || IsFreezed())
1002 return;
1003
1004 // FIXME: Security check missing!
1005 for (Int_t idx=0; idx<fNcells-2; idx++)
1006 {
1007 Double_t val=0;
1008 if (evt.GetPixelContent(val, idx, *fGeomCam, type)/* && !IsUsed(idx)*/)
1009 SetUsed(idx);
1010
1011 SetBinError(idx+1, val); // FIXME: Slow!
1012 }
1013}
1014
1015Stat_t MHCamera::GetBinError(Int_t bin) const
1016{
1017 Double_t rc = 0;
1018 if (TestBit(kVariance) && GetEntries()>0) // error on the mean
1019 {
1020 const Double_t error = fSumw2.fArray[bin]/GetEntries();
1021 const Double_t val = fArray[bin]/GetEntries();
1022 rc = TMath::Sqrt(error - val*val);
1023 }
1024 else
1025 {
1026 rc = TH1D::GetBinError(bin);
1027 rc = Profile(rc);
1028 }
1029
1030 return rc;
1031}
1032
1033// ------------------------------------------------------------------------
1034//
1035// Call this function to add a MHCamera on top of the present contents.
1036// Type:
1037// 0) bin content
1038// 1) errors
1039// 2) rel. errors
1040//
1041void MHCamera::AddCamContent(const MHCamera &d, Int_t type)
1042{
1043 if (fNcells!=d.fNcells || IsFreezed())
1044 return;
1045
1046 // FIXME: Security check missing!
1047 for (Int_t idx=0; idx<fNcells-2; idx++)
1048 if (d.IsUsed(idx))
1049 SetUsed(idx);
1050
1051 switch (type)
1052 {
1053 case 1:
1054 for (Int_t idx=0; idx<fNcells-2; idx++)
1055 Fill(idx, d.GetBinError(idx+1));
1056 break;
1057 case 2:
1058 for (Int_t idx=0; idx<fNcells-2; idx++)
1059 if (d.GetBinContent(idx+1)!=0)
1060 Fill(idx, TMath::Abs(d.GetBinError(idx+1)/d.GetBinContent(idx+1)));
1061 break;
1062 default:
1063 for (Int_t idx=0; idx<fNcells-2; idx++)
1064 Fill(idx, d.GetBinContent(idx+1));
1065 break;
1066 }
1067 fEntries++;
1068}
1069
1070// ------------------------------------------------------------------------
1071//
1072// Call this function to add a TArrayD on top of the present contents.
1073//
1074void MHCamera::AddCamContent(const TArrayD &event, const TArrayC *used)
1075{
1076 if (event.GetSize()!=fNcells-2 || IsFreezed())
1077 return;
1078
1079 if (used && used->GetSize()!=fNcells-2)
1080 return;
1081
1082 for (Int_t idx=0; idx<fNcells-2; idx++)
1083 {
1084 Fill(idx, const_cast<TArrayD&>(event)[idx]); // FIXME: Slow!
1085
1086 if (!used || (*const_cast<TArrayC*>(used))[idx])
1087 SetUsed(idx);
1088 }
1089 fEntries++;
1090}
1091
1092// ------------------------------------------------------------------------
1093//
1094// Call this function to add a MCamEvent on top of the present contents.
1095// 1 is added to each pixel if the contents of MCamEvent>threshold
1096//
1097void MHCamera::CntCamContent(const MCamEvent &event, Double_t threshold, Int_t type)
1098{
1099 if (fNcells<=1 || IsFreezed())
1100 return;
1101
1102 // FIXME: Security check missing!
1103 for (Int_t idx=0; idx<fNcells-2; idx++)
1104 {
1105 Double_t val=threshold;
1106 if (event.GetPixelContent(val, idx, *fGeomCam, type)/* && !IsUsed(idx)*/)
1107 SetUsed(idx);
1108
1109 if (val>threshold)
1110 Fill(idx);
1111 }
1112 fEntries++;
1113}
1114
1115// ------------------------------------------------------------------------
1116//
1117// Call this function to add a TArrayD on top of the present contents.
1118// 1 is added to each pixel if the contents of MCamEvent>threshold
1119//
1120void MHCamera::CntCamContent(const TArrayD &event, Double_t threshold, Bool_t ispos)
1121{
1122 if (event.GetSize()!=fNcells-2 || IsFreezed())
1123 return;
1124
1125 for (Int_t idx=0; idx<fNcells-2; idx++)
1126 {
1127 if (const_cast<TArrayD&>(event)[idx]>threshold)
1128 Fill(idx);
1129
1130 if (!ispos || fArray[idx+1]>0)
1131 SetUsed(idx);
1132 }
1133 fEntries++;
1134}
1135
1136// ------------------------------------------------------------------------
1137//
1138// Fill the pixels with random contents.
1139//
1140void MHCamera::FillRandom()
1141{
1142 if (fNcells<=1 || IsFreezed())
1143 return;
1144
1145 Reset();
1146
1147 // FIXME: Security check missing!
1148 for (Int_t idx=0; idx<fNcells-2; idx++)
1149 {
1150 Fill(idx, gRandom->Uniform()*fGeomCam->GetPixRatio(idx));
1151 SetUsed(idx);
1152 }
1153 fEntries=1;
1154}
1155
1156
1157// ------------------------------------------------------------------------
1158//
1159// The array must be in increasing order, eg: 2.5, 3.7, 4.9
1160// The values in each bin are replaced by the interval in which the value
1161// fits. In the example we have four intervals
1162// (<2.5, 2.5-3.7, 3.7-4.9, >4.9). Maximum and minimum are set
1163// accordingly.
1164//
1165void MHCamera::SetLevels(const TArrayF &arr)
1166{
1167 if (fNcells<=1)
1168 return;
1169
1170 for (Int_t i=0; i<fNcells-2; i++)
1171 {
1172 if (!IsUsed(i))
1173 continue;
1174
1175 Int_t j = arr.GetSize();
1176 while (j && fArray[i+1]<arr[j-1])
1177 j--;
1178
1179 fArray[i+1] = j;
1180 }
1181 SetMaximum(arr.GetSize());
1182 SetMinimum(0);
1183}
1184
1185// ------------------------------------------------------------------------
1186//
1187// Reset the all pixel colors to a default value
1188//
1189void MHCamera::Reset(Option_t *opt)
1190{
1191 if (fNcells<=1 || IsFreezed())
1192 return;
1193
1194 TH1::Reset(opt);
1195
1196 for (Int_t i=0; i<fNcells-2; i++)
1197 {
1198 fArray[i+1]=0;
1199 ResetUsed(i);
1200 }
1201 fArray[0] = 0;
1202 fArray[fNcells-1] = 0;
1203}
1204
1205// ------------------------------------------------------------------------
1206//
1207// Here we calculate the color index for the current value.
1208// The color index is defined with the class TStyle and the
1209// Color palette inside. We use the command gStyle->SetPalette(1,0)
1210// for the display. So we have to convert the value "wert" into
1211// a color index that fits the color palette.
1212// The range of the color palette is defined by the values fMinPhe
1213// and fMaxRange. Between this values we have 50 color index, starting
1214// with 0 up to 49.
1215//
1216Int_t MHCamera::GetColor(Float_t val, Float_t min, Float_t max, Bool_t islog)
1217{
1218 if (TMath::IsNaN(val)) // FIXME: gLog!
1219 return 10;
1220
1221 //
1222 // first treat the over- and under-flows
1223 //
1224 const Int_t maxcolidx = kItemsLegend-1;
1225
1226 if (val >= max)
1227 return fColors[maxcolidx];
1228
1229 if (val <= min)
1230 return fColors[0];
1231
1232 //
1233 // calculate the color index
1234 //
1235 Float_t ratio;
1236 if (islog && min>0)
1237 ratio = log10(val/min) / log10(max/min);
1238 else
1239 ratio = (val-min) / (max-min);
1240
1241 const Int_t colidx = (Int_t)(ratio*maxcolidx + .5);
1242 return fColors[colidx];
1243}
1244
1245TPaveStats *MHCamera::GetStatisticBox()
1246{
1247 TObject *obj = 0;
1248
1249 TIter Next(fFunctions);
1250 while ((obj = Next()))
1251 if (obj->InheritsFrom(TPaveStats::Class()))
1252 return static_cast<TPaveStats*>(obj);
1253
1254 return NULL;
1255}
1256
1257// ------------------------------------------------------------------------
1258//
1259// Change the text on the legend according to the range of the Display
1260//
1261void MHCamera::UpdateLegend(Float_t min, Float_t max, Bool_t islog)
1262{
1263 const Float_t range = fGeomCam->GetMaxRadius()*1.05;
1264
1265 TArrow arr;
1266 arr.PaintArrow(-range*.9, -range*.9, -range*.6, -range*.9, 0.025);
1267 arr.PaintArrow(-range*.9, -range*.9, -range*.9, -range*.6, 0.025);
1268
1269 TString text;
1270 text += (int)(range*.3);
1271 text += "mm";
1272
1273 TText newtxt2;
1274 newtxt2.SetTextSize(0.04);
1275 newtxt2.PaintText(-range*.85, -range*.85, text);
1276
1277 text = "";
1278 text += (float)((int)(range*.3*fGeomCam->GetConvMm2Deg()*10))/10;
1279 text += "\\circ";
1280 text = text.Strip(TString::kLeading);
1281
1282 TLatex latex;
1283 latex.PaintLatex(-range*.85, -range*.75, 0, 0.04, text);
1284
1285 if (TestBit(kNoLegend))
1286 return;
1287
1288 TPaveStats *stats = GetStatisticBox();
1289
1290 const Float_t hndc = 0.92 - (stats ? stats->GetY1NDC() : 1);
1291 const Float_t H = (0.75-hndc)*range;
1292 const Float_t offset = hndc*range;
1293
1294 const Float_t h = 2./kItemsLegend;
1295 const Float_t w = range/sqrt((float)(fNcells-2));
1296
1297 TBox newbox;
1298 TText newtxt;
1299 newtxt.SetTextSize(0.03);
1300 newtxt.SetTextAlign(12);
1301#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
1302 newtxt.SetBit(/*kNoContextMenu|*/kCannotPick);
1303 newbox.SetBit(/*kNoContextMenu|*/kCannotPick);
1304#endif
1305
1306 const Float_t step = (islog && min>0 ? log10(max/min) : max-min) / kItemsLegend;
1307 const Int_t firsts = step*3 < 1e-8 ? 8 : (Int_t)floor(log10(step*3));
1308 const TString opt = Form("%%.%if", firsts>0 ? 0 : TMath::Abs(firsts));
1309
1310 for (Int_t i=0; i<kItemsLegend+1; i+=3)
1311 {
1312 Float_t val;
1313 if (islog && min>0)
1314 val = pow(10, step*i) * min;
1315 else
1316 val = min + step*i;
1317
1318 //const bool dispexp = max-min>1.5 && fabs(val)>0.1 && fabs(val)<1e6;
1319 newtxt.PaintText(range+1.5*w, H*(i*h-1)-offset, Form(opt, val));
1320 }
1321
1322 for (Int_t i=0; i<kItemsLegend; i++)
1323 {
1324 newbox.SetFillColor(fColors[i]);
1325 newbox.PaintBox(range, H*(i*h-1)-offset, range+w, H*((i+1)*h-1)-offset);
1326 }
1327}
1328
1329// ------------------------------------------------------------------------
1330//
1331// Save primitive as a C++ statement(s) on output stream out
1332//
1333void MHCamera::SavePrimitive(ofstream &out, Option_t *opt)
1334{
1335 gLog << err << "MHCamera::SavePrimitive: Must be rewritten!" << endl;
1336 /*
1337 if (!gROOT->ClassSaved(TCanvas::Class()))
1338 fDrawingPad->SavePrimitive(out, opt);
1339
1340 out << " " << fDrawingPad->GetName() << "->SetWindowSize(";
1341 out << fDrawingPad->GetWw() << "," << fDrawingPad->GetWh() << ");" << endl;
1342 */
1343}
1344
1345// ------------------------------------------------------------------------
1346//
1347// compute the distance of a point (px,py) to the Camera
1348// this functions needed for graphical primitives, that
1349// means without this function you are not able to interact
1350// with the graphical primitive with the mouse!!!
1351//
1352// All calcutations are done in pixel coordinates
1353//
1354Int_t MHCamera::DistancetoPrimitive(Int_t px, Int_t py)
1355{
1356 if (fNcells<=1)
1357 return 999999;
1358
1359 TPaveStats *box = (TPaveStats*)gPad->GetPrimitive("stats");
1360 if (box)
1361 {
1362 const Double_t w = box->GetY2NDC()-box->GetY1NDC();
1363 box->SetX1NDC(gStyle->GetStatX()-gStyle->GetStatW());
1364 box->SetY1NDC(gStyle->GetStatY()-w);
1365 box->SetX2NDC(gStyle->GetStatX());
1366 box->SetY2NDC(gStyle->GetStatY());
1367 }
1368
1369 if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
1370 return TH1D::DistancetoPrimitive(px, py);
1371
1372 const Bool_t issame = TString(GetDrawOption()).Contains("same", TString::kIgnoreCase);
1373
1374 const Float_t maxr = (1-fGeomCam->GetConvMm2Deg())*fGeomCam->GetMaxRadius()/2;
1375 const Float_t conv = !issame ||
1376 gPad->GetX1()<-maxr || gPad->GetY1()<-maxr ||
1377 gPad->GetX2()> maxr || gPad->GetY2()>maxr ? 1 : fGeomCam->GetConvMm2Deg();
1378
1379 if (GetPixelIndex(px, py, conv)>=0)
1380 return 0;
1381
1382 if (!box)
1383 return 999999;
1384
1385 const Int_t dist = box->DistancetoPrimitive(px, py);
1386 if (dist > TPad::GetMaxPickDistance())
1387 return 999999;
1388
1389 gPad->SetSelected(box);
1390 return dist;
1391}
1392
1393// ------------------------------------------------------------------------
1394//
1395//
1396Int_t MHCamera::GetPixelIndex(Int_t px, Int_t py, Float_t conv) const
1397{
1398 if (fNcells<=1)
1399 return -1;
1400
1401 Int_t i;
1402 for (i=0; i<fNcells-2; i++)
1403 {
1404 MHexagon hex((*fGeomCam)[i]);
1405 if (hex.DistancetoPrimitive(px, py, conv)>0)
1406 continue;
1407
1408 return i;
1409 }
1410 return -1;
1411}
1412
1413// ------------------------------------------------------------------------
1414//
1415// Returns string containing info about the object at position (px,py).
1416// Returned string will be re-used (lock in MT environment).
1417//
1418char *MHCamera::GetObjectInfo(Int_t px, Int_t py) const
1419{
1420 if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
1421 return TH1D::GetObjectInfo(px, py);
1422
1423 static char info[128];
1424
1425 const Int_t idx=GetPixelIndex(px, py);
1426
1427 if (idx<0)
1428 return TObject::GetObjectInfo(px, py);
1429
1430 sprintf(info, "Software Pixel Index: %d (Hardware Id=%d)", idx, idx+1);
1431 return info;
1432}
1433
1434// ------------------------------------------------------------------------
1435//
1436// Add a MCamEvent which should be displayed when the user clicks on a
1437// pixel.
1438// Warning: The object MUST inherit from TObject AND MCamEvent
1439//
1440void MHCamera::AddNotify(TObject *obj)
1441{
1442 // Make sure, that the object derives from MCamEvent!
1443 MCamEvent *evt = dynamic_cast<MCamEvent*>(obj);
1444 if (!evt)
1445 {
1446 gLog << err << "ERROR: MHCamera::AddNotify - TObject doesn't inherit from MCamEvent... ignored." << endl;
1447 return;
1448 }
1449
1450 // Make sure, that it is deleted from the list too, if the obj is deleted
1451 obj->SetBit(kMustCleanup);
1452
1453 // Add object to list
1454 fNotify->Add(obj);
1455}
1456
1457// ------------------------------------------------------------------------
1458//
1459// Execute a mouse event on the camera
1460//
1461void MHCamera::ExecuteEvent(Int_t event, Int_t px, Int_t py)
1462{
1463 if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
1464 {
1465 TH1D::ExecuteEvent(event, px, py);
1466 return;
1467 }
1468 //if (event==kMouseMotion && fStatusBar)
1469 // fStatusBar->SetText(GetObjectInfo(px, py), 0);
1470 if (event!=kButton1Down)
1471 return;
1472
1473 const Int_t idx = GetPixelIndex(px, py);
1474 if (idx<0)
1475 return;
1476
1477 gLog << all << GetTitle() << " <" << GetName() << ">" << endl;
1478 gLog << "Software Pixel Idx: " << idx << endl;
1479 gLog << "Hardware Pixel Id: " << idx+1 << endl;
1480 gLog << "Contents: " << GetBinContent(idx+1);
1481 if (GetBinError(idx+1)>0)
1482 gLog << " +/- " << GetBinError(idx+1);
1483 gLog << " <" << (IsUsed(idx)?"on":"off") << ">" << endl;
1484
1485 if (fNotify && fNotify->GetSize()>0)
1486 {
1487 // FIXME: Is there a simpler and more convinient way?
1488
1489 // The name which is created here depends on the instance of
1490 // MHCamera and on the pad on which it is drawn --> The name
1491 // is unique. For ExecuteEvent gPad is always correctly set.
1492 const TString name = Form("%p;%p;PixelContent", this, gPad);
1493
1494 TCanvas *old = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(name);
1495 if (old)
1496 old->cd();
1497 else
1498 new TCanvas(name);
1499
1500 /*
1501 TIter Next(gPad->GetListOfPrimitives());
1502 TObject *o;
1503 while (o=Next()) cout << o << ": " << o->GetName() << " " << o->IsA()->GetName() << endl;
1504 */
1505
1506 // FIXME: Make sure, that the old histograms are really deleted.
1507 // Are they already deleted?
1508
1509 // The dynamic_cast is necessary here: We cannot use ForEach
1510 TIter Next(fNotify);
1511 MCamEvent *evt;
1512 while ((evt=dynamic_cast<MCamEvent*>(Next())))
1513 evt->DrawPixelContent(idx);
1514
1515 gPad->Modified();
1516 gPad->Update();
1517 }
1518}
1519
1520UInt_t MHCamera::GetNumPixels() const
1521{
1522 return fGeomCam->GetNumPixels();
1523}
1524
1525TH1 *MHCamera::DrawCopy() const
1526{
1527 gPad=NULL;
1528 return TH1D::DrawCopy(fName+";cpy");
1529}
Note: See TracBrowser for help on using the repository browser.