source: trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc@ 3530

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