source: trunk/MagicSoft/Mars/mcalib/MHCalibrationCam.cc@ 3629

Last change on this file since 3629 was 3629, checked in by gaug, 21 years ago
*** empty log message ***
File size: 11.6 KB
Line 
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): Markus Gaug 02/2004 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24/////////////////////////////////////////////////////////////////////////////
25//
26// MHCalibrationCam
27//
28//
29/////////////////////////////////////////////////////////////////////////////
30#include "MHCalibrationCam.h"
31
32#include <TVirtualPad.h>
33#include <TCanvas.h>
34#include <TPad.h>
35#include <TText.h>
36#include <TPaveText.h>
37
38#include "MLog.h"
39#include "MLogManip.h"
40
41#include "MHGausEvents.h"
42
43#include "MGeomCam.h"
44#include "MGeomPix.h"
45
46ClassImp(MHCalibrationCam);
47
48using namespace std;
49
50const Int_t MHCalibrationCam::fgPulserFrequency = 500;
51// --------------------------------------------------------------------------
52//
53// Default Constructor.
54//
55// Initializes and sets owner of:
56// - fHiGainArray, fLoGainArray
57// - fAverageHiGainAreas, fAverageLoGainAreas
58// - fAverageHiGainSectors, fAverageLoGainSectors
59//
60// Initializes:
61// - fPulserFrequency to fgPulserFrequency
62//
63MHCalibrationCam::MHCalibrationCam(const char *name, const char *title)
64{
65 fName = name ? name : "MHCalibrationCam";
66 fTitle = title ? title : "Class to fill the calibration histograms ";
67
68 fHiGainArray = new TObjArray;
69 fHiGainArray->SetOwner();
70
71 fLoGainArray = new TObjArray;
72 fLoGainArray->SetOwner();
73
74 fAverageHiGainAreas = new TObjArray;
75 fAverageHiGainAreas->SetOwner();
76
77 fAverageLoGainAreas = new TObjArray;
78 fAverageLoGainAreas->SetOwner();
79
80 fAverageHiGainSectors = new TObjArray;
81 fAverageHiGainSectors->SetOwner();
82
83 fAverageLoGainSectors = new TObjArray;
84 fAverageLoGainSectors->SetOwner();
85
86 SetPulserFrequency();
87}
88
89// --------------------------------------------------------------------------
90//
91// Deletes the TClonesArray of:
92// - fHiGainArray, fLoGainArray
93// - fAverageHiGainAreas, fAverageLoGainAreas
94// - fAverageHiGainSectors, fAverageLoGainSectors
95//
96MHCalibrationCam::~MHCalibrationCam()
97{
98 delete fHiGainArray;
99 delete fLoGainArray;
100
101 delete fAverageHiGainAreas;
102 delete fAverageLoGainAreas;
103
104 delete fAverageHiGainSectors;
105 delete fAverageLoGainSectors;
106}
107
108// --------------------------------------------------------------------------
109//
110// Get i-th High Gain pixel (pixel number)
111//
112MHGausEvents &MHCalibrationCam::operator[](UInt_t i)
113{
114 return *static_cast<MHGausEvents*>(fHiGainArray->UncheckedAt(i));
115}
116
117// --------------------------------------------------------------------------
118//
119// Get i-th High Gain pixel (pixel number)
120//
121const MHGausEvents &MHCalibrationCam::operator[](UInt_t i) const
122{
123 return *static_cast<MHGausEvents*>(fHiGainArray->UncheckedAt(i));
124}
125
126// --------------------------------------------------------------------------
127//
128// Get i-th Low Gain pixel (pixel number)
129//
130MHGausEvents &MHCalibrationCam::operator()(UInt_t i)
131{
132 return *static_cast<MHGausEvents*>(fLoGainArray->UncheckedAt(i));
133}
134
135// --------------------------------------------------------------------------
136//
137// Get i-th Low Gain pixel (pixel number)
138//
139const MHGausEvents &MHCalibrationCam::operator()(UInt_t i) const
140{
141 return *static_cast<MHGausEvents*>(fLoGainArray->UncheckedAt(i));
142}
143
144// --------------------------------------------------------------------------
145//
146// Get i-th High Gain pixel Area (area number)
147//
148MHGausEvents &MHCalibrationCam::GetAverageHiGainArea(UInt_t i)
149{
150 return *static_cast<MHGausEvents*>(fAverageHiGainAreas->UncheckedAt(i));
151}
152
153// --------------------------------------------------------------------------
154//
155// Get i-th High Gain pixel Area (area number)
156//
157const MHGausEvents &MHCalibrationCam::GetAverageHiGainArea(UInt_t i) const
158{
159 return *static_cast<MHGausEvents *>(fAverageHiGainAreas->UncheckedAt(i));
160}
161
162// --------------------------------------------------------------------------
163//
164// Get i-th Low Gain pixel Area (area number)
165//
166MHGausEvents &MHCalibrationCam::GetAverageLoGainArea(UInt_t i)
167{
168 return *static_cast<MHGausEvents*>(fAverageLoGainAreas->UncheckedAt(i));
169}
170
171// --------------------------------------------------------------------------
172//
173// Get i-th Low Gain pixel Area (area number)
174//
175const MHGausEvents &MHCalibrationCam::GetAverageLoGainArea(UInt_t i) const
176{
177 return *static_cast<MHGausEvents*>(fAverageLoGainAreas->UncheckedAt(i));
178}
179
180// --------------------------------------------------------------------------
181//
182// Get i-th High Gain Sector (sector number)
183//
184MHGausEvents &MHCalibrationCam::GetAverageHiGainSector(UInt_t i)
185{
186 return *static_cast<MHGausEvents*>(fAverageHiGainSectors->UncheckedAt(i));
187}
188
189// --------------------------------------------------------------------------
190//
191// Get i-th High Gain Sector (sector number)
192//
193const MHGausEvents &MHCalibrationCam::GetAverageHiGainSector(UInt_t i) const
194{
195 return *static_cast<MHGausEvents*>(fAverageHiGainSectors->UncheckedAt(i));
196}
197
198// --------------------------------------------------------------------------
199//
200// Get i-th Low Gain Sector (sector number)
201//
202MHGausEvents &MHCalibrationCam::GetAverageLoGainSector(UInt_t i)
203{
204 return *static_cast<MHGausEvents*>(fAverageLoGainSectors->UncheckedAt(i));
205}
206
207// --------------------------------------------------------------------------
208//
209// Get i-th Low Gain Sector (sector number)
210//
211const MHGausEvents &MHCalibrationCam::GetAverageLoGainSector(UInt_t i) const
212{
213 return *static_cast<MHGausEvents*>(fAverageLoGainSectors->UncheckedAt(i));
214}
215
216
217// --------------------------------------------------------------------------
218//
219// Our own clone function is necessary since root 3.01/06 or Mars 0.4
220// I don't know the reason.
221//
222// Creates new MHCalibrationCam
223// Deletes the TObjArray's and Clones them individually
224// Copies the TArray's
225//
226TObject *MHCalibrationCam::Clone(const char *) const
227{
228
229 const Int_t nhi = fHiGainArray->GetEntries();
230 const Int_t nlo = fLoGainArray->GetEntries();
231 const Int_t navhi = fAverageHiGainAreas->GetEntries();
232 const Int_t navlo = fAverageLoGainAreas->GetEntries();
233 const Int_t nsehi = fAverageHiGainSectors->GetEntries();
234 const Int_t nselo = fAverageLoGainSectors->GetEntries();
235
236 //
237 // FIXME, this might be done faster and more elegant, by direct copy.
238 //
239 MHCalibrationCam *cam = new MHCalibrationCam();
240
241 cam->fHiGainArray->Expand(nhi);
242 cam->fLoGainArray->Expand(nlo);
243 cam->fAverageHiGainAreas->Expand(navhi);
244 cam->fAverageLoGainAreas->Expand(navlo);
245 cam->fAverageHiGainSectors->Expand(nsehi);
246 cam->fAverageLoGainSectors->Expand(nselo);
247
248 for (int i=0; i<nhi; i++)
249 {
250 delete (*cam->fHiGainArray)[i];
251 (*cam->fHiGainArray)[i] = (*fHiGainArray)[i]->Clone();
252 }
253 for (int i=0; i<nlo; i++)
254 {
255 delete (*cam->fLoGainArray)[i];
256 (*cam->fLoGainArray)[i] = (*fLoGainArray)[i]->Clone();
257 }
258 for (int i=0; i<navhi; i++)
259 {
260 delete (*cam->fAverageHiGainAreas)[i];
261 (*cam->fAverageHiGainAreas)[i] = (*fAverageHiGainAreas)[i]->Clone();
262 }
263 for (int i=0; i<navlo; i++)
264 {
265 delete (*cam->fAverageLoGainAreas)[i];
266 (*cam->fAverageLoGainAreas)[i] = (*fAverageLoGainAreas)[i]->Clone();
267 }
268 for (int i=0; i<nsehi; i++)
269 {
270 delete (*cam->fAverageHiGainSectors)[i];
271 (*cam->fAverageHiGainSectors)[i] = (*fAverageHiGainSectors)[i]->Clone();
272 }
273 for (int i=0; i<nselo; i++)
274 {
275 delete (*cam->fAverageLoGainSectors)[i];
276 (*cam->fAverageLoGainSectors)[i] = (*fAverageLoGainSectors)[i]->Clone();
277 }
278
279 cam->fAverageAreaNum = fAverageAreaNum;
280 cam->fAverageAreaSat = fAverageAreaSat;
281 cam->fAverageAreaSigma = fAverageAreaSigma;
282 cam->fAverageAreaSigmaErr = fAverageAreaSigmaErr;
283 cam->fAverageAreaRelSigma = fAverageAreaRelSigma;
284 cam->fAverageAreaRelSigmaErr = fAverageAreaRelSigmaErr;
285 cam->fAverageSectorNum = fAverageSectorNum;
286
287 return cam;
288}
289
290// --------------------------------------------------------------------------
291//
292// Dummy, needed by MCamEvent
293//
294Bool_t MHCalibrationCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
295{
296 return kTRUE;
297}
298
299// --------------------------------------------------------------------------
300//
301// What MHCamera needs in order to draw an individual pixel in the camera
302//
303void MHCalibrationCam::DrawPixelContent(Int_t idx) const
304{
305}
306
307// -----------------------------------------------------------------------------
308//
309// Default draw:
310//
311// Displays the averaged areas, both High Gain and Low Gain
312//
313// The following options can be chosen:
314//
315// Calls the Draw of the fAverageHiGainAreas and fAverageLoGainAreas objects with options
316//
317void MHCalibrationCam::Draw(const Option_t *opt)
318{
319
320 const Int_t nareas = fAverageHiGainAreas->GetEntries();
321 if (nareas == 0)
322 return;
323
324 TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas(this);
325 pad->SetBorderMode(0);
326
327 pad->Divide(2,nareas);
328
329 for (Int_t i=0; i<nareas;i++)
330 {
331 pad->cd(2*(i+1)-1);
332 GetAverageHiGainArea(i).Draw(opt);
333
334 if (!fAverageAreaSat[i])
335 DrawAverageSigma(fAverageAreaSat[i], i,
336 fAverageAreaSigma[i], fAverageAreaSigmaErr[i],
337 fAverageAreaRelSigma[i], fAverageAreaRelSigmaErr[i]);
338
339 pad->cd(2*(i+1));
340 GetAverageLoGainArea(i).Draw(opt);
341
342 if (fAverageAreaSat[i])
343 DrawAverageSigma(fAverageAreaSat[i], i,
344 fAverageAreaSigma[i], fAverageAreaSigmaErr[i],
345 fAverageAreaRelSigma[i], fAverageAreaRelSigmaErr[i]);
346 }
347}
348
349// -----------------------------------------------------------------------------
350//
351// Default draw:
352//
353// Displays a TPaveText with the re-normalized sigmas of the average area
354//
355void MHCalibrationCam::DrawAverageSigma(Bool_t sat, Bool_t inner,
356 Float_t sigma, Float_t sigmaerr,
357 Float_t relsigma, Float_t relsigmaerr) const
358{
359
360 if (sigma != 0)
361 {
362
363 TPad *newpad = new TPad("newpad","transparent",0,0,1,1);
364 newpad->SetFillStyle(4000);
365 newpad->Draw();
366 newpad->cd();
367
368 TPaveText *text = new TPaveText(sat? 0.1 : 0.35,0.7,sat ? 0.4 : 0.7,1.0);
369 text->SetTextSize(0.07);
370 const TString line1 = Form("%s%s%s",inner ? "Outer" : "Inner",
371 " Pixels ", sat ? "Low Gain" : "High Gain");
372 TText *txt1 = text->AddText(line1.Data());
373 const TString line2 = Form("#sigma per pix: %2.2f #pm %2.2f",sigma,sigmaerr);
374 TText *txt2 = text->AddText(line2.Data());
375 const TString line3 = Form("Rel. #sigma per pix: %2.2f #pm %2.2f",relsigma,relsigmaerr);
376 TText *txt3 = text->AddText(line3.Data());
377 text->Draw("");
378
379 text->SetBit(kCanDelete);
380 txt1->SetBit(kCanDelete);
381 txt2->SetBit(kCanDelete);
382 txt3->SetBit(kCanDelete);
383 newpad->SetBit(kCanDelete);
384 }
385}
386
Note: See TracBrowser for help on using the repository browser.