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

Last change on this file since 3473 was 3473, checked in by gaug, 21 years ago
*** empty log message ***
File size: 9.6 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!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MBadPixelsCam //
28//
29// Storage container to store bad pixel of the camera...
30//
31/////////////////////////////////////////////////////////////////////////////
32#include "MBadPixelsCam.h"
33
34#include <fstream>
35
36#include <TClonesArray.h>
37
38#include "MLog.h"
39#include "MLogManip.h"
40
41#include "MBadPixelsPix.h"
42
43ClassImp(MBadPixelsCam);
44
45using namespace std;
46
47// --------------------------------------------------------------------------
48//
49// Default constructor.
50//
51MBadPixelsCam::MBadPixelsCam(const char *name, const char *title)
52{
53 fName = name ? name : "MBadPixelsCam";
54 fTitle = title ? title : "";
55
56 fArray = new TClonesArray("MBadPixelsPix", 1);
57}
58
59// --------------------------------------------------------------------------
60//
61// Delete the array conatining the bad pixel information
62//
63MBadPixelsCam::~MBadPixelsCam()
64{
65 delete fArray;
66}
67
68// --------------------------------------------------------------------------
69//
70// Set the size of the camera
71//
72void MBadPixelsCam::InitSize(const UInt_t i)
73{
74 fArray->ExpandCreate(i);
75}
76
77// --------------------------------------------------------------------------
78//
79// Get the size of the MBadPixelsCam
80//
81Int_t MBadPixelsCam::GetSize() const
82{
83 return fArray->GetEntriesFast();
84}
85
86// --------------------------------------------------------------------------
87//
88// Copy 'constructor'
89//
90void MBadPixelsCam::Copy(TObject &object) const
91{
92 MBadPixelsCam &cam = (MBadPixelsCam&)object;
93
94 const Int_t n = GetSize();
95 if (n==0)
96 return;
97
98 cam.InitSize(n);
99 for (int i=0; i<n; i++)
100 (*this)[i].Copy(cam[i]);
101}
102
103// --------------------------------------------------------------------------
104//
105// Get i-th pixel (pixel number)
106//
107MBadPixelsPix &MBadPixelsCam::operator[](Int_t i)
108{
109 return *static_cast<MBadPixelsPix*>(fArray->UncheckedAt(i));
110}
111
112// --------------------------------------------------------------------------
113//
114// Get i-th pixel (pixel number)
115//
116const MBadPixelsPix &MBadPixelsCam::operator[](Int_t i) const
117{
118 return *static_cast<MBadPixelsPix*>(fArray->UncheckedAt(i));
119}
120
121// --------------------------------------------------------------------------
122//
123// Merge two MBadPixelsCam together, see also MBadPixelsPix::Merge
124//
125void MBadPixelsCam::Merge(const MBadPixelsCam &cam)
126{
127 const Int_t n = cam.GetSize();
128 if (n==0)
129 {
130 *fLog << warn << "MBadPixelsCam::Merge: Container empty." << endl;
131 return;
132 }
133
134 if (GetSize()==0)
135 InitSize(n);
136
137 if (n!=GetSize())
138 {
139 *fLog << warn << "MBadPixelsCam::Merge: Size mismatch... ignored." << endl;
140 return;
141 }
142
143 for (int i=0; i<n; i++)
144 (*this)[i].Merge(cam[i]);
145}
146
147// --------------------------------------------------------------------------
148//
149// Clear the contents of all bad pixels (set=0 means Ok)
150//
151void MBadPixelsCam::Clear(Option_t *o)
152{
153 fArray->ForEach(TObject, Clear)();
154}
155
156// --------------------------------------------------------------------------
157//
158// Print the contents of all bad pixels
159//
160void MBadPixelsCam::Print(Option_t *o) const
161{
162
163 *fLog << all << GetDescriptor() << ":" << endl;
164
165 *fLog << all << "Pixels without problems:" << endl;
166 *fLog << all << endl;
167
168 Int_t count = 0;
169
170 for (Int_t i=0; i<GetSize(); i++)
171 {
172 if ((*this)[i].IsSuitableRun())
173 {
174 *fLog << i << " ";
175 count ++;
176 }
177
178 if (count == 0)
179 continue;
180
181 if (!(count % 25))
182 *fLog << endl;
183 }
184 *fLog << endl;
185 *fLog << all << count << " normal pixels :-))" << endl;
186 *fLog << endl;
187 count = 0;
188
189
190 *fLog << all << "Pixels unsuited for the whole run:" << endl;
191 *fLog << all << endl;
192
193 for (Int_t i=0; i<GetSize(); i++)
194 {
195 if ((*this)[i].IsUnsuitableRun())
196 {
197 *fLog << i << " ";
198 count ++;
199 }
200
201 if (count == 0)
202 continue;
203
204 if (!(count % 25))
205 *fLog << endl;
206 }
207 *fLog << endl;
208 *fLog << all << count << " unsuited pixels :-(" << endl;
209 *fLog << endl;
210
211 count = 0;
212
213 *fLog << all << "Pixels unreliable for the whole run:" << endl;
214 *fLog << all << endl;
215
216 for (Int_t i=0; i<GetSize(); i++)
217 {
218 if ((*this)[i].IsUnreliableRun())
219 {
220 *fLog << i << " ";
221 count ++;
222 }
223
224 if (count == 0)
225 continue;
226
227 if (!(count % 25))
228 *fLog << endl;
229 }
230 *fLog << endl;
231 *fLog << all << count << " unreliable pixels :-(" << endl;
232 *fLog << endl;
233}
234
235// --------------------------------------------------------------------------
236//
237// Read from an ascii file of the format:
238// pixel1 pixel2 pixel3 pixel4
239// while pixel1,2,3,4 are the pixel indices used in the software.
240//
241// To read the pixels corresponding to a given run you can give run!=0
242// and a file of the format:
243// 1234: 17 193 292
244// 1235: 17 193 292 293
245//
246void MBadPixelsCam::AsciiRead(ifstream &fin, UInt_t run=0)
247{
248 Int_t len;
249 TString str;
250
251 while (1)
252 {
253 str.ReadLine(fin);
254 if (!fin)
255 return;
256
257 Int_t r;
258
259 const Int_t n = sscanf(str.Data(), " %d : %n", &r, &len);
260 if (n!=1)
261 return;
262
263 if (run==0 || run && (UInt_t)r==run)
264 break;
265 }
266
267 str.Remove(0, len);
268
269 while (1)
270 {
271 Int_t idx;
272 const Int_t n = sscanf(str.Data(), " %d %n", &idx, &len);
273
274 if (n!=1)
275 break;
276
277 str.Remove(0, len);
278
279 if (idx>=GetSize())
280 InitSize(idx+1);
281
282 (*this)[idx].SetUnsuitableRun();
283 }
284}
285
286// --------------------------------------------------------------------------
287//
288// Write the information into an ascii file. If a run-number is given the
289// run-number will lead the line.
290//
291Bool_t MBadPixelsCam::AsciiWrite(ostream &fout, UInt_t run=0) const
292{
293 if (run)
294 fout << run << ":";
295
296 for (int i=0; i<GetSize(); i++)
297 if ((*this)[i].IsUnsuitableRun())
298 fout << " " << i;
299
300 if (run && GetSize())
301 fout << endl;
302
303 return kTRUE;
304}
305
306Bool_t MBadPixelsCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
307{
308
309 if (idx >= GetSize())
310 return kFALSE;
311
312 switch (type)
313 {
314 case 0:
315 val = (*this)[idx].GetInfo()[0];
316 return (*this)[idx].IsOK();
317 break;
318 case 1:
319 val = (*this)[idx].IsUnsuitableRun();
320 return val;
321 break;
322 case 2:
323 val = (*this)[idx].IsUnsuitableEvt();
324 return val;
325 break;
326 case 3:
327 val = (*this)[idx].IsUnreliableRun();
328 return val;
329 break;
330 case 4:
331 val = (*this)[idx].IsHiGainBad();
332 return val;
333 break;
334 case 5:
335 val = (*this)[idx].IsLoGainBad();
336 return val;
337 break;
338 case 6:
339 val = (*this)[idx].IsCalibrationSignalOK();
340 return val;
341 break;
342 case 7:
343 val = (*this)[idx].IsCalibrationFitOK();
344 return val;
345 break;
346 case 8:
347 val = (*this)[idx].IsCalibrationOscillating();
348 return val;
349 break;
350 case 9:
351 val = (*this)[idx].IsCalibrationResultOK();
352 return val;
353 break;
354 case 10:
355 val = (*this)[idx].IsHiGainSaturation();
356 return val;
357 break;
358 case 11:
359 val = (*this)[idx].IsLoGainSaturation();
360 return val;
361 break;
362 case 12:
363 val = (*this)[idx].IsNotCalibrated();
364 return val;
365 break;
366 case 13:
367 val = (*this)[idx].IsMeanTimeInLastBin();
368 return val;
369 break;
370 case 14:
371 val = (*this)[idx].IsMeanTimeInFirstBin();
372 return val;
373 break;
374 case 15:
375 val = (*this)[idx].IsLoGainOscillating();
376 return val;
377 break;
378 case 16:
379 val = (*this)[idx].IsHiGainOscillating();
380 return val;
381 break;
382 case 17:
383 val = (*this)[idx].IsConvHiLoNotValid();
384 return val;
385 break;
386 case 18:
387 val = (*this)[idx].IsChargeSigmaNotValid();
388 return val;
389 break;
390 case 19:
391 val = (*this)[idx].IsChargeRelErrNotValid();
392 return val;
393 break;
394 case 20:
395 val = (*this)[idx].IsChargeErrNotValid();
396 return val;
397 case 21:
398 val = (*this)[idx].IsChargeIsPedestal();
399 return val;
400 case 22:
401 val = (*this)[idx].IsLoGainNotFitted();
402 return val;
403 break;
404 case 23:
405 val = (*this)[idx].IsHiGainNotFitted();
406 return val;
407 break;
408 default:
409 return kFALSE;
410 }
411
412 return kFALSE;
413}
414
415void MBadPixelsCam::DrawPixelContent(Int_t num) const
416{
417 *fLog << warn << "MBadPixelsCam::DrawPixelContent - not available." << endl;
418}
Note: See TracBrowser for help on using the repository browser.