source: trunk/MagicSoft/Mars/manalysis/MBlindPixelCalc.cc@ 2491

Last change on this file since 2491 was 2470, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 11.2 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): 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-2003
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MBlindPixelCalc
29//
30// This is the specific image cleaning for a list of pixels. This task
31// sets the pixels listed in fPixelsIdx to unused so they should not be
32// used for analysis (eg calculation of hillas parameters).
33//
34// You can use MBlindPixelCalc::SetUseInterpolation to replaced the
35// blind pixels by the average of its neighbors instead of unmapping
36// them. If you want to include the central pixel use
37// MBlindPixelCalc::SetUseCentralPixel.
38//
39// You have three options:
40// 1) Call SetUseBlindPixels():
41// This will take an existing MBlindPixels container filled from
42// elsewhere (eg. MCT1ReadPreProc) and use this pixels as blind
43// pixels.
44// 2) Call SetPixels():
45// This will setup an array with pixel numbers. These pixels are used
46// as blind pixels.
47// 3) Neither 1) nor 2)
48// This options tries to identify the starfield from the
49// MMcRunHeader container and tries to identifies it. If it is known
50// (eg. Crab) the fixed build in pixel numbers are used as blind
51// pixels.
52//
53// If neither an array of pixels is given (or its size is 0) and
54// MMcRunHeader couldn't be found the task removes itself from the
55// tasklist.
56//
57// Implemented star fields:
58// - Crab: 400, 401, 402, 437, 438, 439
59//
60// Input Containers:
61// MCerPhotEvt
62// [MBlindPixels]
63//
64// Output Containers:
65// MCerPhotEvt
66// MBlindPixels
67//
68/////////////////////////////////////////////////////////////////////////////
69#include "MBlindPixelCalc.h"
70
71#include <fstream>
72
73#include "MLog.h"
74#include "MLogManip.h"
75
76#include "MParList.h"
77
78#include "MGeomPix.h"
79#include "MGeomCam.h"
80#include "MCerPhotPix.h"
81#include "MCerPhotEvt.h"
82#include "MPedestalPix.h"
83#include "MPedestalCam.h"
84#include "MBlindPixels.h"
85
86#include "MMcRunHeader.hxx"
87
88ClassImp(MBlindPixelCalc);
89
90using namespace std;
91
92static const TString gsDefName = "MBlindPixelCalc";
93static const TString gsDefTitle = "Find hot spots (star, broken pixels, etc)";
94
95// --------------------------------------------------------------------------
96//
97// Default constructor.
98//
99MBlindPixelCalc::MBlindPixelCalc(const char *name, const char *title)
100 : fFlags(0)
101{
102 fName = name ? name : gsDefName.Data();
103 fTitle = title ? title : gsDefTitle.Data();
104}
105
106// --------------------------------------------------------------------------
107//
108// - Try to find or create MBlindPixels in parameter list.
109// - get the MCerPhotEvt from the parlist (abort if missing)
110// - if no pixels are given by the user try to determin the starfield
111// from the monte carlo run header.
112//
113Int_t MBlindPixelCalc::PreProcess (MParList *pList)
114{
115 if (TESTBIT(fFlags, kUseBlindPixels))
116 fPixels = (MBlindPixels*)pList->FindObject(AddSerialNumber("MBlindPixels"));
117 else
118 fPixels = (MBlindPixels*)pList->FindCreateObj(AddSerialNumber("MBlindPixels"));
119 if (!fPixels)
120 return kFALSE;
121
122 fEvt = (MCerPhotEvt*)pList->FindObject(AddSerialNumber("MCerPhotEvt"));
123 if (!fEvt)
124 {
125 *fLog << err << dbginf << "MCerPhotEvt not found... aborting." << endl;
126 return kFALSE;
127 }
128 fPed = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
129 if (!fEvt)
130 {
131 *fLog << err << dbginf << "MPedestalCam not found... aborting." << endl;
132 return kFALSE;
133 }
134
135 fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
136 if (!fGeomCam)
137 *fLog << warn << dbginf << "No camera geometry available... can't use interpolation." << endl;
138
139 if (TESTBIT(fFlags, kUseBlindPixels))
140 return kTRUE;
141
142 const UShort_t size = fPixelsIdx.GetSize();
143
144 if (size == 0)
145 {
146 if (!pList->FindObject("MMcRunHeader"))
147 {
148 *fLog << warn << "Warning - Neither blind pixels are given nor a MMcRunHeader was found... removing MBlindPixelCalc from list." << endl;
149 return kSKIP;
150 }
151 return kTRUE;
152 }
153
154 // Set as blind pixels the global blind pixels, which are given
155 // through the macros
156
157 UShort_t numids = fPixelsIdx.GetSize();
158
159 for(Int_t i = 0; i<numids; i++)
160 fPixels->SetPixelBlind(fPixelsIdx[i]);
161
162 return kTRUE;
163}
164
165// --------------------------------------------------------------------------
166//
167// Replaces each pixel by the average of its surrounding pixels.
168// If TESTBIT(fFlags, kUseCentralPixel) is set the central pixel is also
169// included.
170//
171void MBlindPixelCalc::Interpolate() const
172{
173 const UShort_t entries = fEvt->GetNumPixels();
174
175 Double_t *nphot = new Double_t[entries];
176 Double_t *perr = new Double_t[entries];
177 Double_t *ped = new Double_t[entries];
178
179 //
180 // remove the pixels in fPixelsIdx if they are set to be used,
181 // (set them to 'unused' state)
182 //
183 for (UShort_t i=0; i<entries; i++)
184 {
185 // FIXME: Loop over blinds instead of all pixels!!!
186 MCerPhotPix &pix = (*fEvt)[i];
187
188 const Int_t idx = pix.GetPixId();
189
190 if (!fPixels->IsBlind(idx))
191 continue;
192
193 const MGeomPix &gpix = (*fGeomCam)[idx];
194
195 Int_t num = TESTBIT(fFlags, kUseCentralPixel) ? 1 : 0;
196
197 nphot[i] = TESTBIT(fFlags, kUseCentralPixel) ? pix.GetNumPhotons() : 0;
198 perr[i] = TESTBIT(fFlags, kUseCentralPixel) ? (*fPed)[idx].GetPedestalRms() : 0;
199 ped[i] = TESTBIT(fFlags, kUseCentralPixel) ? (*fPed)[idx].GetPedestal() : 0;
200
201 nphot[i] *= fGeomCam->GetPixRatio(idx);
202 // FIXME? perr
203 // FIXME? ped
204
205 const Int_t n = gpix.GetNumNeighbors();
206 for (int j=0; j<n; j++)
207 {
208 const UShort_t nidx = gpix.GetNeighbor(j);
209
210 if (fPixels->IsBlind(nidx))
211 continue;
212
213 const MCerPhotPix *evtpix = fEvt->GetPixById(nidx);
214 if (!evtpix)
215 continue;
216
217 nphot[i] += evtpix->GetNumPhotons()*fGeomCam->GetPixRatio(nidx);
218 perr[i] += (*fPed)[nidx].GetPedestalRms();
219 ped[i] += (*fPed)[nidx].GetPedestal();
220 // FIXME? perr
221 // FIXME? ped
222
223 num++;
224 }
225
226 nphot[i] /= num*fGeomCam->GetPixRatio(idx);
227 perr[i] /= num/*FIXME:???*/;
228 ped[i] /= num/*FIXME:???*/;
229 }
230
231 if (TESTBIT(fFlags, kUseInterpolation) && fGeomCam)
232 for (UShort_t i=0; i<entries; i++)
233 {
234 MCerPhotPix &pix = (*fEvt)[i];
235
236 if (fPixels->IsBlind(pix.GetPixId()))
237 {
238 pix.Set(nphot[i], -1);
239 (*fPed)[pix.GetPixId()].Set(ped[i], perr[i]);
240 }
241 }
242
243 delete nphot;
244 delete perr;
245 delete ped;
246}
247
248// --------------------------------------------------------------------------
249//
250// Removes all blind pixels from the analysis by setting their state
251// to unused.
252//
253void MBlindPixelCalc::Unmap() const
254{
255 const UShort_t entries = fEvt->GetNumPixels();
256
257 //
258 // remove the pixels in fPixelsIdx if they are set to be used,
259 // (set them to 'unused' state)
260 //
261 for (UShort_t i=0; i<entries; i++)
262 {
263 MCerPhotPix &pix = (*fEvt)[i];
264
265 if (fPixels->IsBlind(pix.GetPixId()))
266 pix.SetPixelUnused();
267 }
268}
269
270// --------------------------------------------------------------------------
271//
272// Treat the blind pixels
273//
274Int_t MBlindPixelCalc::Process()
275{
276 if (TESTBIT(fFlags, kUseInterpolation) && fGeomCam)
277 Interpolate();
278 else
279 Unmap();
280
281 return kTRUE;
282}
283
284// --------------------------------------------------------------------------
285//
286// - Check whether pixels to disable are available. If pixels are
287// given by the user nothing more is done.
288// - Otherwise try to determin the blind pixels from the starfield
289// given in MMcRunHeader.
290//
291Bool_t MBlindPixelCalc::ReInit(MParList *pList)
292{
293 if (TESTBIT(fFlags, kUseBlindPixels))
294 return kTRUE;
295
296 //
297 // If pixels are given by the user, we are already done
298 //
299 if (fPixelsIdx.GetSize() > 0)
300 return kTRUE;
301
302 //
303 // Delete the old array holding the blind pixels for the last file
304 //
305 fPixels->Clear();
306
307 if (!fGeomCam->InheritsFrom("MGeomCamMagic"))
308 {
309 *fLog << warn << "MBlindPixelCalc::ReInit: Warning - Starfield only implemented for Magic standard Camera... no action." << endl;
310 return kTRUE;
311 }
312
313 //
314 // Set as blind some particular pixels because of a particular
315 // Star Field of View.
316 //
317 MMcRunHeader *mcrun = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
318 if (!mcrun)
319 {
320 *fLog << warn << "MBlindPixelCalc::ReInit: Warning - No run header available... no action." << endl;
321 return kTRUE;
322 }
323
324 Int_t rah, ram, ras;
325 Int_t ded, dem, des;
326 mcrun->GetStarFieldRa(&rah, &ram, &ras);
327 mcrun->GetStarFieldDec(&ded, &dem, &des);
328
329 if (rah!=5 || ram!=34 || ras!=32 || ded!=22 || dem!=0 || des!=55)
330 {
331 *fLog << warn << "Warning - Starfield unknown..." << endl;
332 return kTRUE;
333 }
334
335 //
336 // Case for Crab Nebula FOV
337 //
338 fPixels->SetPixelBlind(400);
339 fPixels->SetPixelBlind(401);
340 fPixels->SetPixelBlind(402);
341 fPixels->SetPixelBlind(437);
342 fPixels->SetPixelBlind(438);
343 fPixels->SetPixelBlind(439);
344
345 *fLog << inf;
346 *fLog << "FOV is centered at CRAB NEBULA: Setting 6 blind pixels" << endl;
347 *fLog << "to avoid bias values of analysis due to CRAB NEBULA:" << endl;
348 *fLog << " Pixels: 400, 401, 402, 437, 438, 439" << endl;
349
350 return kTRUE;
351}
352
353void MBlindPixelCalc::StreamPrimitive(ofstream &out) const
354{
355 out << " MBlindPixelCalc " << GetUniqueName();
356 if (fName!=gsDefName || fTitle!=gsDefTitle)
357 {
358 out << "(\"" << fName << "\"";
359 if (fTitle!=gsDefTitle)
360 out << ", \"" << fTitle << "\"";
361 out <<")";
362 }
363 out << ";" << endl;
364
365 if (TESTBIT(fFlags, kUseInterpolation))
366 out << " " << GetUniqueName() << ".SetUseInterpolation();" << endl;
367 if (TESTBIT(fFlags, kUseCentralPixel))
368 out << " " << GetUniqueName() << ".SetUseCentralPixel();" << endl;
369
370 if (fPixelsIdx.GetSize()==0)
371 return;
372
373 out << " {" << endl;
374 out << " TArrayS dummy;" << endl;
375 for (int i=0; i<fPixelsIdx.GetSize(); i++)
376 out << " dummy[" << i << "]=" << ((TArrayS)fPixelsIdx)[i] << ";" << endl;
377 out << " " << GetUniqueName() << ".SetPixels(dummy);" << endl;
378 out << " }" << endl;
379}
Note: See TracBrowser for help on using the repository browser.