source: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.cc@ 5468

Last change on this file since 5468 was 5463, checked in by gaug, 20 years ago
*** empty log message ***
File size: 19.5 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): Thomas Bretz 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Markus Gaug 3/2004 <mailto:markus@ifae.es>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MBadPixelsCam //
29//
30// Storage container to store bad pixel of the camera...
31//
32/////////////////////////////////////////////////////////////////////////////
33#include "MBadPixelsCam.h"
34
35#include <iostream>
36
37#include <TClonesArray.h>
38
39#include "MLog.h"
40#include "MLogManip.h"
41
42#include "MBadPixelsPix.h"
43
44#include "MGeomCam.h"
45#include "MGeomPix.h"
46
47ClassImp(MBadPixelsCam);
48
49using namespace std;
50
51// --------------------------------------------------------------------------
52//
53// Default constructor.
54//
55MBadPixelsCam::MBadPixelsCam(const char *name, const char *title)
56{
57 fName = name ? name : "MBadPixelsCam";
58 fTitle = title ? title : "Storage container to store bad pixel information";
59
60 fArray = new TClonesArray("MBadPixelsPix", 1);
61}
62
63MBadPixelsCam::MBadPixelsCam(const MBadPixelsCam &cam)
64{
65 fName = "MBadPixelsCam";
66 fTitle = "Storage container to store bad pixel information";
67
68 fArray = new TClonesArray("MBadPixelsPix", 1);
69 cam.Copy(*this);
70}
71
72// --------------------------------------------------------------------------
73//
74// Delete the array conatining the bad pixel information
75//
76MBadPixelsCam::~MBadPixelsCam()
77{
78 delete fArray;
79}
80
81// --------------------------------------------------------------------------
82//
83// Set the size of the camera
84//
85void MBadPixelsCam::InitSize(const UInt_t i)
86{
87 fArray->ExpandCreate(i);
88}
89
90// --------------------------------------------------------------------------
91//
92// Get the size of the MBadPixelsCam
93//
94Int_t MBadPixelsCam::GetSize() const
95{
96 return fArray->GetEntriesFast();
97}
98
99// --------------------------------------------------------------------------
100//
101// Copy 'constructor'
102//
103void MBadPixelsCam::Copy(TObject &object) const
104{
105 MBadPixelsCam &cam = (MBadPixelsCam&)object;
106
107 const Int_t n = GetSize();
108
109 if (n==0)
110 return;
111
112 cam.InitSize(n);
113 for (int i=0; i<n; i++)
114 (*this)[i].Copy(cam[i]);
115}
116
117// --------------------------------------------------------------------------
118//
119// Get i-th pixel (pixel number)
120//
121MBadPixelsPix &MBadPixelsCam::operator[](Int_t i)
122{
123 return *static_cast<MBadPixelsPix*>(fArray->UncheckedAt(i));
124}
125
126// --------------------------------------------------------------------------
127//
128// Get i-th pixel (pixel number)
129//
130const MBadPixelsPix &MBadPixelsCam::operator[](Int_t i) const
131{
132 return *static_cast<MBadPixelsPix*>(fArray->UncheckedAt(i));
133}
134
135// --------------------------------------------------------------------------
136//
137// Merge two MBadPixelsCam together, see also MBadPixelsPix::Merge
138//
139void MBadPixelsCam::Merge(const MBadPixelsCam &cam)
140{
141 const Int_t n = cam.GetSize();
142 if (n==0)
143 {
144 *fLog << warn << "MBadPixelsCam::Merge: Container empty." << endl;
145 return;
146 }
147
148 if (GetSize()==0)
149 InitSize(n);
150
151 if (n!=GetSize())
152 {
153 *fLog << warn << "MBadPixelsCam::Merge: Size mismatch... ignored." << endl;
154 return;
155 }
156
157 for (int i=0; i<n; i++)
158 (*this)[i].Merge(cam[i]);
159}
160
161// --------------------------------------------------------------------------
162//
163// Clear the contents of all bad pixels (set=0 means Ok)
164//
165void MBadPixelsCam::Clear(Option_t *o)
166{
167 fArray->ForEach(TObject, Clear)();
168}
169
170// --------------------------------------------------------------------------
171//
172// Reset event depending bits
173//
174void MBadPixelsCam::Reset()
175{
176 fArray->ForEach(MParContainer, Reset)();
177}
178
179// --------------------------------------------------------------------------
180//
181// Calculate the number of pixels with the given type-flags.
182//
183// The second argument aidx is the area index (see MGeomCam, MGeomPix)
184// The default (or any value less than 0) means: all
185//
186// Returns -1 if the geometry doesn't match.
187//
188Short_t MBadPixelsCam::GetNumUnsuitable(MBadPixelsPix::UnsuitableType_t type, const MGeomCam *geom, Int_t aidx) const
189{
190 const UInt_t n = GetSize();
191
192 if (aidx>=0 && geom->GetNumPixels()!=n)
193 {
194 *fLog << err << GetDescriptor() << "ERROR - Geometry (" << geom->ClassName() << ") size mismatch!" << endl;
195 return -1;
196 }
197
198 Short_t rc = 0;
199 for (UInt_t i=0; i<n; i++)
200 {
201 if (aidx>=0 && (*geom)[i].GetAidx()!=aidx)
202 continue;
203
204 if ((*this)[i].IsUnsuitable(type))
205 rc++;
206 }
207 return rc;
208}
209
210// --------------------------------------------------------------------------
211//
212// Counts the number of neighbors matching NOT UnsuitableType type
213//
214Short_t MBadPixelsCam::GetNumSuitableNeighbors(MBadPixelsPix::UnsuitableType_t type, const MGeomPix &pix) const
215{
216 const Int_t n2 = pix.GetNumNeighbors();
217
218 Int_t cnt=0;
219 for (int j=0; j<n2; j++)
220 {
221 const Int_t id2 = pix.GetNeighbor(j);
222 if (!(*this)[id2].IsUnsuitable(type))
223 cnt++;
224 }
225
226 return cnt;
227}
228
229// --------------------------------------------------------------------------
230//
231// Calculate the number of pixels which are - under no circumstances -
232// interpolatable, called isolated. This means that a pixel (its own status
233// doesn't matter) has less than two reliable neighbor pixels.
234//
235// The second argument aidx is the area index (see MGeomCam, MGeomPix)
236// The default (or any value less than 0) means: all
237//
238// Returns -1 if the geometry doesn't match.
239//
240Short_t MBadPixelsCam::GetNumIsolated(MBadPixelsPix::UnsuitableType_t type, const MGeomCam &geom, Int_t aidx) const
241{
242 const Int_t n = geom.GetNumPixels();
243
244 if (n!=GetSize())
245 {
246 *fLog << err << GetDescriptor() << "ERROR - Geometry (" << geom.ClassName() << ") size mismatch!" << endl;
247 return -1;
248 }
249
250 Short_t rc = 0;
251 for (int i=0; i<n; i++)
252 {
253 const MGeomPix &pix = geom[i];
254 if (aidx>=0 && pix.GetAidx()!=aidx)
255 continue;
256
257 if (GetNumSuitableNeighbors(type, pix)<2)
258 rc++;
259 }
260 return rc;
261}
262
263// --------------------------------------------------------------------------
264//
265// This is a helper function which calculates the size of a single cluster
266// by iterative calling.
267//
268// If a pixel matches the criterias the counter is increased by 1 and
269// the function is called for all its neighbors. If
270//
271// The second argument aidx is the area index (see MGeomCam, MGeomPix)
272// The default (or any value less than 0) means: all
273//
274// Returns -1 if the geometry doesn't match.
275//
276Short_t MBadPixelsCam::GetNumMaxCluster(MBadPixelsPix::UnsuitableType_t type, TObjArray &list, Int_t idx, Int_t aidx) const
277{
278 const MGeomPix *pix = (MGeomPix*)list[idx];
279 if (!pix)
280 return 0;
281
282 if (GetNumSuitableNeighbors(type, *pix)>1)
283 return 0;
284
285 if (aidx>=0 && pix->GetAidx()!=aidx)
286 return 1;
287
288 list.RemoveAt(idx);
289
290 Short_t cnt = 1;
291 const Int_t n = pix->GetNumNeighbors();
292 for (int i=0; i<n; i++)
293 cnt += GetNumMaxCluster(type, list, pix->GetNeighbor(i), aidx);
294
295 return cnt;
296}
297
298// --------------------------------------------------------------------------
299//
300// Returns the size of the biggest cluster with the given USuitableType
301// type and the given area index.
302//
303// The second argument aidx is the area index (see MGeomCam, MGeomPix)
304// The default (or any value less than 0) means: all
305//
306// Returns -1 if the geometry doesn't match.
307//
308Short_t MBadPixelsCam::GetNumMaxCluster(MBadPixelsPix::UnsuitableType_t type, const MGeomCam &geom, Int_t aidx) const
309{
310 const Int_t n = geom.GetNumPixels();
311
312 if (n!=GetSize())
313 {
314 *fLog << err << GetDescriptor() << "ERROR - Geometry (" << geom.ClassName() << ") size mismatch!" << endl;
315 return -1;
316 }
317
318 TObjArray list(n);
319 for (int i=0; i<n; i++)
320 list.AddAt(&geom[i], i);
321
322 Short_t max = 0;
323 for (int i=0; i<n; i++)
324 max = TMath::Max(GetNumMaxCluster(type, list, i, aidx), max);
325
326 return max;
327}
328
329// --------------------------------------------------------------------------
330//
331// Print the contents of all bad pixels
332//
333void MBadPixelsCam::Print(Option_t *o) const
334{
335
336 *fLog << all << GetDescriptor() << ":" << endl;
337 *fLog << "Pixels without problems:" << endl;
338
339 Int_t count = 0;
340
341 for (Int_t i=0; i<GetSize(); i++)
342 {
343 if (!(*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
344 {
345 *fLog << i << " ";
346 count ++;
347 }
348
349 if (count == 0)
350 continue;
351
352 if (!(count % 25))
353 *fLog << endl;
354 }
355 *fLog << count << " normal pixels" << endl;
356 *fLog << endl;
357
358 *fLog << "Pixels unsuited for the whole run:" << endl;
359
360 for (Int_t i=0; i<GetSize(); i++)
361 {
362 if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
363 {
364 *fLog << i << " ";
365 count ++;
366 }
367
368 if (count == 0)
369 continue;
370
371 if (!(count % 25))
372 *fLog << endl;
373 }
374
375 *fLog << count << " unsuited pixels :-(" << endl;
376 *fLog << endl;
377
378 count = 0;
379
380 *fLog << all << "Pixels unreliable for the whole run:" << endl;
381
382 for (Int_t i=0; i<GetSize(); i++)
383 {
384 if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnreliableRun))
385 {
386 *fLog << i << " ";
387 count ++;
388 }
389
390 if (count == 0)
391 continue;
392
393 if (!(count % 25))
394 *fLog << endl;
395 }
396
397 *fLog << count << " unreliable pixels :-(" << endl;
398 *fLog << endl;
399 *fLog << endl;
400 *fLog << all << "Unsuited pixels statistics:" << endl;
401 *fLog << endl;
402
403 PrintBadPixels(MBadPixelsPix::kChargeIsPedestal,"Signal smaller 3 Pedestal RMS");
404 PrintBadPixels(MBadPixelsPix::kChargeSigmaNotValid,"Signal smaller 3 Pedestal RMS");
405 PrintBadPixels(MBadPixelsPix::kChargeRelErrNotValid,"Signal Rel. error too large");
406 PrintBadPixels(MBadPixelsPix::kLoGainSaturation,"Low Gain Saturation");
407 PrintBadPixels(MBadPixelsPix::kMeanTimeInFirstBin,"Mean Arr. Time In First Extraction Bin");
408 PrintBadPixels(MBadPixelsPix::kMeanTimeInLast2Bins,"Mean Arr. Time In Last 2 Extraction Bins");
409 PrintBadPixels(MBadPixelsPix::kDeviatingNumPhes,"Deviating Number of Photo-electrons");
410 PrintBadPixels(MBadPixelsPix::kDeviatingNumPhots,"Deviating Number of Photons");
411 PrintBadPixels(MBadPixelsPix::kHiGainOverFlow,"High-Gain Histogram Overflow");
412 PrintBadPixels(MBadPixelsPix::kLoGainOverFlow,"Low-Gain Histogram Overflow");
413
414 *fLog << endl;
415 *fLog << all << "Unreliable pixels statistics:" << endl;
416 *fLog << endl;
417
418 PrintBadPixels(MBadPixelsPix::kChargeSigmaNotValid,"Signal Sigma smaller Pedestal RMS");
419 PrintBadPixels(MBadPixelsPix::kHiGainNotFitted ,"High Gain Signals could not be fitted");
420 PrintBadPixels(MBadPixelsPix::kLoGainNotFitted ,"Low Gain Signals could not be fitted");
421 PrintBadPixels(MBadPixelsPix::kRelTimeNotFitted ,"Relative Arr. Times could not be fitted");
422 PrintBadPixels(MBadPixelsPix::kHiGainOscillating ,"High Gain Signals Oscillation");
423 PrintBadPixels(MBadPixelsPix::kLoGainOscillating ,"Low Gain Signals Oscillation");
424 PrintBadPixels(MBadPixelsPix::kRelTimeOscillating ,"Relative Arr. Times Oscillation");
425 PrintBadPixels(MBadPixelsPix::kDeviatingFFactor ,"Deviating global F-Factor");
426}
427
428void MBadPixelsCam::PrintBadPixels( MBadPixelsPix::UncalibratedType_t typ, const char *text) const
429{
430
431
432 *fLog << "Pixels with " << text << ": " << endl;
433 UInt_t count = 0;
434
435 for (Int_t i=0; i<GetSize(); i++)
436 {
437 if ((*this)[i].IsUncalibrated(typ))
438 {
439 *fLog << i << " ";
440 count++;
441 }
442
443 if (count == 0)
444 continue;
445
446 if (!(count % 25))
447 *fLog << endl;
448 }
449
450 *fLog << Form("%3i",count) << " pixels in total " << endl;
451 *fLog << endl;
452}
453
454// --------------------------------------------------------------------------
455//
456// Read from an ascii file of the format:
457// pixel1 pixel2 pixel3 pixel4
458// while pixel1,2,3,4 are the pixel indices used in the software.
459//
460// To read the pixels corresponding to a given run you can give run!=0
461// and a file of the format:
462// 1234: 17 193 292
463// 1235: 17 193 292 293
464//
465void MBadPixelsCam::AsciiRead(istream &fin, UInt_t run=0)
466{
467 Int_t len;
468 TString str;
469
470 while (1)
471 {
472 str.ReadLine(fin);
473 if (!fin)
474 return;
475
476 Int_t r;
477
478 const Int_t n = sscanf(str.Data(), " %d : %n", &r, &len);
479 if (n!=1)
480 return;
481
482 if (run==0 || run && (UInt_t)r==run)
483 break;
484 }
485
486 str.Remove(0, len);
487
488 while (1)
489 {
490 Int_t idx;
491 const Int_t n = sscanf(str.Data(), " %d %n", &idx, &len);
492
493 if (n!=1)
494 break;
495
496 str.Remove(0, len);
497
498 if (idx>=GetSize())
499 InitSize(idx+1);
500
501 (*this)[idx].SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
502 }
503}
504
505// --------------------------------------------------------------------------
506//
507// Write the information into an ascii file. If a run-number is given the
508// run-number will lead the line.
509//
510Bool_t MBadPixelsCam::AsciiWrite(ostream &fout, UInt_t run=0) const
511{
512 if (run)
513 fout << run << ":";
514
515 for (int i=0; i<GetSize(); i++)
516 if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
517 fout << " " << i;
518
519 if (run && GetSize())
520 fout << endl;
521
522 return kTRUE;
523}
524
525// --------------------------------------------------------------------------
526//
527// The types are the following:
528// 0: MBadPixelsPix::GetInfo()[0]
529// 1: MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnsuitableRun)
530// 2: MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnsuitableEvt)
531// 3: MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnreliableRun)
532// 4: MBadPixelsPix::IsHiGainBad()
533// 5: MBadPixelsPix::IsLoGainBad()
534// 6: MBadPixelsPix::GetUnsuitableCalibration()
535// 7: MBadPixelsPix::GetUnreliableCalibration()
536// 8: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainNotFitted)
537// 9: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainNotFitted)
538// 10: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainOscillating)
539// 11: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainOscillating)
540// 12: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainSaturation )
541// 13: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeIsPedestal )
542// 14: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeErrNotValid)
543// 15: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid)
544// 16: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid )
545// 17: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin )
546// 18: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins )
547// 19: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes )
548// 20: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kRelTimeNotFitted )
549// 21: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kRelTimeOscillating )
550// 22: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kDeviatingNumPhots )
551// 23: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainOverFlow )
552// 24: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainOverFlow )
553//
554Bool_t MBadPixelsCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
555{
556
557 if (idx >= GetSize())
558 return kFALSE;
559
560 switch (type)
561 {
562 case 0:
563 return (*this)[idx].GetInfo()[0];
564 case 1:
565 if (!(*this)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
566 return kFALSE;
567 val = 1;
568 break;
569 case 2:
570 if (!(*this)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableEvt))
571 return kFALSE;
572 val = 1;
573 break;
574 case 3:
575 if (!(*this)[idx].IsUnsuitable(MBadPixelsPix::kUnreliableRun))
576 return kFALSE;
577 val = 1;
578 break;
579 case 4:
580 if (!(*this)[idx].IsHiGainBad())
581 return kFALSE;
582 val = 1;
583 break;
584 case 5:
585 if (!(*this)[idx].IsLoGainBad())
586 return kFALSE;
587 val = 1;
588 break;
589 case 6:
590 if ((*this)[idx].GetUnsuitableCalibration())
591 val = (*this)[idx].GetUnsuitableCalibration();
592 else
593 return kFALSE;
594 break;
595 case 7:
596 if ((*this)[idx].GetUnreliableCalibration())
597 val = (*this)[idx].GetUnreliableCalibration();
598 else
599 return kFALSE;
600 break;
601 case 8:
602 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainNotFitted))
603 return kFALSE;
604 val = 1;
605 break;
606 case 9:
607 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainNotFitted))
608 return kFALSE;
609 val = 1;
610 break;
611 case 10:
612 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainOscillating))
613 return kFALSE;
614 val = 1;
615 break;
616 case 11:
617 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainOscillating))
618 return kFALSE;
619 val = 1;
620 break;
621 case 12:
622 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainSaturation ))
623 return kFALSE;
624 val = 1;
625 break;
626 case 13:
627 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeIsPedestal ))
628 return kFALSE;
629 val = 1;
630 break;
631 case 14:
632 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeErrNotValid))
633 return kFALSE;
634 val = 1;
635 break;
636 case 15:
637 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid))
638 return kFALSE;
639 val = 1;
640 break;
641 case 16:
642 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid ))
643 return kFALSE;
644 val = 1;
645 break;
646 case 17:
647 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin ))
648 return kFALSE;
649 val = 1;
650 break;
651 case 18:
652 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins ))
653 return kFALSE;
654 val = 1;
655 break;
656 case 19:
657 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes ))
658 return kFALSE;
659 val = 1;
660 break;
661 case 20:
662 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kRelTimeNotFitted ))
663 return kFALSE;
664 val = 1;
665 break;
666 case 21:
667 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kRelTimeOscillating))
668 return kFALSE;
669 val = 1;
670 break;
671 case 22:
672 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kDeviatingNumPhots))
673 return kFALSE;
674 val = 1;
675 break;
676 case 23:
677 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainOverFlow ))
678 return kFALSE;
679 val = 1;
680 break;
681 case 24:
682 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainOverFlow ))
683 return kFALSE;
684 val = 1;
685 break;
686 default:
687 return kFALSE;
688 }
689
690 return kTRUE;
691}
692
693void MBadPixelsCam::DrawPixelContent(Int_t num) const
694{
695 *fLog << warn << "MBadPixelsCam::DrawPixelContent - not available." << endl;
696}
Note: See TracBrowser for help on using the repository browser.