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

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