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