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

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