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

Last change on this file since 4527 was 4342, checked in by gaug, 20 years ago
*** empty log message ***
File size: 14.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): 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// 8: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainNotFitted)
449// 9: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainNotFitted)
450// 10: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainOscillating)
451// 11: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainOscillating)
452// 12: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainSaturation )
453// 13: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeIsPedestal )
454// 14: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeErrNotValid)
455// 15: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid)
456// 16: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid )
457// 17: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin )
458// 18: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins )
459// 19: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes )
460// 20: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kRelTimeNotFitted )
461// 21: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kRelTimeOscillating )
462//
463Bool_t MBadPixelsCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
464{
465
466 if (idx >= GetSize())
467 return kFALSE;
468
469 switch (type)
470 {
471 case 0:
472 return (*this)[idx].GetInfo()[0];
473 case 1:
474 if ((*this)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
475 val = 1;
476 else
477 return kFALSE;
478 break;
479 case 2:
480 if ((*this)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableEvt))
481 val = 1;
482 else
483 return kFALSE;
484 break;
485 case 3:
486 if ((*this)[idx].IsUnsuitable(MBadPixelsPix::kUnreliableRun))
487 val = 1;
488 else
489 return kFALSE;
490 break;
491 case 4:
492 if ((*this)[idx].IsHiGainBad())
493 val = 1;
494 else
495 return kFALSE;
496 break;
497 case 5:
498 if ((*this)[idx].IsLoGainBad())
499 val = 1;
500 else
501 return kFALSE;
502 break;
503 case 8:
504 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainNotFitted))
505 val = 1;
506 else
507 return kFALSE;
508 break;
509 case 9:
510 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainNotFitted))
511 val = 1;
512 else
513 return kFALSE;
514 break;
515 case 10:
516 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainOscillating))
517 val = 1;
518 else
519 return kFALSE;
520 break;
521 case 11:
522 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainOscillating))
523 val = 1;
524 else
525 return kFALSE;
526 break;
527 case 12:
528 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainSaturation ))
529 val = 1;
530 else
531 return kFALSE;
532 break;
533 case 13:
534 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeIsPedestal ))
535 val = 1;
536 else
537 return kFALSE;
538 break;
539 case 14:
540 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeErrNotValid))
541 val = 1;
542 else
543 return kFALSE;
544 break;
545 case 15:
546 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid))
547 val = 1;
548 else
549 return kFALSE;
550 break;
551 case 16:
552 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid ))
553 val = 1;
554 else
555 return kFALSE;
556 break;
557 case 17:
558 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin ))
559 val = 1;
560 else
561 return kFALSE;
562 break;
563 case 18:
564 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins ))
565 val = 1;
566 else
567 return kFALSE;
568 break;
569 case 19:
570 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes ))
571 val = 1;
572 else
573 return kFALSE;
574 break;
575 case 20:
576 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kRelTimeNotFitted ))
577 val = 1;
578 else
579 return kFALSE;
580 break;
581 case 21:
582 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kRelTimeOscillating))
583 val = 1;
584 else
585 return kFALSE;
586 break;
587 default:
588 return kFALSE;
589 }
590
591 return kTRUE;
592}
593
594void MBadPixelsCam::DrawPixelContent(Int_t num) const
595{
596 *fLog << warn << "MBadPixelsCam::DrawPixelContent - not available." << endl;
597}
Note: See TracBrowser for help on using the repository browser.