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

Last change on this file since 4693 was 4679, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 19.1 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 <fstream>
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// Calculate the number of pixels with the given type-flags.
173//
174// The second argument aidx is the area index (see MGeomCam, MGeomPix)
175// The default (or any value less than 0) means: all
176//
177// Returns -1 if the geometry doesn't match.
178//
179Short_t MBadPixelsCam::GetNumUnsuitable(MBadPixelsPix::UnsuitableType_t type, const MGeomCam *geom, Int_t aidx) const
180{
181 const UInt_t n = GetSize();
182
183 if (aidx>=0 && geom->GetNumPixels()!=n)
184 {
185 *fLog << err << GetDescriptor() << "ERROR - Geometry (" << geom->ClassName() << ") size mismatch!" << endl;
186 return -1;
187 }
188
189 Short_t rc = 0;
190 for (UInt_t i=0; i<n; i++)
191 {
192 if (aidx>=0 && (*geom)[i].GetAidx()!=aidx)
193 continue;
194
195 if ((*this)[i].IsUnsuitable(type))
196 rc++;
197 }
198 return rc;
199}
200
201// --------------------------------------------------------------------------
202//
203// Counts the number of neighbors matching NOT UnsuitableType type
204//
205Short_t MBadPixelsCam::GetNumSuitableNeighbors(MBadPixelsPix::UnsuitableType_t type, const MGeomPix &pix) const
206{
207 const Int_t n2 = pix.GetNumNeighbors();
208
209 Int_t cnt=0;
210 for (int j=0; j<n2; j++)
211 {
212 const Int_t id2 = pix.GetNeighbor(j);
213 if (!(*this)[id2].IsUnsuitable(type))
214 cnt++;
215 }
216
217 return cnt;
218}
219
220// --------------------------------------------------------------------------
221//
222// Calculate the number of pixels which are - under no circumstances -
223// interpolatable, called isolated. This means that a pixel (its own status
224// doesn't matter) has less than two reliable neighbor pixels.
225//
226// The second argument aidx is the area index (see MGeomCam, MGeomPix)
227// The default (or any value less than 0) means: all
228//
229// Returns -1 if the geometry doesn't match.
230//
231Short_t MBadPixelsCam::GetNumIsolated(MBadPixelsPix::UnsuitableType_t type, const MGeomCam &geom, Int_t aidx) const
232{
233 const Int_t n = geom.GetNumPixels();
234
235 if (n!=GetSize())
236 {
237 *fLog << err << GetDescriptor() << "ERROR - Geometry (" << geom.ClassName() << ") size mismatch!" << endl;
238 return -1;
239 }
240
241 Short_t rc = 0;
242 for (int i=0; i<n; i++)
243 {
244 const MGeomPix &pix = geom[i];
245 if (aidx>=0 && pix.GetAidx()!=aidx)
246 continue;
247
248 if (GetNumSuitableNeighbors(type, pix)<2)
249 rc++;
250 }
251 return rc;
252}
253
254// --------------------------------------------------------------------------
255//
256// This is a helper function which calculates the size of a single cluster
257// by iterative calling.
258//
259// If a pixel matches the criterias the counter is increased by 1 and
260// the function is called for all its neighbors. If
261//
262// The second argument aidx is the area index (see MGeomCam, MGeomPix)
263// The default (or any value less than 0) means: all
264//
265// Returns -1 if the geometry doesn't match.
266//
267Short_t MBadPixelsCam::GetNumMaxCluster(MBadPixelsPix::UnsuitableType_t type, TObjArray &list, Int_t idx, Int_t aidx) const
268{
269 const MGeomPix *pix = (MGeomPix*)list[idx];
270 if (!pix)
271 return 0;
272
273 if (GetNumSuitableNeighbors(type, *pix)>1)
274 return 0;
275
276 if (aidx>=0 && pix->GetAidx()!=aidx)
277 return 1;
278
279 list.RemoveAt(idx);
280
281 Short_t cnt = 1;
282 const Int_t n = pix->GetNumNeighbors();
283 for (int i=0; i<n; i++)
284 cnt += GetNumMaxCluster(type, list, pix->GetNeighbor(i), aidx);
285
286 return cnt;
287}
288
289// --------------------------------------------------------------------------
290//
291// Returns the size of the biggest cluster with the given USuitableType
292// type and the given area index.
293//
294// The second argument aidx is the area index (see MGeomCam, MGeomPix)
295// The default (or any value less than 0) means: all
296//
297// Returns -1 if the geometry doesn't match.
298//
299Short_t MBadPixelsCam::GetNumMaxCluster(MBadPixelsPix::UnsuitableType_t type, const MGeomCam &geom, Int_t aidx) const
300{
301 const Int_t n = geom.GetNumPixels();
302
303 if (n!=GetSize())
304 {
305 *fLog << err << GetDescriptor() << "ERROR - Geometry (" << geom.ClassName() << ") size mismatch!" << endl;
306 return -1;
307 }
308
309 TObjArray list(n);
310 for (int i=0; i<n; i++)
311 list.AddAt(&geom[i], i);
312
313 Short_t max = 0;
314 for (int i=0; i<n; i++)
315 max = TMath::Max(GetNumMaxCluster(type, list, i, aidx), max);
316
317 return max;
318}
319
320// --------------------------------------------------------------------------
321//
322// Print the contents of all bad pixels
323//
324void MBadPixelsCam::Print(Option_t *o) const
325{
326 *fLog << all << GetDescriptor() << ":" << endl;
327
328 *fLog << "Pixels without problems:" << endl;
329 *fLog << endl;
330
331 Int_t count = 0;
332
333 for (Int_t i=0; i<GetSize(); i++)
334 {
335 if (!(*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
336 {
337 *fLog << i << " ";
338 count ++;
339 }
340
341 if (count == 0)
342 continue;
343
344 if (!(count % 25))
345 *fLog << endl;
346 }
347 *fLog << endl;
348 *fLog << count << " normal pixels :-))" << endl;
349 *fLog << endl;
350 count = 0;
351
352
353 *fLog << "Pixels unsuited for the whole run:" << endl;
354 *fLog << endl;
355
356 for (Int_t i=0; i<GetSize(); i++)
357 {
358 if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
359 {
360 *fLog << i << " ";
361 count ++;
362 }
363
364 if (count == 0)
365 continue;
366
367 if (!(count % 25))
368 *fLog << endl;
369 }
370 *fLog << endl;
371 *fLog << count << " unsuited pixels :-(" << endl;
372 *fLog << endl;
373
374 count = 0;
375
376 *fLog << all << "Pixels unreliable for the whole run:" << endl;
377 *fLog << all << endl;
378
379 for (Int_t i=0; i<GetSize(); i++)
380 {
381 if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnreliableRun))
382 {
383 *fLog << i << " ";
384 count ++;
385 }
386
387 if (count == 0)
388 continue;
389
390 if (!(count % 25))
391 *fLog << endl;
392 }
393
394 *fLog << endl;
395 *fLog << count << " unreliable pixels :-(" << endl;
396 *fLog << endl;
397
398 count = 0;
399
400 *fLog << all << "Charge is Pedestal:" << endl;
401 *fLog << all << endl;
402
403 for (Int_t i=0; i<GetSize(); i++)
404 {
405 if ((*this)[i].IsUncalibrated(MBadPixelsPix::kChargeIsPedestal))
406 {
407 *fLog << i << " ";
408 count ++;
409 }
410
411 if (count == 0)
412 continue;
413
414 if (!(count % 25))
415 *fLog << endl;
416 }
417
418 *fLog << endl;
419 *fLog << count << " ChargeIsPedestal :-(" << endl;
420 *fLog << endl;
421
422 count = 0;
423
424 *fLog << all << "Charge Sigma not valid:" << endl;
425 *fLog << all << endl;
426
427 for (Int_t i=0; i<GetSize(); i++)
428 {
429 if ((*this)[i].IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid))
430 {
431 *fLog << i << " ";
432 count ++;
433 }
434
435 if (count == 0)
436 continue;
437
438 if (!(count % 25))
439 *fLog << endl;
440 }
441
442 *fLog << endl;
443 *fLog << count << " ChargeSigmaNotValid :-(" << endl;
444 *fLog << endl;
445
446 count = 0;
447
448 *fLog << all << "Rel. Error Charge not valid:" << endl;
449 *fLog << all << endl;
450
451 for (Int_t i=0; i<GetSize(); i++)
452 {
453 if ((*this)[i].IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid))
454 {
455 *fLog << i << " ";
456 count ++;
457 }
458
459 if (count == 0)
460 continue;
461
462 if (!(count % 25))
463 *fLog << endl;
464 }
465
466 *fLog << endl;
467 *fLog << count << " ChargeRelErrNotValid :-(" << endl;
468 *fLog << endl;
469
470
471 count = 0;
472
473 *fLog << all << " Deviating number photo-electrons:" << endl;
474 *fLog << all << endl;
475
476 for (Int_t i=0; i<GetSize(); i++)
477 {
478 if ((*this)[i].IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes))
479 {
480 *fLog << i << " ";
481 count ++;
482 }
483
484 if (count == 0)
485 continue;
486
487 if (!(count % 25))
488 *fLog << endl;
489 }
490
491 *fLog << endl;
492 *fLog << count << " DeviatingNumPhes :-(" << endl;
493 *fLog << endl;
494
495 count = 0;
496
497 *fLog << all << " Deviating F-Factor:" << endl;
498 *fLog << all << endl;
499
500 for (Int_t i=0; i<GetSize(); i++)
501 {
502 if ((*this)[i].IsUncalibrated(MBadPixelsPix::kDeviatingFFactor))
503 {
504 *fLog << i << " ";
505 count ++;
506 }
507
508 if (count == 0)
509 continue;
510
511 if (!(count % 25))
512 *fLog << endl;
513 }
514
515 *fLog << endl;
516 *fLog << count << " DeviatingFFactor :-(" << endl;
517 *fLog << endl;
518
519}
520
521// --------------------------------------------------------------------------
522//
523// Read from an ascii file of the format:
524// pixel1 pixel2 pixel3 pixel4
525// while pixel1,2,3,4 are the pixel indices used in the software.
526//
527// To read the pixels corresponding to a given run you can give run!=0
528// and a file of the format:
529// 1234: 17 193 292
530// 1235: 17 193 292 293
531//
532void MBadPixelsCam::AsciiRead(ifstream &fin, UInt_t run=0)
533{
534 Int_t len;
535 TString str;
536
537 while (1)
538 {
539 str.ReadLine(fin);
540 if (!fin)
541 return;
542
543 Int_t r;
544
545 const Int_t n = sscanf(str.Data(), " %d : %n", &r, &len);
546 if (n!=1)
547 return;
548
549 if (run==0 || run && (UInt_t)r==run)
550 break;
551 }
552
553 str.Remove(0, len);
554
555 while (1)
556 {
557 Int_t idx;
558 const Int_t n = sscanf(str.Data(), " %d %n", &idx, &len);
559
560 if (n!=1)
561 break;
562
563 str.Remove(0, len);
564
565 if (idx>=GetSize())
566 InitSize(idx+1);
567
568 (*this)[idx].SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
569 }
570}
571
572// --------------------------------------------------------------------------
573//
574// Write the information into an ascii file. If a run-number is given the
575// run-number will lead the line.
576//
577Bool_t MBadPixelsCam::AsciiWrite(ostream &fout, UInt_t run=0) const
578{
579 if (run)
580 fout << run << ":";
581
582 for (int i=0; i<GetSize(); i++)
583 if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
584 fout << " " << i;
585
586 if (run && GetSize())
587 fout << endl;
588
589 return kTRUE;
590}
591
592// --------------------------------------------------------------------------
593//
594// The types are the following:
595// 0: MBadPixelsPix::GetInfo()[0]
596// 1: MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnsuitableRun)
597// 2: MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnsuitableEvt)
598// 3: MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnreliableRun)
599// 4: MBadPixelsPix::IsHiGainBad()
600// 5: MBadPixelsPix::IsLoGainBad()
601// 6: MBadPixelsPix::GetUnsuitableCalibration()
602// 7: MBadPixelsPix::GetUnreliableCalibration()
603// 8: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainNotFitted)
604// 9: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainNotFitted)
605// 10: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainOscillating)
606// 11: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainOscillating)
607// 12: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainSaturation )
608// 13: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeIsPedestal )
609// 14: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeErrNotValid)
610// 15: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid)
611// 16: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid )
612// 17: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin )
613// 18: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins )
614// 19: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes )
615// 20: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kRelTimeNotFitted )
616// 21: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kRelTimeOscillating )
617// 22: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kDeviatingNumPhots )
618//
619Bool_t MBadPixelsCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
620{
621
622 if (idx >= GetSize())
623 return kFALSE;
624
625 switch (type)
626 {
627 case 0:
628 return (*this)[idx].GetInfo()[0];
629 case 1:
630 if (!(*this)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
631 return kFALSE;
632 val = 1;
633 break;
634 case 2:
635 if (!(*this)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableEvt))
636 return kFALSE;
637 val = 1;
638 break;
639 case 3:
640 if (!(*this)[idx].IsUnsuitable(MBadPixelsPix::kUnreliableRun))
641 return kFALSE;
642 val = 1;
643 break;
644 case 4:
645 if (!(*this)[idx].IsHiGainBad())
646 return kFALSE;
647 val = 1;
648 break;
649 case 5:
650 if (!(*this)[idx].IsLoGainBad())
651 return kFALSE;
652 val = 1;
653 break;
654 case 6:
655 if ((*this)[idx].GetUnsuitableCalibration())
656 val = (*this)[idx].GetUnsuitableCalibration();
657 else
658 return kFALSE;
659 break;
660 case 7:
661 if ((*this)[idx].GetUnreliableCalibration())
662 val = (*this)[idx].GetUnreliableCalibration();
663 else
664 return kFALSE;
665 break;
666 case 8:
667 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainNotFitted))
668 return kFALSE;
669 val = 1;
670 break;
671 case 9:
672 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainNotFitted))
673 return kFALSE;
674 val = 1;
675 break;
676 case 10:
677 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainOscillating))
678 return kFALSE;
679 val = 1;
680 break;
681 case 11:
682 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainOscillating))
683 return kFALSE;
684 val = 1;
685 break;
686 case 12:
687 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainSaturation ))
688 return kFALSE;
689 val = 1;
690 break;
691 case 13:
692 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeIsPedestal ))
693 return kFALSE;
694 val = 1;
695 break;
696 case 14:
697 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeErrNotValid))
698 return kFALSE;
699 val = 1;
700 break;
701 case 15:
702 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid))
703 return kFALSE;
704 val = 1;
705 break;
706 case 16:
707 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid ))
708 return kFALSE;
709 val = 1;
710 break;
711 case 17:
712 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin ))
713 return kFALSE;
714 val = 1;
715 break;
716 case 18:
717 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins ))
718 return kFALSE;
719 val = 1;
720 break;
721 case 19:
722 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes ))
723 return kFALSE;
724 val = 1;
725 break;
726 case 20:
727 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kRelTimeNotFitted ))
728 return kFALSE;
729 val = 1;
730 break;
731 case 21:
732 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kRelTimeOscillating))
733 return kFALSE;
734 val = 1;
735 break;
736 case 22:
737 if (!(*this)[idx].IsUncalibrated(MBadPixelsPix::kDeviatingNumPhots))
738 return kFALSE;
739 val = 1;
740 break;
741 default:
742 return kFALSE;
743 }
744
745 return kTRUE;
746}
747
748void MBadPixelsCam::DrawPixelContent(Int_t num) const
749{
750 *fLog << warn << "MBadPixelsCam::DrawPixelContent - not available." << endl;
751}
Note: See TracBrowser for help on using the repository browser.