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

Last change on this file since 2273 was 2206, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 10.7 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 fPixelsID 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 = fPixelsID.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 = fPixelsID.GetSize();
148
149 for(Int_t i = 0; i<numids; i++)
150 fPixels->SetPixelBlind(fPixelsID[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 fPixelsID 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 id = pix.GetPixId();
177
178 if (!fPixels->IsBlind(id))
179 continue;
180
181 const MGeomPix &gpix = (*fGeomCam)[id];
182
183 const Int_t n = gpix.GetNumNeighbors();
184
185 Int_t num = TESTBIT(fFlags, kUseCentralPixel) ? 1 : 0;
186
187 nphot[i] = TESTBIT(fFlags, kUseCentralPixel) ? pix.GetNumPhotons() : 0;
188 perr[i] = TESTBIT(fFlags, kUseCentralPixel) ? pix.GetErrorPhot() : 0;
189
190 nphot[i] *= fGeomCam->GetPixRatio(id);
191 // FIXME: perr[i] ???
192
193 for (int j=0; j<n; j++)
194 {
195 const UShort_t nid = gpix.GetNeighbor(j);
196
197 if (fPixels->IsBlind(nid))
198 continue;
199
200 const MCerPhotPix *evtpix = fEvt->GetPixById(nid);
201 if (evtpix)
202 {
203 nphot[i] += evtpix->GetNumPhotons()*fGeomCam->GetPixRatio(nid);
204 perr[i] += evtpix->GetErrorPhot();
205 // FIXME: perr[i] ???
206 }
207 num++;
208 }
209
210 nphot[i] /= num*fGeomCam->GetPixRatio(id);
211 perr[i] /= num/*FIXME:???*/;
212 }
213
214 if (TESTBIT(fFlags, kUseInterpolation) && fGeomCam)
215 for (UShort_t i=0; i<entries; i++)
216 {
217 MCerPhotPix &pix = (*fEvt)[i];
218
219 if (fPixels->IsBlind(pix.GetPixId()))
220 pix.Set(nphot[i], perr[i]);
221 }
222
223 delete nphot;
224 delete perr;
225}
226
227// --------------------------------------------------------------------------
228//
229// Removes all blind pixels from the analysis by setting their state
230// to unused.
231//
232void MBlindPixelCalc::Unmap() const
233{
234 const UShort_t entries = fEvt->GetNumPixels();
235
236 //
237 // remove the pixels in fPixelsID if they are set to be used,
238 // (set them to 'unused' state)
239 //
240 for (UShort_t i=0; i<entries; i++)
241 {
242 MCerPhotPix &pix = (*fEvt)[i];
243
244 if (fPixels->IsBlind(pix.GetPixId()))
245 pix.SetPixelUnused();
246
247 }
248}
249
250// --------------------------------------------------------------------------
251//
252// Treat the blind pixels
253//
254Int_t MBlindPixelCalc::Process()
255{
256 if (TESTBIT(fFlags, kUseInterpolation) && fGeomCam)
257 Interpolate();
258 else
259 Unmap();
260
261 return kTRUE;
262}
263
264// --------------------------------------------------------------------------
265//
266// Set pixels to no be used.
267// This member function (public) should be called from the macro (or
268// analysis program) setting the desired blind pixels.
269// In the future, the blind pixels may be extracted from information which
270// is already in the root file.
271//
272void MBlindPixelCalc::SetPixels(Int_t num, Short_t *ids)
273{
274 fPixelsID.Adopt(num, ids);
275}
276
277// --------------------------------------------------------------------------
278//
279// - Check whether pixels to disable are available. If pixels are
280// given by the user nothing more is done.
281// - Otherwise try to determin the blind pixels from the starfield
282// given in MMcRunHeader.
283//
284Bool_t MBlindPixelCalc::ReInit(MParList *pList)
285{
286 if (TESTBIT(fFlags, kUseBlindPixels))
287 return kTRUE;
288
289 //
290 // If pixels are given by the user, we are already done
291 //
292 if (fPixelsID.GetSize() > 0)
293 return kTRUE;
294
295 //
296 // Delete the old array holding the blind pixels for the last file
297 //
298 fPixels->Clear();
299
300 //
301 // Set as blind some particular pixels because of a particular
302 // Star Field of View.
303 //
304 MMcRunHeader *mcrun = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
305 if (!mcrun)
306 {
307 *fLog << warn << "MBlindPixelCalc::ReInit: Warning - No run header available... no action." << endl;
308 return kTRUE;
309 }
310
311 Int_t rah, ram, ras;
312 Int_t ded, dem, des;
313 mcrun->GetStarFieldRa(&rah, &ram, &ras);
314 mcrun->GetStarFieldDec(&ded, &dem, &des);
315
316 if (rah!=5 || ram!=34 || ras!=32 || ded!=22 || dem!=0 || des!=55)
317 {
318 *fLog << warn << "Warning - Starfield unknown..." << endl;
319 return kTRUE;
320 }
321
322 //
323 // Case for Crab Nebula FOV
324 //
325 fPixels->SetPixelBlind(400);
326 fPixels->SetPixelBlind(401);
327 fPixels->SetPixelBlind(402);
328 fPixels->SetPixelBlind(437);
329 fPixels->SetPixelBlind(438);
330 fPixels->SetPixelBlind(439);
331
332 *fLog << inf;
333 *fLog << "FOV is centered at CRAB NEBULA: Setting 6 blind pixels" << endl;
334 *fLog << "to avoid bias values of analysis due to CRAB NEBULA:" << endl;
335 *fLog << " Pixels: 400, 401, 402, 437, 438, 439" << endl;
336
337 return kTRUE;
338}
339
340void MBlindPixelCalc::StreamPrimitive(ofstream &out) const
341{
342 out << " MBlindPixelCalc " << GetUniqueName();
343 if (fName!=gsDefName || fTitle!=gsDefTitle)
344 {
345 out << "(\"" << fName << "\"";
346 if (fTitle!=gsDefTitle)
347 out << ", \"" << fTitle << "\"";
348 out <<")";
349 }
350 out << ";" << endl;
351
352 if (TESTBIT(fFlags, kUseInterpolation))
353 out << " " << GetUniqueName() << ".SetUseInterpolation();" << endl;
354 if (TESTBIT(fFlags, kUseCentralPixel))
355 out << " " << GetUniqueName() << ".SetUseCentralPixel();" << endl;
356
357 if (fPixelsID.GetSize()==0)
358 return;
359
360 out << " {" << endl;
361 out << " TArrayS dummy;" << endl;
362 for (int i=0; i<fPixelsID.GetSize(); i++)
363 out << " dummy[" << i << "]=" << ((TArrayS)fPixelsID)[i] << ";" << endl;
364 out << " " << GetUniqueName() << ".SetPixels(dummy);" << endl;
365 out << " }" << endl;
366}
Note: See TracBrowser for help on using the repository browser.