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

Last change on this file since 3601 was 3601, checked in by gaug, 21 years ago
*** empty log message ***
File size: 9.7 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 : "";
56
57 fArray = new TClonesArray("MBadPixelsPix", 1);
58}
59
60// --------------------------------------------------------------------------
61//
62// Delete the array conatining the bad pixel information
63//
64MBadPixelsCam::~MBadPixelsCam()
65{
66 delete fArray;
67}
68
69// --------------------------------------------------------------------------
70//
71// Set the size of the camera
72//
73void MBadPixelsCam::InitSize(const UInt_t i)
74{
75 fArray->ExpandCreate(i);
76}
77
78// --------------------------------------------------------------------------
79//
80// Get the size of the MBadPixelsCam
81//
82Int_t MBadPixelsCam::GetSize() const
83{
84 return fArray->GetEntriesFast();
85}
86
87// --------------------------------------------------------------------------
88//
89// Copy 'constructor'
90//
91void MBadPixelsCam::Copy(TObject &object) const
92{
93 MBadPixelsCam &cam = (MBadPixelsCam&)object;
94
95 const Int_t n = GetSize();
96 if (n==0)
97 return;
98
99 cam.InitSize(n);
100 for (int i=0; i<n; i++)
101 (*this)[i].Copy(cam[i]);
102}
103
104// --------------------------------------------------------------------------
105//
106// Get i-th pixel (pixel number)
107//
108MBadPixelsPix &MBadPixelsCam::operator[](Int_t i)
109{
110 return *static_cast<MBadPixelsPix*>(fArray->UncheckedAt(i));
111}
112
113// --------------------------------------------------------------------------
114//
115// Get i-th pixel (pixel number)
116//
117const MBadPixelsPix &MBadPixelsCam::operator[](Int_t i) const
118{
119 return *static_cast<MBadPixelsPix*>(fArray->UncheckedAt(i));
120}
121
122// --------------------------------------------------------------------------
123//
124// Merge two MBadPixelsCam together, see also MBadPixelsPix::Merge
125//
126void MBadPixelsCam::Merge(const MBadPixelsCam &cam)
127{
128 const Int_t n = cam.GetSize();
129 if (n==0)
130 {
131 *fLog << warn << "MBadPixelsCam::Merge: Container empty." << endl;
132 return;
133 }
134
135 if (GetSize()==0)
136 InitSize(n);
137
138 if (n!=GetSize())
139 {
140 *fLog << warn << "MBadPixelsCam::Merge: Size mismatch... ignored." << endl;
141 return;
142 }
143
144 for (int i=0; i<n; i++)
145 (*this)[i].Merge(cam[i]);
146}
147
148// --------------------------------------------------------------------------
149//
150// Clear the contents of all bad pixels (set=0 means Ok)
151//
152void MBadPixelsCam::Clear(Option_t *o)
153{
154 fArray->ForEach(TObject, Clear)();
155}
156
157// --------------------------------------------------------------------------
158//
159// Print the contents of all bad pixels
160//
161void MBadPixelsCam::Print(Option_t *o) const
162{
163 *fLog << all << GetDescriptor() << ":" << endl;
164
165 *fLog << "Pixels without problems:" << endl;
166 *fLog << endl;
167
168 Int_t count = 0;
169
170 for (Int_t i=0; i<GetSize(); i++)
171 {
172 if (!(*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
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 << count << " normal pixels :-))" << endl;
186 *fLog << endl;
187 count = 0;
188
189
190 *fLog << "Pixels unsuited for the whole run:" << endl;
191 *fLog << endl;
192
193 for (Int_t i=0; i<GetSize(); i++)
194 {
195 if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
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 << 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].IsUnsuitable(MBadPixelsPix::kUnreliableRun))
219 {
220 *fLog << i << " ";
221 count ++;
222 }
223
224 if (count == 0)
225 continue;
226
227 if (!(count % 25))
228 *fLog << endl;
229 }
230
231 *fLog << endl;
232 *fLog << count << " unreliable pixels :-(" << endl;
233 *fLog << endl;
234}
235
236// --------------------------------------------------------------------------
237//
238// Read from an ascii file of the format:
239// pixel1 pixel2 pixel3 pixel4
240// while pixel1,2,3,4 are the pixel indices used in the software.
241//
242// To read the pixels corresponding to a given run you can give run!=0
243// and a file of the format:
244// 1234: 17 193 292
245// 1235: 17 193 292 293
246//
247void MBadPixelsCam::AsciiRead(ifstream &fin, UInt_t run=0)
248{
249 Int_t len;
250 TString str;
251
252 while (1)
253 {
254 str.ReadLine(fin);
255 if (!fin)
256 return;
257
258 Int_t r;
259
260 const Int_t n = sscanf(str.Data(), " %d : %n", &r, &len);
261 if (n!=1)
262 return;
263
264 if (run==0 || run && (UInt_t)r==run)
265 break;
266 }
267
268 str.Remove(0, len);
269
270 while (1)
271 {
272 Int_t idx;
273 const Int_t n = sscanf(str.Data(), " %d %n", &idx, &len);
274
275 if (n!=1)
276 break;
277
278 str.Remove(0, len);
279
280 if (idx>=GetSize())
281 InitSize(idx+1);
282
283 (*this)[idx].SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
284 }
285}
286
287// --------------------------------------------------------------------------
288//
289// Write the information into an ascii file. If a run-number is given the
290// run-number will lead the line.
291//
292Bool_t MBadPixelsCam::AsciiWrite(ostream &fout, UInt_t run=0) const
293{
294 if (run)
295 fout << run << ":";
296
297 for (int i=0; i<GetSize(); i++)
298 if ((*this)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
299 fout << " " << i;
300
301 if (run && GetSize())
302 fout << endl;
303
304 return kTRUE;
305}
306
307Bool_t MBadPixelsCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
308{
309
310 if (idx >= GetSize())
311 return kFALSE;
312
313 switch (type)
314 {
315 case 0:
316 val = (*this)[idx].GetInfo()[0];
317 return (*this)[idx].IsOK();
318 break;
319 case 1:
320 val = (*this)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableRun);
321 return val;
322 break;
323 case 2:
324 val = (*this)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableEvt);
325 return val;
326 break;
327 case 3:
328 val = (*this)[idx].IsUnsuitable(MBadPixelsPix::kUnreliableRun);
329 return val;
330 break;
331 case 4:
332 val = (*this)[idx].IsHiGainBad();
333 return val;
334 break;
335 case 5:
336 val = (*this)[idx].IsLoGainBad();
337 return val;
338 break;
339 case 6:
340 val = !(*this)[idx].IsCalibrationSignalOK();
341 return val;
342 break;
343 case 7:
344 val = !(*this)[idx].IsCalibrationResultOK();
345 return val;
346 break;
347 case 8:
348 val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainNotFitted);
349 return val;
350 break;
351 case 9:
352 val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainNotFitted);
353 return val;
354 break;
355 case 10:
356 val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainOscillating);
357 return val;
358 break;
359 case 11:
360 val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainSaturation );
361 return val;
362 break;
363 case 12:
364 val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeIsPedestal );
365 return val;
366 break;
367 case 13:
368 val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeErrNotValid);
369 return val;
370 break;
371 case 14:
372 val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid);
373 return val;
374 break;
375 case 15:
376 val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid );
377 return val;
378 break;
379 case 16:
380 val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin );
381 return val;
382 break;
383 case 17:
384 val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins );
385 return val;
386 break;
387 case 18:
388 val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes );
389 return val;
390 break;
391 default:
392 return kFALSE;
393 }
394
395 return kFALSE;
396}
397
398void MBadPixelsCam::DrawPixelContent(Int_t num) const
399{
400 *fLog << warn << "MBadPixelsCam::DrawPixelContent - not available." << endl;
401}
Note: See TracBrowser for help on using the repository browser.