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

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