source: tags/Mars-V0.8.6/mbadpixels/MBadPixelsCam.cc

Last change on this file was 5117, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 19.7 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 *fLog << all << GetDescriptor() << ":" << endl;
336
337 *fLog << "Pixels without problems:" << endl;
338 *fLog << endl;
339
340 Int_t count = 0;
341
342 for (Int_t i=0; i<GetSize(); i++)
343 {
344 if (!(*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
345 {
346 *fLog << i << " ";
347 count ++;
348 }
349
350 if (count == 0)
351 continue;
352
353 if (!(count % 25))
354 *fLog << endl;
355 }
356 *fLog << endl;
357 *fLog << count << " normal pixels :-))" << endl;
358 *fLog << endl;
359 count = 0;
360
361
362 *fLog << "Pixels unsuited for the whole run:" << endl;
363 *fLog << endl;
364
365 for (Int_t i=0; i<GetSize(); i++)
366 {
367 if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
368 {
369 *fLog << i << " ";
370 count ++;
371 }
372
373 if (count == 0)
374 continue;
375
376 if (!(count % 25))
377 *fLog << endl;
378 }
379 *fLog << endl;
380 *fLog << count << " unsuited pixels :-(" << endl;
381 *fLog << endl;
382
383 count = 0;
384
385 *fLog << all << "Pixels unreliable for the whole run:" << endl;
386 *fLog << all << endl;
387
388 for (Int_t i=0; i<GetSize(); i++)
389 {
390 if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnreliableRun))
391 {
392 *fLog << i << " ";
393 count ++;
394 }
395
396 if (count == 0)
397 continue;
398
399 if (!(count % 25))
400 *fLog << endl;
401 }
402
403 *fLog << endl;
404 *fLog << count << " unreliable pixels :-(" << endl;
405 *fLog << endl;
406
407 count = 0;
408
409 *fLog << all << "Charge is Pedestal:" << endl;
410 *fLog << all << endl;
411
412 for (Int_t i=0; i<GetSize(); i++)
413 {
414 if ((*this)[i].IsUncalibrated(MBadPixelsPix::kChargeIsPedestal))
415 {
416 *fLog << i << " ";
417 count ++;
418 }
419
420 if (count == 0)
421 continue;
422
423 if (!(count % 25))
424 *fLog << endl;
425 }
426
427 *fLog << endl;
428 *fLog << count << " ChargeIsPedestal :-(" << endl;
429 *fLog << endl;
430
431 count = 0;
432
433 *fLog << all << "Charge Sigma not valid:" << endl;
434 *fLog << all << endl;
435
436 for (Int_t i=0; i<GetSize(); i++)
437 {
438 if ((*this)[i].IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid))
439 {
440 *fLog << i << " ";
441 count ++;
442 }
443
444 if (count == 0)
445 continue;
446
447 if (!(count % 25))
448 *fLog << endl;
449 }
450
451 *fLog << endl;
452 *fLog << count << " ChargeSigmaNotValid :-(" << endl;
453 *fLog << endl;
454
455 count = 0;
456
457 *fLog << all << "Rel. Error Charge not valid:" << endl;
458 *fLog << all << endl;
459
460 for (Int_t i=0; i<GetSize(); i++)
461 {
462 if ((*this)[i].IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid))
463 {
464 *fLog << i << " ";
465 count ++;
466 }
467
468 if (count == 0)
469 continue;
470
471 if (!(count % 25))
472 *fLog << endl;
473 }
474
475 *fLog << endl;
476 *fLog << count << " ChargeRelErrNotValid :-(" << endl;
477 *fLog << endl;
478
479
480 count = 0;
481
482 *fLog << all << " Deviating number photo-electrons:" << endl;
483 *fLog << all << endl;
484
485 for (Int_t i=0; i<GetSize(); i++)
486 {
487 if ((*this)[i].IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes))
488 {
489 *fLog << i << " ";
490 count ++;
491 }
492
493 if (count == 0)
494 continue;
495
496 if (!(count % 25))
497 *fLog << endl;
498 }
499
500 *fLog << endl;
501 *fLog << count << " DeviatingNumPhes :-(" << endl;
502 *fLog << endl;
503
504 count = 0;
505
506 *fLog << all << " Deviating F-Factor:" << endl;
507 *fLog << all << endl;
508
509 for (Int_t i=0; i<GetSize(); i++)
510 {
511 if ((*this)[i].IsUncalibrated(MBadPixelsPix::kDeviatingFFactor))
512 {
513 *fLog << i << " ";
514 count ++;
515 }
516
517 if (count == 0)
518 continue;
519
520 if (!(count % 25))
521 *fLog << endl;
522 }
523
524 *fLog << endl;
525 *fLog << count << " DeviatingFFactor :-(" << endl;
526 *fLog << endl;
527
528}
529
530// --------------------------------------------------------------------------
531//
532// Read from an ascii file of the format:
533// pixel1 pixel2 pixel3 pixel4
534// while pixel1,2,3,4 are the pixel indices used in the software.
535//
536// To read the pixels corresponding to a given run you can give run!=0
537// and a file of the format:
538// 1234: 17 193 292
539// 1235: 17 193 292 293
540//
541void MBadPixelsCam::AsciiRead(istream &fin, UInt_t run=0)
542{
543 Int_t len;
544 TString str;
545
546 while (1)
547 {
548 str.ReadLine(fin);
549 if (!fin)
550 return;
551
552 Int_t r;
553
554 const Int_t n = sscanf(str.Data(), " %d : %n", &r, &len);
555 if (n!=1)
556 return;
557
558 if (run==0 || run && (UInt_t)r==run)
559 break;
560 }
561
562 str.Remove(0, len);
563
564 while (1)
565 {
566 Int_t idx;
567 const Int_t n = sscanf(str.Data(), " %d %n", &idx, &len);
568
569 if (n!=1)
570 break;
571
572 str.Remove(0, len);
573
574 if (idx>=GetSize())
575 InitSize(idx+1);
576
577 (*this)[idx].SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
578 }
579}
580
581// --------------------------------------------------------------------------
582//
583// Write the information into an ascii file. If a run-number is given the
584// run-number will lead the line.
585//
586Bool_t MBadPixelsCam::AsciiWrite(ostream &fout, UInt_t run=0) const
587{
588 if (run)
589 fout << run << ":";
590
591 for (int i=0; i<GetSize(); i++)
592 if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
593 fout << " " << i;
594
595 if (run && GetSize())
596 fout << endl;
597
598 return kTRUE;
599}
600
601// --------------------------------------------------------------------------
602//
603// The types are the following:
604// 0: MBadPixelsPix::GetInfo()[0]
605// 1: MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnsuitableRun)
606// 2: MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnsuitableEvt)
607// 3: MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnreliableRun)
608// 4: MBadPixelsPix::IsHiGainBad()
609// 5: MBadPixelsPix::IsLoGainBad()
610// 6: MBadPixelsPix::GetUnsuitableCalibration()
611// 7: MBadPixelsPix::GetUnreliableCalibration()
612// 8: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainNotFitted)
613// 9: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainNotFitted)
614// 10: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainOscillating)
615// 11: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainOscillating)
616// 12: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainSaturation )
617// 13: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeIsPedestal )
618// 14: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeErrNotValid)
619// 15: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid)
620// 16: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid )
621// 17: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin )
622// 18: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins )
623// 19: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes )
624// 20: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kRelTimeNotFitted )
625// 21: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kRelTimeOscillating )
626// 22: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kDeviatingNumPhots )
627// 23: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainOverFlow )
628// 24: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainOverFlow )
629//
630Bool_t MBadPixelsCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
631{
632
633 if (idx >= GetSize())
634 return kFALSE;
635
636 switch (type)
637 {
638 case 0:
639 return (*this)[idx].GetInfo()[0];
640 case 1:
641 if (!(*this)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
642 return kFALSE;
643 val = 1;
644 break;
645 case 2:
646 if (!(*this)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableEvt))
647 return kFALSE;
648 val = 1;
649 break;
650 case 3:
651 if (!(*this)[idx].IsUnsuitable(MBadPixelsPix::kUnreliableRun))
652 return kFALSE;
653 val = 1;
654 break;
655 case 4:
656 if (!(*this)[idx].IsHiGainBad())
657 return kFALSE;
658 val = 1;
659 break;
660 case 5:
661 if (!(*this)[idx].IsLoGainBad())
662 return kFALSE;
663 val = 1;
664 break;
665 case 6:
666 if ((*this)[idx].GetUnsuitableCalibration())
667 val = (*this)[idx].GetUnsuitableCalibration();
668 else
669 return kFALSE;
670 break;
671 case 7:
672 if ((*this)[idx].GetUnreliableCalibration())
673 val = (*this)[idx].GetUnreliableCalibration();
674 else
675 return kFALSE;
676 break;
677 case 8:
678 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainNotFitted))
679 return kFALSE;
680 val = 1;
681 break;
682 case 9:
683 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainNotFitted))
684 return kFALSE;
685 val = 1;
686 break;
687 case 10:
688 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainOscillating))
689 return kFALSE;
690 val = 1;
691 break;
692 case 11:
693 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainOscillating))
694 return kFALSE;
695 val = 1;
696 break;
697 case 12:
698 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainSaturation ))
699 return kFALSE;
700 val = 1;
701 break;
702 case 13:
703 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeIsPedestal ))
704 return kFALSE;
705 val = 1;
706 break;
707 case 14:
708 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeErrNotValid))
709 return kFALSE;
710 val = 1;
711 break;
712 case 15:
713 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid))
714 return kFALSE;
715 val = 1;
716 break;
717 case 16:
718 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid ))
719 return kFALSE;
720 val = 1;
721 break;
722 case 17:
723 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin ))
724 return kFALSE;
725 val = 1;
726 break;
727 case 18:
728 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins ))
729 return kFALSE;
730 val = 1;
731 break;
732 case 19:
733 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes ))
734 return kFALSE;
735 val = 1;
736 break;
737 case 20:
738 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kRelTimeNotFitted ))
739 return kFALSE;
740 val = 1;
741 break;
742 case 21:
743 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kRelTimeOscillating))
744 return kFALSE;
745 val = 1;
746 break;
747 case 22:
748 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kDeviatingNumPhots))
749 return kFALSE;
750 val = 1;
751 break;
752 case 23:
753 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainOverFlow ))
754 return kFALSE;
755 val = 1;
756 break;
757 case 24:
758 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainOverFlow ))
759 return kFALSE;
760 val = 1;
761 break;
762 default:
763 return kFALSE;
764 }
765
766 return kTRUE;
767}
768
769void MBadPixelsCam::DrawPixelContent(Int_t num) const
770{
771 *fLog << warn << "MBadPixelsCam::DrawPixelContent - not available." << endl;
772}
Note: See TracBrowser for help on using the repository browser.