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): Oscar Blanch 12/2001 <mailto:blanch@ifae.es>
|
---|
19 | ! Author(s): Thomas Bretz 08/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MBadPixelsTreat
|
---|
29 | //
|
---|
30 | // You can use MBadPixelsTreat::SetUseInterpolation to replaced the
|
---|
31 | // bad pixels by the average of its neighbors instead of unmapping
|
---|
32 | // them. If you want to include the central pixel use
|
---|
33 | // MBadPixelsTreat::SetUseCentralPixel. The bad pixels are taken from
|
---|
34 | // an existing MBadPixelsCam.
|
---|
35 | //
|
---|
36 | // It check if there are enough neighbors to calculate the mean
|
---|
37 | // If not, unmap the pixel. The minimum number of good neighbors
|
---|
38 | // should be set using SetNumMinNeighbors
|
---|
39 | //
|
---|
40 | // If you want to interpolate unreliable pixels and unsuitable
|
---|
41 | // (broken) pixels use SetHardTreatment().
|
---|
42 | //
|
---|
43 | //
|
---|
44 | // Options:
|
---|
45 | // --------
|
---|
46 | // SetHardTreatment: Also interpolate unreliable pixels not only unsuitable
|
---|
47 | // SetUseInterpolation: Interpolate pixels instead of unmapping them
|
---|
48 | // SetUseCentralPixel: also use the pixel itself for interpolation
|
---|
49 | // SetProcessPedestalRun: process the pedestals once per run/file
|
---|
50 | // SetProcessPedestalEvt: process the pedestal once per event
|
---|
51 | // SetProcessTimes: also do some rough interpolation of the arrival time
|
---|
52 | //
|
---|
53 | //
|
---|
54 | // Input Containers:
|
---|
55 | // MCerPhotEvt
|
---|
56 | // MPedPhotCam
|
---|
57 | // MBadPixelsCam
|
---|
58 | // [MGeomCam]
|
---|
59 | //
|
---|
60 | // Output Containers:
|
---|
61 | // MCerPhotEvt
|
---|
62 | //
|
---|
63 | /////////////////////////////////////////////////////////////////////////////
|
---|
64 | #include "MBadPixelsTreat.h"
|
---|
65 |
|
---|
66 | #include <fstream>
|
---|
67 |
|
---|
68 | #include <TEnv.h>
|
---|
69 | #include <TObjString.h>
|
---|
70 |
|
---|
71 | #include "MArrayD.h" // Used instead of TArrayD because operator[] has no range check
|
---|
72 |
|
---|
73 | #include "MLog.h"
|
---|
74 | #include "MLogManip.h"
|
---|
75 |
|
---|
76 | #include "MParList.h"
|
---|
77 |
|
---|
78 | #include "MGeomPix.h"
|
---|
79 | #include "MGeomCam.h"
|
---|
80 |
|
---|
81 | #include "MCerPhotPix.h"
|
---|
82 | #include "MCerPhotEvt.h"
|
---|
83 |
|
---|
84 | #include "MPedPhotPix.h"
|
---|
85 | #include "MPedPhotCam.h"
|
---|
86 |
|
---|
87 | #include "MBadPixelsPix.h"
|
---|
88 | #include "MBadPixelsCam.h"
|
---|
89 |
|
---|
90 | #include "MArrivalTime.h"
|
---|
91 |
|
---|
92 | ClassImp(MBadPixelsTreat);
|
---|
93 |
|
---|
94 | using namespace std;
|
---|
95 |
|
---|
96 | static const TString gsDefName = "MBadPixelsTreat";
|
---|
97 | static const TString gsDefTitle = "Task to treat bad pixels (interpolation, unmapping)";
|
---|
98 |
|
---|
99 | // --------------------------------------------------------------------------
|
---|
100 | //
|
---|
101 | // Default constructor.
|
---|
102 | //
|
---|
103 | MBadPixelsTreat::MBadPixelsTreat(const char *name, const char *title)
|
---|
104 | : fFlags(0), fNumMinNeighbors(3)
|
---|
105 | {
|
---|
106 | fName = name ? name : gsDefName.Data();
|
---|
107 | fTitle = title ? title : gsDefTitle.Data();
|
---|
108 |
|
---|
109 | SetUseInterpolation();
|
---|
110 | SetProcessPedestal();
|
---|
111 | SetProcessTimes();
|
---|
112 | }
|
---|
113 |
|
---|
114 | // --------------------------------------------------------------------------
|
---|
115 | //
|
---|
116 | // Returns the status of a pixel. If kHardTreatment is set a pixel must
|
---|
117 | // be unsuitable or uriliable to be treated. If not it is treated only if
|
---|
118 | // it is unsuitable
|
---|
119 | // (IsBad() checks for any flag)
|
---|
120 | //
|
---|
121 | Bool_t MBadPixelsTreat::IsPixelBad(Int_t idx) const
|
---|
122 | {
|
---|
123 | return TESTBIT(fFlags, kHardTreatment) ? (*fBadPixels)[idx].IsBad():(*fBadPixels)[idx].IsUnsuitable();
|
---|
124 | }
|
---|
125 |
|
---|
126 | void MBadPixelsTreat::AddNamePedPhotCam(const char *name)
|
---|
127 | {
|
---|
128 | fNamePedPhotCams.Add(new TObjString(name));
|
---|
129 | }
|
---|
130 |
|
---|
131 | // --------------------------------------------------------------------------
|
---|
132 | //
|
---|
133 | // - Try to find or create MBlindPixels in parameter list.
|
---|
134 | // - get the MCerPhotEvt from the parlist (abort if missing)
|
---|
135 | // - if no pixels are given by the user try to determin the starfield
|
---|
136 | // from the monte carlo run header.
|
---|
137 | //
|
---|
138 | Int_t MBadPixelsTreat::PreProcess (MParList *pList)
|
---|
139 | {
|
---|
140 | fBadPixels = (MBadPixelsCam*)pList->FindObject(AddSerialNumber("MBadPixelsCam"));
|
---|
141 | if (!fBadPixels)
|
---|
142 | {
|
---|
143 | *fLog << err << AddSerialNumber("MBadPixelsCam") << " not found... aborting." << endl;
|
---|
144 | return kFALSE;
|
---|
145 | }
|
---|
146 |
|
---|
147 | fEvt = (MCerPhotEvt*)pList->FindObject(AddSerialNumber("MCerPhotEvt"));
|
---|
148 | if (!fEvt)
|
---|
149 | {
|
---|
150 | *fLog << err << AddSerialNumber("MCerPhotEvt") << " not found... aborting." << endl;
|
---|
151 | return kFALSE;
|
---|
152 | }
|
---|
153 |
|
---|
154 | fGeomCam = 0;
|
---|
155 | if (!IsUseInterpolation())
|
---|
156 | return kTRUE;
|
---|
157 |
|
---|
158 | fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
|
---|
159 | if (!fGeomCam)
|
---|
160 | {
|
---|
161 | *fLog << err << AddSerialNumber("MGeomCam") << " not found - can't use interpolation... abort." << endl;
|
---|
162 | *fLog << " Use MBadPixelsTreat::SetUseInterpolation(kFALSE) to switch interpolation" << endl;
|
---|
163 | *fLog << " off and use unmapping instead." << endl;
|
---|
164 | return kFALSE;
|
---|
165 | }
|
---|
166 |
|
---|
167 | const Bool_t proc = IsProcessPedestalEvt() || IsProcessPedestalRun();
|
---|
168 |
|
---|
169 | if (fNamePedPhotCams.GetSize()>0 && !proc)
|
---|
170 | {
|
---|
171 | *fLog << err << "Pedestal list contains entries, but pedestal treatment is switched off... abort." << endl;
|
---|
172 | return kFALSE;
|
---|
173 | }
|
---|
174 |
|
---|
175 | if (proc)
|
---|
176 | {
|
---|
177 | if (fNamePedPhotCams.GetSize()==0)
|
---|
178 | {
|
---|
179 | *fLog << inf << "No container names specified... using default: MPedPhotCam." << endl;
|
---|
180 | AddNamePedPhotCam();
|
---|
181 | }
|
---|
182 |
|
---|
183 | fPedPhotCams.Clear();
|
---|
184 |
|
---|
185 | TIter Next(&fNamePedPhotCams);
|
---|
186 | TObject *o=0;
|
---|
187 | while ((o=Next()))
|
---|
188 | {
|
---|
189 | TObject *p = pList->FindObject(AddSerialNumber(o->GetName()), "MPedPhotCam");
|
---|
190 | if (!p)
|
---|
191 | {
|
---|
192 | *fLog << err << AddSerialNumber(o->GetName()) << " [MPedPhotCam] not found... aborting." << endl;
|
---|
193 | //*fLog << " Use MBadPixelsTreat::SetProcessPedestalRun(kFALSE) and" << endl;
|
---|
194 | //*fLog << " MBadPixelsTreat::SetProcessPedestalEvt(kFALSE) to switch" << endl;
|
---|
195 | //*fLog << " Pedestal treatment off." << endl;
|
---|
196 | return kFALSE;
|
---|
197 | }
|
---|
198 |
|
---|
199 | fPedPhotCams.Add(p);
|
---|
200 | }
|
---|
201 | }
|
---|
202 |
|
---|
203 | fTimes = 0;
|
---|
204 | if (IsProcessTimes())
|
---|
205 | {
|
---|
206 | fTimes = (MArrivalTime*)pList->FindObject(AddSerialNumber("MArrivalTime"));
|
---|
207 | if (!fTimes)
|
---|
208 | {
|
---|
209 | *fLog << err << AddSerialNumber("MArrivalTime") << " not found... aborting." << endl;
|
---|
210 | *fLog << " Use MBadPixelsTreat::SetProcessTimes(kFALSE) to switch time interpolation off." << endl;
|
---|
211 | return kFALSE;
|
---|
212 | }
|
---|
213 | }
|
---|
214 |
|
---|
215 | if (IsProcessPedestalEvt())
|
---|
216 | *fLog << inf << "Processing Pedestals once per event..." << endl;
|
---|
217 | if (IsProcessPedestalRun())
|
---|
218 | *fLog << inf << "Processing Pedestals once per run..." << endl;
|
---|
219 | if (IsProcessTimes())
|
---|
220 | *fLog << inf << "Processing Arrival Times once per event..." << endl;
|
---|
221 |
|
---|
222 | return kTRUE;
|
---|
223 | }
|
---|
224 |
|
---|
225 | // --------------------------------------------------------------------------
|
---|
226 | //
|
---|
227 | // Replaces each pixel (signal, signal error, pedestal, pedestal rms)
|
---|
228 | // by the average of its surrounding pixels.
|
---|
229 | // If TESTBIT(fFlags, kUseCentralPixel) is set the central pixel is also
|
---|
230 | // included.
|
---|
231 | //
|
---|
232 | void MBadPixelsTreat::InterpolateSignal() const
|
---|
233 | {
|
---|
234 | const UShort_t entries = fGeomCam->GetNumPixels();
|
---|
235 |
|
---|
236 | //
|
---|
237 | // Create arrays (FIXME: Check if its possible to create it only once)
|
---|
238 | //
|
---|
239 | MArrayD nphot(entries);
|
---|
240 | MArrayD perr(entries);
|
---|
241 |
|
---|
242 | //
|
---|
243 | // Loop over all pixels
|
---|
244 | //
|
---|
245 | for (UShort_t i=0; i<entries; i++)
|
---|
246 | {
|
---|
247 | MCerPhotPix *pix = fEvt->GetPixById(i);
|
---|
248 |
|
---|
249 | //
|
---|
250 | // Check whether pixel with idx i is blind
|
---|
251 | //
|
---|
252 | if (pix && !IsPixelBad(i))
|
---|
253 | continue;
|
---|
254 |
|
---|
255 | //
|
---|
256 | // Get a pointer to this pixel. If it is not yet existing
|
---|
257 | // create a new entry for this pixel in MCerPhotEvt
|
---|
258 | //
|
---|
259 | if (!pix)
|
---|
260 | {
|
---|
261 | pix = fEvt->AddPixel(i, 0, 0);
|
---|
262 | (*fBadPixels)[i].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
|
---|
263 | }
|
---|
264 |
|
---|
265 | //
|
---|
266 | // Get the corresponding geometry and pedestal
|
---|
267 | //
|
---|
268 | const MGeomPix &gpix = (*fGeomCam)[i];
|
---|
269 |
|
---|
270 | // Do Not-Use-Central-Pixel
|
---|
271 | const Bool_t nucp = !TESTBIT(fFlags, kUseCentralPixel);
|
---|
272 |
|
---|
273 | Int_t num = nucp ? 0 : 1;
|
---|
274 |
|
---|
275 | nphot[i] = nucp ? 0 : pix->GetNumPhotons();
|
---|
276 | perr[i] = nucp ? 0 : Pow2(pix->GetErrorPhot());
|
---|
277 |
|
---|
278 | //
|
---|
279 | // The values are rescaled to the small pixels area for the right comparison
|
---|
280 | //
|
---|
281 | const Double_t ratio = fGeomCam->GetPixRatio(i);
|
---|
282 |
|
---|
283 | nphot[i] *= ratio;
|
---|
284 | perr[i] *= ratio;
|
---|
285 |
|
---|
286 | //
|
---|
287 | // Loop over all its neighbors
|
---|
288 | //
|
---|
289 | const Int_t n = gpix.GetNumNeighbors();
|
---|
290 | for (int j=0; j<n; j++)
|
---|
291 | {
|
---|
292 | const UShort_t nidx = gpix.GetNeighbor(j);
|
---|
293 |
|
---|
294 | //
|
---|
295 | // Do not use blind neighbors
|
---|
296 | //
|
---|
297 | if (IsPixelBad(nidx))
|
---|
298 | continue;
|
---|
299 |
|
---|
300 | //
|
---|
301 | // Check whether the neighbor has a signal stored
|
---|
302 | //
|
---|
303 | const MCerPhotPix *evtpix = fEvt->GetPixById(nidx);
|
---|
304 | if (!evtpix)
|
---|
305 | continue;
|
---|
306 |
|
---|
307 | //
|
---|
308 | // Get the geometry for the neighbor
|
---|
309 | //
|
---|
310 | const Double_t nratio = fGeomCam->GetPixRatio(nidx);
|
---|
311 |
|
---|
312 | //
|
---|
313 | //The error is calculated as the quadratic sum of the errors
|
---|
314 | //
|
---|
315 | nphot[i] += nratio*evtpix->GetNumPhotons();
|
---|
316 | perr[i] += nratio* Pow2(evtpix->GetErrorPhot());
|
---|
317 |
|
---|
318 | num++;
|
---|
319 | }
|
---|
320 |
|
---|
321 | // Check if there are enough neighbors to calculate the mean
|
---|
322 | // If not, unmap the pixel. The maximum number of blind neighbors
|
---|
323 | // should be 2
|
---|
324 | if (num<fNumMinNeighbors)
|
---|
325 | {
|
---|
326 | pix->SetPixelUnmapped();
|
---|
327 | continue;
|
---|
328 | }
|
---|
329 |
|
---|
330 | //
|
---|
331 | // Now the mean is calculated and the values rescaled back
|
---|
332 | // to the pixel area
|
---|
333 | //
|
---|
334 | nphot[i] /= (num*ratio);
|
---|
335 | perr[i] = TMath::Sqrt(perr[i]/(num*ratio));
|
---|
336 |
|
---|
337 | pix->Set(nphot[i], perr[i]);
|
---|
338 | }
|
---|
339 | }
|
---|
340 |
|
---|
341 | // --------------------------------------------------------------------------
|
---|
342 | //
|
---|
343 | void MBadPixelsTreat::InterpolatePedestals(MPedPhotCam &pedphot) const
|
---|
344 | {
|
---|
345 | const Int_t entries = pedphot.GetSize();
|
---|
346 |
|
---|
347 | // Create arrays (FIXME: Check if its possible to create it only once)
|
---|
348 | MArrayD ped(entries);
|
---|
349 | MArrayD rms(entries);
|
---|
350 |
|
---|
351 | //
|
---|
352 | // Loop over all pixels
|
---|
353 | //
|
---|
354 | for (UShort_t i=0; i<entries; i++)
|
---|
355 | {
|
---|
356 | //
|
---|
357 | // Check whether pixel with idx i is blind
|
---|
358 | //
|
---|
359 | if (!IsPixelBad(i))
|
---|
360 | continue;
|
---|
361 |
|
---|
362 | //
|
---|
363 | // Get the corresponding geometry and pedestal
|
---|
364 | //
|
---|
365 | const MGeomPix &gpix = (*fGeomCam)[i];
|
---|
366 | const MPedPhotPix &ppix = pedphot[i];
|
---|
367 |
|
---|
368 | // Do Not-Use-Central-Pixel
|
---|
369 | const Bool_t nucp = !TESTBIT(fFlags, kUseCentralPixel);
|
---|
370 |
|
---|
371 | Int_t num = nucp ? 0 : 1;
|
---|
372 |
|
---|
373 | ped[i] = nucp ? 0 : ppix.GetMean();
|
---|
374 | rms[i] = nucp ? 0 : Pow2(ppix.GetRms());
|
---|
375 |
|
---|
376 | //
|
---|
377 | // The values are rescaled to the small pixels area for the right comparison
|
---|
378 | //
|
---|
379 | const Double_t ratio = fGeomCam->GetPixRatio(i);
|
---|
380 |
|
---|
381 | ped[i] *= ratio;
|
---|
382 | rms[i] *= ratio;
|
---|
383 |
|
---|
384 | //
|
---|
385 | // Loop over all its neighbors
|
---|
386 | //
|
---|
387 | const Int_t n = gpix.GetNumNeighbors();
|
---|
388 | for (int j=0; j<n; j++)
|
---|
389 | {
|
---|
390 | const UShort_t nidx = gpix.GetNeighbor(j);
|
---|
391 |
|
---|
392 | //
|
---|
393 | // Do not use blind neighbors
|
---|
394 | //
|
---|
395 | if (IsPixelBad(nidx))
|
---|
396 | continue;
|
---|
397 |
|
---|
398 | //
|
---|
399 | // Get the geometry for the neighbor
|
---|
400 | //
|
---|
401 | const Double_t nratio = fGeomCam->GetPixRatio(nidx);
|
---|
402 | const MPedPhotPix &nppix = pedphot[nidx];
|
---|
403 |
|
---|
404 | //
|
---|
405 | //The error is calculated as the quadratic sum of the errors
|
---|
406 | //
|
---|
407 | ped[i] += nratio*nppix.GetMean();
|
---|
408 | rms[i] += nratio*Pow2(nppix.GetRms());
|
---|
409 |
|
---|
410 | num++;
|
---|
411 | }
|
---|
412 |
|
---|
413 | // Check if there are enough neighbors to calculate the mean
|
---|
414 | // If not, unmap the pixel. The minimum number of good neighbors
|
---|
415 | // should be fNumMinNeighbors
|
---|
416 | if (num < fNumMinNeighbors)
|
---|
417 | {
|
---|
418 | MCerPhotPix *pix =fEvt->GetPixById(i);
|
---|
419 | if (!pix)
|
---|
420 | pix = fEvt->AddPixel(i, 0, 0);
|
---|
421 | pix->SetPixelUnmapped();
|
---|
422 | continue;
|
---|
423 | }
|
---|
424 |
|
---|
425 | //
|
---|
426 | // Now the mean is calculated and the values rescaled back
|
---|
427 | // to the pixel area
|
---|
428 | //
|
---|
429 | ped[i] /= (num*ratio);
|
---|
430 | rms[i] = TMath::Sqrt(rms[i]/(num*ratio));
|
---|
431 |
|
---|
432 | pedphot[i].Set(ped[i], rms[i]);
|
---|
433 | }
|
---|
434 | pedphot.SetReadyToSave();
|
---|
435 | }
|
---|
436 |
|
---|
437 | // --------------------------------------------------------------------------
|
---|
438 | //
|
---|
439 | // loop over all MPedPhotCam and interpolate them
|
---|
440 | //
|
---|
441 | void MBadPixelsTreat::InterpolatePedestals() const
|
---|
442 | {
|
---|
443 | TIter Next(&fPedPhotCams);
|
---|
444 | MPedPhotCam *cam=0;
|
---|
445 | while ((cam=(MPedPhotCam*)Next()))
|
---|
446 | {
|
---|
447 | InterpolatePedestals(*cam);
|
---|
448 | cam->ReCalc(*fGeomCam, fBadPixels);
|
---|
449 | }
|
---|
450 | }
|
---|
451 |
|
---|
452 | // --------------------------------------------------------------------------
|
---|
453 | //
|
---|
454 | void MBadPixelsTreat::InterpolateTimes() const
|
---|
455 | {
|
---|
456 | Int_t n = fTimes->GetSize();
|
---|
457 |
|
---|
458 | for (int i=0; i<n; i++)
|
---|
459 | {
|
---|
460 | //
|
---|
461 | // Check whether pixel with idx i is blind
|
---|
462 | //
|
---|
463 | if (!IsPixelBad(i))
|
---|
464 | continue;
|
---|
465 |
|
---|
466 | //
|
---|
467 | // Get the corresponding geometry and pedestal
|
---|
468 | //
|
---|
469 | const MGeomPix &gpix = (*fGeomCam)[i];
|
---|
470 |
|
---|
471 | MArrayD time(gpix.GetNumNeighbors());
|
---|
472 |
|
---|
473 | Int_t n0 = 0;
|
---|
474 | for (unsigned int j=0; j<time.GetSize(); j++)
|
---|
475 | {
|
---|
476 | const Double_t t = (*fTimes)[gpix.GetNeighbor(j)];
|
---|
477 | if (t>=0)
|
---|
478 | time[n0++] = t;
|
---|
479 | }
|
---|
480 |
|
---|
481 | Int_t p0=-1;
|
---|
482 | Int_t p1=-1;
|
---|
483 |
|
---|
484 | Double_t min=FLT_MAX;
|
---|
485 | for (int j=0; j<n0; j++)
|
---|
486 | for (int k=0; k<j; k++)
|
---|
487 | {
|
---|
488 | const Double_t diff = TMath::Abs(time[j] - time[k]);
|
---|
489 |
|
---|
490 | if (diff>=min && diff<250)
|
---|
491 | continue;
|
---|
492 |
|
---|
493 | p0 = j;
|
---|
494 | p1 = k;
|
---|
495 | min = diff;
|
---|
496 | }
|
---|
497 |
|
---|
498 | // FIXME: Request a minimum number of neighbors to take action?
|
---|
499 | if (p0>=0 && p1>=0 && TMath::Abs(time[p0] - time[p1])<250)
|
---|
500 | fTimes->SetTime(i, (time[p0]+time[p1])/2);
|
---|
501 | }
|
---|
502 | }
|
---|
503 |
|
---|
504 | // --------------------------------------------------------------------------
|
---|
505 | //
|
---|
506 | // Replaces each pixel (signal, signal error, pedestal, pedestal rms)
|
---|
507 | // by the average of its surrounding pixels.
|
---|
508 | // If TESTBIT(fFlags, kUseCentralPixel) is set the central pixel is also
|
---|
509 | // included.
|
---|
510 | //
|
---|
511 | // NT: Informations about the interpolated pedestals are added.
|
---|
512 | // When the option Interpolated is called, the blind pixel with the new
|
---|
513 | // values of signal and fluttuation is included in the calculation of
|
---|
514 | // the Image Parameters.
|
---|
515 | //
|
---|
516 | /*
|
---|
517 | void MBadPixelsTreat::Interpolate() const
|
---|
518 | {
|
---|
519 | const UShort_t entries = fGeomCam->GetNumPixels();
|
---|
520 |
|
---|
521 | //
|
---|
522 | // Create arrays
|
---|
523 | //
|
---|
524 | TArrayD nphot(entries);
|
---|
525 | TArrayD perr(entries);
|
---|
526 | TArrayD ped(entries);
|
---|
527 | TArrayD pedrms(entries);
|
---|
528 |
|
---|
529 | //
|
---|
530 | // Loop over all pixels
|
---|
531 | //
|
---|
532 | for (UShort_t i=0; i<entries; i++)
|
---|
533 | {
|
---|
534 | MCerPhotPix *pix = fEvt->GetPixById(i);
|
---|
535 |
|
---|
536 | //
|
---|
537 | // Check whether pixel with idx i is blind
|
---|
538 | //
|
---|
539 | if (pix && (*fBadPixels)[i].IsOK())
|
---|
540 | continue;
|
---|
541 |
|
---|
542 | //
|
---|
543 | // Get a pointer to this pixel. If it is not yet existing
|
---|
544 | // create a new entry for this pixel in MCerPhotEvt
|
---|
545 | //
|
---|
546 | if (!pix)
|
---|
547 | {
|
---|
548 | pix = fEvt->AddPixel(i, 0, 0);
|
---|
549 | (*fBadPixels)[i].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
|
---|
550 | }
|
---|
551 |
|
---|
552 | //
|
---|
553 | // Get the corresponding geometry and pedestal
|
---|
554 | //
|
---|
555 | const MGeomPix &gpix = (*fGeomCam)[i];
|
---|
556 | const MPedPhotPix &ppix = (*fPedPhot)[i];
|
---|
557 |
|
---|
558 | // Do Not-Use-Central-Pixel
|
---|
559 | const Bool_t nucp = !TESTBIT(fFlags, kUseCentralPixel);
|
---|
560 |
|
---|
561 | Int_t num = nucp ? 0 : 1;
|
---|
562 |
|
---|
563 | nphot[i] = nucp ? 0 : pix->GetNumPhotons();
|
---|
564 | ped[i] = nucp ? 0 : ppix.GetMean();
|
---|
565 | perr[i] = nucp ? 0 : Pow2(pix->GetErrorPhot());
|
---|
566 | pedrms[i] = nucp ? 0 : Pow2(ppix.GetRms());
|
---|
567 |
|
---|
568 | //
|
---|
569 | // The values are rescaled to the small pixels area for the right comparison
|
---|
570 | //
|
---|
571 | const Double_t ratio = fGeomCam->GetPixRatio(i);
|
---|
572 |
|
---|
573 | if (nucp)
|
---|
574 | {
|
---|
575 | nphot[i] *= ratio;
|
---|
576 | perr[i] *= ratio;
|
---|
577 | ped[i] *= ratio;
|
---|
578 | pedrms[i] *= ratio;
|
---|
579 | }
|
---|
580 |
|
---|
581 | //
|
---|
582 | // Loop over all its neighbors
|
---|
583 | //
|
---|
584 | const Int_t n = gpix.GetNumNeighbors();
|
---|
585 | for (int j=0; j<n; j++)
|
---|
586 | {
|
---|
587 | const UShort_t nidx = gpix.GetNeighbor(j);
|
---|
588 |
|
---|
589 | //
|
---|
590 | // Do not use blind neighbors
|
---|
591 | //
|
---|
592 | if ((*fBadPixels)[nidx].IsBad())
|
---|
593 | continue;
|
---|
594 |
|
---|
595 | //
|
---|
596 | // Check whether the neighbor has a signal stored
|
---|
597 | //
|
---|
598 | const MCerPhotPix *evtpix = fEvt->GetPixById(nidx);
|
---|
599 | if (!evtpix)
|
---|
600 | continue;
|
---|
601 |
|
---|
602 | //
|
---|
603 | // Get the geometry for the neighbor
|
---|
604 | //
|
---|
605 | const Double_t nratio = fGeomCam->GetPixRatio(nidx);
|
---|
606 | MPedPhotPix &nppix = (*fPedPhot)[nidx];
|
---|
607 |
|
---|
608 | //
|
---|
609 | // The error is calculated as the quadratic sum of the errors
|
---|
610 | //
|
---|
611 | nphot[i] += nratio*evtpix->GetNumPhotons();
|
---|
612 | ped[i] += nratio*nppix.GetMean();
|
---|
613 | perr[i] += nratio*Pow2(evtpix->GetErrorPhot());
|
---|
614 | pedrms[i] += nratio*Pow2(nppix.GetRms());
|
---|
615 |
|
---|
616 | num++;
|
---|
617 | }
|
---|
618 |
|
---|
619 | if (num<fNumMinNeighbors)
|
---|
620 | {
|
---|
621 | pix->SetPixelUnmapped();
|
---|
622 | nphot[i] = 0;
|
---|
623 | ped[i] = 0;
|
---|
624 | perr[i] = 0;
|
---|
625 | pedrms[i] = 0;
|
---|
626 | continue;
|
---|
627 | }
|
---|
628 |
|
---|
629 | //
|
---|
630 | // Now the mean is calculated and the values rescaled back to the pixel area
|
---|
631 | //
|
---|
632 | nphot[i] /= num*ratio;
|
---|
633 | ped[i] /= num*ratio;
|
---|
634 | perr[i] = TMath::Sqrt(perr[i]/(num*ratio));
|
---|
635 | pedrms[i] = TMath::Sqrt(pedrms[i]/(num*ratio));
|
---|
636 |
|
---|
637 | }
|
---|
638 |
|
---|
639 | //
|
---|
640 | // Now the new pixel values are calculated and can be replaced in
|
---|
641 | // the corresponding containers
|
---|
642 | //
|
---|
643 | for (UShort_t i=0; i<entries; i++)
|
---|
644 | {
|
---|
645 | //
|
---|
646 | // Do not use blind neighbors
|
---|
647 | //
|
---|
648 | if ((*fBadPixels)[i].IsOK())
|
---|
649 | continue;
|
---|
650 |
|
---|
651 | //
|
---|
652 | // It must exist, we have created it in the loop before.
|
---|
653 | //
|
---|
654 | fEvt->GetPixById(i)->Set(nphot[i], perr[i]);
|
---|
655 | (*fPedPhot)[i].Set(ped[i], pedrms[i]);
|
---|
656 | }
|
---|
657 | }
|
---|
658 | */
|
---|
659 |
|
---|
660 | // --------------------------------------------------------------------------
|
---|
661 | //
|
---|
662 | // Removes all blind pixels from the analysis by setting their state
|
---|
663 | // to unused.
|
---|
664 | //
|
---|
665 | void MBadPixelsTreat::Unmap() const
|
---|
666 | {
|
---|
667 | const UShort_t entries = fEvt->GetNumPixels();
|
---|
668 |
|
---|
669 | //
|
---|
670 | // remove the pixels in fPixelsIdx if they are set to be used,
|
---|
671 | // (set them to 'unused' state)
|
---|
672 | //
|
---|
673 | for (UShort_t i=0; i<entries; i++)
|
---|
674 | {
|
---|
675 | MCerPhotPix &pix = (*fEvt)[i];
|
---|
676 |
|
---|
677 | if (IsPixelBad(pix.GetPixId()))
|
---|
678 | pix.SetPixelUnmapped();
|
---|
679 | }
|
---|
680 | }
|
---|
681 |
|
---|
682 | // --------------------------------------------------------------------------
|
---|
683 | //
|
---|
684 | // Interpolate Pedestals if kProcessPedestal not set
|
---|
685 | //
|
---|
686 | Bool_t MBadPixelsTreat::ReInit(MParList *pList)
|
---|
687 | {
|
---|
688 | if (IsUseInterpolation() && IsProcessPedestalRun())
|
---|
689 | InterpolatePedestals();
|
---|
690 | return kTRUE;
|
---|
691 | }
|
---|
692 |
|
---|
693 | // --------------------------------------------------------------------------
|
---|
694 | //
|
---|
695 | // Treat the blind pixels
|
---|
696 | //
|
---|
697 | Int_t MBadPixelsTreat::Process()
|
---|
698 | {
|
---|
699 | if (IsUseInterpolation())
|
---|
700 | {
|
---|
701 | InterpolateSignal();
|
---|
702 | if (IsProcessPedestalEvt())
|
---|
703 | InterpolatePedestals();
|
---|
704 | if (IsProcessTimes())
|
---|
705 | InterpolateTimes();
|
---|
706 | }
|
---|
707 | else
|
---|
708 | Unmap();
|
---|
709 |
|
---|
710 | return kTRUE;
|
---|
711 | }
|
---|
712 |
|
---|
713 | void MBadPixelsTreat::StreamPrimitive(ofstream &out) const
|
---|
714 | {
|
---|
715 | out << " MBadPixelsTreat " << GetUniqueName();
|
---|
716 | if (fName!=gsDefName || fTitle!=gsDefTitle)
|
---|
717 | {
|
---|
718 | out << "(\"" << fName << "\"";
|
---|
719 | if (fTitle!=gsDefTitle)
|
---|
720 | out << ", \"" << fTitle << "\"";
|
---|
721 | out <<")";
|
---|
722 | }
|
---|
723 | out << ";" << endl;
|
---|
724 |
|
---|
725 | if (IsUseInterpolation())
|
---|
726 | out << " " << GetUniqueName() << ".SetUseInterpolation();" << endl;
|
---|
727 | if (IsUseCentralPixel())
|
---|
728 | out << " " << GetUniqueName() << ".SetUseCentralPixel();" << endl;
|
---|
729 | if (IsProcessPedestalRun())
|
---|
730 | out << " " << GetUniqueName() << ".SetProcessPedestalRun();" << endl;
|
---|
731 | if (IsProcessPedestalEvt())
|
---|
732 | out << " " << GetUniqueName() << ".SetProcessPedestalEvt();" << endl;
|
---|
733 | if (IsProcessTimes())
|
---|
734 | out << " " << GetUniqueName() << ".SetProcessTimes();" << endl;
|
---|
735 | if (IsHardTreatment())
|
---|
736 | out << " " << GetUniqueName() << ".SetHardTreatment();" << endl;
|
---|
737 | if (fNumMinNeighbors!=3)
|
---|
738 | out << " " << GetUniqueName() << ".SetNumMinNeighbors(" << (int)fNumMinNeighbors << ");" << endl;
|
---|
739 | }
|
---|
740 |
|
---|
741 | // --------------------------------------------------------------------------
|
---|
742 | //
|
---|
743 | // Read the setup from a TEnv, eg:
|
---|
744 | // MBadPixelsTreat.UseInterpolation: no
|
---|
745 | // MBadPixelsTreat.UseCentralPixel: no
|
---|
746 | // MBadPixelsTreat.HardTreatment: no
|
---|
747 | // MBadPixelsTreat.ProcessPedestalRun: no
|
---|
748 | // MBadPixelsTreat.ProcessPedestalEvt: no
|
---|
749 | // MBadPixelsTreat.NumMinNeighbors: 3
|
---|
750 | //
|
---|
751 | Int_t MBadPixelsTreat::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
752 | {
|
---|
753 | Bool_t rc = kFALSE;
|
---|
754 | if (IsEnvDefined(env, prefix, "UseInterpolation", print))
|
---|
755 | {
|
---|
756 | rc = kTRUE;
|
---|
757 | SetUseInterpolation(GetEnvValue(env, prefix, "UseInterpolation", IsUseInterpolation()));
|
---|
758 | }
|
---|
759 | if (IsEnvDefined(env, prefix, "UseCentralPixel", print))
|
---|
760 | {
|
---|
761 | rc = kTRUE;
|
---|
762 | SetUseCentralPixel(GetEnvValue(env, prefix, "UseCentralPixel", IsUseCentralPixel()));
|
---|
763 | }
|
---|
764 | if (IsEnvDefined(env, prefix, "HardTreatment", print))
|
---|
765 | {
|
---|
766 | rc = kTRUE;
|
---|
767 | SetHardTreatment(GetEnvValue(env, prefix, "HardTreatment", IsHardTreatment()));
|
---|
768 | }
|
---|
769 | if (IsEnvDefined(env, prefix, "ProcessPedestalRun", print))
|
---|
770 | {
|
---|
771 | rc = kTRUE;
|
---|
772 | SetProcessPedestalRun(GetEnvValue(env, prefix, "ProcessPedestalRun", IsProcessPedestalRun()));
|
---|
773 | }
|
---|
774 | if (IsEnvDefined(env, prefix, "ProcessPedestalEvt", print))
|
---|
775 | {
|
---|
776 | rc = kTRUE;
|
---|
777 | SetProcessPedestalEvt(GetEnvValue(env, prefix, "ProcessPedestalEvt", IsProcessPedestalEvt()));
|
---|
778 | }
|
---|
779 | if (IsEnvDefined(env, prefix, "ProcessTimes", print))
|
---|
780 | {
|
---|
781 | rc = kTRUE;
|
---|
782 | SetProcessTimes(GetEnvValue(env, prefix, "ProcessTimes", IsProcessTimes()));
|
---|
783 | }
|
---|
784 | if (IsEnvDefined(env, prefix, "NumMinNeighbors", print))
|
---|
785 | {
|
---|
786 | rc = kTRUE;
|
---|
787 | SetNumMinNeighbors(GetEnvValue(env, prefix, "NumMinNeighbors", fNumMinNeighbors));
|
---|
788 | }
|
---|
789 | return rc;
|
---|
790 | }
|
---|