source: trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc@ 6612

Last change on this file since 6612 was 5047, checked in by gaug, 20 years ago
*** empty log message ***
File size: 15.4 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 11/2003 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MCalibrationCam
28//
29// Base class for Camera Calibration results.
30//
31// Contains TOrdCollections for the following objects:
32// - fPixels: Array of classes derived from MCalibrationPix, one entry
33// per pixel. Has to be created
34// - fAverageAreas: Array of classes derived from MCalibrationPix, one entry
35// per pixel AREA. Has to be created
36// - fAverageSectors: Array of classes derived from MCalibrationPix, one entry
37// per camera SECTOR. Has to be created
38//
39// - fAverageBadAreas: Array of classes derived from MBadPixelsPix, one entry
40// per pixel AREA. Is created automatically.
41// - fAverageBadSectors: Array of classes derived from MBadPixelsPix, one entry
42// per camera SECTOR. Is created automatically.
43//
44// All TOrdCollections have to enlarged by the corresponding calls to (e.g. in MGeomApply):
45// - InitSize()
46// - InitAverageAreas()
47// - InitAverageSectors()
48//
49/////////////////////////////////////////////////////////////////////////////
50#include "MCalibrationCam.h"
51
52#include <TOrdCollection.h>
53
54#include "MGeomCam.h"
55#include "MGeomPix.h"
56
57#include "MBadPixelsCam.h"
58#include "MBadPixelsPix.h"
59
60#include "MCalibrationPix.h"
61
62#include "MLog.h"
63#include "MLogManip.h"
64
65ClassImp(MCalibrationCam);
66
67using namespace std;
68
69const Int_t MCalibrationCam::gkNumPulserColors = 4;
70// --------------------------------------------------------------------------
71//
72// Default constructor.
73//
74// Set the following pointer to NULL:
75// - fPixels
76// - fAverageAreas
77// - fAverageSectors
78//
79// Initializes:
80// - fPulserColor to kNONE
81// - fNumHiGainFADCSlices to 0.
82// - fNumLoGainFADCSlices to 0.
83//
84// Creates a TOrdCollection of MBadPixelsPix containers for the TOrdCollection's:
85// - fAverageBadAreas
86// - fAverageBadSectors
87// all initialized to 1 entry
88//
89// Later, a call to InitAverageAreas() and InitAverageSectors() (or Init())
90// has to be performed in order to get the dimension correctly.
91//
92MCalibrationCam::MCalibrationCam(const char *name, const char *title)
93 : fPulserColor(kNONE)
94{
95
96 fPixels = new TOrdCollection;
97 fPixels->SetOwner();
98
99 fAverageAreas = new TOrdCollection;
100 fAverageAreas->SetOwner();
101
102 fAverageSectors = new TOrdCollection;
103 fAverageSectors->SetOwner();
104
105 fAverageBadAreas = new TOrdCollection;
106 fAverageBadAreas->SetOwner();
107
108 fAverageBadSectors = new TOrdCollection;
109 fAverageBadSectors->SetOwner();
110
111 fNumHiGainFADCSlices.Set(1);
112 fNumLoGainFADCSlices.Set(1);
113}
114
115// --------------------------------------------------------------------------
116//
117// Deletes the following TOrdCollection's of MCalibrationPix containers (if exist):
118// - fPixels
119// - fAverageAreas
120// - fAverageSectors
121//
122// Deletes the following TOrdCollection's of MBadPixelsPix containers (if exist):
123// - fAverageBadAreas
124// - fAverageBadSectors
125//
126MCalibrationCam::~MCalibrationCam()
127{
128
129 //
130 // delete fPixels should delete all Objects stored inside
131 //
132 if (fPixels)
133 delete fPixels;
134
135 if (fAverageAreas)
136 delete fAverageAreas;
137
138 if (fAverageSectors)
139 delete fAverageSectors;
140
141 if (fAverageBadAreas)
142 delete fAverageBadAreas;
143
144 if (fAverageBadSectors)
145 delete fAverageBadSectors;
146
147}
148
149// --------------------------------------
150//
151// Calls the ForEach macro for the TOrdCollection fPixels with the argument Clear()
152//
153// Loops over the fAverageAreas, calling the function Clear() for
154// every entry in:
155// - fAverageAreas
156// - fAverageBadAreas
157//
158// Loops over the fAverageSectors, calling the function Clear() for
159// every entry in:
160// - fAverageSectors
161// - fAverageBadSectors
162//
163void MCalibrationCam::Clear(Option_t *o)
164{
165
166 { fPixels ->ForEach(TObject, Clear)(); }
167 { fAverageAreas ->ForEach(TObject, Clear)(); }
168 { fAverageSectors->ForEach(TObject, Clear)(); }
169
170 return;
171}
172
173// --------------------------------------------------------------------------
174//
175// Copy 'constructor'
176//
177void MCalibrationCam::Copy(TObject& object) const
178{
179
180 MCalibrationCam &calib = (MCalibrationCam&)object;
181
182 MParContainer::Copy(calib);
183
184 calib.fPulserColor = fPulserColor;
185
186 const Int_t n = GetSize();
187 if (n != 0)
188 {
189 calib.InitSize(n);
190 for (int i=0; i<n; i++)
191 (*this)[i].Copy(calib[i]);
192 }
193
194 const Int_t n2 = GetAverageAreas();
195 if (n2 != 0)
196 {
197 calib.InitAverageAreas(n2);
198 for (int i=0; i<n2; i++)
199 {
200 GetAverageArea (i).Copy(calib.GetAverageArea(i));
201 GetAverageBadArea(i).Copy(calib.GetAverageBadArea(i));
202 calib.fNumUnsuitable [i] = fNumUnsuitable[i];
203 calib.fNumUnreliable [i] = fNumUnreliable[i];
204 calib.fNumHiGainFADCSlices[i] = fNumHiGainFADCSlices[i];
205 calib.fNumLoGainFADCSlices[i] = fNumLoGainFADCSlices[i];
206 }
207 }
208
209 const Int_t n3 = GetAverageSectors();
210 if (n3 != 0)
211 {
212 calib.InitAverageSectors(n3);
213 for (int i=0; i<n3; i++)
214 {
215 GetAverageSector (i).Copy(calib.GetAverageSector(i));
216 GetAverageBadSector(i).Copy(calib.GetAverageBadSector(i));
217 }
218 }
219}
220
221// -------------------------------------------------------------------
222//
223// Initialize the objects inside the TOrdCollection using the
224// virtual function Add().
225//
226//
227// InitSize can only increase the size, but not shrink.
228//
229// It can be called more than one time. New Containers are
230// added only from the current size to the argument i.
231//
232void MCalibrationCam::InitSize(const UInt_t i)
233{
234
235 const UInt_t save = GetSize();
236
237 if (i==save)
238 return;
239
240 if (i>save)
241 Add(save,i);
242}
243
244void MCalibrationCam::Add(const UInt_t a, const UInt_t b)
245{
246 for (UInt_t i=a; i<b; i++)
247 fPixels->AddAt(new MCalibrationPix,i);
248}
249
250void MCalibrationCam::AddArea(const UInt_t a, const UInt_t b)
251{
252 for (UInt_t i=a; i<b; i++)
253 fAverageAreas->AddAt(new MCalibrationPix,i);
254}
255
256void MCalibrationCam::AddSector(const UInt_t a, const UInt_t b)
257{
258 for (UInt_t i=a; i<b; i++)
259 fAverageSectors->AddAt(new MCalibrationPix,i);
260}
261
262
263// -------------------------------------------------------------------
264//
265// Initialize the objects inside the TOrdCollections
266// - fAverageAreas
267// - fAverageBadAreas
268// using the virtual function Add().
269//
270// InitSize can only increase the size, but not shrink.
271//
272// It can be called more than one time. New Containers are
273// added only from the current size to the argument i.
274//
275void MCalibrationCam::InitAverageAreas(const UInt_t i)
276{
277
278 const UInt_t save = GetAverageAreas();
279
280 if (i==save)
281 return;
282
283 fNumUnsuitable.Set(i);
284 fNumUnreliable.Set(i);
285 fNumHiGainFADCSlices.Set(i);
286 fNumLoGainFADCSlices.Set(i);
287
288 if (i < save)
289 return;
290
291 for (UInt_t j=save; j<i; j++)
292 fAverageBadAreas->AddAt(new MBadPixelsPix,j);
293
294 AddArea(save,i);
295
296 for (UInt_t j=save; j<i; j++)
297 GetAverageArea(j).SetPixId(j);
298
299}
300
301// -------------------------------------------------------------------
302//
303// Initialize the objects inside the TOrdCollections
304// - fAverageSectors
305// - fAverageBadSectors
306// using the virtual function Add().
307//
308// InitSize can only increase the size, but not shrink.
309//
310// It can be called more than one time. New Containers are
311// added only from the current size to the argument i.
312//
313void MCalibrationCam::InitAverageSectors(const UInt_t i)
314{
315
316 const UInt_t save = GetAverageSectors();
317
318 if (i==save)
319 return;
320
321 if (i < save)
322 return;
323
324 for (UInt_t j=save; j<i; j++)
325 fAverageBadSectors->AddAt(new MBadPixelsPix,j);
326
327 AddSector(save,i);
328
329 for (UInt_t j=save; j<i; j++)
330 GetAverageSector(j).SetPixId(j);
331}
332
333// -------------------------------------------------------------------
334//
335// Calls:
336// - InitSize()
337// - InitAverageAreas()
338// - InitAverageSectors()
339//
340void MCalibrationCam::Init(const MGeomCam &geom)
341{
342 InitSize (geom.GetNumPixels() );
343 InitAverageAreas (geom.GetNumAreas() );
344 InitAverageSectors(geom.GetNumSectors());
345}
346
347// --------------------------------------------------------------------------
348//
349// Returns the number of un-suitable pixels per area index and -1 if
350// the area index exceeds the initialized array.
351//
352const Int_t MCalibrationCam::GetNumUnsuitable( const Int_t aidx ) const
353{
354 if (aidx < 0)
355 {
356 Int_t num = 0;
357 for (Int_t i=0;i<fNumUnsuitable.GetSize();i++)
358 num += fNumUnsuitable[i];
359 return num;
360 }
361
362 return aidx > fNumUnsuitable.GetSize() ? -1 : fNumUnsuitable[aidx];
363}
364
365// --------------------------------------------------------------------------
366//
367// Returns the number of un-reliable pixels per area index and -1 if
368// the area index exceeds the initialized array.
369//
370const Int_t MCalibrationCam::GetNumUnreliable( const Int_t aidx ) const
371{
372 if (aidx < 0)
373 {
374 Int_t num = 0;
375 for (Int_t i=0;i<fNumUnreliable.GetSize();i++)
376 num += fNumUnreliable[i];
377 return num;
378 }
379
380 return aidx > fNumUnreliable.GetSize() ? -1 : fNumUnreliable[aidx];
381}
382
383// --------------------------------------------------------------------------
384//
385// Returns the mean number of High-Gain FADC slices per area index and -1 if
386// the area index exceeds the initialized array.
387//
388const Float_t MCalibrationCam::GetNumHiGainFADCSlices( const Int_t aidx ) const
389{
390 if (aidx < 0)
391 return -1;
392
393 return aidx > fNumHiGainFADCSlices.GetSize() ? -1 : fNumHiGainFADCSlices[aidx];
394}
395
396// --------------------------------------------------------------------------
397//
398// Returns the mean number of Low-Gain FADC slices per area index and -1 if
399// the area index exceeds the initialized array.
400//
401const Float_t MCalibrationCam::GetNumLoGainFADCSlices( const Int_t aidx ) const
402{
403 if (aidx < 0)
404 return -1;
405
406 return aidx > fNumLoGainFADCSlices.GetSize() ? -1 : fNumLoGainFADCSlices[aidx];
407}
408
409
410
411// --------------------------------------------------------------------------
412//
413// Returns the current size of the TOrdCollection fAverageAreas
414// independently if the MCalibrationPix is filled with values or not.
415//
416const Int_t MCalibrationCam::GetAverageAreas() const
417{
418 return fAverageAreas->GetSize();
419}
420
421// --------------------------------------------------------------------------
422//
423// Returns the current size of the TOrdCollection fAverageSectors
424// independently if the MCalibrationPix is filled with values or not.
425//
426const Int_t MCalibrationCam::GetAverageSectors() const
427{
428 return fAverageSectors->GetSize();
429}
430
431
432// --------------------------------------------------------------------------
433//
434// Get i-th pixel (pixel number)
435//
436MCalibrationPix &MCalibrationCam::operator[](UInt_t i)
437{
438 return *static_cast<MCalibrationPix*>(fPixels->At(i));
439}
440
441// --------------------------------------------------------------------------
442//
443// Get i-th pixel (pixel number)
444//
445const MCalibrationPix &MCalibrationCam::operator[](UInt_t i) const
446{
447 return *static_cast<MCalibrationPix*>(fPixels->At(i));
448}
449
450// --------------------------------------------------------------------------
451//
452// Returns the current size of the TOrdCollection fPixels
453// independently if the MCalibrationPix is filled with values or not.
454//
455const Int_t MCalibrationCam::GetSize() const
456{
457 return fPixels->GetSize();
458}
459
460// --------------------------------------------------------------------------
461//
462// Get i-th average pixel (area number)
463//
464MCalibrationPix &MCalibrationCam::GetAverageArea(const UInt_t i)
465{
466 return *static_cast<MCalibrationPix*>(fAverageAreas->At(i));
467}
468
469// --------------------------------------------------------------------------
470//
471// Get i-th average pixel (area number)
472//
473const MCalibrationPix &MCalibrationCam::GetAverageArea(const UInt_t i) const
474{
475 return *static_cast<MCalibrationPix*>(fAverageAreas->At(i));
476}
477
478// --------------------------------------------------------------------------
479//
480// Get i-th average pixel (sector number)
481//
482MCalibrationPix &MCalibrationCam::GetAverageSector(const UInt_t i)
483{
484 return *static_cast<MCalibrationPix*>(fAverageSectors->At(i));
485}
486
487// --------------------------------------------------------------------------
488//
489// Get i-th average pixel (sector number)
490//
491const MCalibrationPix &MCalibrationCam::GetAverageSector(const UInt_t i) const
492{
493 return *static_cast<MCalibrationPix*>(fAverageSectors->At(i));
494}
495
496// --------------------------------------------------------------------------
497//
498// Get i-th average pixel (area number)
499//
500MBadPixelsPix &MCalibrationCam::GetAverageBadArea(const UInt_t i)
501{
502 return *static_cast<MBadPixelsPix*>(fAverageBadAreas->At(i));
503}
504
505// --------------------------------------------------------------------------
506//
507// Get i-th average pixel (area number)
508//
509const MBadPixelsPix &MCalibrationCam::GetAverageBadArea(const UInt_t i) const
510{
511 return *static_cast<MBadPixelsPix*>(fAverageBadAreas->At(i));
512}
513
514// --------------------------------------------------------------------------
515//
516// Get i-th average pixel (sector number)
517//
518MBadPixelsPix &MCalibrationCam::GetAverageBadSector(const UInt_t i)
519{
520 return *static_cast<MBadPixelsPix*>(fAverageBadSectors->At(i));
521}
522
523// --------------------------------------------------------------------------
524//
525// Get i-th average pixel (sector number)
526//
527const MBadPixelsPix &MCalibrationCam::GetAverageBadSector(const UInt_t i) const
528{
529 return *static_cast<MBadPixelsPix*>(fAverageBadSectors->At(i));
530}
531
532
533
534// --------------------------------------------------------------------------
535//
536// Dummy needed for compilation with MCamEvent
537//
538Bool_t MCalibrationCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
539{
540 return kTRUE;
541}
542
543
544
545// --------------------------------------------------------------------------
546//
547// Calls MCalibrationPix::DrawClone()
548//
549void MCalibrationCam::DrawPixelContent(Int_t idx) const
550{
551 (*this)[idx].DrawClone();
552}
553
554void MCalibrationCam::SetNumHiGainFADCSlices( const Float_t i, const Int_t aidx)
555{
556 if (aidx < 0)
557 return;
558
559 if (aidx < fNumHiGainFADCSlices.GetSize())
560 fNumHiGainFADCSlices[aidx] = i;
561}
562
563void MCalibrationCam::SetNumLoGainFADCSlices( const Float_t i, const Int_t aidx)
564{
565 if (aidx < 0)
566 return;
567 if (aidx < fNumLoGainFADCSlices.GetSize())
568 fNumLoGainFADCSlices[aidx] = i;
569}
570
571void MCalibrationCam::SetNumUnsuitable( const UInt_t i, const Int_t aidx)
572{
573 if (aidx < 0)
574 return;
575
576 if (aidx < fNumUnsuitable.GetSize())
577 fNumUnsuitable[aidx] = i;
578}
579
580void MCalibrationCam::SetNumUnreliable( const UInt_t i, const Int_t aidx)
581{
582 if (aidx < 0)
583 return;
584 if (aidx < fNumUnreliable.GetSize())
585 fNumUnreliable[aidx] = i;
586}
Note: See TracBrowser for help on using the repository browser.