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

Last change on this file since 4637 was 4637, checked in by gaug, 20 years ago
*** empty log message ***
File size: 14.8 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
44ClassImp(MBadPixelsCam);
45
46using namespace std;
47
48// --------------------------------------------------------------------------
49//
50// Default constructor.
51//
52MBadPixelsCam::MBadPixelsCam(const char *name, const char *title)
53{
54 fName = name ? name : "MBadPixelsCam";
55 fTitle = title ? title : "Storage container to store bad pixel information";
56
57 fArray = new TClonesArray("MBadPixelsPix", 1);
58}
59
60MBadPixelsCam::MBadPixelsCam(const MBadPixelsCam &cam)
61{
62 fName = "MBadPixelsCam";
63 fTitle = "Storage container to store bad pixel information";
64
65 fArray = new TClonesArray("MBadPixelsPix", 1);
66 cam.Copy(*this);
67}
68
69// --------------------------------------------------------------------------
70//
71// Delete the array conatining the bad pixel information
72//
73MBadPixelsCam::~MBadPixelsCam()
74{
75 delete fArray;
76}
77
78// --------------------------------------------------------------------------
79//
80// Set the size of the camera
81//
82void MBadPixelsCam::InitSize(const UInt_t i)
83{
84 fArray->ExpandCreate(i);
85}
86
87// --------------------------------------------------------------------------
88//
89// Get the size of the MBadPixelsCam
90//
91Int_t MBadPixelsCam::GetSize() const
92{
93 return fArray->GetEntriesFast();
94}
95
96// --------------------------------------------------------------------------
97//
98// Copy 'constructor'
99//
100void MBadPixelsCam::Copy(TObject &object) const
101{
102 MBadPixelsCam &cam = (MBadPixelsCam&)object;
103
104 const Int_t n = GetSize();
105
106 if (n==0)
107 return;
108
109 cam.InitSize(n);
110 for (int i=0; i<n; i++)
111 (*this)[i].Copy(cam[i]);
112}
113
114// --------------------------------------------------------------------------
115//
116// Get i-th pixel (pixel number)
117//
118MBadPixelsPix &MBadPixelsCam::operator[](Int_t i)
119{
120 return *static_cast<MBadPixelsPix*>(fArray->UncheckedAt(i));
121}
122
123// --------------------------------------------------------------------------
124//
125// Get i-th pixel (pixel number)
126//
127const MBadPixelsPix &MBadPixelsCam::operator[](Int_t i) const
128{
129 return *static_cast<MBadPixelsPix*>(fArray->UncheckedAt(i));
130}
131
132// --------------------------------------------------------------------------
133//
134// Merge two MBadPixelsCam together, see also MBadPixelsPix::Merge
135//
136void MBadPixelsCam::Merge(const MBadPixelsCam &cam)
137{
138 const Int_t n = cam.GetSize();
139 if (n==0)
140 {
141 *fLog << warn << "MBadPixelsCam::Merge: Container empty." << endl;
142 return;
143 }
144
145 if (GetSize()==0)
146 InitSize(n);
147
148 if (n!=GetSize())
149 {
150 *fLog << warn << "MBadPixelsCam::Merge: Size mismatch... ignored." << endl;
151 return;
152 }
153
154 for (int i=0; i<n; i++)
155 (*this)[i].Merge(cam[i]);
156}
157
158// --------------------------------------------------------------------------
159//
160// Clear the contents of all bad pixels (set=0 means Ok)
161//
162void MBadPixelsCam::Clear(Option_t *o)
163{
164 fArray->ForEach(TObject, Clear)();
165}
166
167// --------------------------------------------------------------------------
168//
169// Print the contents of all bad pixels
170//
171void MBadPixelsCam::Print(Option_t *o) const
172{
173 *fLog << all << GetDescriptor() << ":" << endl;
174
175 *fLog << "Pixels without problems:" << endl;
176 *fLog << endl;
177
178 Int_t count = 0;
179
180 for (Int_t i=0; i<GetSize(); i++)
181 {
182 if (!(*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
183 {
184 *fLog << i << " ";
185 count ++;
186 }
187
188 if (count == 0)
189 continue;
190
191 if (!(count % 25))
192 *fLog << endl;
193 }
194 *fLog << endl;
195 *fLog << count << " normal pixels :-))" << endl;
196 *fLog << endl;
197 count = 0;
198
199
200 *fLog << "Pixels unsuited for the whole run:" << endl;
201 *fLog << endl;
202
203 for (Int_t i=0; i<GetSize(); i++)
204 {
205 if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
206 {
207 *fLog << i << " ";
208 count ++;
209 }
210
211 if (count == 0)
212 continue;
213
214 if (!(count % 25))
215 *fLog << endl;
216 }
217 *fLog << endl;
218 *fLog << count << " unsuited pixels :-(" << endl;
219 *fLog << endl;
220
221 count = 0;
222
223 *fLog << all << "Pixels unreliable for the whole run:" << endl;
224 *fLog << all << endl;
225
226 for (Int_t i=0; i<GetSize(); i++)
227 {
228 if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnreliableRun))
229 {
230 *fLog << i << " ";
231 count ++;
232 }
233
234 if (count == 0)
235 continue;
236
237 if (!(count % 25))
238 *fLog << endl;
239 }
240
241 *fLog << endl;
242 *fLog << count << " unreliable pixels :-(" << endl;
243 *fLog << endl;
244
245 count = 0;
246
247 *fLog << all << "Charge is Pedestal:" << endl;
248 *fLog << all << endl;
249
250 for (Int_t i=0; i<GetSize(); i++)
251 {
252 if ((*this)[i].IsUncalibrated(MBadPixelsPix::kChargeIsPedestal))
253 {
254 *fLog << i << " ";
255 count ++;
256 }
257
258 if (count == 0)
259 continue;
260
261 if (!(count % 25))
262 *fLog << endl;
263 }
264
265 *fLog << endl;
266 *fLog << count << " ChargeIsPedestal :-(" << endl;
267 *fLog << endl;
268
269 count = 0;
270
271 *fLog << all << "Charge Sigma not valid:" << endl;
272 *fLog << all << endl;
273
274 for (Int_t i=0; i<GetSize(); i++)
275 {
276 if ((*this)[i].IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid))
277 {
278 *fLog << i << " ";
279 count ++;
280 }
281
282 if (count == 0)
283 continue;
284
285 if (!(count % 25))
286 *fLog << endl;
287 }
288
289 *fLog << endl;
290 *fLog << count << " ChargeSigmaNotValid :-(" << endl;
291 *fLog << endl;
292
293 count = 0;
294
295 *fLog << all << "Rel. Error Charge not valid:" << endl;
296 *fLog << all << endl;
297
298 for (Int_t i=0; i<GetSize(); i++)
299 {
300 if ((*this)[i].IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid))
301 {
302 *fLog << i << " ";
303 count ++;
304 }
305
306 if (count == 0)
307 continue;
308
309 if (!(count % 25))
310 *fLog << endl;
311 }
312
313 *fLog << endl;
314 *fLog << count << " ChargeRelErrNotValid :-(" << endl;
315 *fLog << endl;
316
317
318 count = 0;
319
320 *fLog << all << " Deviating number photo-electrons:" << endl;
321 *fLog << all << endl;
322
323 for (Int_t i=0; i<GetSize(); i++)
324 {
325 if ((*this)[i].IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes))
326 {
327 *fLog << i << " ";
328 count ++;
329 }
330
331 if (count == 0)
332 continue;
333
334 if (!(count % 25))
335 *fLog << endl;
336 }
337
338 *fLog << endl;
339 *fLog << count << " DeviatingNumPhes :-(" << endl;
340 *fLog << endl;
341
342 count = 0;
343
344 *fLog << all << " Deviating F-Factor:" << endl;
345 *fLog << all << endl;
346
347 for (Int_t i=0; i<GetSize(); i++)
348 {
349 if ((*this)[i].IsUncalibrated(MBadPixelsPix::kDeviatingFFactor))
350 {
351 *fLog << i << " ";
352 count ++;
353 }
354
355 if (count == 0)
356 continue;
357
358 if (!(count % 25))
359 *fLog << endl;
360 }
361
362 *fLog << endl;
363 *fLog << count << " DeviatingFFactor :-(" << endl;
364 *fLog << endl;
365
366}
367
368// --------------------------------------------------------------------------
369//
370// Read from an ascii file of the format:
371// pixel1 pixel2 pixel3 pixel4
372// while pixel1,2,3,4 are the pixel indices used in the software.
373//
374// To read the pixels corresponding to a given run you can give run!=0
375// and a file of the format:
376// 1234: 17 193 292
377// 1235: 17 193 292 293
378//
379void MBadPixelsCam::AsciiRead(ifstream &fin, UInt_t run=0)
380{
381 Int_t len;
382 TString str;
383
384 while (1)
385 {
386 str.ReadLine(fin);
387 if (!fin)
388 return;
389
390 Int_t r;
391
392 const Int_t n = sscanf(str.Data(), " %d : %n", &r, &len);
393 if (n!=1)
394 return;
395
396 if (run==0 || run && (UInt_t)r==run)
397 break;
398 }
399
400 str.Remove(0, len);
401
402 while (1)
403 {
404 Int_t idx;
405 const Int_t n = sscanf(str.Data(), " %d %n", &idx, &len);
406
407 if (n!=1)
408 break;
409
410 str.Remove(0, len);
411
412 if (idx>=GetSize())
413 InitSize(idx+1);
414
415 (*this)[idx].SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
416 }
417}
418
419// --------------------------------------------------------------------------
420//
421// Write the information into an ascii file. If a run-number is given the
422// run-number will lead the line.
423//
424Bool_t MBadPixelsCam::AsciiWrite(ostream &fout, UInt_t run=0) const
425{
426 if (run)
427 fout << run << ":";
428
429 for (int i=0; i<GetSize(); i++)
430 if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
431 fout << " " << i;
432
433 if (run && GetSize())
434 fout << endl;
435
436 return kTRUE;
437}
438
439// --------------------------------------------------------------------------
440//
441// The types are the following:
442// 0: MBadPixelsPix::GetInfo()[0]
443// 1: MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnsuitableRun)
444// 2: MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnsuitableEvt)
445// 3: MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnreliableRun)
446// 4: MBadPixelsPix::IsHiGainBad()
447// 5: MBadPixelsPix::IsLoGainBad()
448// 6: MBadPixelsPix::GetUnsuitableCalibration()
449// 7: MBadPixelsPix::GetUnreliableCalibration()
450// 8: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainNotFitted)
451// 9: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainNotFitted)
452// 10: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainOscillating)
453// 11: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainOscillating)
454// 12: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainSaturation )
455// 13: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeIsPedestal )
456// 14: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeErrNotValid)
457// 15: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid)
458// 16: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid )
459// 17: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin )
460// 18: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins )
461// 19: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes )
462// 20: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kRelTimeNotFitted )
463// 21: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kRelTimeOscillating )
464//
465Bool_t MBadPixelsCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
466{
467
468 if (idx >= GetSize())
469 return kFALSE;
470
471 switch (type)
472 {
473 case 0:
474 return (*this)[idx].GetInfo()[0];
475 case 1:
476 if ((*this)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
477 val = 1;
478 else
479 return kFALSE;
480 break;
481 case 2:
482 if ((*this)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableEvt))
483 val = 1;
484 else
485 return kFALSE;
486 break;
487 case 3:
488 if ((*this)[idx].IsUnsuitable(MBadPixelsPix::kUnreliableRun))
489 val = 1;
490 else
491 return kFALSE;
492 break;
493 case 4:
494 if ((*this)[idx].IsHiGainBad())
495 val = 1;
496 else
497 return kFALSE;
498 break;
499 case 5:
500 if ((*this)[idx].IsLoGainBad())
501 val = 1;
502 else
503 return kFALSE;
504 break;
505 case 6:
506 if ((*this)[idx].GetUnsuitableCalibration())
507 val = (*this)[idx].GetUnsuitableCalibration();
508 else
509 return kFALSE;
510 break;
511 case 7:
512 if ((*this)[idx].GetUnreliableCalibration())
513 val = (*this)[idx].GetUnreliableCalibration();
514 else
515 return kFALSE;
516 break;
517 case 8:
518 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainNotFitted))
519 val = 1;
520 else
521 return kFALSE;
522 break;
523 case 9:
524 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainNotFitted))
525 val = 1;
526 else
527 return kFALSE;
528 break;
529 case 10:
530 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainOscillating))
531 val = 1;
532 else
533 return kFALSE;
534 break;
535 case 11:
536 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainOscillating))
537 val = 1;
538 else
539 return kFALSE;
540 break;
541 case 12:
542 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainSaturation ))
543 val = 1;
544 else
545 return kFALSE;
546 break;
547 case 13:
548 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeIsPedestal ))
549 val = 1;
550 else
551 return kFALSE;
552 break;
553 case 14:
554 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeErrNotValid))
555 val = 1;
556 else
557 return kFALSE;
558 break;
559 case 15:
560 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid))
561 val = 1;
562 else
563 return kFALSE;
564 break;
565 case 16:
566 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid ))
567 val = 1;
568 else
569 return kFALSE;
570 break;
571 case 17:
572 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin ))
573 val = 1;
574 else
575 return kFALSE;
576 break;
577 case 18:
578 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins ))
579 val = 1;
580 else
581 return kFALSE;
582 break;
583 case 19:
584 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes ))
585 val = 1;
586 else
587 return kFALSE;
588 break;
589 case 20:
590 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kRelTimeNotFitted ))
591 val = 1;
592 else
593 return kFALSE;
594 break;
595 case 21:
596 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kRelTimeOscillating))
597 val = 1;
598 else
599 return kFALSE;
600 break;
601 default:
602 return kFALSE;
603 }
604
605 return kTRUE;
606}
607
608void MBadPixelsCam::DrawPixelContent(Int_t num) const
609{
610 *fLog << warn << "MBadPixelsCam::DrawPixelContent - not available." << endl;
611}
Note: See TracBrowser for help on using the repository browser.