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

Last change on this file since 3450 was 3378, 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 if (fPixels->GetEntriesFast() == (Int_t)fNumPixels)
106 return;
107
108 fPixels->ExpandCreateFast(fNumPixels);
109}
110
111// --------------------------------------------------------------------------
112//
113// Dump the cerenkov photon event to *fLog
114//
115void MCerPhotEvt::Print(Option_t *) const
116{
117 const Int_t entries = fPixels->GetEntries();
118
119 *fLog << GetDescriptor() << dec << endl;
120 *fLog << " Number of Pixels: " << fNumPixels << "(" << entries << ")" << endl;
121
122 for (Int_t i=0; i<entries; i++ )
123 (*this)[i].Print();
124}
125
126// --------------------------------------------------------------------------
127//
128// Checks if in the pixel list is an entry with pixel id
129//
130Bool_t MCerPhotEvt::IsPixelExisting(Int_t id) const
131{
132 return GetPixById(id) ? kTRUE : kFALSE;
133}
134
135// --------------------------------------------------------------------------
136//
137// Checks if in the pixel list is an entry with pixel id
138//
139Bool_t MCerPhotEvt::IsPixelUsed(Int_t id) const
140{
141 const MCerPhotPix *pix = GetPixById(id);
142 return pix ? pix->IsPixelUsed() : kFALSE;
143}
144
145// --------------------------------------------------------------------------
146//
147// Checks if in the pixel list is an entry with pixel id
148//
149Bool_t MCerPhotEvt::IsPixelCore(Int_t id) const
150{
151 const MCerPhotPix *pix = GetPixById(id);
152 return pix ? pix->IsPixelCore() : kFALSE;
153}
154
155// --------------------------------------------------------------------------
156//
157// get the minimum number of photons of all valid pixels in the list
158// If you specify a geometry the number of photons is weighted with the
159// area of the pixel
160//
161Float_t MCerPhotEvt::GetNumPhotonsMin(const MGeomCam *geom) const
162{
163 if (fNumPixels <= 0)
164 return -5.;
165
166 const UInt_t n = geom->GetNumPixels();
167
168 Float_t minval = FLT_MAX;
169
170 for (UInt_t i=0; i<fNumPixels; i++)
171 {
172 const MCerPhotPix &pix = (*this)[i];
173 if (!pix.IsPixelUsed())
174 continue;
175
176 const UInt_t id = pix.GetPixId();
177 if (id<0 || id>=n)
178 continue;
179
180 Float_t testval = pix.GetNumPhotons();
181
182 if (geom)
183 testval *= geom->GetPixRatio(id);
184
185 if (testval < minval)
186 minval = testval;
187 }
188
189 return minval;
190}
191
192// --------------------------------------------------------------------------
193//
194// get the maximum number of photons of all valid pixels in the list
195// If you specify a geometry the number of photons is weighted with the
196// area of the pixel
197//
198Float_t MCerPhotEvt::GetNumPhotonsMax(const MGeomCam *geom) const
199{
200 if (fNumPixels <= 0)
201 return 50.;
202
203 const UInt_t n = geom->GetNumPixels();
204
205 Float_t maxval = -FLT_MAX;
206
207 for (UInt_t i=0; i<fNumPixels; i++)
208 {
209 const MCerPhotPix &pix = (*this)[i];
210 if (!pix.IsPixelUsed())
211 continue;
212
213 const UInt_t id = pix.GetPixId();
214 if (id<0 || id>=n)
215 continue;
216
217 Float_t testval = pix.GetNumPhotons();
218 if (geom)
219 testval *= geom->GetPixRatio(id);
220
221 if (testval > maxval)
222 maxval = testval;
223 }
224 return maxval;
225}
226
227// --------------------------------------------------------------------------
228//
229// get the minimum ratio of photons/error
230//
231Float_t MCerPhotEvt::GetRatioMin(const MGeomCam *geom) const
232{
233 if (fNumPixels <= 0)
234 return -5.;
235
236 Float_t minval = FLT_MAX;
237
238 for (UInt_t i=0; i<fNumPixels; i++)
239 {
240 const MCerPhotPix &pix = (*this)[i];
241 if (!pix.IsPixelUsed())
242 continue;
243
244 Float_t testval = pix.GetNumPhotons()/pix.GetErrorPhot();
245 if (geom)
246 testval *= TMath::Sqrt(geom->GetPixRatio(pix.GetPixId()));
247
248 if (testval < minval)
249 minval = testval;
250 }
251
252 return minval;
253}
254
255// --------------------------------------------------------------------------
256//
257// get the maximum ratio of photons/error
258//
259Float_t MCerPhotEvt::GetRatioMax(const MGeomCam *geom) const
260{
261 if (fNumPixels <= 0)
262 return -5.;
263
264 Float_t maxval = -FLT_MAX;
265
266 for (UInt_t i=0; i<fNumPixels; i++)
267 {
268 const MCerPhotPix &pix = (*this)[i];
269 if (!pix.IsPixelUsed())
270 continue;
271
272 Float_t testval = pix.GetNumPhotons()/pix.GetErrorPhot();
273 if (geom)
274 testval *= TMath::Sqrt(geom->GetPixRatio(pix.GetPixId()));
275
276 if (testval > maxval)
277 maxval = testval;
278 }
279
280 return maxval;
281}
282
283// --------------------------------------------------------------------------
284//
285// get the minimum of error
286// If you specify a geometry the number of photons is weighted with the
287// area of the pixel
288//
289Float_t MCerPhotEvt::GetErrorPhotMin(const MGeomCam *geom) const
290{
291 if (fNumPixels <= 0)
292 return 50.;
293
294 Float_t minval = FLT_MAX;
295
296 for (UInt_t i=0; i<fNumPixels; i++)
297 {
298 const MCerPhotPix &pix = (*this)[i];
299 if (!pix.IsPixelUsed())
300 continue;
301
302 Float_t testval = pix.GetErrorPhot();
303
304 if (geom)
305 testval *= geom->GetPixRatio(pix.GetPixId());
306
307 if (testval < minval)
308 minval = testval;
309 }
310 return minval;
311}
312
313// --------------------------------------------------------------------------
314//
315// get the maximum ratio of photons/error
316// If you specify a geometry the number of photons is weighted with the
317// area of the pixel
318//
319Float_t MCerPhotEvt::GetErrorPhotMax(const MGeomCam *geom) const
320{
321 if (fNumPixels <= 0)
322 return 50.;
323
324 Float_t maxval = -FLT_MAX;
325
326 for (UInt_t i=0; i<fNumPixels; i++)
327 {
328 const MCerPhotPix &pix = (*this)[i];
329 if (!pix.IsPixelUsed())
330 continue;
331
332 Float_t testval = pix.GetErrorPhot();
333
334 if (geom)
335 testval *= geom->GetPixRatio(pix.GetPixId());
336
337 if (testval > maxval)
338 maxval = testval;
339 }
340 return maxval;
341}
342
343void MCerPhotEvt::RemoveUnusedPixels()
344{
345 TIter Next(fPixels);
346 MCerPhotPix *pix = NULL;
347
348 while ((pix=(MCerPhotPix*)Next()))
349 if (!pix->IsPixelUsed())
350 fPixels->Remove(pix);
351
352 fPixels->Compress();
353 fNumPixels=fPixels->GetEntriesFast();
354}
355
356// --------------------------------------------------------------------------
357//
358// Return a pointer to the pixel with the requested idx. NULL if it doesn't
359// exist. The Look-up-table fLut is used. If its size is zero (according
360// to Rene this will happen if an old class object is loaded) we still
361// try to search in the array.
362//
363MCerPhotPix *MCerPhotEvt::GetPixById(Int_t idx) const
364{
365 if (idx<0)
366 return 0;
367
368 if (fLut.GetSize()>0)
369 {
370 if (idx>=fLut.GetSize())
371 return 0;
372
373 return fLut[idx]<0 ? 0 : (MCerPhotPix*)(fPixels->UncheckedAt(fLut[idx]));
374 }
375
376 TIter Next(fPixels);
377 MCerPhotPix *pix = NULL;
378
379 while ((pix=(MCerPhotPix*)Next()))
380 if (pix->GetPixId()==idx)
381 return pix;
382
383 return NULL;
384}
385
386// --------------------------------------------------------------------------
387//
388// Returns, depending on the type flag:
389//
390// 0: Number of Photons*PixRatio
391// 1: Error*sqrt(PixRatio)
392// 2: Cleaning level = Num Photons*sqrt(PixRatio)/Error
393// 3: Number of Photons
394// 4: Error
395//
396Bool_t MCerPhotEvt::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
397{
398 MCerPhotPix *pix = GetPixById(idx);
399 if (!pix || !pix->IsPixelUsed())
400 return kFALSE;
401
402 const Double_t ratio = cam.GetPixRatio(idx);
403
404 switch (type)
405 {
406 case 1:
407 val = pix->GetErrorPhot()*TMath::Sqrt(ratio);
408 return kTRUE;
409 case 2:
410 if (pix->GetErrorPhot()<=0)
411 return kFALSE;
412 val = pix->GetNumPhotons()*TMath::Sqrt(ratio)/pix->GetErrorPhot();
413 return kTRUE;
414 case 3:
415 val = pix->GetNumPhotons();
416 break;
417 case 4:
418 val = pix->GetErrorPhot();
419 break;
420 default:
421 val = pix->GetNumPhotons()*ratio;
422 return kTRUE;
423 }
424 return kTRUE;
425}
426
427void MCerPhotEvt::DrawPixelContent(Int_t num) const
428{
429 *fLog << warn << "MCerPhotEvt::DrawPixelContent - not available." << endl;
430}
431
432TObject *MCerPhotEvtIter::Next()
433{
434 if (!fUsedOnly)
435 return TObjArrayIter::Next();
436
437 MCerPhotPix *pix;
438 while ((pix = (MCerPhotPix*)TObjArrayIter::Next()))
439 if (pix->IsPixelUsed())
440 return pix;
441 return pix;
442}
Note: See TracBrowser for help on using the repository browser.