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

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