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