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

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