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

Last change on this file since 4262 was 4217, checked in by merck, 20 years ago
MMerck: Changed copy constructor to call Copy method with a reference to this as argument.
File size: 12.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
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
246// --------------------------------------------------------------------------
247//
248// Read from an ascii file of the format:
249// pixel1 pixel2 pixel3 pixel4
250// while pixel1,2,3,4 are the pixel indices used in the software.
251//
252// To read the pixels corresponding to a given run you can give run!=0
253// and a file of the format:
254// 1234: 17 193 292
255// 1235: 17 193 292 293
256//
257void MBadPixelsCam::AsciiRead(ifstream &fin, UInt_t run=0)
258{
259 Int_t len;
260 TString str;
261
262 while (1)
263 {
264 str.ReadLine(fin);
265 if (!fin)
266 return;
267
268 Int_t r;
269
270 const Int_t n = sscanf(str.Data(), " %d : %n", &r, &len);
271 if (n!=1)
272 return;
273
274 if (run==0 || run && (UInt_t)r==run)
275 break;
276 }
277
278 str.Remove(0, len);
279
280 while (1)
281 {
282 Int_t idx;
283 const Int_t n = sscanf(str.Data(), " %d %n", &idx, &len);
284
285 if (n!=1)
286 break;
287
288 str.Remove(0, len);
289
290 if (idx>=GetSize())
291 InitSize(idx+1);
292
293 (*this)[idx].SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
294 }
295}
296
297// --------------------------------------------------------------------------
298//
299// Write the information into an ascii file. If a run-number is given the
300// run-number will lead the line.
301//
302Bool_t MBadPixelsCam::AsciiWrite(ostream &fout, UInt_t run=0) const
303{
304 if (run)
305 fout << run << ":";
306
307 for (int i=0; i<GetSize(); i++)
308 if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
309 fout << " " << i;
310
311 if (run && GetSize())
312 fout << endl;
313
314 return kTRUE;
315}
316
317// --------------------------------------------------------------------------
318//
319// The types are the following:
320// 0: MBadPixelsPix::GetInfo()[0]
321// 1: MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnsuitableRun)
322// 2: MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnsuitableEvt)
323// 3: MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnreliableRun)
324// 4: MBadPixelsPix::IsHiGainBad()
325// 5: MBadPixelsPix::IsLoGainBad()
326// 8: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainNotFitted)
327// 9: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainNotFitted)
328// 10: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainOscillating)
329// 11: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainOscillating)
330// 12: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainSaturation )
331// 13: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeIsPedestal )
332// 14: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeErrNotValid)
333// 15: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid)
334// 16: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid )
335// 17: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin )
336// 18: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins )
337// 19: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes )
338// 20: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kRelTimeNotFitted )
339// 21: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kRelTimeOscillating )
340//
341Bool_t MBadPixelsCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
342{
343
344 if (idx >= GetSize())
345 return kFALSE;
346
347 switch (type)
348 {
349 case 0:
350 return (*this)[idx].GetInfo()[0];
351 case 1:
352 if ((*this)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
353 val = 1;
354 else
355 return kFALSE;
356 break;
357 case 2:
358 if ((*this)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableEvt))
359 val = 1;
360 else
361 return kFALSE;
362 break;
363 case 3:
364 if ((*this)[idx].IsUnsuitable(MBadPixelsPix::kUnreliableRun))
365 val = 1;
366 else
367 return kFALSE;
368 break;
369 case 4:
370 if ((*this)[idx].IsHiGainBad())
371 val = 1;
372 else
373 return kFALSE;
374 break;
375 case 5:
376 if ((*this)[idx].IsLoGainBad())
377 val = 1;
378 else
379 return kFALSE;
380 break;
381 case 8:
382 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainNotFitted))
383 val = 1;
384 else
385 return kFALSE;
386 break;
387 case 9:
388 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainNotFitted))
389 val = 1;
390 else
391 return kFALSE;
392 break;
393 case 10:
394 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainOscillating))
395 val = 1;
396 else
397 return kFALSE;
398 break;
399 case 11:
400 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainOscillating))
401 val = 1;
402 else
403 return kFALSE;
404 break;
405 case 12:
406 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainSaturation ))
407 val = 1;
408 else
409 return kFALSE;
410 break;
411 case 13:
412 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeIsPedestal ))
413 val = 1;
414 else
415 return kFALSE;
416 break;
417 case 14:
418 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeErrNotValid))
419 val = 1;
420 else
421 return kFALSE;
422 break;
423 case 15:
424 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid))
425 val = 1;
426 else
427 return kFALSE;
428 break;
429 case 16:
430 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid ))
431 val = 1;
432 else
433 return kFALSE;
434 break;
435 case 17:
436 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin ))
437 val = 1;
438 else
439 return kFALSE;
440 break;
441 case 18:
442 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins ))
443 val = 1;
444 else
445 return kFALSE;
446 break;
447 case 19:
448 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes ))
449 val = 1;
450 else
451 return kFALSE;
452 break;
453 case 20:
454 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kRelTimeNotFitted ))
455 val = 1;
456 else
457 return kFALSE;
458 break;
459 case 21:
460 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kRelTimeOscillating))
461 val = 1;
462 else
463 return kFALSE;
464 break;
465 default:
466 return kFALSE;
467 }
468
469 return kTRUE;
470}
471
472void MBadPixelsCam::DrawPixelContent(Int_t num) const
473{
474 *fLog << warn << "MBadPixelsCam::DrawPixelContent - not available." << endl;
475}
Note: See TracBrowser for help on using the repository browser.