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