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

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