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

Last change on this file since 3819 was 3736, checked in by gaug, 21 years ago
*** empty log message ***
File size: 11.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// 6: !MBadPixelsPix::IsCalibrationSignalOK()
326// 7: !MBadPixelsPix::IsCalibrationResultOK();
327// 8: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainNotFitted)
328// 9: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainNotFitted)
329// 10: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainOscillating)
330// 11: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainOscillating)
331// 12: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainSaturation )
332// 13: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeIsPedestal )
333// 14: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeErrNotValid)
334// 15: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid)
335// 16: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid )
336// 17: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin )
337// 18: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins )
338// 19: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes )
339// 20: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kRelTimeNotFitted )
340// 21: MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kRelTimeOscillating )
341//
342Bool_t MBadPixelsCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
343{
344
345 if (idx >= GetSize())
346 return kFALSE;
347
348 switch (type)
349 {
350 case 0:
351 return (*this)[idx].GetInfo()[0];
352 case 1:
353 return (*this)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableRun);
354 case 2:
355 return (*this)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableEvt);
356 case 3:
357 return (*this)[idx].IsUnsuitable(MBadPixelsPix::kUnreliableRun);
358 case 4:
359 return (*this)[idx].IsHiGainBad();
360 case 5:
361 return (*this)[idx].IsLoGainBad();
362 case 6:
363 return !(*this)[idx].IsCalibrationSignalOK();
364 case 7:
365 return !(*this)[idx].IsCalibrationResultOK();
366 case 8:
367 return (*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainNotFitted);
368 case 9:
369 return (*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainNotFitted);
370 case 10:
371 return (*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainOscillating);
372 case 11:
373 return(*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainOscillating);
374 case 12:
375 return (*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainSaturation );
376 case 13:
377 return (*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeIsPedestal );
378 case 14:
379 return (*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeErrNotValid);
380 case 15:
381 return (*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid);
382 case 16:
383 return (*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid );
384 case 17:
385 return (*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin );
386 case 18:
387 return (*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins );
388 case 19:
389 return (*this)[idx].IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes );
390 case 20:
391 return (*this)[idx].IsUncalibrated(MBadPixelsPix::kRelTimeNotFitted );
392 case 21:
393 return (*this)[idx].IsUncalibrated(MBadPixelsPix::kRelTimeOscillating );
394 default:
395 return kFALSE;
396 }
397
398 return kFALSE;
399}
400
401void MBadPixelsCam::DrawPixelContent(Int_t num) const
402{
403 *fLog << warn << "MBadPixelsCam::DrawPixelContent - not available." << endl;
404}
Note: See TracBrowser for help on using the repository browser.