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

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