source: tags/Mars-V0.10.3/mhist/MHCamera.cc

Last change on this file was 8106, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 66.6 KB
Line 
1/* ======================================================================== *\
2! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.95 2006-10-17 17:16:00 tbretz Exp $
3! --------------------------------------------------------------------------
4!
5! *
6! * This file is part of MARS, the MAGIC Analysis and Reconstruction
7! * Software. It is distributed to you in the hope that it can be a useful
8! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
9! * It is distributed WITHOUT ANY WARRANTY.
10! *
11! * Permission to use, copy, modify and distribute this software and its
12! * documentation for any purpose is hereby granted without fee,
13! * provided that the above copyright notice appear in all copies and
14! * that both that copyright notice and this permission notice appear
15! * in supporting documentation. It is provided "as is" without express
16! * or implied warranty.
17! *
18!
19!
20! Author(s): Thomas Bretz, 05/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
21! Author(s): Harald Kornmayer, 1/2001
22! Author(s): Markus Gaug, 03/2004 <mailto:markus@ifae.es>
23!
24! Copyright: MAGIC Software Development, 2000-2004
25!
26!
27\* ======================================================================== */
28
29/////////////////////////////////////////////////////////////////////////////
30//
31// MHCamera
32//
33// Camera Display, based on a TH1D. Pleas be carefull using the
34// underlaying TH1D.
35//
36// To change the scale to a logarithmic scale SetLogy() of the Pad.
37//
38// You can correct for the abberation. Assuming that the distance
39// between the mean position of the light distribution and the position
40// of a perfect reflection on a perfect mirror in the distance r on
41// the camera plane is dr it is d = a*dr while a is the abberation
42// constant (for the MAGIC mirror it is roughly 0.0713). You can
43// set this constant by calling SetAbberation(a) which results in a
44// 'corrected' display (all outer pixels are shifted towards the center
45// of the camera to correct for this abberation)
46//
47// Be carefull: Entries in this context means Entries/bin or Events
48//
49// FIXME? Maybe MHCamera can take the fLog object from MGeomCam?
50//
51////////////////////////////////////////////////////////////////////////////
52#include "MHCamera.h"
53
54#include <fstream>
55#include <iostream>
56
57#include <TBox.h>
58#include <TArrow.h>
59#include <TLatex.h>
60#include <TStyle.h>
61#include <TCanvas.h>
62#include <TArrayF.h>
63#include <TRandom.h>
64#include <TPaveText.h>
65#include <TPaveStats.h>
66#include <TClonesArray.h>
67#include <THistPainter.h>
68#include <THLimitsFinder.h>
69#include <TProfile.h>
70#include <TH1.h>
71#include <TF1.h>
72#include <TCanvas.h>
73#include <TLegend.h>
74
75#include "MLog.h"
76#include "MLogManip.h"
77
78#include "MH.h"
79#include "MBinning.h"
80#include "MHexagon.h"
81
82#include "MGeomPix.h"
83#include "MGeomCam.h"
84
85#include "MCamEvent.h"
86
87#include "MArrayD.h"
88#include "MMath.h" // MMath::GaussProb
89
90#define kItemsLegend 48 // see SetPalette(1,0)
91
92ClassImp(MHCamera);
93
94using namespace std;
95
96void MHCamera::Init()
97{
98 Sumw2();
99
100 UseCurrentStyle();
101
102 SetDirectory(NULL);
103
104 SetLineColor(kGreen);
105 SetMarkerStyle(kFullDotMedium);
106 SetXTitle("Pixel Index");
107
108 fNotify = new TList;
109 fNotify->SetBit(kMustCleanup);
110 gROOT->GetListOfCleanups()->Add(fNotify);
111
112 TVirtualPad *save = gPad;
113 gPad = 0;
114 /*
115#if ROOT_VERSION_CODE < ROOT_VERSION(3,01,06)
116 SetPalette(1, 0);
117#endif
118 */
119/*
120#if ROOT_VERSION_CODE < ROOT_VERSION(4,04,00)
121 SetPrettyPalette();
122#elese
123 // WORAROUND - FIXME: Calling it many times becomes slower and slower
124 SetInvDeepBlueSeaPalette();
125#endif
126*/
127 gPad = save;
128}
129
130// ------------------------------------------------------------------------
131//
132// Default Constructor. To be used by the root system ONLY.
133//
134MHCamera::MHCamera() : TH1D(), fGeomCam(NULL), fAbberation(0)
135{
136 Init();
137}
138
139// ------------------------------------------------------------------------
140//
141// Constructor. Makes a clone of MGeomCam. Removed the TH1D from the
142// current directory. Calls Sumw2(). Set the histogram line color
143// (for error bars) to Green and the marker style to kFullDotMedium.
144//
145MHCamera::MHCamera(const MGeomCam &geom, const char *name, const char *title)
146: fGeomCam(NULL), fAbberation(0)
147{
148 //fGeomCam = (MGeomCam*)geom.Clone();
149 SetGeometry(geom, name, title);
150 Init();
151
152 //
153 // root 3.02
154 // * base/inc/TObject.h:
155 // register BIT(8) as kNoContextMenu. If an object has this bit set it will
156 // not get an automatic context menu when clicked with the right mouse button.
157}
158
159void MHCamera::SetGeometry(const MGeomCam &geom, const char *name, const char *title)
160{
161 SetNameTitle(name, title);
162
163 TAxis &x = *GetXaxis();
164
165 SetBins(geom.GetNumPixels(), 0, 1);
166 x.Set(geom.GetNumPixels(), -0.5, geom.GetNumPixels()-0.5);
167
168 //SetBins(geom.GetNumPixels(), -0.5, geom.GetNumPixels()-0.5);
169 //Rebuild();
170
171 if (fGeomCam)
172 delete fGeomCam;
173 fGeomCam = (MGeomCam*)geom.Clone();
174
175 fUsed.Set(geom.GetNumPixels());
176 for (Int_t i=0; i<fNcells-2; i++)
177 ResetUsed(i);
178
179 fBinEntries.Set(geom.GetNumPixels()+2);
180 fBinEntries.Reset();
181}
182
183// ------------------------------------------------------------------------
184//
185// Destructor. Deletes the cloned fGeomCam and the notification list.
186//
187MHCamera::~MHCamera()
188{
189 if (fGeomCam)
190 delete fGeomCam;
191 if (fNotify)
192 delete fNotify;
193}
194
195// ------------------------------------------------------------------------
196//
197// Return kTRUE for sector<0. Otherwise return kTRUE only if the specified
198// sector idx matches the sector of the pixel with index idx.
199//
200Bool_t MHCamera::MatchSector(Int_t idx, const TArrayI &sector, const TArrayI &aidx) const
201{
202 const MGeomPix &pix = (*fGeomCam)[idx];
203 return FindVal(sector, pix.GetSector()) && FindVal(aidx, pix.GetAidx());
204}
205
206// ------------------------------------------------------------------------
207//
208// Taken from TH1D::Fill(). Uses the argument directly as bin index.
209// Doesn't increment the number of entries.
210//
211// -*-*-*-*-*-*-*-*Increment bin with abscissa X by 1*-*-*-*-*-*-*-*-*-*-*
212// ==================================
213//
214// if x is less than the low-edge of the first bin, the Underflow bin is incremented
215// if x is greater than the upper edge of last bin, the Overflow bin is incremented
216//
217// If the storage of the sum of squares of weights has been triggered,
218// via the function Sumw2, then the sum of the squares of weights is incremented
219// by 1 in the bin corresponding to x.
220//
221// -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
222Int_t MHCamera::Fill(Axis_t x)
223{
224#if ROOT_VERSION_CODE > ROOT_VERSION(3,05,00)
225 if (fBuffer) return BufferFill(x,1);
226#endif
227 const Int_t bin = (Int_t)x+1;
228 AddBinContent(bin);
229 fBinEntries[bin]++;
230 if (fSumw2.fN)
231 fSumw2.fArray[bin]++;
232
233 if (bin<=0 || bin>fNcells-2)
234 return -1;
235
236 fTsumw++;
237 fTsumw2++;
238 fTsumwx += x;
239 fTsumwx2 += x*x;
240 return bin;
241}
242
243// ------------------------------------------------------------------------
244//
245// Taken from TH1D::Fill(). Uses the argument directly as bin index.
246// Doesn't increment the number of entries.
247//
248// -*-*-*-*-*-*Increment bin with abscissa X with a weight w*-*-*-*-*-*-*-*
249// =============================================
250//
251// if x is less than the low-edge of the first bin, the Underflow bin is incremented
252// if x is greater than the upper edge of last bin, the Overflow bin is incremented
253//
254// If the storage of the sum of squares of weights has been triggered,
255// via the function Sumw2, then the sum of the squares of weights is incremented
256// by w^2 in the bin corresponding to x.
257//
258// -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
259Int_t MHCamera::Fill(Axis_t x, Stat_t w)
260{
261#if ROOT_VERSION_CODE > ROOT_VERSION(3,05,00)
262 if (fBuffer) return BufferFill(x,w);
263#endif
264 const Int_t bin = (Int_t)x+1;
265 AddBinContent(bin, w);
266 fBinEntries[bin]++;
267 if (fSumw2.fN)
268 fSumw2.fArray[bin] += w*w;
269
270 if (bin<=0 || bin>fNcells-2)
271 return -1;
272
273 const Stat_t z = (w > 0 ? w : -w);
274 fTsumw += z;
275 fTsumw2 += z*z;
276 fTsumwx += z*x;
277 fTsumwx2 += z*x*x;
278 return bin;
279}
280
281// ------------------------------------------------------------------------
282//
283// Use x and y in millimeters
284//
285Int_t MHCamera::Fill(Axis_t x, Axis_t y, Stat_t w)
286{
287 if (fNcells<=1 || IsFreezed())
288 return -1;
289
290 for (Int_t idx=0; idx<fNcells-2; idx++)
291 {
292 MHexagon hex((*fGeomCam)[idx]);
293 if (hex.DistanceToPrimitive(x, y)>0)
294 continue;
295
296 SetUsed(idx);
297 return Fill(idx, w);
298 }
299 return -1;
300}
301
302// ------------------------------------------------------------------------
303//
304// Call this if you want to change the display status (displayed or not)
305// for all pixels. val==0 means that the pixel is not displayed.
306//
307void MHCamera::SetUsed(const TArrayC &arr)
308{
309 if (fNcells-2 != arr.GetSize())
310 {
311 gLog << warn << "WARNING - MHCamera::SetUsed: array size mismatch... ignored." << endl;
312 return;
313 }
314
315 for (Int_t idx=0; idx<fNcells-2; idx++)
316 arr[idx] ? SetUsed(idx) : ResetUsed(idx);
317}
318
319// ------------------------------------------------------------------------
320//
321// Return the median value on the y-axis (profile option is correctly taken
322// into account)
323//
324Stat_t MHCamera::GetMedian() const
325{
326 // Just for speed reasons
327 if (!TestBit(kProfile))
328 return TMath::Median(GetSize()-2, GetArray()+1);
329
330 // Copy profiled data into new array (FIXME: Should we take errors into account?)
331 TArrayD arr(fNcells-2);
332 for (int i=1; i<fNcells-1; i++)
333 arr[i-1] = GetBinContent(i);
334
335 // return Median of the profile data
336 return TMath::Median(arr.GetSize(), arr.GetArray());
337}
338
339// ------------------------------------------------------------------------
340//
341// Return the median value (divided by MMath::GausProb(1.0)) of the
342// distribution of abs(y[i]-Median). This is my Median equivalent of the RMS
343//
344Stat_t MHCamera::GetMedianDev() const
345{
346 // Just for speed reasons
347 if (!TestBit(kProfile))
348 return MMath::MedianDev(GetSize()-2, GetArray()+1);
349
350 // Copy profiled data into new array (FIXME: Should we take errors into account?)
351 TArrayD arr(fNcells-2);
352 for (int i=1; i<fNcells-1; i++)
353 arr[i-1] = GetBinContent(i);
354
355 // return MedianDev of the profile data
356 return MMath::MedianDev(arr.GetSize(), arr.GetArray());
357}
358
359// ------------------------------------------------------------------------
360//
361// Return the mean value of all entries which are used if all=kFALSE and
362// of all entries if all=kTRUE if sector<0. If sector>=0 only
363// entries with match the given sector are taken into account.
364//
365Stat_t MHCamera::GetMeanSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t ball) const
366{
367 if (fNcells<=1)
368 return 0;
369
370 Int_t n=0;
371
372 Stat_t mean = 0;
373 for (int i=0; i<fNcells-2; i++)
374 {
375 if ((ball || IsUsed(i)) && MatchSector(i, sector, aidx))
376 {
377 if (TestBit(kProfile) && fBinEntries[i+1]==0)
378 continue;
379
380 mean += TestBit(kProfile) ? fArray[i+1]/fBinEntries[i+1] : fArray[i+1];
381 n++;
382 }
383 }
384
385 return n==0 ? 0 : mean/n;
386}
387
388// ------------------------------------------------------------------------
389//
390// Return the sqrt variance of all entries which are used if all=kFALSE and
391// of all entries if all=kTRUE if sector<0. If sector>=0 only
392// entries with match the given sector are taken into account.
393//
394Stat_t MHCamera::GetRmsSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t ball) const
395{
396 if (fNcells<=1)
397 return -1;
398
399 Int_t n=0;
400
401 Stat_t sum = 0;
402 Stat_t sq = 0;
403 for (int i=0; i<fNcells-2; i++)
404 {
405 if ((ball || IsUsed(i)) && MatchSector(i, sector, aidx))
406 {
407 if (TestBit(kProfile) && fBinEntries[i+1]==0)
408 continue;
409
410 const Double_t val = TestBit(kProfile) ? fArray[i+1]/fBinEntries[i+1] : fArray[i+1];
411
412 sum += val;
413 sq += val*val;
414 n++;
415 }
416 }
417
418 if (n==0)
419 return 0;
420
421 sum /= n;
422 sq /= n;
423
424 return TMath::Sqrt(sq-sum*sum);
425}
426
427// ------------------------------------------------------------------------
428//
429// Return the minimum contents of all pixels (if all is set, otherwise
430// only of all 'used' pixels), fMinimum if fMinimum set. If sector>=0
431// only pixels with matching sector number are taken into account.
432//
433Double_t MHCamera::GetMinimumSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t ball) const
434{
435 if (fMinimum != -1111)
436 return fMinimum;
437
438 if (fNcells<=1)
439 return 0;
440
441 Double_t minimum=FLT_MAX;
442
443 for (Int_t i=0; i<fNcells-2; i++)
444 {
445 if (TestBit(kProfile) && fBinEntries[i+1]==0)
446 continue;
447
448 const Double_t val = TestBit(kProfile) ? fArray[i+1]/fBinEntries[i+1] : fArray[i+1];
449 if (MatchSector(i, sector, aidx) && (ball || IsUsed(i)) && val<minimum)
450 minimum = val;
451 }
452
453 return minimum;
454}
455
456// ------------------------------------------------------------------------
457//
458// Return the maximum contents of all pixels (if all is set, otherwise
459// only of all 'used' pixels), fMaximum if fMaximum set. If sector>=0
460// only pixels with matching sector number are taken into account.
461//
462Double_t MHCamera::GetMaximumSectors(const TArrayI &sector, const TArrayI &aidx, Bool_t ball) const
463{
464 if (fMaximum!=-1111)
465 return fMaximum;
466
467 if (fNcells<=1)
468 return 1;
469
470 Double_t maximum=-FLT_MAX;
471 for (Int_t i=0; i<fNcells-2; i++)
472 {
473 if (TestBit(kProfile) && fBinEntries[i+1]==0)
474 continue;
475
476 const Double_t val = TestBit(kProfile) ? fArray[i+1]/fBinEntries[i+1] : fArray[i+1];
477 if (MatchSector(i, sector, aidx) && (ball || IsUsed(i)) && val>maximum)
478 maximum = val;
479 }
480
481 return maximum;
482}
483
484// ------------------------------------------------------------------------
485//
486// Call this function to draw the camera layout into your canvas.
487// Setup a drawing canvas. Add this object and all child objects
488// (hexagons, etc) to the current pad. If no pad exists a new one is
489// created. (To access the 'real' pad containing the camera you have
490// to do a cd(1) in the current layer.
491//
492// To draw a camera into its own pad do something like:
493//
494// MGeomCamMagic m;
495// MHCamera *d=new MHCamera(m);
496//
497// TCanvas *c = new TCanvas;
498// c->Divide(2,1);
499// c->cd(1);
500//
501// d->FillRandom();
502// d->Draw();
503// d->SetBit(kCanDelete);
504//
505// There are several drawing options:
506// 'hist' Draw as a standard TH1 histogram (value vs. pixel index)
507// 'box' Draw hexagons which size is in respect to its contents
508// 'nocol' Leave the 'boxed' hexagons empty
509// 'pixelindex' Display the pixel index in each pixel
510// 'sectorindex' Display the sector index in each pixel
511// 'content' Display the relative content aligned to GetMaximum() and
512// GeMinimum() ((val-min)/(max-min))
513// 'proj' Display the y-projection of the histogram
514// 'pal0' Use Pretty palette
515// 'pal1' Use Deep Blue Sea palette
516// 'pal2' Use Inverse Depp Blue Sea palette
517// 'same' Draw trandparent pixels on top of an existing pad. This
518// makes it possible to draw the camera image on top of an
519// existing TH2, but also allows for distorted camera images
520//
521void MHCamera::Draw(Option_t *option)
522{
523 const Bool_t hassame = TString(option).Contains("same", TString::kIgnoreCase) && gPad;
524
525 // root 3.02:
526 // gPad->SetFixedAspectRatio()
527 const Color_t col = gPad ? gPad->GetFillColor() : 16;
528 TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas("CamDisplay", "Mars Camera Display", 656, 600);
529
530 if (!hassame)
531 {
532 pad->SetBorderMode(0);
533 pad->SetFillColor(col);
534
535 //
536 // Create an own pad for the MHCamera-Object which can be
537 // resized in paint to keep the correct aspect ratio
538 //
539 // The margin != 0 is a workaround for a problem in root 4.02/00
540 pad->Divide(1, 1, 1e-10, 1e-10, col);
541 pad->cd(1);
542 gPad->SetBorderMode(0);
543 }
544
545 AppendPad(option);
546 //fGeomCam->AppendPad();
547
548 //
549 // Do not change gPad. The user should not see, that Draw
550 // changes gPad...
551 //
552 if (!hassame)
553 pad->cd();
554}
555
556// ------------------------------------------------------------------------
557//
558// This is TObject::DrawClone but completely ignores
559// gROOT->GetSelectedPad(). tbretz had trouble with this in the past.
560// If this makes trouble please write a bug report.
561//
562TObject *MHCamera::DrawClone(Option_t *option) const
563{
564 // Draw a clone of this object in the current pad
565
566 //TVirtualPad *pad = gROOT->GetSelectedPad();
567 TVirtualPad *padsav = gPad;
568 //if (pad) pad->cd();
569
570 TObject *newobj = Clone();
571
572 if (!newobj)
573 return 0;
574
575 /*
576 if (pad) {
577 if (strlen(option)) pad->GetListOfPrimitives()->Add(newobj,option);
578 else pad->GetListOfPrimitives()->Add(newobj,GetDrawOption());
579 pad->Modified(kTRUE);
580 pad->Update();
581 if (padsav) padsav->cd();
582 return newobj;
583 }
584 */
585
586 TString opt(option);
587 opt.ToLower();
588
589 newobj->Draw(opt.IsNull() ? GetDrawOption() : option);
590
591 if (padsav)
592 padsav->cd();
593
594 return newobj;
595}
596
597// ------------------------------------------------------------------------
598//
599// Creates a TH1D which contains the projection of the contents of the
600// MHCamera onto the y-axis. The maximum and minimum are calculated
601// such that a slighly wider range than (GetMinimum(), GetMaximum()) is
602// displayed using THLimitsFinder::OptimizeLimits.
603//
604// If no name is given the newly allocated histogram is removed from
605// the current directory calling SetDirectory(0) in any other case
606// the newly created histogram is removed from the current directory
607// and added to gROOT such the gROOT->FindObject can find the histogram.
608//
609// If the standard name "_py" is given "_py" is appended to the name
610// of the MHCamera and the corresponding histogram is searched using
611// gROOT->FindObject and updated with the present projection.
612//
613// It is the responsibility of the user to make sure, that the newly
614// created histogram is freed correctly.
615//
616// Currently the new histogram is restrictred to 50 bins.
617// Maybe a optimal number can be calulated from the number of
618// bins on the x-axis of the MHCamera?
619//
620// The code was taken mainly from TH2::ProjectX such the interface
621// is more or less the same than to TH2-projections.
622//
623// If sector>=0 only entries with matching sector index are taken
624// into account.
625//
626TH1D *MHCamera::ProjectionS(const TArrayI &sector, const TArrayI &aidx, const char *name, const Int_t nbins) const
627{
628
629 // Create the projection histogram
630 TString pname(name);
631 if (name=="_py")
632 {
633 pname.Prepend(GetName());
634 if (sector.GetSize()>0)
635 {
636 pname += ";";
637 for (int i=0; i<sector.GetSize(); i++)
638 pname += sector[i];
639 }
640 if (aidx.GetSize()>0)
641 {
642 pname += ";";
643 for (int i=0; i<aidx.GetSize(); i++)
644 pname += aidx[i];
645 }
646 }
647
648 TH1D *h1=0;
649
650 //check if histogram with identical name exist
651 TObject *h1obj = gROOT->FindObject(pname);
652 if (h1obj && h1obj->InheritsFrom("TH1D")) {
653 h1 = (TH1D*)h1obj;
654 h1->Reset();
655 }
656
657 if (!h1)
658 {
659 h1 = new TH1D;
660 h1->UseCurrentStyle();
661 h1->SetName(pname);
662 h1->SetTitle(GetTitle());
663 h1->SetDirectory(0);
664 h1->SetXTitle(GetYaxis()->GetTitle());
665 h1->SetYTitle("Counts");
666 //h1->Sumw2();
667 }
668
669 Double_t min = GetMinimumSectors(sector, aidx);
670 Double_t max = GetMaximumSectors(sector, aidx);
671
672 if (min==max && max>0)
673 min=0;
674 if (min==max && min<0)
675 max=0;
676
677 Int_t newbins=0;
678 THLimitsFinder::OptimizeLimits(nbins, newbins, min, max, kFALSE);
679
680 MBinning bins(nbins, min, max);
681 bins.Apply(*h1);
682
683 // Fill the projected histogram
684 for (Int_t idx=0; idx<fNcells-2; idx++)
685 if (IsUsed(idx) && MatchSector(idx, sector, aidx))
686 h1->Fill(GetBinContent(idx+1));
687
688 return h1;
689}
690
691// ------------------------------------------------------------------------
692//
693// Creates a TH1D which contains the projection of the contents of the
694// MHCamera onto the radius from the camera center.
695// The maximum and minimum are calculated
696// such that a slighly wider range than (GetMinimum(), GetMaximum()) is
697// displayed using THLimitsFinder::OptimizeLimits.
698//
699// If no name is given the newly allocated histogram is removed from
700// the current directory calling SetDirectory(0) in any other case
701// the newly created histogram is removed from the current directory
702// and added to gROOT such the gROOT->FindObject can find the histogram.
703//
704// If the standard name "_rad" is given "_rad" is appended to the name
705// of the MHCamera and the corresponding histogram is searched using
706// gROOT->FindObject and updated with the present projection.
707//
708// It is the responsibility of the user to make sure, that the newly
709// created histogram is freed correctly.
710//
711// Currently the new histogram is restrictred to 50 bins.
712// Maybe a optimal number can be calulated from the number of
713// bins on the x-axis of the MHCamera?
714//
715// The code was taken mainly from TH2::ProjectX such the interface
716// is more or less the same than to TH2-projections.
717//
718// If sector>=0 only entries with matching sector index are taken
719// into account.
720//
721TProfile *MHCamera::RadialProfileS(const TArrayI &sector, const TArrayI &aidx, const char *name, const Int_t nbins) const
722{
723 // Create the projection histogram
724 TString pname(name);
725 if (name=="_rad")
726 {
727 pname.Prepend(GetName());
728 if (sector.GetSize()>0)
729 {
730 pname += ";";
731 for (int i=0; i<sector.GetSize(); i++)
732 pname += sector[i];
733 }
734 if (aidx.GetSize()>0)
735 {
736 pname += ";";
737 for (int i=0; i<aidx.GetSize(); i++)
738 pname += aidx[i];
739 }
740 }
741
742 TProfile *h1=0;
743
744 //check if histogram with identical name exist
745 TObject *h1obj = gROOT->FindObject(pname);
746 if (h1obj && h1obj->InheritsFrom("TProfile")) {
747 h1 = (TProfile*)h1obj;
748 h1->Reset();
749 }
750
751 if (!h1)
752 {
753 h1 = new TProfile;
754 h1->UseCurrentStyle();
755 h1->SetName(pname);
756 h1->SetTitle(GetTitle());
757 h1->SetDirectory(0);
758 h1->SetXTitle("Radius from camera center [mm]");
759 h1->SetYTitle(GetYaxis()->GetTitle());
760 }
761
762 const Double_t m2d = fGeomCam->GetConvMm2Deg();
763
764 Double_t min = 0.;
765 Double_t max = fGeomCam->GetMaxRadius()*m2d;
766
767 Int_t newbins=0;
768
769 THLimitsFinder::OptimizeLimits(nbins, newbins, min, max, kFALSE);
770
771 MBinning bins(nbins, min, max);
772 bins.Apply(*h1);
773
774 // Fill the projected histogram
775 for (Int_t idx=0; idx<fNcells-2; idx++)
776 if (IsUsed(idx) && MatchSector(idx, sector, aidx))
777 h1->Fill(TMath::Hypot((*fGeomCam)[idx].GetX(),(*fGeomCam)[idx].GetY())*m2d,
778 GetBinContent(idx+1));
779 return h1;
780}
781
782
783// ------------------------------------------------------------------------
784//
785// Creates a TH1D which contains the projection of the contents of the
786// MHCamera onto the azimuth angle in the camera.
787//
788// If no name is given the newly allocated histogram is removed from
789// the current directory calling SetDirectory(0) in any other case
790// the newly created histogram is removed from the current directory
791// and added to gROOT such the gROOT->FindObject can find the histogram.
792//
793// If the standard name "_azi" is given "_azi" is appended to the name
794// of the MHCamera and the corresponding histogram is searched using
795// gROOT->FindObject and updated with the present projection.
796//
797// It is the responsibility of the user to make sure, that the newly
798// created histogram is freed correctly.
799//
800// Currently the new histogram is restrictred to 60 bins.
801// Maybe a optimal number can be calulated from the number of
802// bins on the x-axis of the MHCamera?
803//
804// The code was taken mainly from TH2::ProjectX such the interface
805// is more or less the same than to TH2-projections.
806//
807TProfile *MHCamera::AzimuthProfileA(const TArrayI &aidx, const char *name, const Int_t nbins) const
808{
809 // Create the projection histogram
810 TString pname(name);
811 if (name=="_azi")
812 {
813 pname.Prepend(GetName());
814 if (aidx.GetSize()>0)
815 {
816 pname += ";";
817 for (int i=0; i<aidx.GetSize(); i++)
818 pname += aidx[i];
819 }
820 }
821
822 TProfile *h1=0;
823
824 //check if histogram with identical name exist
825 TObject *h1obj = gROOT->FindObject(pname);
826 if (h1obj && h1obj->InheritsFrom("TProfile")) {
827 h1 = (TProfile*)h1obj;
828 h1->Reset();
829 }
830
831 if (!h1)
832 {
833
834 h1 = new TProfile;
835 h1->UseCurrentStyle();
836 h1->SetName(pname);
837 h1->SetTitle(GetTitle());
838 h1->SetDirectory(0);
839 h1->SetXTitle("Azimuth in camera [deg]");
840 h1->SetYTitle(GetYaxis()->GetTitle());
841 }
842
843 //Double_t min = 0;
844 //Double_t max = 360;
845
846 //Int_t newbins=0;
847 //THLimitsFinder::OptimizeLimits(nbins, newbins, min, max, kFALSE);
848
849 MBinning bins(nbins, 0, 360);
850 bins.Apply(*h1);
851
852 // Fill the projected histogram
853 for (Int_t idx=0; idx<fNcells-2; idx++)
854 {
855 if (IsUsed(idx) && MatchSector(idx, TArrayI(), aidx))
856 h1->Fill(TMath::ATan2((*fGeomCam)[idx].GetY(),(*fGeomCam)[idx].GetX())*TMath::RadToDeg()+180,
857 GetPixContent(idx));
858
859 }
860
861 return h1;
862}
863
864
865// ------------------------------------------------------------------------
866//
867// Resizes the current pad so that the camera is displayed in its
868// correct aspect ratio
869//
870void MHCamera::SetRange()
871{
872 const Float_t range = fGeomCam->GetMaxRadius()*1.05;
873
874 //
875 // Maintain aspect ratio
876 //
877 const float ratio = TestBit(kNoLegend) ? 1 : 1.15;
878
879 //
880 // Calculate width and height of the current pad in pixels
881 //
882 Float_t w = gPad->GetWw();
883 Float_t h = gPad->GetWh()*ratio;
884
885 //
886 // This prevents the pad from resizing itself wrongly
887 //
888 if (gPad->GetMother() != gPad)
889 {
890 w *= gPad->GetMother()->GetAbsWNDC();
891 h *= gPad->GetMother()->GetAbsHNDC();
892 }
893
894 //
895 // Set Range (coordinate system) of pad
896 //
897 gPad->Range(-range, -range, (2*ratio-1)*range, range);
898
899 //
900 // Resize Pad to given ratio
901 //
902 if (h<w)
903 gPad->SetPad((1.-h/w)/2, 0, (h/w+1.)/2, 1);
904 else
905 gPad->SetPad(0, (1.-w/h)/2, 1, (w/h+1.)/2);
906}
907
908// ------------------------------------------------------------------------
909//
910// Updates the pixel colors and paints the pixels
911//
912void MHCamera::Update(Bool_t islog, Bool_t isbox, Bool_t iscol, Bool_t issame)
913{
914 Double_t min = GetMinimum(kFALSE);
915 Double_t max = GetMaximum(kFALSE);
916 if (min==FLT_MAX)
917 {
918 min = 0;
919 max = 1;
920 }
921
922 if (min==max)
923 max += 1;
924
925 if (!issame)
926 UpdateLegend(min, max, islog);
927
928 // Try to estimate the units of the current display. This is only
929 // necessary for 'same' option and allows distorted images of the camera!
930 const Float_t maxr = (1-fGeomCam->GetConvMm2Deg())*fGeomCam->GetMaxRadius()/2;
931 const Float_t conv = !issame ||
932 gPad->GetX1()<-maxr || gPad->GetY1()<-maxr ||
933 gPad->GetX2()> maxr || gPad->GetY2()>maxr ? 1 : fGeomCam->GetConvMm2Deg();
934
935 MHexagon hex;
936 for (Int_t i=0; i<fNcells-2; i++)
937 {
938 hex.SetFillStyle(issame || (IsTransparent() && !IsUsed(i)) ? 0 : 1001);
939
940 if (!issame)
941 {
942 const Bool_t isnan = !TMath::Finite(fArray[i+1]);
943 if (!IsUsed(i) || !iscol || isnan)
944 {
945 hex.SetFillColor(10);
946
947 if (isnan)
948 gLog << warn << "MHCamera::Update: " << GetName() << " <" << GetTitle() << "> - Pixel Index #" << i << " contents is not finite..." << endl;
949 }
950 else
951 hex.SetFillColor(GetColor(GetBinContent(i+1), min, max, islog));
952 }
953
954 const MGeomPix &pix = (*fGeomCam)[i];
955
956 Float_t x = pix.GetX()*conv/(fAbberation+1);
957 Float_t y = pix.GetY()*conv/(fAbberation+1);
958 Float_t d = pix.GetD()*conv;
959
960 if (!isbox)
961 if (IsUsed(i) || !TestBit(kNoUnused))
962 hex.PaintHexagon(x, y, d);
963 else
964 if (IsUsed(i) && TMath::Finite(fArray[i+1]))
965 {
966 Float_t size = d*(GetBinContent(i+1)-min)/(max-min);
967 if (size>d)
968 size=d;
969 hex.PaintHexagon(x, y, size);
970 }
971 }
972}
973
974// ------------------------------------------------------------------------
975//
976// Print minimum and maximum
977//
978void MHCamera::Print(Option_t *) const
979{
980 gLog << all << "Minimum: " << GetMinimum();
981 if (fMinimum==-1111)
982 gLog << " <autoscaled>";
983 gLog << endl;
984 gLog << "Maximum: " << GetMaximum();
985 if (fMaximum==-1111)
986 gLog << " <autoscaled>";
987 gLog << endl;
988}
989
990// ------------------------------------------------------------------------
991//
992// Paint the y-axis title
993//
994void MHCamera::PaintAxisTitle()
995{
996 const Float_t range = fGeomCam->GetMaxRadius()*1.05;
997 const Float_t w = (1 + 1.5/sqrt((float)(fNcells-2)))*range;
998
999 TLatex *ptitle = new TLatex(w, -.90*range, GetYaxis()->GetTitle());
1000
1001 ptitle->SetTextSize(0.05);
1002 ptitle->SetTextAlign(21);
1003
1004 // box with the histogram title
1005 ptitle->SetTextColor(gStyle->GetTitleTextColor());
1006#if ROOT_VERSION_CODE > ROOT_VERSION(3,05,01)
1007 ptitle->SetTextFont(gStyle->GetTitleFont(""));
1008#endif
1009 ptitle->Paint();
1010}
1011
1012// ------------------------------------------------------------------------
1013//
1014// Paints the camera.
1015//
1016void MHCamera::Paint(Option_t *o)
1017{
1018 if (fNcells<=1)
1019 return;
1020
1021 TString opt(o);
1022 opt.ToLower();
1023
1024 if (opt.Contains("hist"))
1025 {
1026 opt.ReplaceAll("hist", "");
1027 opt.ReplaceAll("box", "");
1028 opt.ReplaceAll("pixelindex", "");
1029 opt.ReplaceAll("sectorindex", "");
1030 opt.ReplaceAll("abscontent", "");
1031 opt.ReplaceAll("content", "");
1032 opt.ReplaceAll("proj", "");
1033 opt.ReplaceAll("pal0", "");
1034 opt.ReplaceAll("pal1", "");
1035 opt.ReplaceAll("pal2", "");
1036 opt.ReplaceAll("nopal", "");
1037 TH1D::Paint(opt);
1038 return;
1039 }
1040
1041 if (opt.Contains("proj"))
1042 {
1043 opt.ReplaceAll("proj", "");
1044 Projection(GetName())->Paint(opt);
1045 return;
1046 }
1047
1048 const Bool_t hassame = opt.Contains("same");
1049 const Bool_t hasbox = opt.Contains("box");
1050 const Bool_t hascol = hasbox ? !opt.Contains("nocol") : kTRUE;
1051
1052 if (!hassame)
1053 {
1054 gPad->Clear();
1055
1056 // Maintain aspect ratio
1057 SetRange();
1058
1059 if (GetPainter())
1060 {
1061 // Paint statistics
1062 if (!TestBit(TH1::kNoStats))
1063 fPainter->PaintStat(gStyle->GetOptStat(), NULL);
1064
1065 // Paint primitives (pixels, color legend, photons, ...)
1066 if (fPainter->InheritsFrom(THistPainter::Class()))
1067 {
1068 static_cast<THistPainter*>(fPainter)->MakeChopt("");
1069 static_cast<THistPainter*>(fPainter)->PaintTitle();
1070 }
1071 }
1072 }
1073
1074 const Bool_t pal1 = opt.Contains("pal1");
1075 const Bool_t pal2 = opt.Contains("pal2");
1076 const Bool_t nopal = opt.Contains("nopal");
1077
1078 if (!pal1 && !pal2 && !nopal)
1079 SetPrettyPalette();
1080
1081 if (pal1)
1082 SetDeepBlueSeaPalette();
1083
1084 if (pal2)
1085 SetInvDeepBlueSeaPalette();
1086
1087 // Update Contents of the pixels and paint legend
1088 Update(gPad->GetLogy(), hasbox, hascol, hassame);
1089
1090 if (!hassame)
1091 PaintAxisTitle();
1092
1093 if (opt.Contains("pixelindex"))
1094 {
1095 PaintIndices(0);
1096 return;
1097 }
1098 if (opt.Contains("sectorindex"))
1099 {
1100 PaintIndices(1);
1101 return;
1102 }
1103 if (opt.Contains("abscontent"))
1104 {
1105 PaintIndices(3);
1106 return;
1107 }
1108 if (opt.Contains("content"))
1109 {
1110 PaintIndices(2);
1111 return;
1112 }
1113 if (opt.Contains("pixelentries"))
1114 {
1115 PaintIndices(4);
1116 return;
1117 }
1118}
1119
1120void MHCamera::SetDrawOption(Option_t *option)
1121{
1122 // This is a workaround. For some reason MHCamera is
1123 // stored in a TObjLink instead of a TObjOptLink
1124 if (!option || !gPad)
1125 return;
1126
1127 TListIter next(gPad->GetListOfPrimitives());
1128 delete gPad->FindObject("Tframe");
1129 TObject *obj;
1130 while ((obj = next()))
1131 if (obj == this && (TString)next.GetOption()!=(TString)option)
1132 {
1133 gPad->GetListOfPrimitives()->Remove(this);
1134 gPad->GetListOfPrimitives()->AddFirst(this, option);
1135 return;
1136 }
1137}
1138
1139// ------------------------------------------------------------------------
1140//
1141// With this function you can change the color palette. For more
1142// information see TStyle::SetPalette. Only palettes with 50 colors
1143// are allowed.
1144// In addition you can use SetPalette(52, 0) to create an inverse
1145// deep blue sea palette
1146//
1147void MHCamera::SetPalette(Int_t ncolors, Int_t *colors)
1148{
1149 //
1150 // If not enough colors are specified skip this.
1151 //
1152 if (ncolors>1 && ncolors<50)
1153 {
1154 gLog << err << "MHCamera::SetPalette: Only default palettes with 50 colors are allowed... ignored." << endl;
1155 return;
1156 }
1157
1158 //
1159 // If ncolors==52 create a reversed deep blue sea palette
1160 //
1161 if (ncolors==52)
1162 {
1163 gStyle->SetPalette(51, NULL);
1164 TArrayI c(kItemsLegend);
1165 for (int i=0; i<kItemsLegend; i++)
1166 c[kItemsLegend-i-1] = gStyle->GetColorPalette(i);
1167 gStyle->SetPalette(kItemsLegend, c.GetArray());
1168 }
1169 else
1170 gStyle->SetPalette(ncolors, colors);
1171}
1172
1173
1174// ------------------------------------------------------------------------
1175//
1176// Changes the palette of the displayed camera histogram.
1177//
1178// Change to the right pad first - otherwise GetDrawOption() might fail.
1179//
1180void MHCamera::SetPrettyPalette()
1181{
1182 TString opt(GetDrawOption());
1183
1184 if (!opt.Contains("hist", TString::kIgnoreCase))
1185 SetPalette(1, 0);
1186
1187 opt.ReplaceAll("pal1", "");
1188 opt.ReplaceAll("pal2", "");
1189
1190 SetDrawOption(opt);
1191}
1192
1193// ------------------------------------------------------------------------
1194//
1195// Changes the palette of the displayed camera histogram.
1196//
1197// Change to the right pad first - otherwise GetDrawOption() might fail.
1198//
1199void MHCamera::SetDeepBlueSeaPalette()
1200{
1201 TString opt(GetDrawOption());
1202
1203 if (!opt.Contains("hist", TString::kIgnoreCase))
1204 SetPalette(51, 0);
1205
1206 opt.ReplaceAll("pal1", "");
1207 opt.ReplaceAll("pal2", "");
1208 opt += "pal1";
1209
1210 SetDrawOption(opt);
1211}
1212
1213// ------------------------------------------------------------------------
1214//
1215// Changes the palette of the displayed camera histogram.
1216//
1217// Change to the right pad first - otherwise GetDrawOption() might fail.
1218//
1219void MHCamera::SetInvDeepBlueSeaPalette()
1220{
1221 TString opt(GetDrawOption());
1222
1223 if (!opt.Contains("hist", TString::kIgnoreCase))
1224 SetPalette(52, 0);
1225
1226 opt.ReplaceAll("pal1", "");
1227 opt.ReplaceAll("pal2", "");
1228 opt += "pal2";
1229
1230 SetDrawOption(opt);
1231}
1232
1233// ------------------------------------------------------------------------
1234//
1235// Paint indices (as text) inside the pixels. Depending of the type-
1236// argument we paint:
1237// 0: pixel number
1238// 1: sector number
1239// 2: content
1240//
1241void MHCamera::PaintIndices(Int_t type)
1242{
1243 if (fNcells<=1)
1244 return;
1245
1246 const Double_t min = GetMinimum();
1247 const Double_t max = GetMaximum();
1248
1249 if (type==2 && max==min)
1250 return;
1251
1252 TText txt;
1253 txt.SetTextFont(122);
1254 txt.SetTextAlign(22); // centered/centered
1255
1256 for (Int_t i=0; i<fNcells-2; i++)
1257 {
1258 const MGeomPix &h = (*fGeomCam)[i];
1259
1260 TString num;
1261 switch (type)
1262 {
1263 case 0: num += i; break;
1264 case 1: num += h.GetSector(); break;
1265 case 2: num += TMath::Nint((fArray[i+1]-min)/(max-min)); break;
1266 case 3: num += TMath::Nint(fArray[i+1]); break;
1267 case 4: num += fBinEntries[i+1]; break;
1268 }
1269
1270 // FIXME: Should depend on the color of the pixel...
1271 //(GetColor(GetBinContent(i+1), min, max, 0));
1272 txt.SetTextColor(kRed);
1273 txt.SetTextSize(0.3*h.GetD()/fGeomCam->GetMaxRadius()/1.05);
1274 txt.PaintText(h.GetX(), h.GetY(), num);
1275 }
1276}
1277
1278// ------------------------------------------------------------------------
1279//
1280// Call this function to add a MCamEvent on top of the present contents.
1281//
1282void MHCamera::AddCamContent(const MCamEvent &event, Int_t type)
1283{
1284 if (fNcells<=1 || IsFreezed())
1285 return;
1286
1287 // FIXME: Security check missing!
1288 for (Int_t idx=0; idx<fNcells-2; idx++)
1289 {
1290 Double_t val=0;
1291 if (event.GetPixelContent(val, idx, *fGeomCam, type)/* && !IsUsed(idx)*/)
1292 {
1293 SetUsed(idx);
1294 Fill(idx, val); // FIXME: Slow!
1295 }
1296 }
1297 fEntries++;
1298}
1299
1300// ------------------------------------------------------------------------
1301//
1302// Call this function to add a MCamEvent on top of the present contents.
1303//
1304void MHCamera::SetCamError(const MCamEvent &evt, Int_t type)
1305{
1306
1307 if (fNcells<=1 || IsFreezed())
1308 return;
1309
1310 // FIXME: Security check missing!
1311 for (Int_t idx=0; idx<fNcells-2; idx++)
1312 {
1313 Double_t val=0;
1314 if (evt.GetPixelContent(val, idx, *fGeomCam, type)/* && !IsUsed(idx)*/)
1315 SetUsed(idx);
1316
1317 SetBinError(idx+1, val); // FIXME: Slow!
1318 }
1319}
1320
1321Stat_t MHCamera::GetBinContent(Int_t bin) const
1322{
1323 if (fBuffer) ((TH1D*)this)->BufferEmpty();
1324 if (bin < 0) bin = 0;
1325 if (bin >= fNcells) bin = fNcells-1;
1326 if (!fArray) return 0;
1327
1328 if (!TestBit(kProfile))
1329 return Stat_t (fArray[bin]);
1330
1331 if (fBinEntries.fArray[bin] == 0) return 0;
1332 return fArray[bin]/fBinEntries.fArray[bin];
1333}
1334
1335Stat_t MHCamera::GetBinError(Int_t bin) const
1336{
1337 if (!TestBit(kProfile))
1338 return TH1D::GetBinError(bin);
1339
1340 const UInt_t n = (UInt_t)fBinEntries[bin];
1341
1342 if (n==0)
1343 return 0;
1344
1345 const Double_t sqr = fSumw2.fArray[bin] / n;
1346 const Double_t val = fArray[bin] / n;
1347
1348 return sqr>val*val ? TMath::Sqrt(sqr - val*val) / n : 0;
1349
1350 /*
1351 Double_t rc = 0;
1352 if (TestBit(kSqrtVariance) && GetEntries()>0) // error on the mean
1353 {
1354 const Double_t error = fSumw2.fArray[bin]/GetEntries();
1355 const Double_t val = fArray[bin]/GetEntries();
1356 rc = val*val>error ? 0 : TMath::Sqrt(error - val*val);
1357 }
1358 else
1359 rc = TH1D::GetBinError(bin);
1360
1361 return Profile(rc);*/
1362}
1363
1364// ------------------------------------------------------------------------
1365//
1366// Call this function to add a MHCamera on top of the present contents.
1367// Type:
1368// 0) bin content
1369// 1) errors
1370// 2) rel. errors
1371//
1372void MHCamera::AddCamContent(const MHCamera &d, Int_t type)
1373{
1374 if (fNcells!=d.fNcells || IsFreezed())
1375 return;
1376
1377 // FIXME: Security check missing!
1378 for (Int_t idx=0; idx<fNcells-2; idx++)
1379 if (d.IsUsed(idx))
1380 SetUsed(idx);
1381
1382 switch (type)
1383 {
1384 case 1:
1385 for (Int_t idx=0; idx<fNcells-2; idx++)
1386 Fill(idx, d.GetBinError(idx+1));
1387 break;
1388 case 2:
1389 for (Int_t idx=0; idx<fNcells-2; idx++)
1390 if (d.GetBinContent(idx+1)!=0)
1391 Fill(idx, TMath::Abs(d.GetBinError(idx+1)/d.GetBinContent(idx+1)));
1392 break;
1393 default:
1394 for (Int_t idx=0; idx<fNcells-2; idx++)
1395 Fill(idx, d.GetBinContent(idx+1));
1396 break;
1397 }
1398 fEntries++;
1399}
1400
1401// ------------------------------------------------------------------------
1402//
1403// Call this function to add a TArrayD on top of the present contents.
1404//
1405void MHCamera::AddCamContent(const TArrayD &event, const TArrayC *used)
1406{
1407 if (event.GetSize()!=fNcells-2 || IsFreezed())
1408 return;
1409
1410 if (used && used->GetSize()!=fNcells-2)
1411 return;
1412
1413 for (Int_t idx=0; idx<fNcells-2; idx++)
1414 {
1415 Fill(idx, event[idx]); // FIXME: Slow!
1416
1417 if (!used || (*used)[idx])
1418 SetUsed(idx);
1419 }
1420 fEntries++;
1421}
1422
1423// ------------------------------------------------------------------------
1424//
1425// Call this function to add a MArrayD on top of the present contents.
1426//
1427void MHCamera::AddCamContent(const MArrayD &event, const TArrayC *used)
1428{
1429 if (event.GetSize()!=(UInt_t)(fNcells-2) || IsFreezed())
1430 return;
1431
1432 if (used && used->GetSize()!=fNcells-2)
1433 return;
1434
1435 for (Int_t idx=0; idx<fNcells-2; idx++)
1436 {
1437 Fill(idx, event[idx]); // FIXME: Slow!
1438
1439 if (!used || (*used)[idx])
1440 SetUsed(idx);
1441 }
1442 fEntries++;
1443}
1444
1445// ------------------------------------------------------------------------
1446//
1447// Call this function to add a MCamEvent on top of the present contents.
1448// 1 is added to each pixel if the contents of MCamEvent>threshold (in case isabove is set to kTRUE == default)
1449// 1 is added to each pixel if the contents of MCamEvent<threshold (in case isabove is set to kFALSE)
1450//
1451// in unused pixel is not counted if it didn't fullfill the condition.
1452//
1453void MHCamera::CntCamContent(const MCamEvent &event, Double_t threshold, Int_t type, Bool_t isabove)
1454{
1455 if (fNcells<=1 || IsFreezed())
1456 return;
1457
1458 // FIXME: Security check missing!
1459 for (Int_t idx=0; idx<fNcells-2; idx++)
1460 {
1461 Double_t val=threshold;
1462 const Bool_t rc = event.GetPixelContent(val, idx, *fGeomCam, type);
1463 if (rc)
1464 SetUsed(idx);
1465
1466 const Bool_t cond =
1467 ( isabove && val>threshold) ||
1468 (!isabove && val<threshold);
1469
1470 Fill(idx, rc && cond ? 1 : 0);
1471 }
1472 fEntries++;
1473}
1474
1475// ------------------------------------------------------------------------
1476//
1477// Call this function to add a MCamEvent on top of the present contents.
1478// - the contents of the pixels in event are added to each pixel
1479// if the pixel of thresevt<threshold (in case isabove is set
1480// to kTRUE == default)
1481// - the contents of the pixels in event are added to each pixel
1482// if the pixel of thresevt<threshold (in case isabove is set
1483// to kFALSE)
1484//
1485// in unused pixel is not counted if it didn't fullfill the condition.
1486//
1487void MHCamera::CntCamContent(const MCamEvent &event, Int_t type1, const MCamEvent &thresevt, Int_t type2, Double_t threshold, Bool_t isabove)
1488{
1489 if (fNcells<=1 || IsFreezed())
1490 return;
1491
1492 // FIXME: Security check missing!
1493 for (Int_t idx=0; idx<fNcells-2; idx++)
1494 {
1495 Double_t th=0;
1496 if (!thresevt.GetPixelContent(th, idx, *fGeomCam, type2))
1497 continue;
1498
1499 if ((isabove && th>threshold) || (!isabove && th<threshold))
1500 continue;
1501
1502 Double_t val=th;
1503 if (event.GetPixelContent(val, idx, *fGeomCam, type1))
1504 {
1505 SetUsed(idx);
1506 Fill(idx, val);
1507 }
1508 }
1509 fEntries++;
1510}
1511
1512// ------------------------------------------------------------------------
1513//
1514// Call this function to add a MCamEvent on top of the present contents.
1515// 1 is added to each pixel if the contents of MCamEvent>threshold (in case isabove is set to kTRUE == default)
1516// 1 is added to each pixel if the contents of MCamEvent<threshold (in case isabove is set to kFALSE)
1517//
1518// in unused pixel is not counted if it didn't fullfill the condition.
1519//
1520void MHCamera::CntCamContent(const MCamEvent &event, TArrayD threshold, Int_t type, Bool_t isabove)
1521{
1522 if (fNcells<=1 || IsFreezed())
1523 return;
1524
1525 // FIXME: Security check missing!
1526 for (Int_t idx=0; idx<fNcells-2; idx++)
1527 {
1528 Double_t val=threshold[idx];
1529 if (event.GetPixelContent(val, idx, *fGeomCam, type)/* && !IsUsed(idx)*/)
1530 {
1531 SetUsed(idx);
1532
1533 if (val>threshold[idx] && isabove)
1534 Fill(idx);
1535 if (val<threshold[idx] && !isabove)
1536 Fill(idx);
1537 }
1538 }
1539 fEntries++;
1540}
1541
1542// ------------------------------------------------------------------------
1543//
1544// Call this function to add a TArrayD on top of the present contents.
1545// 1 is added to each pixel if the contents of MCamEvent>threshold
1546//
1547void MHCamera::CntCamContent(const TArrayD &event, Double_t threshold, Bool_t ispos)
1548{
1549 if (event.GetSize()!=fNcells-2 || IsFreezed())
1550 return;
1551
1552 for (Int_t idx=0; idx<fNcells-2; idx++)
1553 {
1554 if (event[idx]>threshold)
1555 Fill(idx);
1556
1557 if (!ispos || fArray[idx+1]>0)
1558 SetUsed(idx);
1559 }
1560 fEntries++;
1561}
1562
1563// ------------------------------------------------------------------------
1564//
1565// Fill the pixels with random contents.
1566//
1567void MHCamera::FillRandom()
1568{
1569 if (fNcells<=1 || IsFreezed())
1570 return;
1571
1572 Reset();
1573
1574 // FIXME: Security check missing!
1575 for (Int_t idx=0; idx<fNcells-2; idx++)
1576 {
1577 Fill(idx, gRandom->Uniform()*fGeomCam->GetPixRatio(idx));
1578 SetUsed(idx);
1579 }
1580 fEntries=1;
1581}
1582
1583
1584// ------------------------------------------------------------------------
1585//
1586// The array must be in increasing order, eg: 2.5, 3.7, 4.9
1587// The values in each bin are replaced by the interval in which the value
1588// fits. In the example we have four intervals
1589// (<2.5, 2.5-3.7, 3.7-4.9, >4.9). Maximum and minimum are set
1590// accordingly.
1591//
1592void MHCamera::SetLevels(const TArrayF &arr)
1593{
1594 if (fNcells<=1)
1595 return;
1596
1597 for (Int_t i=0; i<fNcells-2; i++)
1598 {
1599 if (!IsUsed(i))
1600 continue;
1601
1602 Int_t j = arr.GetSize();
1603 while (j && fArray[i+1]<arr[j-1])
1604 j--;
1605
1606 fArray[i+1] = j;
1607 }
1608 SetMaximum(arr.GetSize());
1609 SetMinimum(0);
1610}
1611
1612// ------------------------------------------------------------------------
1613//
1614// Reset the all pixel colors to a default value
1615//
1616void MHCamera::Reset(Option_t *opt)
1617{
1618 if (fNcells<=1 || IsFreezed())
1619 return;
1620
1621 TH1::Reset(opt);
1622
1623 for (Int_t i=0; i<fNcells-2; i++)
1624 {
1625 fArray[i+1]=0;
1626 fBinEntries[i]=0;
1627 ResetUsed(i);
1628 }
1629
1630 fArray[0] = 0;
1631 fArray[fNcells-1] = 0;
1632}
1633
1634// ------------------------------------------------------------------------
1635//
1636// Here we calculate the color index for the current value.
1637// The color index is defined with the class TStyle and the
1638// Color palette inside. We use the command gStyle->SetPalette(1,0)
1639// for the display. So we have to convert the value "wert" into
1640// a color index that fits the color palette.
1641// The range of the color palette is defined by the values fMinPhe
1642// and fMaxRange. Between this values we have 50 color index, starting
1643// with 0 up to 49.
1644//
1645Int_t MHCamera::GetColor(Float_t val, Float_t min, Float_t max, Bool_t islog)
1646{
1647 //
1648 // first treat the over- and under-flows
1649 //
1650 const Int_t maxcolidx = kItemsLegend-1;
1651
1652 if (!TMath::Finite(val)) // FIXME: gLog!
1653 return maxcolidx/2;
1654
1655 if (val >= max)
1656 return gStyle->GetColorPalette(maxcolidx);
1657
1658 if (val <= min)
1659 return gStyle->GetColorPalette(0);
1660
1661 //
1662 // calculate the color index
1663 //
1664 Float_t ratio;
1665 if (islog && min>0)
1666 ratio = log10(val/min) / log10(max/min);
1667 else
1668 ratio = (val-min) / (max-min);
1669
1670 const Int_t colidx = (Int_t)(ratio*maxcolidx + .5);
1671 return gStyle->GetColorPalette(colidx);
1672}
1673
1674TPaveStats *MHCamera::GetStatisticBox()
1675{
1676 TObject *obj = 0;
1677
1678 TIter Next(fFunctions);
1679 while ((obj = Next()))
1680 if (obj->InheritsFrom(TPaveStats::Class()))
1681 return static_cast<TPaveStats*>(obj);
1682
1683 return NULL;
1684}
1685
1686// ------------------------------------------------------------------------
1687//
1688// Change the text on the legend according to the range of the Display
1689//
1690void MHCamera::UpdateLegend(Float_t min, Float_t max, Bool_t islog)
1691{
1692 const Float_t range = fGeomCam->GetMaxRadius()*1.05;
1693
1694 if (!TestBit(kNoScale))
1695 {
1696 TArrow arr;
1697 arr.PaintArrow(-range*.9, -range*.9, -range*.6, -range*.9, 0.025);
1698 arr.PaintArrow(-range*.9, -range*.9, -range*.9, -range*.6, 0.025);
1699
1700 TString text;
1701 text += (int)(range*.3);
1702 text += "mm";
1703
1704 TText newtxt2;
1705 newtxt2.SetTextSize(0.04);
1706 newtxt2.PaintText(-range*.85, -range*.85, text);
1707
1708 text = "";
1709 text += Form("%.2f", (float)((int)(range*.3*fGeomCam->GetConvMm2Deg()*10))/10);
1710 text += "\\circ";
1711 text = text.Strip(TString::kLeading);
1712
1713 TLatex latex;
1714 latex.PaintLatex(-range*.85, -range*.75, 0, 0.04, text);
1715 }
1716
1717 if (!TestBit(kNoLegend))
1718 {
1719 TPaveStats *stats = GetStatisticBox();
1720
1721 const Float_t hndc = 0.92 - (stats ? stats->GetY1NDC() : 1);
1722 const Float_t H = (0.75-hndc)*range;
1723 const Float_t offset = hndc*range;
1724
1725 const Float_t h = 2./kItemsLegend;
1726 const Float_t w = range/sqrt((float)(fNcells-2));
1727
1728 TBox newbox;
1729 TText newtxt;
1730 newtxt.SetTextSize(0.03);
1731 newtxt.SetTextAlign(12);
1732#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
1733 newtxt.SetBit(/*kNoContextMenu|*/kCannotPick);
1734 newbox.SetBit(/*kNoContextMenu|*/kCannotPick);
1735#endif
1736
1737 const Float_t step = (islog && min>0 ? log10(max/min) : max-min) / kItemsLegend;
1738 const Int_t firsts = step*3 < 1e-8 ? 8 : (Int_t)floor(log10(step*3));
1739 const TString opt = Form("%%.%if", firsts>0 ? 0 : TMath::Abs(firsts));
1740
1741 for (Int_t i=0; i<kItemsLegend+1; i+=3)
1742 {
1743 Float_t val;
1744 if (islog && min>0)
1745 val = pow(10, step*i) * min;
1746 else
1747 val = min + step*i;
1748
1749 //const bool dispexp = max-min>1.5 && fabs(val)>0.1 && fabs(val)<1e6;
1750 newtxt.PaintText(range+1.5*w, H*(i*h-1)-offset, Form(opt, val));
1751 }
1752
1753 for (Int_t i=0; i<kItemsLegend; i++)
1754 {
1755 newbox.SetFillColor(gStyle->GetColorPalette(i));
1756 newbox.PaintBox(range, H*(i*h-1)-offset, range+w, H*((i+1)*h-1)-offset);
1757 }
1758 }
1759}
1760
1761// ------------------------------------------------------------------------
1762//
1763// Save primitive as a C++ statement(s) on output stream out
1764//
1765void MHCamera::SavePrimitive(ostream &out, Option_t *opt)
1766{
1767 gLog << err << "MHCamera::SavePrimitive: Must be rewritten!" << endl;
1768 /*
1769 if (!gROOT->ClassSaved(TCanvas::Class()))
1770 fDrawingPad->SavePrimitive(out, opt);
1771
1772 out << " " << fDrawingPad->GetName() << "->SetWindowSize(";
1773 out << fDrawingPad->GetWw() << "," << fDrawingPad->GetWh() << ");" << endl;
1774 */
1775}
1776
1777void MHCamera::SavePrimitive(ofstream &out, Option_t *)
1778{
1779 MHCamera::SavePrimitive(static_cast<ostream&>(out), "");
1780}
1781
1782// ------------------------------------------------------------------------
1783//
1784// compute the distance of a point (px,py) to the Camera
1785// this functions needed for graphical primitives, that
1786// means without this function you are not able to interact
1787// with the graphical primitive with the mouse!!!
1788//
1789// All calcutations are done in pixel coordinates
1790//
1791Int_t MHCamera::DistancetoPrimitive(Int_t px, Int_t py)
1792{
1793 if (fNcells<=1)
1794 return 999999;
1795
1796 TPaveStats *box = (TPaveStats*)gPad->GetPrimitive("stats");
1797 if (box)
1798 {
1799 const Double_t w = box->GetY2NDC()-box->GetY1NDC();
1800 box->SetX1NDC(gStyle->GetStatX()-gStyle->GetStatW());
1801 box->SetY1NDC(gStyle->GetStatY()-w);
1802 box->SetX2NDC(gStyle->GetStatX());
1803 box->SetY2NDC(gStyle->GetStatY());
1804 }
1805
1806 if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
1807 return TH1D::DistancetoPrimitive(px, py);
1808
1809 const Bool_t issame = TString(GetDrawOption()).Contains("same", TString::kIgnoreCase);
1810
1811 const Float_t maxr = (1-fGeomCam->GetConvMm2Deg())*fGeomCam->GetMaxRadius()/2;
1812 const Float_t conv = !issame ||
1813 gPad->GetX1()<-maxr || gPad->GetY1()<-maxr ||
1814 gPad->GetX2()> maxr || gPad->GetY2()>maxr ? 1 : fGeomCam->GetConvMm2Deg();
1815
1816 if (GetPixelIndex(px, py, conv)>=0)
1817 return 0;
1818
1819 if (!box)
1820 return 999999;
1821
1822 const Int_t dist = box->DistancetoPrimitive(px, py);
1823 if (dist > TPad::GetMaxPickDistance())
1824 return 999999;
1825
1826 gPad->SetSelected(box);
1827 return dist;
1828}
1829
1830// ------------------------------------------------------------------------
1831//
1832//
1833Int_t MHCamera::GetPixelIndex(Int_t px, Int_t py, Float_t conv) const
1834{
1835 if (fNcells<=1)
1836 return -1;
1837
1838 Int_t i;
1839 for (i=0; i<fNcells-2; i++)
1840 {
1841 MHexagon hex((*fGeomCam)[i]);
1842 if (hex.DistancetoPrimitive(px, py, conv)>0)
1843 continue;
1844
1845 return i;
1846 }
1847 return -1;
1848}
1849
1850// ------------------------------------------------------------------------
1851//
1852// Returns string containing info about the object at position (px,py).
1853// Returned string will be re-used (lock in MT environment).
1854//
1855char *MHCamera::GetObjectInfo(Int_t px, Int_t py) const
1856{
1857 if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
1858 return TH1D::GetObjectInfo(px, py);
1859
1860 static char info[128];
1861
1862 const Int_t idx=GetPixelIndex(px, py);
1863
1864 if (idx<0)
1865 return TObject::GetObjectInfo(px, py);
1866
1867 sprintf(info, "Software Pixel Idx: %d (Hardware Id=%d) c=%.1f <%s>",
1868 idx, idx+1, GetBinContent(idx+1), IsUsed(idx)?"on":"off");
1869 return info;
1870}
1871
1872// ------------------------------------------------------------------------
1873//
1874// Add a MCamEvent which should be displayed when the user clicks on a
1875// pixel.
1876// Warning: The object MUST inherit from TObject AND MCamEvent
1877//
1878void MHCamera::AddNotify(TObject *obj)
1879{
1880 // Make sure, that the object derives from MCamEvent!
1881 MCamEvent *evt = dynamic_cast<MCamEvent*>(obj);
1882 if (!evt)
1883 {
1884 gLog << err << "ERROR: MHCamera::AddNotify - TObject doesn't inherit from MCamEvent... ignored." << endl;
1885 return;
1886 }
1887
1888 // Make sure, that it is deleted from the list too, if the obj is deleted
1889 obj->SetBit(kMustCleanup);
1890
1891 // Add object to list
1892 fNotify->Add(obj);
1893}
1894
1895// ------------------------------------------------------------------------
1896//
1897// Execute a mouse event on the camera
1898//
1899void MHCamera::ExecuteEvent(Int_t event, Int_t px, Int_t py)
1900{
1901 if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
1902 {
1903 TH1D::ExecuteEvent(event, px, py);
1904 return;
1905 }
1906 //if (event==kMouseMotion && fStatusBar)
1907 // fStatusBar->SetText(GetObjectInfo(px, py), 0);
1908 if (event!=kButton1Down)
1909 return;
1910
1911 const Int_t idx = GetPixelIndex(px, py);
1912 if (idx<0)
1913 return;
1914
1915 gLog << all << GetTitle() << " <" << GetName() << ">" << dec << endl;
1916 gLog << "Software Pixel Idx: " << idx << endl;
1917 gLog << "Hardware Pixel Id: " << idx+1 << endl;
1918 gLog << "Contents: " << GetBinContent(idx+1);
1919 if (GetBinError(idx+1)>0)
1920 gLog << " +/- " << GetBinError(idx+1);
1921 gLog << " <" << (IsUsed(idx)?"on":"off") << "> n=" << fBinEntries[idx+1] << endl;
1922
1923 if (fNotify && fNotify->GetSize()>0)
1924 {
1925 // FIXME: Is there a simpler and more convinient way?
1926
1927 // The name which is created here depends on the instance of
1928 // MHCamera and on the pad on which it is drawn --> The name
1929 // is unique. For ExecuteEvent gPad is always correctly set.
1930 const TString name = Form("%p;%p;PixelContent", this, gPad);
1931
1932 TCanvas *old = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(name);
1933 if (old)
1934 old->cd();
1935 else
1936 new TCanvas(name);
1937
1938 /*
1939 TIter Next(gPad->GetListOfPrimitives());
1940 TObject *o;
1941 while (o=Next()) cout << o << ": " << o->GetName() << " " << o->IsA()->GetName() << endl;
1942 */
1943
1944 // FIXME: Make sure, that the old histograms are really deleted.
1945 // Are they already deleted?
1946
1947 // The dynamic_cast is necessary here: We cannot use ForEach
1948 TIter Next(fNotify);
1949 MCamEvent *evt;
1950 while ((evt=dynamic_cast<MCamEvent*>(Next())))
1951 evt->DrawPixelContent(idx);
1952
1953 gPad->Modified();
1954 gPad->Update();
1955 }
1956}
1957
1958UInt_t MHCamera::GetNumPixels() const
1959{
1960 return fGeomCam ? fGeomCam->GetNumPixels() : 0;
1961}
1962
1963TH1 *MHCamera::DrawCopy() const
1964{
1965 gPad=NULL;
1966 return TH1D::DrawCopy(fName+";cpy");
1967}
1968
1969// --------------------------------------------------------------------------
1970//
1971// Draw a projection of MHCamera onto the y-axis values. Depending on the
1972// variable fit, the following fits are performed:
1973//
1974// 0: No fit, simply draw the projection
1975// 1: Single Gauss (for distributions flat-fielded over the whole camera)
1976// 2: Double Gauss (for distributions different for inner and outer pixels)
1977// 3: Triple Gauss (for distributions with inner, outer pixels and outliers)
1978// 4: flat (for the probability distributions)
1979// (1-4:) Moreover, sectors 6,1 and 2 of the camera and sectors 3,4 and 5 are
1980// drawn separately, for inner and outer pixels.
1981// 5: Fit Inner and Outer pixels separately by a single Gaussian
1982// (only for MAGIC cameras)
1983// 6: Fit Inner and Outer pixels separately by a single Gaussian and display
1984// additionally the two camera halfs separately (for MAGIC camera)
1985// 7: Single Gauss with TLegend to show the meaning of the colours
1986//
1987void MHCamera::DrawProjection(Int_t fit) const
1988{
1989 TArrayI inner(1);
1990 inner[0] = 0;
1991
1992 TArrayI outer(1);
1993 outer[0] = 1;
1994
1995 if (fit==5 || fit==6)
1996 {
1997 if (GetGeomCam().InheritsFrom("MGeomCamMagic"))
1998 {
1999 TArrayI s0(6);
2000 s0[0] = 6;
2001 s0[1] = 1;
2002 s0[2] = 2;
2003 s0[3] = 3;
2004 s0[4] = 4;
2005 s0[5] = 5;
2006
2007 TArrayI s1(3);
2008 s1[0] = 6;
2009 s1[1] = 1;
2010 s1[2] = 2;
2011
2012 TArrayI s2(3);
2013 s2[0] = 3;
2014 s2[1] = 4;
2015 s2[2] = 5;
2016
2017 gPad->Clear();
2018 TVirtualPad *pad = gPad;
2019 pad->Divide(2,1);
2020
2021 TH1D *inout[2];
2022 inout[0] = ProjectionS(s0, inner, "Inner");
2023 inout[1] = ProjectionS(s0, outer, "Outer");
2024
2025 inout[0]->SetDirectory(NULL);
2026 inout[1]->SetDirectory(NULL);
2027
2028 for (int i=0; i<2; i++)
2029 {
2030 pad->cd(i+1);
2031 gPad->SetBorderMode(0);
2032
2033 inout[i]->SetLineColor(kRed+i);
2034 inout[i]->SetBit(kCanDelete);
2035 inout[i]->Draw();
2036 inout[i]->Fit("gaus","Q");
2037
2038 if (fit == 6)
2039 {
2040 TH1D *half[2];
2041 half[0] = ProjectionS(s1, i==0 ? inner : outer , "Sector 6-1-2");
2042 half[1] = ProjectionS(s2, i==0 ? inner : outer , "Sector 3-4-5");
2043
2044 for (int j=0; j<2; j++)
2045 {
2046 half[j]->SetLineColor(kRed+i+2*j+1);
2047 half[j]->SetDirectory(NULL);
2048 half[j]->SetBit(kCanDelete);
2049 half[j]->Draw("same");
2050 }
2051 }
2052
2053 }
2054 }
2055 return;
2056 }
2057
2058 TH1D *obj2 = (TH1D*)Projection(GetName());
2059 obj2->SetDirectory(0);
2060 obj2->Draw();
2061 obj2->SetBit(kCanDelete);
2062
2063 if (fit == 0)
2064 return;
2065
2066 if (GetGeomCam().InheritsFrom("MGeomCamMagic"))
2067 {
2068 TArrayI s0(3);
2069 s0[0] = 6;
2070 s0[1] = 1;
2071 s0[2] = 2;
2072
2073 TArrayI s1(3);
2074 s1[0] = 3;
2075 s1[1] = 4;
2076 s1[2] = 5;
2077
2078 TH1D *halfInOut[4];
2079
2080 // Just to get the right (maximum) binning
2081 halfInOut[0] = ProjectionS(s0, inner, "Sector 6-1-2 Inner");
2082 halfInOut[1] = ProjectionS(s1, inner, "Sector 3-4-5 Inner");
2083 halfInOut[2] = ProjectionS(s0, outer, "Sector 6-1-2 Outer");
2084 halfInOut[3] = ProjectionS(s1, outer, "Sector 3-4-5 Outer");
2085
2086 TLegend *leg = new TLegend(0.05,0.65,0.35,0.9);
2087
2088 for (int i=0; i<4; i++)
2089 {
2090 halfInOut[i]->SetLineColor(kRed+i);
2091 halfInOut[i]->SetDirectory(0);
2092 halfInOut[i]->SetBit(kCanDelete);
2093 halfInOut[i]->Draw("same");
2094 leg->AddEntry(halfInOut[i],halfInOut[i]->GetTitle(),"l");
2095 }
2096
2097 if (fit==7)
2098 leg->Draw();
2099
2100 gPad->Modified();
2101 gPad->Update();
2102 }
2103
2104 const Double_t min = obj2->GetBinCenter(obj2->GetXaxis()->GetFirst());
2105 const Double_t max = obj2->GetBinCenter(obj2->GetXaxis()->GetLast());
2106 const Double_t integ = obj2->Integral("width")/2.5;
2107 const Double_t mean = obj2->GetMean();
2108 const Double_t rms = obj2->GetRMS();
2109 const Double_t width = max-min;
2110
2111 const TString dgausformula = "([0]-[3])/[2]*exp(-0.5*(x-[1])*(x-[1])/[2]/[2])"
2112 "+[3]/[5]*exp(-0.5*(x-[4])*(x-[4])/[5]/[5])";
2113
2114 const TString tgausformula = "([0]-[3]-[6])/[2]*exp(-0.5*(x-[1])*(x-[1])/[2]/[2])"
2115 "+[3]/[5]*exp(-0.5*(x-[4])*(x-[4])/[5]/[5])"
2116 "+[6]/[8]*exp(-0.5*(x-[7])*(x-[7])/[8]/[8])";
2117
2118 TF1 *f=0;
2119 switch (fit)
2120 {
2121 case 1:
2122 f = new TF1("sgaus", "gaus(0)", min, max);
2123 f->SetLineColor(kYellow);
2124 f->SetBit(kCanDelete);
2125 f->SetParNames("Area", "#mu", "#sigma");
2126 f->SetParameters(integ/rms, mean, rms);
2127 f->SetParLimits(0, 0, integ);
2128 f->SetParLimits(1, min, max);
2129 f->SetParLimits(2, 0, width/1.5);
2130
2131 obj2->Fit(f, "QLR");
2132 break;
2133
2134 case 2:
2135 f = new TF1("dgaus",dgausformula.Data(),min,max);
2136 f->SetLineColor(kYellow);
2137 f->SetBit(kCanDelete);
2138 f->SetParNames("A_{tot}", "#mu1", "#sigma1", "A2", "#mu2", "#sigma2");
2139 f->SetParameters(integ,(min+mean)/2.,width/4.,
2140 integ/width/2.,(max+mean)/2.,width/4.);
2141 // The left-sided Gauss
2142 f->SetParLimits(0,integ-1.5 , integ+1.5);
2143 f->SetParLimits(1,min+(width/10.), mean);
2144 f->SetParLimits(2,0 , width/2.);
2145 // The right-sided Gauss
2146 f->SetParLimits(3,0 , integ);
2147 f->SetParLimits(4,mean, max-(width/10.));
2148 f->SetParLimits(5,0 , width/2.);
2149 obj2->Fit(f,"QLRM");
2150 break;
2151
2152 case 3:
2153 f = new TF1("tgaus",tgausformula.Data(),min,max);
2154 f->SetLineColor(kYellow);
2155 f->SetBit(kCanDelete);
2156 f->SetParNames("A_{tot}","#mu_{1}","#sigma_{1}",
2157 "A_{2}","#mu_{2}","#sigma_{2}",
2158 "A_{3}","#mu_{3}","#sigma_{3}");
2159 f->SetParameters(integ,(min+mean)/2,width/4.,
2160 integ/width/3.,(max+mean)/2.,width/4.,
2161 integ/width/3.,mean,width/2.);
2162 // The left-sided Gauss
2163 f->SetParLimits(0,integ-1.5,integ+1.5);
2164 f->SetParLimits(1,min+(width/10.),mean);
2165 f->SetParLimits(2,width/15.,width/2.);
2166 // The right-sided Gauss
2167 f->SetParLimits(3,0.,integ);
2168 f->SetParLimits(4,mean,max-(width/10.));
2169 f->SetParLimits(5,width/15.,width/2.);
2170 // The Gauss describing the outliers
2171 f->SetParLimits(6,0.,integ);
2172 f->SetParLimits(7,min,max);
2173 f->SetParLimits(8,width/4.,width/1.5);
2174 obj2->Fit(f,"QLRM");
2175 break;
2176
2177 case 4:
2178 obj2->Fit("pol0", "Q");
2179 obj2->GetFunction("pol0")->SetLineColor(kYellow);
2180 break;
2181
2182 case 9:
2183 break;
2184
2185 default:
2186 obj2->Fit("gaus", "Q");
2187 obj2->GetFunction("gaus")->SetLineColor(kYellow);
2188 break;
2189 }
2190}
2191
2192// --------------------------------------------------------------------------
2193//
2194// Draw a projection of MHCamera vs. the radius from the central pixel.
2195//
2196// The inner and outer pixels are drawn separately, both fitted by a polynomial
2197// of grade 1.
2198//
2199void MHCamera::DrawRadialProfile() const
2200{
2201 TProfile *obj2 = (TProfile*)RadialProfile(GetName());
2202 obj2->SetDirectory(0);
2203 obj2->Draw();
2204 obj2->SetBit(kCanDelete);
2205
2206 if (GetGeomCam().InheritsFrom("MGeomCamMagic"))
2207 {
2208 TArrayI s0(6);
2209 s0[0] = 1;
2210 s0[1] = 2;
2211 s0[2] = 3;
2212 s0[3] = 4;
2213 s0[4] = 5;
2214 s0[5] = 6;
2215
2216 TArrayI inner(1);
2217 inner[0] = 0;
2218
2219 TArrayI outer(1);
2220 outer[0] = 1;
2221
2222 // Just to get the right (maximum) binning
2223 TProfile *half[2];
2224 half[0] = RadialProfileS(s0, inner,Form("%sInner",GetName()));
2225 half[1] = RadialProfileS(s0, outer,Form("%sOuter",GetName()));
2226
2227 for (Int_t i=0; i<2; i++)
2228 {
2229 Double_t min = GetGeomCam().GetMinRadius(i);
2230 Double_t max = GetGeomCam().GetMaxRadius(i);
2231
2232 half[i]->SetLineColor(kRed+i);
2233 half[i]->SetDirectory(0);
2234 half[i]->SetBit(kCanDelete);
2235 half[i]->Draw("same");
2236 half[i]->Fit("pol1","Q","",min,max);
2237 half[i]->GetFunction("pol1")->SetLineColor(kRed+i);
2238 half[i]->GetFunction("pol1")->SetLineWidth(1);
2239 }
2240 }
2241}
2242
2243// --------------------------------------------------------------------------
2244//
2245// Draw a projection of MHCamera vs. the azimuth angle inside the camera.
2246//
2247// The inner and outer pixels are drawn separately.
2248// The general azimuth profile is fitted by a straight line
2249//
2250void MHCamera::DrawAzimuthProfile() const
2251{
2252 TProfile *obj2 = (TProfile*)AzimuthProfile(GetName());
2253 obj2->SetDirectory(0);
2254 obj2->Draw();
2255 obj2->SetBit(kCanDelete);
2256 obj2->Fit("pol0","Q","");
2257 obj2->GetFunction("pol0")->SetLineWidth(1);
2258
2259 if (GetGeomCam().InheritsFrom("MGeomCamMagic"))
2260 {
2261 TArrayI inner(1);
2262 inner[0] = 0;
2263
2264 TArrayI outer(1);
2265 outer[0] = 1;
2266
2267 // Just to get the right (maximum) binning
2268 TProfile *half[2];
2269 half[0] = AzimuthProfileA(inner,Form("%sInner",GetName()));
2270 half[1] = AzimuthProfileA(outer,Form("%sOuter",GetName()));
2271
2272 for (Int_t i=0; i<2; i++)
2273 {
2274 half[i]->SetLineColor(kRed+i);
2275 half[i]->SetDirectory(0);
2276 half[i]->SetBit(kCanDelete);
2277 half[i]->SetMarkerSize(0.5);
2278 half[i]->Draw("same");
2279 }
2280 }
2281}
2282
2283// --------------------------------------------------------------------------
2284//
2285// Draw the MHCamera into the MStatusDisplay:
2286//
2287// 1) Draw it as histogram (MHCamera::DrawCopy("hist")
2288// 2) Draw it as a camera, with MHCamera::SetPrettyPalette() set.
2289// 3) If "rad" is not zero, draw its values vs. the radius from the camera center.
2290// (DrawRadialProfile())
2291// 4) Depending on the variable "fit", draw the values projection on the y-axis
2292// (DrawProjection()):
2293// 0: don't draw
2294// 1: Draw fit to Single Gauss (for distributions flat-fielded over the whole camera)
2295// 2: Draw and fit to Double Gauss (for distributions different for inner and outer pixels)
2296// 3: Draw and fit to Triple Gauss (for distributions with inner, outer pixels and outliers)
2297// 4: Draw and fit to Polynomial grade 0: (for the probability distributions)
2298// >4: Draw and don;t fit.
2299//
2300void MHCamera::CamDraw(TCanvas &c, const Int_t x, const Int_t y,
2301 const Int_t fit, const Int_t rad, const Int_t azi,
2302 TObject *notify)
2303{
2304 c.cd(x);
2305 gPad->SetBorderMode(0);
2306 gPad->SetTicks();
2307 MHCamera *obj1=(MHCamera*)DrawCopy("hist");
2308 obj1->SetDirectory(NULL);
2309
2310 if (notify)
2311 obj1->AddNotify(notify);
2312
2313 c.cd(x+y);
2314 gPad->SetBorderMode(0);
2315 obj1->SetPrettyPalette();
2316 obj1->Draw();
2317
2318 Int_t cnt = 2;
2319
2320 if (rad)
2321 {
2322 c.cd(x+2*y);
2323 gPad->SetBorderMode(0);
2324 gPad->SetTicks();
2325 DrawRadialProfile();
2326 cnt++;
2327 }
2328
2329 if (azi)
2330 {
2331 c.cd(x+cnt*y);
2332 gPad->SetBorderMode(0);
2333 gPad->SetTicks();
2334 DrawAzimuthProfile();
2335 cnt++;
2336 }
2337
2338 if (!fit)
2339 return;
2340
2341 c.cd(x + cnt*y);
2342 gPad->SetBorderMode(0);
2343 gPad->SetTicks();
2344 DrawProjection(fit);
2345}
Note: See TracBrowser for help on using the repository browser.