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): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | ! Author(s): Harald Kornmayer, 1/2001
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2003
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MCerPhotEvt
|
---|
29 | //
|
---|
30 | // Class Version 1:
|
---|
31 | // - first version
|
---|
32 | //
|
---|
33 | // Class Version 2:
|
---|
34 | // - added fLut to accelerate GetPixById a lot
|
---|
35 | //
|
---|
36 | /////////////////////////////////////////////////////////////////////////////
|
---|
37 | #include "MCerPhotEvt.h"
|
---|
38 |
|
---|
39 | #include <math.h>
|
---|
40 | #include <limits.h>
|
---|
41 | #include <fstream>
|
---|
42 |
|
---|
43 | #include <TCanvas.h>
|
---|
44 |
|
---|
45 | #include "MLog.h"
|
---|
46 | #include "MLogManip.h"
|
---|
47 |
|
---|
48 | #include "MGeomCam.h"
|
---|
49 |
|
---|
50 | ClassImp(MCerPhotEvt);
|
---|
51 |
|
---|
52 | using namespace std;
|
---|
53 |
|
---|
54 | // --------------------------------------------------------------------------
|
---|
55 | //
|
---|
56 | // Creates a MCerPhotPix object for each pixel in the event
|
---|
57 | //
|
---|
58 | MCerPhotEvt::MCerPhotEvt(const char *name, const char *title) : fNumPixels(0)
|
---|
59 | {
|
---|
60 | fName = name ? name : "MCerPhotEvt";
|
---|
61 | fTitle = title ? title : "(Number of Photon)-Event Information";
|
---|
62 |
|
---|
63 | fPixels = new TClonesArray("MCerPhotPix", 0);
|
---|
64 | }
|
---|
65 |
|
---|
66 | // --------------------------------------------------------------------------
|
---|
67 | //
|
---|
68 | // This is not yet implemented like it should.
|
---|
69 | //
|
---|
70 | /*
|
---|
71 | void MCerPhotEvt::Draw(Option_t* option)
|
---|
72 | {
|
---|
73 | //
|
---|
74 | // FIXME!!! Here the Draw function of the CamDisplay
|
---|
75 | // should be called to add the CamDisplay to the Pad.
|
---|
76 | // The drawing should be done in MCamDisplay::Paint
|
---|
77 | //
|
---|
78 |
|
---|
79 | // MGeomCam *geom = fType ? new MGeomCamMagic : new MGeomCamCT1;
|
---|
80 | // MCamDisplay *disp = new MCamDisplay(geom);
|
---|
81 | // delete geom;
|
---|
82 | // disp->DrawPhotNum(this);
|
---|
83 | }
|
---|
84 | */
|
---|
85 |
|
---|
86 | // --------------------------------------------------------------------------
|
---|
87 | //
|
---|
88 | // reset counter and delete netries in list.
|
---|
89 | //
|
---|
90 | void MCerPhotEvt::Reset()
|
---|
91 | {
|
---|
92 | fNumPixels = 0;
|
---|
93 | fLut.Set(0);
|
---|
94 | // fPixels->Delete();
|
---|
95 | }
|
---|
96 |
|
---|
97 | void MCerPhotEvt::FixSize()
|
---|
98 | {
|
---|
99 | if (fPixels->GetEntriesFast() == (Int_t)fNumPixels)
|
---|
100 | return;
|
---|
101 |
|
---|
102 | fPixels->ExpandCreateFast(fNumPixels);
|
---|
103 | }
|
---|
104 |
|
---|
105 | // --------------------------------------------------------------------------
|
---|
106 | //
|
---|
107 | // Dump the cerenkov photon event to *fLog
|
---|
108 | //
|
---|
109 | void MCerPhotEvt::Print(Option_t *) const
|
---|
110 | {
|
---|
111 | const Int_t entries = fPixels->GetEntries();
|
---|
112 |
|
---|
113 | *fLog << GetDescriptor() << dec << endl;
|
---|
114 | *fLog << " Number of Pixels: " << fNumPixels << "(" << entries << ")" << endl;
|
---|
115 |
|
---|
116 | for (Int_t i=0; i<entries; i++ )
|
---|
117 | (*this)[i].Print();
|
---|
118 | }
|
---|
119 |
|
---|
120 | // --------------------------------------------------------------------------
|
---|
121 | //
|
---|
122 | // Checks if in the pixel list is an entry with pixel id
|
---|
123 | //
|
---|
124 | Bool_t MCerPhotEvt::IsPixelExisting(Int_t id) const
|
---|
125 | {
|
---|
126 | const MCerPhotPix *pix = GetPixById(id);
|
---|
127 | return pix ? kTRUE : kFALSE;
|
---|
128 | }
|
---|
129 |
|
---|
130 | // --------------------------------------------------------------------------
|
---|
131 | //
|
---|
132 | // Checks if in the pixel list is an entry with pixel id
|
---|
133 | //
|
---|
134 | Bool_t MCerPhotEvt::IsPixelUsed(Int_t id) const
|
---|
135 | {
|
---|
136 | const MCerPhotPix *pix = GetPixById(id);
|
---|
137 | return pix ? pix->IsPixelUsed() : kFALSE;
|
---|
138 | }
|
---|
139 |
|
---|
140 | // --------------------------------------------------------------------------
|
---|
141 | //
|
---|
142 | // Checks if in the pixel list is an entry with pixel id
|
---|
143 | //
|
---|
144 | Bool_t MCerPhotEvt::IsPixelCore(Int_t id) const
|
---|
145 | {
|
---|
146 | const MCerPhotPix *pix = GetPixById(id);
|
---|
147 | return pix ? pix->IsPixelCore() : kFALSE;
|
---|
148 | }
|
---|
149 |
|
---|
150 | // --------------------------------------------------------------------------
|
---|
151 | //
|
---|
152 | // get the minimum number of photons of all valid pixels in the list
|
---|
153 | // If you specify a geometry the number of photons is weighted with the
|
---|
154 | // area of the pixel
|
---|
155 | //
|
---|
156 | Float_t MCerPhotEvt::GetNumPhotonsMin(const MGeomCam *geom) const
|
---|
157 | {
|
---|
158 | if (fNumPixels <= 0)
|
---|
159 | return -5.;
|
---|
160 |
|
---|
161 | const UInt_t n = geom->GetNumPixels();
|
---|
162 |
|
---|
163 | Float_t minval = FLT_MAX;
|
---|
164 |
|
---|
165 | for (UInt_t i=1; i<fNumPixels; i++)
|
---|
166 | {
|
---|
167 | const MCerPhotPix &pix = (*this)[i];
|
---|
168 | if (!pix.IsPixelUsed())
|
---|
169 | continue;
|
---|
170 |
|
---|
171 | const UInt_t id = pix.GetPixId();
|
---|
172 | if (id>=n)
|
---|
173 | continue;
|
---|
174 |
|
---|
175 | Float_t testval = pix.GetNumPhotons();
|
---|
176 |
|
---|
177 | if (geom)
|
---|
178 | testval *= geom->GetPixRatio(id);
|
---|
179 |
|
---|
180 | if (testval < minval)
|
---|
181 | minval = testval;
|
---|
182 | }
|
---|
183 |
|
---|
184 | return minval;
|
---|
185 | }
|
---|
186 |
|
---|
187 | // --------------------------------------------------------------------------
|
---|
188 | //
|
---|
189 | // get the maximum number of photons of all valid pixels in the list
|
---|
190 | // If you specify a geometry the number of photons is weighted with the
|
---|
191 | // area of the pixel
|
---|
192 | //
|
---|
193 | Float_t MCerPhotEvt::GetNumPhotonsMax(const MGeomCam *geom) const
|
---|
194 | {
|
---|
195 | if (fNumPixels <= 0)
|
---|
196 | return 50.;
|
---|
197 |
|
---|
198 | const UInt_t n = geom->GetNumPixels();
|
---|
199 |
|
---|
200 | Float_t maxval = -FLT_MAX;
|
---|
201 |
|
---|
202 | for (UInt_t i=1; i<fNumPixels; i++)
|
---|
203 | {
|
---|
204 | const MCerPhotPix &pix = (*this)[i];
|
---|
205 | if (!pix.IsPixelUsed())
|
---|
206 | continue;
|
---|
207 |
|
---|
208 | const UInt_t id = pix.GetPixId();
|
---|
209 | if (id>=n)
|
---|
210 | continue;
|
---|
211 |
|
---|
212 | Float_t testval = pix.GetNumPhotons();
|
---|
213 | if (geom)
|
---|
214 | testval *= geom->GetPixRatio(id);
|
---|
215 |
|
---|
216 | if (testval > maxval)
|
---|
217 | maxval = testval;
|
---|
218 | }
|
---|
219 | return maxval;
|
---|
220 | }
|
---|
221 |
|
---|
222 | // --------------------------------------------------------------------------
|
---|
223 | //
|
---|
224 | // get the minimum ratio of photons/error
|
---|
225 | //
|
---|
226 | Float_t MCerPhotEvt::GetRatioMin(const MGeomCam *geom) const
|
---|
227 | {
|
---|
228 | if (fNumPixels <= 0)
|
---|
229 | return -5.;
|
---|
230 |
|
---|
231 | Float_t minval = (*this)[0].GetNumPhotons()/(*this)[0].GetErrorPhot();
|
---|
232 |
|
---|
233 | for (UInt_t i=1; i<fNumPixels; i++)
|
---|
234 | {
|
---|
235 | const MCerPhotPix &pix = (*this)[i];
|
---|
236 | if (!pix.IsPixelUsed())
|
---|
237 | continue;
|
---|
238 |
|
---|
239 | Float_t testval = pix.GetNumPhotons()/pix.GetErrorPhot();
|
---|
240 | if (geom)
|
---|
241 | testval *= TMath::Sqrt(geom->GetPixRatio(pix.GetPixId()));
|
---|
242 |
|
---|
243 | if (testval < minval)
|
---|
244 | minval = testval;
|
---|
245 | }
|
---|
246 |
|
---|
247 | return minval;
|
---|
248 | }
|
---|
249 |
|
---|
250 | // --------------------------------------------------------------------------
|
---|
251 | //
|
---|
252 | // get the maximum ratio of photons/error
|
---|
253 | //
|
---|
254 | Float_t MCerPhotEvt::GetRatioMax(const MGeomCam *geom) const
|
---|
255 | {
|
---|
256 | if (fNumPixels <= 0)
|
---|
257 | return -5.;
|
---|
258 |
|
---|
259 | Float_t maxval = -FLT_MAX;
|
---|
260 |
|
---|
261 | for (UInt_t i=1; i<fNumPixels; i++)
|
---|
262 | {
|
---|
263 | const MCerPhotPix &pix = (*this)[i];
|
---|
264 | if (!pix.IsPixelUsed())
|
---|
265 | continue;
|
---|
266 |
|
---|
267 | Float_t testval = pix.GetNumPhotons()/pix.GetErrorPhot();
|
---|
268 | if (geom)
|
---|
269 | testval *= TMath::Sqrt(geom->GetPixRatio(pix.GetPixId()));
|
---|
270 |
|
---|
271 | if (testval > maxval)
|
---|
272 | maxval = testval;
|
---|
273 | }
|
---|
274 |
|
---|
275 | return maxval;
|
---|
276 | }
|
---|
277 |
|
---|
278 | // --------------------------------------------------------------------------
|
---|
279 | //
|
---|
280 | // get the minimum of error
|
---|
281 | // If you specify a geometry the number of photons is weighted with the
|
---|
282 | // area of the pixel
|
---|
283 | //
|
---|
284 | Float_t MCerPhotEvt::GetErrorPhotMin(const MGeomCam *geom) const
|
---|
285 | {
|
---|
286 | if (fNumPixels <= 0)
|
---|
287 | return 50.;
|
---|
288 |
|
---|
289 | Float_t minval = FLT_MAX;
|
---|
290 |
|
---|
291 | for (UInt_t i=1; i<fNumPixels; i++)
|
---|
292 | {
|
---|
293 | const MCerPhotPix &pix = (*this)[i];
|
---|
294 | if (!pix.IsPixelUsed())
|
---|
295 | continue;
|
---|
296 |
|
---|
297 | Float_t testval = pix.GetErrorPhot();
|
---|
298 |
|
---|
299 | if (geom)
|
---|
300 | testval *= geom->GetPixRatio(pix.GetPixId());
|
---|
301 |
|
---|
302 | if (testval < minval)
|
---|
303 | minval = testval;
|
---|
304 | }
|
---|
305 | return minval;
|
---|
306 | }
|
---|
307 |
|
---|
308 | // --------------------------------------------------------------------------
|
---|
309 | //
|
---|
310 | // get the maximum ratio of photons/error
|
---|
311 | // If you specify a geometry the number of photons is weighted with the
|
---|
312 | // area of the pixel
|
---|
313 | //
|
---|
314 | Float_t MCerPhotEvt::GetErrorPhotMax(const MGeomCam *geom) const
|
---|
315 | {
|
---|
316 | if (fNumPixels <= 0)
|
---|
317 | return 50.;
|
---|
318 |
|
---|
319 | Float_t maxval = -FLT_MAX;
|
---|
320 |
|
---|
321 | for (UInt_t i=1; i<fNumPixels; i++)
|
---|
322 | {
|
---|
323 | const MCerPhotPix &pix = (*this)[i];
|
---|
324 | if (!pix.IsPixelUsed())
|
---|
325 | continue;
|
---|
326 |
|
---|
327 | Float_t testval = pix.GetErrorPhot();
|
---|
328 |
|
---|
329 | if (geom)
|
---|
330 | testval *= geom->GetPixRatio(pix.GetPixId());
|
---|
331 |
|
---|
332 | if (testval > maxval)
|
---|
333 | maxval = testval;
|
---|
334 | }
|
---|
335 | return maxval;
|
---|
336 | }
|
---|
337 |
|
---|
338 | void MCerPhotEvt::RemoveUnusedPixels()
|
---|
339 | {
|
---|
340 | TIter Next(fPixels);
|
---|
341 | MCerPhotPix *pix = NULL;
|
---|
342 |
|
---|
343 | while ((pix=(MCerPhotPix*)Next()))
|
---|
344 | if (!pix->IsPixelUsed())
|
---|
345 | fPixels->Remove(pix);
|
---|
346 |
|
---|
347 | fPixels->Compress();
|
---|
348 | fNumPixels=fPixels->GetEntriesFast();
|
---|
349 | }
|
---|
350 |
|
---|
351 | // --------------------------------------------------------------------------
|
---|
352 | //
|
---|
353 | // Return a pointer to the pixel with the requested idx. NULL if it doesn't
|
---|
354 | // exist. The Look-up-table fLut is used. If its size is zero (according
|
---|
355 | // to Rene this will happen if an old class object is loaded) we still
|
---|
356 | // try to search in the array.
|
---|
357 | //
|
---|
358 | MCerPhotPix *MCerPhotEvt::GetPixById(int idx) const
|
---|
359 | {
|
---|
360 | if (fLut.GetSize()>0)
|
---|
361 | return idx>=0 && idx<fLut.GetSize() ? (MCerPhotPix*)(fPixels->UncheckedAt(fLut[idx])) : 0;
|
---|
362 |
|
---|
363 | TIter Next(fPixels);
|
---|
364 | MCerPhotPix *pix = NULL;
|
---|
365 |
|
---|
366 | while ((pix=(MCerPhotPix*)Next()))
|
---|
367 | if (pix->GetPixId()==idx)
|
---|
368 | return pix;
|
---|
369 |
|
---|
370 | return NULL;
|
---|
371 | }
|
---|
372 |
|
---|
373 | // --------------------------------------------------------------------------
|
---|
374 | //
|
---|
375 | // Returns, depending on the type flag:
|
---|
376 | //
|
---|
377 | // 0: Number of Photons*PixRatio
|
---|
378 | // 1: Error*sqrt(PixRatio)
|
---|
379 | // 2: Cleaning level = Num Photons*sqrt(PixRatio)/Error
|
---|
380 | // 3: Number of Photons
|
---|
381 | // 4: Error
|
---|
382 | //
|
---|
383 | Bool_t MCerPhotEvt::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
|
---|
384 | {
|
---|
385 | MCerPhotPix *pix = GetPixById(idx);
|
---|
386 | if (!pix || !pix->IsPixelUsed())
|
---|
387 | return kFALSE;
|
---|
388 |
|
---|
389 | const Double_t ratio = cam.GetPixRatio(idx);
|
---|
390 |
|
---|
391 | switch (type)
|
---|
392 | {
|
---|
393 | case 1:
|
---|
394 | val = pix->GetErrorPhot()*TMath::Sqrt(ratio);
|
---|
395 | return kTRUE;
|
---|
396 | case 2:
|
---|
397 | if (pix->GetErrorPhot()<=0)
|
---|
398 | return kFALSE;
|
---|
399 | val = pix->GetNumPhotons()*TMath::Sqrt(ratio)/pix->GetErrorPhot();
|
---|
400 | return kTRUE;
|
---|
401 | case 3:
|
---|
402 | val = pix->GetNumPhotons();
|
---|
403 | break;
|
---|
404 | case 4:
|
---|
405 | val = pix->GetErrorPhot();
|
---|
406 | break;
|
---|
407 | default:
|
---|
408 | val = pix->GetNumPhotons()*ratio;
|
---|
409 | return kTRUE;
|
---|
410 | }
|
---|
411 | return kTRUE;
|
---|
412 | }
|
---|
413 |
|
---|
414 | void MCerPhotEvt::DrawPixelContent(Int_t num) const
|
---|
415 | {
|
---|
416 | *fLog << warn << "MCerPhotEvt::DrawPixelContent - not available." << endl;
|
---|
417 | }
|
---|