1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Thomas Bretz, 05/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | ! Author(s): Harald Kornmayer, 1/2001
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2003
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MHCamera
|
---|
29 | //
|
---|
30 | // Camera Display, based on a TH1D. Pleas be carefull using the
|
---|
31 | // underlaying TH1D.
|
---|
32 | //
|
---|
33 | // To change the scale to a logarithmic scale SetLogy() of the Pad.
|
---|
34 | //
|
---|
35 | ////////////////////////////////////////////////////////////////////////////
|
---|
36 | #include "MHCamera.h"
|
---|
37 |
|
---|
38 | #include <fstream>
|
---|
39 | #include <iostream>
|
---|
40 |
|
---|
41 | #include <TBox.h>
|
---|
42 | #include <TArrow.h>
|
---|
43 | #include <TLatex.h>
|
---|
44 | #include <TStyle.h>
|
---|
45 | #include <TCanvas.h>
|
---|
46 | #include <TArrayF.h>
|
---|
47 | #include <TRandom.h>
|
---|
48 | #include <TPaveText.h>
|
---|
49 | #include <TPaveStats.h>
|
---|
50 | #include <TClonesArray.h>
|
---|
51 | #include <THistPainter.h>
|
---|
52 |
|
---|
53 | #include "MLog.h"
|
---|
54 | #include "MLogManip.h"
|
---|
55 |
|
---|
56 | #include "MH.h"
|
---|
57 | #include "MHexagon.h"
|
---|
58 |
|
---|
59 | #include "MGeomPix.h"
|
---|
60 | #include "MGeomCam.h"
|
---|
61 |
|
---|
62 | #include "MCerPhotPix.h"
|
---|
63 | #include "MCerPhotEvt.h"
|
---|
64 |
|
---|
65 | #include "MPedestalPix.h"
|
---|
66 | #include "MPedestalCam.h"
|
---|
67 |
|
---|
68 | #include "MCurrents.h"
|
---|
69 | #include "MCamEvent.h"
|
---|
70 |
|
---|
71 | #include "MImgCleanStd.h"
|
---|
72 |
|
---|
73 |
|
---|
74 | #define kItemsLegend 48 // see SetPalette(1,0)
|
---|
75 |
|
---|
76 | ClassImp(MHCamera);
|
---|
77 |
|
---|
78 | using namespace std;
|
---|
79 |
|
---|
80 | void MHCamera::Init()
|
---|
81 | {
|
---|
82 | UseCurrentStyle();
|
---|
83 |
|
---|
84 | SetDirectory(NULL);
|
---|
85 |
|
---|
86 | SetLineColor(kGreen);
|
---|
87 | SetMarkerStyle(kFullDotMedium);
|
---|
88 | SetXTitle("Pixel Index");
|
---|
89 |
|
---|
90 | fNotify = new TList;
|
---|
91 |
|
---|
92 | #if ROOT_VERSION_CODE < ROOT_VERSION(3,01,06)
|
---|
93 | SetPalette(1, 0);
|
---|
94 | #else
|
---|
95 | SetPalette(51, 0);
|
---|
96 | #endif
|
---|
97 | }
|
---|
98 |
|
---|
99 | // ------------------------------------------------------------------------
|
---|
100 | //
|
---|
101 | // Default Constructor. To be used by the root system ONLY.
|
---|
102 | //
|
---|
103 | MHCamera::MHCamera() : TH1D(), fGeomCam(NULL), fColors(kItemsLegend)
|
---|
104 | {
|
---|
105 | Init();
|
---|
106 | }
|
---|
107 |
|
---|
108 | // ------------------------------------------------------------------------
|
---|
109 | //
|
---|
110 | // Constructor. Makes a clone of MGeomCam. Removed the TH1D from the
|
---|
111 | // current directory. Calls Sumw2(). Set the histogram line color
|
---|
112 | // (for error bars) to Green and the marker style to kFullDotMedium.
|
---|
113 | //
|
---|
114 | MHCamera::MHCamera(const MGeomCam &geom, const char *name, const char *title)
|
---|
115 | : fGeomCam(NULL), /*TH1D(name, title, geom.GetNumPixels(), -0.5, geom.GetNumPixels()-0.5),
|
---|
116 | fUsed(geom.GetNumPixels()),*/ fColors(kItemsLegend)
|
---|
117 | {
|
---|
118 | //fGeomCam = (MGeomCam*)geom.Clone();
|
---|
119 | SetGeometry(geom, name, title);
|
---|
120 | Init();
|
---|
121 |
|
---|
122 | //
|
---|
123 | // root 3.02
|
---|
124 | // * base/inc/TObject.h:
|
---|
125 | // register BIT(8) as kNoContextMenu. If an object has this bit set it will
|
---|
126 | // not get an automatic context menu when clicked with the right mouse button.
|
---|
127 | }
|
---|
128 |
|
---|
129 | void MHCamera::SetGeometry(const MGeomCam &geom, const char *name, const char *title)
|
---|
130 | {
|
---|
131 | SetNameTitle(name, title);
|
---|
132 |
|
---|
133 | TAxis &x = *GetXaxis();
|
---|
134 |
|
---|
135 | SetBins(geom.GetNumPixels(), 0, 1);
|
---|
136 | x.Set(geom.GetNumPixels(), -0.5, geom.GetNumPixels()-0.5);
|
---|
137 |
|
---|
138 | //SetBins(geom.GetNumPixels(), -0.5, geom.GetNumPixels()-0.5);
|
---|
139 | //Rebuild();
|
---|
140 |
|
---|
141 | Sumw2(); // necessary?
|
---|
142 |
|
---|
143 | if (fGeomCam)
|
---|
144 | delete fGeomCam;
|
---|
145 | fGeomCam = (MGeomCam*)geom.Clone();
|
---|
146 |
|
---|
147 | fUsed.Set(geom.GetNumPixels());
|
---|
148 | for (Int_t i=0; i<fNcells-2; i++)
|
---|
149 | ResetUsed(i);
|
---|
150 |
|
---|
151 | }
|
---|
152 |
|
---|
153 | // ------------------------------------------------------------------------
|
---|
154 | //
|
---|
155 | // Destructor. Deletes the cloned fGeomCam and the notification list.
|
---|
156 | //
|
---|
157 | MHCamera::~MHCamera()
|
---|
158 | {
|
---|
159 | if (fGeomCam)
|
---|
160 | delete fGeomCam;
|
---|
161 | if (fNotify)
|
---|
162 | delete fNotify;
|
---|
163 | }
|
---|
164 |
|
---|
165 | // ------------------------------------------------------------------------
|
---|
166 | //
|
---|
167 | // Taken from TH1D::Fill(). Uses the argument directly as bin index.
|
---|
168 | // Doesn't increment the number of entries.
|
---|
169 | //
|
---|
170 | // -*-*-*-*-*-*-*-*Increment bin with abscissa X by 1*-*-*-*-*-*-*-*-*-*-*
|
---|
171 | // ==================================
|
---|
172 | //
|
---|
173 | // if x is less than the low-edge of the first bin, the Underflow bin is incremented
|
---|
174 | // if x is greater than the upper edge of last bin, the Overflow bin is incremented
|
---|
175 | //
|
---|
176 | // If the storage of the sum of squares of weights has been triggered,
|
---|
177 | // via the function Sumw2, then the sum of the squares of weights is incremented
|
---|
178 | // by 1 in the bin corresponding to x.
|
---|
179 | //
|
---|
180 | // -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
---|
181 | Int_t MHCamera::Fill(Axis_t x)
|
---|
182 | {
|
---|
183 |
|
---|
184 | #if ROOT_VERSION_CODE > ROOT_VERSION(3,05,00)
|
---|
185 | if (fBuffer) return BufferFill(x,1);
|
---|
186 | #endif
|
---|
187 | const Int_t bin = (Int_t)x+1;
|
---|
188 | AddBinContent(bin);
|
---|
189 | if (fSumw2.fN)
|
---|
190 | fSumw2.fArray[bin]++;
|
---|
191 |
|
---|
192 | if (bin<=0 || bin>fNcells-2)
|
---|
193 | return -1;
|
---|
194 |
|
---|
195 | fTsumw++;
|
---|
196 | fTsumw2++;
|
---|
197 | fTsumwx += x;
|
---|
198 | fTsumwx2 += x*x;
|
---|
199 | return bin;
|
---|
200 | }
|
---|
201 |
|
---|
202 | // ------------------------------------------------------------------------
|
---|
203 | //
|
---|
204 | // Taken from TH1D::Fill(). Uses the argument directly as bin index.
|
---|
205 | // Doesn't increment the number of entries.
|
---|
206 | //
|
---|
207 | // -*-*-*-*-*-*Increment bin with abscissa X with a weight w*-*-*-*-*-*-*-*
|
---|
208 | // =============================================
|
---|
209 | //
|
---|
210 | // if x is less than the low-edge of the first bin, the Underflow bin is incremented
|
---|
211 | // if x is greater than the upper edge of last bin, the Overflow bin is incremented
|
---|
212 | //
|
---|
213 | // If the storage of the sum of squares of weights has been triggered,
|
---|
214 | // via the function Sumw2, then the sum of the squares of weights is incremented
|
---|
215 | // by w^2 in the bin corresponding to x.
|
---|
216 | //
|
---|
217 | // -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
---|
218 | Int_t MHCamera::Fill(Axis_t x, Stat_t w)
|
---|
219 | {
|
---|
220 | #if ROOT_VERSION_CODE > ROOT_VERSION(3,05,00)
|
---|
221 | if (fBuffer) return BufferFill(x,w);
|
---|
222 | #endif
|
---|
223 | const Int_t bin = (Int_t)x+1;
|
---|
224 | AddBinContent(bin, w);
|
---|
225 | if (fSumw2.fN)
|
---|
226 | fSumw2.fArray[bin] += w*w;
|
---|
227 |
|
---|
228 | if (bin<=0 || bin>fNcells-2)
|
---|
229 | return -1;
|
---|
230 |
|
---|
231 | const Stat_t z = (w > 0 ? w : -w);
|
---|
232 | fTsumw += z;
|
---|
233 | fTsumw2 += z*z;
|
---|
234 | fTsumwx += z*x;
|
---|
235 | fTsumwx2 += z*x*x;
|
---|
236 | return bin;
|
---|
237 | }
|
---|
238 |
|
---|
239 | // ------------------------------------------------------------------------
|
---|
240 | //
|
---|
241 | // Use x and y in millimeters
|
---|
242 | //
|
---|
243 | Int_t MHCamera::Fill(Axis_t x, Axis_t y, Stat_t w)
|
---|
244 | {
|
---|
245 | if (fNcells<=1 || IsFreezed())
|
---|
246 | return -1;
|
---|
247 |
|
---|
248 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
---|
249 | {
|
---|
250 | MHexagon hex((*fGeomCam)[idx]);
|
---|
251 | if (hex.DistanceToPrimitive(x, y)>0)
|
---|
252 | continue;
|
---|
253 |
|
---|
254 | SetUsed(idx);
|
---|
255 | return Fill(idx, w);
|
---|
256 | }
|
---|
257 | return -1;
|
---|
258 | }
|
---|
259 |
|
---|
260 | Stat_t MHCamera::GetMean(Int_t axis) const
|
---|
261 | {
|
---|
262 | if (fNcells<=1)
|
---|
263 | return 0;
|
---|
264 |
|
---|
265 | Stat_t mean = 0;
|
---|
266 | for (int i=1; i<fNcells-1; i++)
|
---|
267 | mean += fArray[i];
|
---|
268 |
|
---|
269 | return Profile(mean/(fNcells-2));
|
---|
270 | }
|
---|
271 |
|
---|
272 | Stat_t MHCamera::GetRMS(Int_t axis) const
|
---|
273 | {
|
---|
274 | if (fNcells<=1)
|
---|
275 | return -1;
|
---|
276 |
|
---|
277 | const Int_t n = fNcells-2;
|
---|
278 |
|
---|
279 | Stat_t sum = 0;
|
---|
280 | Stat_t sq = 0;
|
---|
281 | for (int i=1; i<n+1; i++)
|
---|
282 | {
|
---|
283 | sum += fArray[i];
|
---|
284 | sq += fArray[i]*fArray[i];
|
---|
285 | }
|
---|
286 |
|
---|
287 | sum /= n;
|
---|
288 | sq /= n;
|
---|
289 |
|
---|
290 | return Profile(sqrt(sq-sum*sum));
|
---|
291 | }
|
---|
292 |
|
---|
293 | // ------------------------------------------------------------------------
|
---|
294 | //
|
---|
295 | // Return the minimum contents of all pixels (if all is set, otherwise
|
---|
296 | // only of all 'used' pixels), fMinimum if fMinimum set
|
---|
297 | //
|
---|
298 | Double_t MHCamera::GetMinimum(Bool_t all) const
|
---|
299 | {
|
---|
300 | if (fMinimum != -1111)
|
---|
301 | return Profile(fMinimum);
|
---|
302 |
|
---|
303 | if (fNcells<=1)
|
---|
304 | return 0;
|
---|
305 |
|
---|
306 | Double_t minimum=FLT_MAX;
|
---|
307 |
|
---|
308 | if (all)
|
---|
309 | {
|
---|
310 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
---|
311 | if (fArray[idx+1] < minimum)
|
---|
312 | minimum = fArray[idx+1];
|
---|
313 | }
|
---|
314 | else
|
---|
315 | {
|
---|
316 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
---|
317 | if (IsUsed(idx) && fArray[idx+1] < minimum)
|
---|
318 | minimum = fArray[idx+1];
|
---|
319 | }
|
---|
320 | return Profile(minimum);
|
---|
321 | }
|
---|
322 |
|
---|
323 | // ------------------------------------------------------------------------
|
---|
324 | //
|
---|
325 | // Return the maximum contents of all pixels (if all is set, otherwise
|
---|
326 | // only of all 'used' pixels), fMaximum if fMaximum set
|
---|
327 | //
|
---|
328 | Double_t MHCamera::GetMaximum(Bool_t all) const
|
---|
329 | {
|
---|
330 | if (fMaximum!=-1111)
|
---|
331 | return Profile(fMaximum);
|
---|
332 |
|
---|
333 | if (fNcells<=1)
|
---|
334 | return 1;
|
---|
335 |
|
---|
336 | Double_t maximum=-FLT_MAX;
|
---|
337 | if (all)
|
---|
338 | {
|
---|
339 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
---|
340 | if (fArray[idx+1] > maximum)
|
---|
341 | maximum = fArray[idx+1];
|
---|
342 | }
|
---|
343 | else
|
---|
344 | {
|
---|
345 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
---|
346 | if (IsUsed(idx) && fArray[idx+1] > maximum)
|
---|
347 | maximum = fArray[idx+1];
|
---|
348 | }
|
---|
349 | return Profile(maximum);
|
---|
350 | }
|
---|
351 |
|
---|
352 | // ------------------------------------------------------------------------
|
---|
353 | //
|
---|
354 | // Call this function to draw the camera layout into your canvas.
|
---|
355 | // Setup a drawing canvas. Add this object and all child objects
|
---|
356 | // (hexagons, etc) to the current pad. If no pad exists a new one is
|
---|
357 | // created.
|
---|
358 | //
|
---|
359 | // To draw a camera into its own pad do something like:
|
---|
360 | //
|
---|
361 | // TCanvas *c = new TCanvas;
|
---|
362 | // c->Divide(2,1);
|
---|
363 | // MGeomCamMagic m;
|
---|
364 | // MHCamera *d=new MHCamera(&m);
|
---|
365 | // d->FillRandom();
|
---|
366 | // c->cd(1);
|
---|
367 | // gPad->SetBorderMode(0);
|
---|
368 | // gPad->Divide(1,1);
|
---|
369 | // gPad->cd(1);
|
---|
370 | // d->Draw();
|
---|
371 | // d->SetBit(kCanDelete);
|
---|
372 | //
|
---|
373 | void MHCamera::Draw(Option_t *option)
|
---|
374 | {
|
---|
375 | // root 3.02:
|
---|
376 | // gPad->SetFixedAspectRatio()
|
---|
377 | Int_t col = 16;
|
---|
378 |
|
---|
379 | if (gPad)
|
---|
380 | col = gPad->GetFillColor();
|
---|
381 |
|
---|
382 | TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas("CamDisplay", "Mars Camera Display", 656, 600);
|
---|
383 | pad->SetBorderMode(0);
|
---|
384 | pad->SetFillColor(col);
|
---|
385 |
|
---|
386 | AppendPad(option);
|
---|
387 | }
|
---|
388 |
|
---|
389 | // ------------------------------------------------------------------------
|
---|
390 | //
|
---|
391 | // Resizes the current pad so that the camera is displayed in its
|
---|
392 | // correct aspect ratio
|
---|
393 | //
|
---|
394 | void MHCamera::SetRange()
|
---|
395 | {
|
---|
396 | const Float_t range = fGeomCam->GetMaxRadius()*1.05;
|
---|
397 |
|
---|
398 | //
|
---|
399 | // Maintain aspect ratio
|
---|
400 | //
|
---|
401 | const float ratio = 1.15;
|
---|
402 |
|
---|
403 | //
|
---|
404 | // Calculate width and height of the current pad in pixels
|
---|
405 | //
|
---|
406 | Float_t w = gPad->GetWw();
|
---|
407 | Float_t h = gPad->GetWh()*ratio;
|
---|
408 |
|
---|
409 | //
|
---|
410 | // This prevents the pad from resizing itself wrongly
|
---|
411 | //
|
---|
412 | if (gPad->GetMother() != gPad)
|
---|
413 | {
|
---|
414 | w *= gPad->GetMother()->GetAbsWNDC();
|
---|
415 | h *= gPad->GetMother()->GetAbsHNDC();
|
---|
416 | }
|
---|
417 |
|
---|
418 | //
|
---|
419 | // Set Range (coordinate system) of pad
|
---|
420 | //
|
---|
421 | gPad->Range(-range, -range, (2*ratio-1)*range, range);
|
---|
422 |
|
---|
423 | //
|
---|
424 | // Resize Pad to given ratio
|
---|
425 | //
|
---|
426 | if (h<w)
|
---|
427 | gPad->SetPad((1.-h/w)/2, 0, (h/w+1.)/2, 1);
|
---|
428 | else
|
---|
429 | gPad->SetPad(0, (1.-w/h)/2, 1, (w/h+1.)/2);
|
---|
430 | }
|
---|
431 |
|
---|
432 | // ------------------------------------------------------------------------
|
---|
433 | //
|
---|
434 | // Updates the pixel colors and paints the pixels
|
---|
435 | //
|
---|
436 | void MHCamera::Update(Bool_t islog, Bool_t isbox, Bool_t iscol)
|
---|
437 | {
|
---|
438 | Double_t min = GetMinimum(kFALSE);
|
---|
439 | Double_t max = GetMaximum(kFALSE);
|
---|
440 | if (min==FLT_MAX)
|
---|
441 | {
|
---|
442 | min = 0;
|
---|
443 | max = 1;
|
---|
444 | }
|
---|
445 |
|
---|
446 | if (min==max)
|
---|
447 | max += 1;
|
---|
448 |
|
---|
449 | UpdateLegend(min, max, islog);
|
---|
450 |
|
---|
451 | MHexagon hex;
|
---|
452 | for (Int_t i=0; i<fNcells-2; i++)
|
---|
453 | {
|
---|
454 | if (IsUsed(i) && iscol)
|
---|
455 | {
|
---|
456 | if (TMath::IsNaN(fArray[i+1]))
|
---|
457 | gLog << warn << "MHCamera::Update: " << GetName() << " <" << GetTitle() << "> - Pixel Index #" << i << " contents is NaN (Not a Number)..." << endl;
|
---|
458 |
|
---|
459 | hex.SetFillColor(GetColor(GetBinContent(i+1), min, max, islog));
|
---|
460 | }
|
---|
461 | else
|
---|
462 | hex.SetFillColor(10);
|
---|
463 |
|
---|
464 | MGeomPix &pix = (*fGeomCam)[i];
|
---|
465 | if (!isbox)
|
---|
466 | hex.PaintHexagon(pix.GetX(), pix.GetY(), pix.GetD());
|
---|
467 | else
|
---|
468 | if (IsUsed(i) && !TMath::IsNaN(fArray[i+1]))
|
---|
469 | {
|
---|
470 | Float_t size = pix.GetD()*(GetBinContent(i+1)-min)/(max-min);
|
---|
471 | if (size>pix.GetD())
|
---|
472 | size=pix.GetD();
|
---|
473 | hex.PaintHexagon(pix.GetX(), pix.GetY(), size);
|
---|
474 | }
|
---|
475 | }
|
---|
476 | }
|
---|
477 |
|
---|
478 | // ------------------------------------------------------------------------
|
---|
479 | //
|
---|
480 | // Print minimum and maximum
|
---|
481 | //
|
---|
482 | void MHCamera::Print(Option_t *) const
|
---|
483 | {
|
---|
484 | cout << "Minimum: " << GetMinimum();
|
---|
485 | if (fMinimum==-1111)
|
---|
486 | cout << " <autoscaled>";
|
---|
487 | cout << endl;
|
---|
488 | cout << "Maximum: " << GetMaximum();
|
---|
489 | if (fMaximum==-1111)
|
---|
490 | cout << " <autoscaled>";
|
---|
491 | cout << endl;
|
---|
492 | }
|
---|
493 |
|
---|
494 | // ------------------------------------------------------------------------
|
---|
495 | //
|
---|
496 | // Paint the y-axis title
|
---|
497 | //
|
---|
498 | void MHCamera::PaintAxisTitle()
|
---|
499 | {
|
---|
500 | const Float_t range = fGeomCam->GetMaxRadius()*1.05;
|
---|
501 | const Float_t w = (1 + 1.5/sqrt((float)(fNcells-2)))*range;
|
---|
502 |
|
---|
503 | TLatex *ptitle = new TLatex(w, -.90*range, GetYaxis()->GetTitle());
|
---|
504 |
|
---|
505 | ptitle->SetTextSize(0.05);
|
---|
506 | ptitle->SetTextAlign(21);
|
---|
507 |
|
---|
508 | // box with the histogram title
|
---|
509 | ptitle->SetTextColor(gStyle->GetTitleTextColor());
|
---|
510 | #if ROOT_VERSION_CODE > ROOT_VERSION(3,05,01)
|
---|
511 | ptitle->SetTextFont(gStyle->GetTitleFont(""));
|
---|
512 | #endif
|
---|
513 | ptitle->Paint();
|
---|
514 | }
|
---|
515 |
|
---|
516 | // ------------------------------------------------------------------------
|
---|
517 | //
|
---|
518 | // Paints the camera.
|
---|
519 | //
|
---|
520 | void MHCamera::Paint(Option_t *o)
|
---|
521 | {
|
---|
522 | if (fNcells<=1)
|
---|
523 | return;
|
---|
524 |
|
---|
525 | TString opt(o);
|
---|
526 | opt.ToLower();
|
---|
527 |
|
---|
528 | if (opt.Contains("hist"))
|
---|
529 | {
|
---|
530 | opt.ReplaceAll("hist", "");
|
---|
531 | TH1D::Paint(opt);
|
---|
532 | return;
|
---|
533 | }
|
---|
534 |
|
---|
535 | // Maintain aspect ratio
|
---|
536 | SetRange();
|
---|
537 |
|
---|
538 | Bool_t isbox = opt.Contains("box");
|
---|
539 | Bool_t iscol = isbox ? !opt.Contains("nocol") : 1;
|
---|
540 |
|
---|
541 | GetPainter();
|
---|
542 | if (fPainter)
|
---|
543 | {
|
---|
544 | if (!TestBit(TH1::kNoStats))
|
---|
545 | {
|
---|
546 | fPainter->SetHistogram(this);
|
---|
547 | fPainter->PaintStat(gStyle->GetOptStat(), NULL);
|
---|
548 | }
|
---|
549 |
|
---|
550 | // Paint primitives (pixels, color legend, photons, ...)
|
---|
551 | if (fPainter->InheritsFrom(THistPainter::Class()))
|
---|
552 | ((THistPainter*)fPainter)->PaintTitle();
|
---|
553 | }
|
---|
554 |
|
---|
555 | // Update Contents of the pixels and paint legend
|
---|
556 | Update(gPad->GetLogy(), isbox, iscol);
|
---|
557 | PaintAxisTitle();
|
---|
558 | }
|
---|
559 |
|
---|
560 | // ------------------------------------------------------------------------
|
---|
561 | //
|
---|
562 | // With this function you can change the color palette. For more
|
---|
563 | // information see TStyle::SetPalette. Only palettes with 50 colors
|
---|
564 | // are allowed.
|
---|
565 | // In addition you can use SetPalette(52, 0) to create an inverse
|
---|
566 | // deep blue sea palette
|
---|
567 | //
|
---|
568 | void MHCamera::SetPalette(Int_t ncolors, Int_t *colors)
|
---|
569 | {
|
---|
570 | //
|
---|
571 | // If not enough colors are specified skip this.
|
---|
572 | //
|
---|
573 | if (ncolors>1 && ncolors<50)
|
---|
574 | {
|
---|
575 | cout << "MHCamera::SetPalette: Only default palettes with 50 colors are allowed... ignored." << endl;
|
---|
576 | return;
|
---|
577 | }
|
---|
578 |
|
---|
579 | //
|
---|
580 | // If ncolors==52 create a reversed deep blue sea palette
|
---|
581 | //
|
---|
582 | if (ncolors==52)
|
---|
583 | {
|
---|
584 | gStyle->SetPalette(51, NULL);
|
---|
585 | TArrayI c(kItemsLegend);
|
---|
586 | for (int i=0; i<kItemsLegend; i++)
|
---|
587 | c[kItemsLegend-i-1] = gStyle->GetColorPalette(i);
|
---|
588 | gStyle->SetPalette(kItemsLegend, c.GetArray());
|
---|
589 | }
|
---|
590 | else
|
---|
591 | gStyle->SetPalette(ncolors, colors);
|
---|
592 |
|
---|
593 | fColors.Set(kItemsLegend);
|
---|
594 | for (int i=0; i<kItemsLegend; i++)
|
---|
595 | fColors[i] = gStyle->GetColorPalette(i);
|
---|
596 | }
|
---|
597 |
|
---|
598 |
|
---|
599 | void MHCamera::SetPrettyPalette()
|
---|
600 | {
|
---|
601 | if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
|
---|
602 | SetPalette(1, 0);
|
---|
603 | }
|
---|
604 |
|
---|
605 | void MHCamera::SetDeepBlueSeaPalette()
|
---|
606 | {
|
---|
607 | if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
|
---|
608 | SetPalette(51, 0);
|
---|
609 | }
|
---|
610 |
|
---|
611 | void MHCamera::SetInvDeepBlueSeaPalette()
|
---|
612 | {
|
---|
613 | if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
|
---|
614 | SetPalette(52, 0);
|
---|
615 | }
|
---|
616 |
|
---|
617 | void MHCamera::DrawPixelIndices()
|
---|
618 | {
|
---|
619 | if (fNcells<=1)
|
---|
620 | return;
|
---|
621 |
|
---|
622 | // FIXME: Is this correct?
|
---|
623 | for (int i=0; i<kItemsLegend; i++)
|
---|
624 | fColors[i] = 16;
|
---|
625 |
|
---|
626 | if (!gPad)
|
---|
627 | Draw();
|
---|
628 |
|
---|
629 | TText txt;
|
---|
630 | txt.SetTextFont(122);
|
---|
631 | txt.SetTextAlign(22); // centered/centered
|
---|
632 |
|
---|
633 | for (Int_t i=0; i<fNcells-2; i++)
|
---|
634 | {
|
---|
635 | TString num;
|
---|
636 | num += i;
|
---|
637 |
|
---|
638 | const MGeomPix &h = (*fGeomCam)[i];
|
---|
639 | TText *nt = txt.DrawText(h.GetX(), h.GetY(), num);
|
---|
640 | nt->SetTextSize(0.3*h.GetD()/fGeomCam->GetMaxRadius()/1.05);
|
---|
641 | }
|
---|
642 | }
|
---|
643 |
|
---|
644 | void MHCamera::DrawSectorIndices()
|
---|
645 | {
|
---|
646 | if (fNcells<=1)
|
---|
647 | return;
|
---|
648 |
|
---|
649 | for (int i=0; i<kItemsLegend; i++)
|
---|
650 | fColors[i] = 16;
|
---|
651 |
|
---|
652 | if (!gPad)
|
---|
653 | Draw();
|
---|
654 |
|
---|
655 | TText txt;
|
---|
656 | txt.SetTextFont(122);
|
---|
657 | txt.SetTextAlign(22); // centered/centered
|
---|
658 |
|
---|
659 | for (Int_t i=0; i<fNcells-2; i++)
|
---|
660 | {
|
---|
661 | TString num;
|
---|
662 | num += (*fGeomCam)[i].GetSector();
|
---|
663 |
|
---|
664 | const MGeomPix &h = (*fGeomCam)[i];
|
---|
665 | TText *nt = txt.DrawText(h.GetX(), h.GetY(), num);
|
---|
666 | nt->SetTextSize(0.3*h.GetD()/fGeomCam->GetMaxRadius()/1.05);
|
---|
667 | }
|
---|
668 | }
|
---|
669 |
|
---|
670 | // ------------------------------------------------------------------------
|
---|
671 | //
|
---|
672 | // Call this function to add a MCamEvent on top of the present contents.
|
---|
673 | // Only 'used' pixels are added.
|
---|
674 | //
|
---|
675 | void MHCamera::AddCamContent(const MCamEvent &event, Int_t type)
|
---|
676 | {
|
---|
677 | if (fNcells<=1 || IsFreezed())
|
---|
678 | return;
|
---|
679 |
|
---|
680 | // FIXME: Security check missing!
|
---|
681 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
---|
682 | {
|
---|
683 | Double_t val=0;
|
---|
684 | if (event.GetPixelContent(val, idx, *fGeomCam, type) && !IsUsed(idx))
|
---|
685 | SetUsed(idx);
|
---|
686 |
|
---|
687 | Fill(idx, val); // FIXME: Slow!
|
---|
688 | }
|
---|
689 | fEntries++;
|
---|
690 | }
|
---|
691 |
|
---|
692 | // ------------------------------------------------------------------------
|
---|
693 | //
|
---|
694 | // Call this function to add a MHCamera on top of the present contents.
|
---|
695 | // Only 'used' pixels are added.
|
---|
696 | // Type:
|
---|
697 | // 0) bin content
|
---|
698 | // 1) errors
|
---|
699 | // 2) rel. errors
|
---|
700 | //
|
---|
701 | void MHCamera::AddCamContent(const MHCamera &d, Int_t type)
|
---|
702 | {
|
---|
703 | if (fNcells!=d.fNcells || IsFreezed())
|
---|
704 | return;
|
---|
705 |
|
---|
706 | // FIXME: Security check missing!
|
---|
707 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
---|
708 | if (d.IsUsed(idx))
|
---|
709 | SetUsed(idx);
|
---|
710 |
|
---|
711 | switch (type)
|
---|
712 | {
|
---|
713 | case 1:
|
---|
714 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
---|
715 | Fill(idx, d.GetBinError(idx+1));
|
---|
716 | break;
|
---|
717 | case 2:
|
---|
718 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
---|
719 | if (d.GetBinContent(idx+1)!=0)
|
---|
720 | Fill(idx, TMath::Abs(d.GetBinError(idx+1)/d.GetBinContent(idx+1)));
|
---|
721 | break;
|
---|
722 | default:
|
---|
723 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
---|
724 | Fill(idx, d.GetBinContent(idx+1));
|
---|
725 | break;
|
---|
726 | }
|
---|
727 | fEntries++;
|
---|
728 | }
|
---|
729 |
|
---|
730 | // ------------------------------------------------------------------------
|
---|
731 | //
|
---|
732 | // Call this function to add a TArrayD on top of the present contents.
|
---|
733 | // Only 'used' pixels are added.
|
---|
734 | //
|
---|
735 | void MHCamera::AddCamContent(const TArrayD &event, const TArrayC *used)
|
---|
736 | {
|
---|
737 | if (event.GetSize()!=fNcells-2 || IsFreezed())
|
---|
738 | return;
|
---|
739 |
|
---|
740 | if (used && used->GetSize()!=fNcells-2)
|
---|
741 | return;
|
---|
742 |
|
---|
743 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
---|
744 | {
|
---|
745 | Fill(idx, const_cast<TArrayD&>(event)[idx]); // FIXME: Slow!
|
---|
746 |
|
---|
747 | if (used && (*const_cast<TArrayC*>(used))[idx])
|
---|
748 | SetUsed(idx);
|
---|
749 | }
|
---|
750 | fEntries++;
|
---|
751 | }
|
---|
752 |
|
---|
753 | // ------------------------------------------------------------------------
|
---|
754 | //
|
---|
755 | // Call this function to add a MCamEvent on top of the present contents.
|
---|
756 | // 1 is added to each pixel if the contents of MCamEvent>threshold
|
---|
757 | //
|
---|
758 | void MHCamera::CntCamContent(const MCamEvent &event, Double_t threshold, Int_t type)
|
---|
759 | {
|
---|
760 | if (fNcells<=1 || IsFreezed())
|
---|
761 | return;
|
---|
762 |
|
---|
763 | // FIXME: Security check missing!
|
---|
764 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
---|
765 | {
|
---|
766 | Double_t val=0;
|
---|
767 | if (event.GetPixelContent(val, idx, *fGeomCam, type) && !IsUsed(idx))
|
---|
768 | SetUsed(idx);
|
---|
769 |
|
---|
770 | if (val>threshold)
|
---|
771 | Fill(idx);
|
---|
772 | }
|
---|
773 | fEntries++;
|
---|
774 | }
|
---|
775 |
|
---|
776 | // ------------------------------------------------------------------------
|
---|
777 | //
|
---|
778 | // Call this function to add a TArrayD on top of the present contents.
|
---|
779 | // 1 is added to each pixel if the contents of MCamEvent>threshold
|
---|
780 | //
|
---|
781 | void MHCamera::CntCamContent(const TArrayD &event, Double_t threshold, Bool_t ispos)
|
---|
782 | {
|
---|
783 | if (event.GetSize()!=fNcells-2 || IsFreezed())
|
---|
784 | return;
|
---|
785 |
|
---|
786 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
---|
787 | {
|
---|
788 | if (const_cast<TArrayD&>(event)[idx]>threshold)
|
---|
789 | Fill(idx);
|
---|
790 |
|
---|
791 | if (!ispos || fArray[idx+1]>0)
|
---|
792 | SetUsed(idx);
|
---|
793 | }
|
---|
794 | fEntries++;
|
---|
795 | }
|
---|
796 |
|
---|
797 | // ------------------------------------------------------------------------
|
---|
798 | //
|
---|
799 | // Fill the pixels with random contents.
|
---|
800 | //
|
---|
801 | void MHCamera::FillRandom()
|
---|
802 | {
|
---|
803 | if (fNcells<=1 || IsFreezed())
|
---|
804 | return;
|
---|
805 |
|
---|
806 | Reset();
|
---|
807 |
|
---|
808 | // FIXME: Security check missing!
|
---|
809 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
---|
810 | {
|
---|
811 | Fill(idx, gRandom->Uniform()*fGeomCam->GetPixRatio(idx));
|
---|
812 | SetUsed(idx);
|
---|
813 | }
|
---|
814 | fEntries=1;
|
---|
815 | }
|
---|
816 |
|
---|
817 |
|
---|
818 | // ------------------------------------------------------------------------
|
---|
819 | //
|
---|
820 | // Fill the colors in respect to the cleaning levels
|
---|
821 | //
|
---|
822 | void MHCamera::FillLevels(const MCerPhotEvt &event, Float_t lvl1, Float_t lvl2)
|
---|
823 | {
|
---|
824 | if (fNcells<=1)
|
---|
825 | return;
|
---|
826 |
|
---|
827 | SetCamContent(event, 2);
|
---|
828 |
|
---|
829 | for (Int_t i=0; i<fNcells-2; i++)
|
---|
830 | {
|
---|
831 | if (!IsUsed(i))
|
---|
832 | continue;
|
---|
833 |
|
---|
834 | if (fArray[i+1]>lvl1)
|
---|
835 | fArray[i+1] = 0;
|
---|
836 | else
|
---|
837 | if (fArray[i+1]>lvl2)
|
---|
838 | fArray[i+1] = 1;
|
---|
839 | else
|
---|
840 | fArray[i+1] = 2;
|
---|
841 | }
|
---|
842 | }
|
---|
843 |
|
---|
844 | // ------------------------------------------------------------------------
|
---|
845 | //
|
---|
846 | // Fill the colors in respect to the cleaning levels
|
---|
847 | //
|
---|
848 | void MHCamera::FillLevels(const MCerPhotEvt &event, const MImgCleanStd &clean)
|
---|
849 | {
|
---|
850 | FillLevels(event, clean.GetCleanLvl1(), clean.GetCleanLvl2());
|
---|
851 | }
|
---|
852 |
|
---|
853 | // ------------------------------------------------------------------------
|
---|
854 | //
|
---|
855 | // Reset the all pixel colors to a default value
|
---|
856 | //
|
---|
857 | void MHCamera::Reset(Option_t *opt)
|
---|
858 | {
|
---|
859 | if (fNcells<=1 || IsFreezed())
|
---|
860 | return;
|
---|
861 |
|
---|
862 | TH1::Reset(opt);
|
---|
863 |
|
---|
864 | for (Int_t i=0; i<fNcells-2; i++)
|
---|
865 | {
|
---|
866 | fArray[i+1]=0;
|
---|
867 | ResetUsed(i);
|
---|
868 | }
|
---|
869 | fArray[0] = 0;
|
---|
870 | fArray[fNcells-1] = 0;
|
---|
871 | }
|
---|
872 |
|
---|
873 | // ------------------------------------------------------------------------
|
---|
874 | //
|
---|
875 | // Here we calculate the color index for the current value.
|
---|
876 | // The color index is defined with the class TStyle and the
|
---|
877 | // Color palette inside. We use the command gStyle->SetPalette(1,0)
|
---|
878 | // for the display. So we have to convert the value "wert" into
|
---|
879 | // a color index that fits the color palette.
|
---|
880 | // The range of the color palette is defined by the values fMinPhe
|
---|
881 | // and fMaxRange. Between this values we have 50 color index, starting
|
---|
882 | // with 0 up to 49.
|
---|
883 | //
|
---|
884 | Int_t MHCamera::GetColor(Float_t val, Float_t min, Float_t max, Bool_t islog)
|
---|
885 | {
|
---|
886 | if (TMath::IsNaN(val)) // FIXME: gLog!
|
---|
887 | return 10;
|
---|
888 |
|
---|
889 | //
|
---|
890 | // first treat the over- and under-flows
|
---|
891 | //
|
---|
892 | const Int_t maxcolidx = kItemsLegend-1;
|
---|
893 |
|
---|
894 | if (val >= max)
|
---|
895 | return fColors[maxcolidx];
|
---|
896 |
|
---|
897 | if (val <= min)
|
---|
898 | return fColors[0];
|
---|
899 |
|
---|
900 | //
|
---|
901 | // calculate the color index
|
---|
902 | //
|
---|
903 | Float_t ratio;
|
---|
904 | if (islog && min>0)
|
---|
905 | ratio = log10(val/min) / log10(max/min);
|
---|
906 | else
|
---|
907 | ratio = (val-min) / (max-min);
|
---|
908 |
|
---|
909 | const Int_t colidx = (Int_t)(ratio*maxcolidx + .5);
|
---|
910 | return fColors[colidx];
|
---|
911 | }
|
---|
912 |
|
---|
913 | TPaveStats *MHCamera::GetStatisticBox()
|
---|
914 | {
|
---|
915 | TObject *obj = 0;
|
---|
916 |
|
---|
917 | TIter Next(fFunctions);
|
---|
918 | while ((obj = Next()))
|
---|
919 | if (obj->InheritsFrom(TPaveStats::Class()))
|
---|
920 | return static_cast<TPaveStats*>(obj);
|
---|
921 |
|
---|
922 | return NULL;
|
---|
923 | }
|
---|
924 |
|
---|
925 | // ------------------------------------------------------------------------
|
---|
926 | //
|
---|
927 | // Change the text on the legend according to the range of the Display
|
---|
928 | //
|
---|
929 | void MHCamera::UpdateLegend(Float_t min, Float_t max, Bool_t islog)
|
---|
930 | {
|
---|
931 | TPaveStats *stats = GetStatisticBox();
|
---|
932 |
|
---|
933 | const Float_t hndc = 0.92 - (stats ? stats->GetY1NDC() : 1);
|
---|
934 | const Float_t range = fGeomCam->GetMaxRadius()*1.05;
|
---|
935 | const Float_t H = (0.75-hndc)*range;
|
---|
936 | const Float_t offset = hndc*range;
|
---|
937 |
|
---|
938 | const Float_t h = 2./kItemsLegend;
|
---|
939 | const Float_t w = range/sqrt((float)(fNcells-2));
|
---|
940 |
|
---|
941 | TBox newbox;
|
---|
942 | TText newtxt;
|
---|
943 | newtxt.SetTextSize(0.03);
|
---|
944 | newtxt.SetTextAlign(12);
|
---|
945 | #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
|
---|
946 | newtxt.SetBit(/*kNoContextMenu|*/kCannotPick);
|
---|
947 | newbox.SetBit(/*kNoContextMenu|*/kCannotPick);
|
---|
948 | #endif
|
---|
949 |
|
---|
950 | const Float_t step = (islog && min>0 ? log10(max/min) : max-min) / kItemsLegend;
|
---|
951 | const Int_t firsts = step*3 < 1e-8 ? 8 : (Int_t)floor(log10(step*3));
|
---|
952 | const TString opt = Form("%%.%if", firsts>0 ? 0 : TMath::Abs(firsts));
|
---|
953 |
|
---|
954 | for (Int_t i=0; i<kItemsLegend+1; i+=3)
|
---|
955 | {
|
---|
956 | Float_t val;
|
---|
957 | if (islog && min>0)
|
---|
958 | val = pow(10, step*i) * min;
|
---|
959 | else
|
---|
960 | val = min + step*i;
|
---|
961 |
|
---|
962 | //const bool dispexp = max-min>1.5 && fabs(val)>0.1 && fabs(val)<1e6;
|
---|
963 | newtxt.PaintText(range+1.5*w, H*(i*h-1)-offset, Form(opt, val));
|
---|
964 | }
|
---|
965 |
|
---|
966 | for (Int_t i=0; i<kItemsLegend; i++)
|
---|
967 | {
|
---|
968 | newbox.SetFillColor(fColors[i]);
|
---|
969 | newbox.PaintBox(range, H*(i*h-1)-offset, range+w, H*((i+1)*h-1)-offset);
|
---|
970 | }
|
---|
971 |
|
---|
972 | TArrow arr;
|
---|
973 | arr.PaintArrow(-range*.9, -range*.9, -range*.6, -range*.9, 0.025);
|
---|
974 | arr.PaintArrow(-range*.9, -range*.9, -range*.9, -range*.6, 0.025);
|
---|
975 |
|
---|
976 | TString text;
|
---|
977 | text += (int)(range*.3);
|
---|
978 | text += "mm";
|
---|
979 |
|
---|
980 | TText newtxt2;
|
---|
981 | newtxt2.SetTextSize(0.04);
|
---|
982 | newtxt2.PaintText(-range*.85, -range*.85, text);
|
---|
983 |
|
---|
984 | text = "";
|
---|
985 | text += (float)((int)(range*.3*fGeomCam->GetConvMm2Deg()*10))/10;
|
---|
986 | text += "\\circ";
|
---|
987 | text = text.Strip(TString::kLeading);
|
---|
988 |
|
---|
989 | TLatex latex;
|
---|
990 | latex.PaintLatex(-range*.85, -range*.75, 0, 0.04, text);
|
---|
991 | }
|
---|
992 |
|
---|
993 | // ------------------------------------------------------------------------
|
---|
994 | //
|
---|
995 | // Save primitive as a C++ statement(s) on output stream out
|
---|
996 | //
|
---|
997 | void MHCamera::SavePrimitive(ofstream &out, Option_t *opt)
|
---|
998 | {
|
---|
999 | cout << "MHCamera::SavePrimitive: Must be rewritten!" << endl;
|
---|
1000 | /*
|
---|
1001 | if (!gROOT->ClassSaved(TCanvas::Class()))
|
---|
1002 | fDrawingPad->SavePrimitive(out, opt);
|
---|
1003 |
|
---|
1004 | out << " " << fDrawingPad->GetName() << "->SetWindowSize(";
|
---|
1005 | out << fDrawingPad->GetWw() << "," << fDrawingPad->GetWh() << ");" << endl;
|
---|
1006 | */
|
---|
1007 | }
|
---|
1008 |
|
---|
1009 | // ------------------------------------------------------------------------
|
---|
1010 | //
|
---|
1011 | // compute the distance of a point (px,py) to the Camera
|
---|
1012 | // this functions needed for graphical primitives, that
|
---|
1013 | // means without this function you are not able to interact
|
---|
1014 | // with the graphical primitive with the mouse!!!
|
---|
1015 | //
|
---|
1016 | // All calcutations are done in pixel coordinates
|
---|
1017 | //
|
---|
1018 | Int_t MHCamera::DistancetoPrimitive(Int_t px, Int_t py)
|
---|
1019 | {
|
---|
1020 | if (fNcells<=1)
|
---|
1021 | return 999999;
|
---|
1022 |
|
---|
1023 | const Int_t kMaxDiff = 7;
|
---|
1024 |
|
---|
1025 | TPaveStats *box = (TPaveStats*)gPad->GetPrimitive("stats");
|
---|
1026 | if (box)
|
---|
1027 | {
|
---|
1028 | const Double_t w = box->GetY2NDC()-box->GetY1NDC();
|
---|
1029 | box->SetX1NDC(gStyle->GetStatX()-gStyle->GetStatW());
|
---|
1030 | box->SetY1NDC(gStyle->GetStatY()-w);
|
---|
1031 | box->SetX2NDC(gStyle->GetStatX());
|
---|
1032 | box->SetY2NDC(gStyle->GetStatY());
|
---|
1033 | }
|
---|
1034 |
|
---|
1035 | if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
|
---|
1036 | return TH1D::DistancetoPrimitive(px, py);
|
---|
1037 |
|
---|
1038 | for (Int_t i=0; i<fNcells-2; i++)
|
---|
1039 | {
|
---|
1040 | MHexagon hex((*fGeomCam)[i]);
|
---|
1041 | if (hex.DistancetoPrimitive(px, py)==0)
|
---|
1042 | return 0;
|
---|
1043 | }
|
---|
1044 |
|
---|
1045 | if (!box)
|
---|
1046 | return 999999;
|
---|
1047 |
|
---|
1048 | const Int_t dist = box->DistancetoPrimitive(px, py);
|
---|
1049 | if (dist > kMaxDiff)
|
---|
1050 | return 999999;
|
---|
1051 |
|
---|
1052 | gPad->SetSelected(box);
|
---|
1053 | return dist;
|
---|
1054 | }
|
---|
1055 |
|
---|
1056 | // ------------------------------------------------------------------------
|
---|
1057 | //
|
---|
1058 | // Function introduced (31-01-03) WILL BE REMOVED IN THE FUTURE! DON'T
|
---|
1059 | // USE IT!
|
---|
1060 | //
|
---|
1061 | void MHCamera::SetPix(const Int_t idx, const Int_t color, Float_t min, Float_t max)
|
---|
1062 | {
|
---|
1063 | fArray[idx+1] = color;
|
---|
1064 | SetUsed(idx);
|
---|
1065 | }
|
---|
1066 |
|
---|
1067 | // ------------------------------------------------------------------------
|
---|
1068 | //
|
---|
1069 | //
|
---|
1070 | Int_t MHCamera::GetPixelIndex(Int_t px, Int_t py) const
|
---|
1071 | {
|
---|
1072 | if (fNcells<=1)
|
---|
1073 | return -1;
|
---|
1074 |
|
---|
1075 | Int_t i;
|
---|
1076 | for (i=0; i<fNcells-2; i++)
|
---|
1077 | {
|
---|
1078 | MHexagon hex((*fGeomCam)[i]);
|
---|
1079 | if (hex.DistancetoPrimitive(px, py)>0)
|
---|
1080 | continue;
|
---|
1081 |
|
---|
1082 | return i;
|
---|
1083 | }
|
---|
1084 | return -1;
|
---|
1085 | }
|
---|
1086 |
|
---|
1087 | // ------------------------------------------------------------------------
|
---|
1088 | //
|
---|
1089 | // Returns string containing info about the object at position (px,py).
|
---|
1090 | // Returned string will be re-used (lock in MT environment).
|
---|
1091 | //
|
---|
1092 | char *MHCamera::GetObjectInfo(Int_t px, Int_t py) const
|
---|
1093 | {
|
---|
1094 | if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
|
---|
1095 | return TH1D::GetObjectInfo(px, py);
|
---|
1096 |
|
---|
1097 | static char info[128];
|
---|
1098 |
|
---|
1099 | const Int_t idx=GetPixelIndex(px, py);
|
---|
1100 |
|
---|
1101 | if (idx<0)
|
---|
1102 | return TObject::GetObjectInfo(px, py);
|
---|
1103 |
|
---|
1104 | sprintf(info, "Software Pixel Index: %d (Hardware Id=%d)", idx, idx+1);
|
---|
1105 | return info;
|
---|
1106 | }
|
---|
1107 |
|
---|
1108 | // ------------------------------------------------------------------------
|
---|
1109 | //
|
---|
1110 | // Execute a mouse event on the camera
|
---|
1111 | //
|
---|
1112 | void MHCamera::ExecuteEvent(Int_t event, Int_t px, Int_t py)
|
---|
1113 | {
|
---|
1114 | if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
|
---|
1115 | {
|
---|
1116 | TH1D::ExecuteEvent(event, px, py);
|
---|
1117 | return;
|
---|
1118 | }
|
---|
1119 | //if (event==kMouseMotion && fStatusBar)
|
---|
1120 | // fStatusBar->SetText(GetObjectInfo(px, py), 0);
|
---|
1121 | if (event!=kButton1Down)
|
---|
1122 | return;
|
---|
1123 |
|
---|
1124 | const Int_t idx = GetPixelIndex(px, py);
|
---|
1125 | if (idx<0)
|
---|
1126 | return;
|
---|
1127 |
|
---|
1128 | cout << GetTitle() << " <" << GetName() << ">" << endl;
|
---|
1129 | cout << "Software Pixel Index: " << idx << endl;
|
---|
1130 | cout << "Hardware Pixel Id: " << idx+1 << endl;
|
---|
1131 | cout << "Contents: " << GetBinContent(idx+1) << " <";
|
---|
1132 | cout << (IsUsed(idx)?"on":"off");
|
---|
1133 | cout << ">" << endl;
|
---|
1134 |
|
---|
1135 | if (fNotify && fNotify->GetSize()>0)
|
---|
1136 | {
|
---|
1137 | TCanvas *c=new TCanvas;
|
---|
1138 | fNotify->ForEach(MCamEvent, DrawPixelContent)(idx, c);
|
---|
1139 | }
|
---|
1140 | }
|
---|
1141 |
|
---|
1142 | UInt_t MHCamera::GetNumPixels() const
|
---|
1143 | {
|
---|
1144 | return fGeomCam->GetNumPixels();
|
---|
1145 | }
|
---|
1146 |
|
---|
1147 | TH1 *MHCamera::DrawCopy() const
|
---|
1148 | {
|
---|
1149 | gPad=NULL;
|
---|
1150 | return TH1D::DrawCopy();
|
---|
1151 | }
|
---|