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

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