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