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

Last change on this file since 3873 was 3851, checked in by gaug, 21 years ago
*** empty log message ***
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(*fArray);
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 if (n==0)
106 return;
107
108 cam.InitSize(n);
109 for (int i=0; i<n; i++)
110 (*this)[i].Copy(cam[i]);
111}
112
113// --------------------------------------------------------------------------
114//
115// Get i-th pixel (pixel number)
116//
117MBadPixelsPix &MBadPixelsCam::operator[](Int_t i)
118{
119 return *static_cast<MBadPixelsPix*>(fArray->UncheckedAt(i));
120}
121
122// --------------------------------------------------------------------------
123//
124// Get i-th pixel (pixel number)
125//
126const MBadPixelsPix &MBadPixelsCam::operator[](Int_t i) const
127{
128 return *static_cast<MBadPixelsPix*>(fArray->UncheckedAt(i));
129}
130
131// --------------------------------------------------------------------------
132//
133// Merge two MBadPixelsCam together, see also MBadPixelsPix::Merge
134//
135void MBadPixelsCam::Merge(const MBadPixelsCam &cam)
136{
137 const Int_t n = cam.GetSize();
138 if (n==0)
139 {
140 *fLog << warn << "MBadPixelsCam::Merge: Container empty." << endl;
141 return;
142 }
143
144 if (GetSize()==0)
145 InitSize(n);
146
147 if (n!=GetSize())
148 {
149 *fLog << warn << "MBadPixelsCam::Merge: Size mismatch... ignored." << endl;
150 return;
151 }
152
153 for (int i=0; i<n; i++)
154 (*this)[i].Merge(cam[i]);
155}
156
157// --------------------------------------------------------------------------
158//
159// Clear the contents of all bad pixels (set=0 means Ok)
160//
161void MBadPixelsCam::Clear(Option_t *o)
162{
163 fArray->ForEach(TObject, Clear)();
164}
165
166// --------------------------------------------------------------------------
167//
168// Print the contents of all bad pixels
169//
170void MBadPixelsCam::Print(Option_t *o) const
171{
172 *fLog << all << GetDescriptor() << ":" << endl;
173
174 *fLog << "Pixels without problems:" << endl;
175 *fLog << endl;
176
177 Int_t count = 0;
178
179 for (Int_t i=0; i<GetSize(); i++)
180 {
181 if (!(*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
182 {
183 *fLog << i << " ";
184 count ++;
185 }
186
187 if (count == 0)
188 continue;
189
190 if (!(count % 25))
191 *fLog << endl;
192 }
193 *fLog << endl;
194 *fLog << count << " normal pixels :-))" << endl;
195 *fLog << endl;
196 count = 0;
197
198
199 *fLog << "Pixels unsuited for the whole run:" << endl;
200 *fLog << endl;
201
202 for (Int_t i=0; i<GetSize(); i++)
203 {
204 if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
205 {
206 *fLog << i << " ";
207 count ++;
208 }
209
210 if (count == 0)
211 continue;
212
213 if (!(count % 25))
214 *fLog << endl;
215 }
216 *fLog << endl;
217 *fLog << count << " unsuited pixels :-(" << endl;
218 *fLog << endl;
219
220 count = 0;
221
222 *fLog << all << "Pixels unreliable for the whole run:" << endl;
223 *fLog << all << endl;
224
225 for (Int_t i=0; i<GetSize(); i++)
226 {
227 if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnreliableRun))
228 {
229 *fLog << i << " ";
230 count ++;
231 }
232
233 if (count == 0)
234 continue;
235
236 if (!(count % 25))
237 *fLog << endl;
238 }
239
240 *fLog << endl;
241 *fLog << count << " unreliable pixels :-(" << endl;
242 *fLog << endl;
243}
244
245// --------------------------------------------------------------------------
246//
247// Read from an ascii file of the format:
248// pixel1 pixel2 pixel3 pixel4
249// while pixel1,2,3,4 are the pixel indices used in the software.
250//
251// To read the pixels corresponding to a given run you can give run!=0
252// and a file of the format:
253// 1234: 17 193 292
254// 1235: 17 193 292 293
255//
256void MBadPixelsCam::AsciiRead(ifstream &fin, UInt_t run=0)
257{
258 Int_t len;
259 TString str;
260
261 while (1)
262 {
263 str.ReadLine(fin);
264 if (!fin)
265 return;
266
267 Int_t r;
268
269 const Int_t n = sscanf(str.Data(), " %d : %n", &r, &len);
270 if (n!=1)
271 return;
272
273 if (run==0 || run && (UInt_t)r==run)
274 break;
275 }
276
277 str.Remove(0, len);
278
279 while (1)
280 {
281 Int_t idx;
282 const Int_t n = sscanf(str.Data(), " %d %n", &idx, &len);
283
284 if (n!=1)
285 break;
286
287 str.Remove(0, len);
288
289 if (idx>=GetSize())
290 InitSize(idx+1);
291
292 (*this)[idx].SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
293 }
294}
295
296// --------------------------------------------------------------------------
297//
298// Write the information into an ascii file. If a run-number is given the
299// run-number will lead the line.
300//
301Bool_t MBadPixelsCam::AsciiWrite(ostream &fout, UInt_t run=0) const
302{
303 if (run)
304 fout << run << ":";
305
306 for (int i=0; i<GetSize(); i++)
307 if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
308 fout << " " << i;
309
310 if (run && GetSize())
311 fout << endl;
312
313 return kTRUE;
314}
315
316// --------------------------------------------------------------------------
317//
318// The types are the following:
319// 0: MBadPixelsPix::GetInfo()[0]
320// 1: MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnsuitableRun)
321// 2: MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnsuitableEvt)
322// 3: MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnreliableRun)
323// 4: MBadPixelsPix::IsHiGainBad()
324// 5: MBadPixelsPix::IsLoGainBad()
325// 8: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainNotFitted)
326// 9: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainNotFitted)
327// 10: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainOscillating)
328// 11: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainOscillating)
329// 12: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainSaturation )
330// 13: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeIsPedestal )
331// 14: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeErrNotValid)
332// 15: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid)
333// 16: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid )
334// 17: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin )
335// 18: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins )
336// 19: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes )
337// 20: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kRelTimeNotFitted )
338// 21: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kRelTimeOscillating )
339//
340Bool_t MBadPixelsCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
341{
342
343 if (idx >= GetSize())
344 return kFALSE;
345
346 switch (type)
347 {
348 case 0:
349 return (*this)[idx].GetInfo()[0];
350 case 1:
351 if ((*this)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
352 val = 1;
353 else
354 return kFALSE;
355 break;
356 case 2:
357 if ((*this)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableEvt))
358 val = 1;
359 else
360 return kFALSE;
361 break;
362 case 3:
363 if ((*this)[idx].IsUnsuitable(MBadPixelsPix::kUnreliableRun))
364 val = 1;
365 else
366 return kFALSE;
367 break;
368 case 4:
369 if ((*this)[idx].IsHiGainBad())
370 val = 1;
371 else
372 return kFALSE;
373 break;
374 case 5:
375 if ((*this)[idx].IsLoGainBad())
376 val = 1;
377 else
378 return kFALSE;
379 break;
380 case 8:
381 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainNotFitted))
382 val = 1;
383 else
384 return kFALSE;
385 break;
386 case 9:
387 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainNotFitted))
388 val = 1;
389 else
390 return kFALSE;
391 break;
392 case 10:
393 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainOscillating))
394 val = 1;
395 else
396 return kFALSE;
397 break;
398 case 11:
399 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainOscillating))
400 val = 1;
401 else
402 return kFALSE;
403 break;
404 case 12:
405 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainSaturation ))
406 val = 1;
407 else
408 return kFALSE;
409 break;
410 case 13:
411 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeIsPedestal ))
412 val = 1;
413 else
414 return kFALSE;
415 break;
416 case 14:
417 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeErrNotValid))
418 val = 1;
419 else
420 return kFALSE;
421 break;
422 case 15:
423 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid))
424 val = 1;
425 else
426 return kFALSE;
427 break;
428 case 16:
429 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid ))
430 val = 1;
431 else
432 return kFALSE;
433 break;
434 case 17:
435 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin ))
436 val = 1;
437 else
438 return kFALSE;
439 break;
440 case 18:
441 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins ))
442 val = 1;
443 else
444 return kFALSE;
445 break;
446 case 19:
447 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes ))
448 val = 1;
449 else
450 return kFALSE;
451 break;
452 case 20:
453 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kRelTimeNotFitted ))
454 val = 1;
455 else
456 return kFALSE;
457 break;
458 case 21:
459 if ((*this)[idx].IsUncalibrated(MBadPixelsPix::kRelTimeOscillating))
460 val = 1;
461 else
462 return kFALSE;
463 break;
464 default:
465 return kFALSE;
466 }
467
468 return kTRUE;
469}
470
471void MBadPixelsCam::DrawPixelContent(Int_t num) const
472{
473 *fLog << warn << "MBadPixelsCam::DrawPixelContent - not available." << endl;
474}
Note: See TracBrowser for help on using the repository browser.