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

Last change on this file since 2143 was 2139, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 9.1 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@uni-sw.gwdg.de>
19! Author(s): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
20!
21! Copyright: MAGIC Software Development, 2000-2001
22!
23!
24\* ======================================================================== */
25
26#include "MCerPhotEvt.h"
27
28#include <math.h>
29#include <limits.h>
30#include <fstream.h>
31
32#include <TCanvas.h>
33
34#include "MLog.h"
35
36#include "MGeomCam.h"
37
38ClassImp(MCerPhotEvt);
39
40// --------------------------------------------------------------------------
41//
42// Creates a MCerPhotPix object for each pixel in the event
43//
44MCerPhotEvt::MCerPhotEvt(const char *name, const char *title) : fNumPixels(0)
45{
46 fName = name ? name : "MCerPhotEvt";
47 fTitle = title ? title : "(Number of Photon)-Event Information";
48
49 fPixels = new TClonesArray("MCerPhotPix", 0);
50}
51
52// --------------------------------------------------------------------------
53//
54// This is not yet implemented like it should.
55//
56void MCerPhotEvt::Draw(Option_t* option)
57{
58 //
59 // FIXME!!! Here the Draw function of the CamDisplay
60 // should be called to add the CamDisplay to the Pad.
61 // The drawing should be done in MCamDisplay::Paint
62 //
63
64 // MGeomCam *geom = fType ? new MGeomCamMagic : new MGeomCamCT1;
65 // MCamDisplay *disp = new MCamDisplay(geom);
66 // delete geom;
67 // disp->DrawPhotNum(this);
68}
69
70// --------------------------------------------------------------------------
71//
72// reset counter and delete netries in list.
73//
74void MCerPhotEvt::Reset()
75{
76 fNumPixels = 0;
77// fPixels->Delete();
78}
79
80void MCerPhotEvt::FixSize()
81{
82 if (fPixels->GetEntriesFast() == (Int_t)fNumPixels)
83 return;
84
85 fPixels->ExpandCreateFast(fNumPixels);
86}
87
88// --------------------------------------------------------------------------
89//
90// Dump the cerenkov photon event to *fLog
91//
92void MCerPhotEvt::Print(Option_t *) const
93{
94 const Int_t entries = fPixels->GetEntries();
95
96 *fLog << GetDescriptor() << dec << endl;
97 *fLog << " Number of Pixels: " << fNumPixels << "(" << entries << ")" << endl;
98
99 for (Int_t i=0; i<entries; i++ )
100 (*this)[i].Print();
101}
102
103// --------------------------------------------------------------------------
104//
105// Checks if in the pixel list is an entry with pixel id
106//
107Bool_t MCerPhotEvt::IsPixelExisting(Int_t id) const
108{
109 const Int_t entries = fPixels->GetEntries();
110
111 for (Int_t i=0; i<entries; i++)
112 {
113 if (id == (*this)[i].GetPixId())
114 return kTRUE;
115 }
116
117 return kFALSE;
118}
119
120// --------------------------------------------------------------------------
121//
122// Checks if in the pixel list is an entry with pixel id
123//
124Bool_t MCerPhotEvt::IsPixelUsed(Int_t id) const
125{
126 const Int_t entries = fPixels->GetEntries();
127
128 for (Int_t i=0; i<entries; i++)
129 {
130 const MCerPhotPix &pix = (*this)[i];
131 if (!pix.IsPixelUsed())
132 continue;
133
134 if (id == pix.GetPixId() && pix.IsPixelUsed())
135 return kTRUE;
136 }
137
138 return kFALSE;
139}
140
141// --------------------------------------------------------------------------
142//
143// Checks if in the pixel list is an entry with pixel id
144//
145Bool_t MCerPhotEvt::IsPixelCore(Int_t id) const
146{
147 const Int_t entries = fPixels->GetEntries();
148
149 for (Int_t i=0; i<entries; i++)
150 {
151 const MCerPhotPix &pix = (*this)[i];
152 if (!pix.IsPixelUsed())
153 continue;
154
155 if (id == pix.GetPixId() && pix.IsPixelCore())
156 return kTRUE;
157 }
158
159 return kFALSE;
160}
161
162// --------------------------------------------------------------------------
163//
164// get the minimum number of photons of all valid pixels in the list
165// If you specify a geometry the number of photons is weighted with the
166// area of the pixel
167//
168Float_t MCerPhotEvt::GetNumPhotonsMin(const MGeomCam *geom) const
169{
170 if (fNumPixels <= 0)
171 return -5.;
172
173 const UInt_t n = geom->GetNumPixels();
174
175 Float_t minval = FLT_MAX;
176
177 for (UInt_t i=1; i<fNumPixels; i++)
178 {
179 const MCerPhotPix &pix = (*this)[i];
180 if (!pix.IsPixelUsed())
181 continue;
182
183 const UInt_t id = pix.GetPixId();
184 if (id>=n)
185 continue;
186
187 Float_t testval = pix.GetNumPhotons();
188
189 if (geom)
190 testval *= geom->GetPixRatio(id);
191
192 if (testval < minval)
193 minval = testval;
194 }
195
196 return minval;
197}
198
199// --------------------------------------------------------------------------
200//
201// get the maximum number of photons of all valid pixels in the list
202// If you specify a geometry the number of photons is weighted with the
203// area of the pixel
204//
205Float_t MCerPhotEvt::GetNumPhotonsMax(const MGeomCam *geom) const
206{
207 if (fNumPixels <= 0)
208 return 50.;
209
210 const UInt_t n = geom->GetNumPixels();
211
212 Float_t maxval = -FLT_MAX;
213
214 for (UInt_t i=1; i<fNumPixels; i++)
215 {
216 const MCerPhotPix &pix = (*this)[i];
217 if (!pix.IsPixelUsed())
218 continue;
219
220 const UInt_t id = pix.GetPixId();
221 if (id>=n)
222 continue;
223
224 Float_t testval = pix.GetNumPhotons();
225 if (geom)
226 testval *= geom->GetPixRatio(id);
227
228 if (testval > maxval)
229 maxval = testval;
230 }
231 return maxval;
232}
233
234// --------------------------------------------------------------------------
235//
236// get the minimum ratio of photons/error
237//
238Float_t MCerPhotEvt::GetRatioMin() const
239{
240 if (fNumPixels <= 0)
241 return -5.;
242
243 Float_t minval = (*this)[0].GetNumPhotons()/(*this)[0].GetErrorPhot();
244
245 for (UInt_t i=1; i<fNumPixels; i++)
246 {
247 const MCerPhotPix &pix = (*this)[i];
248 if (!pix.IsPixelUsed())
249 continue;
250
251 Float_t testval = pix.GetNumPhotons()/pix.GetErrorPhot();
252 if (testval < minval)
253 minval = testval;
254 }
255
256 return minval;
257}
258
259// --------------------------------------------------------------------------
260//
261// get the maximum ratio of photons/error
262//
263Float_t MCerPhotEvt::GetRatioMax() const
264{
265 if (fNumPixels <= 0)
266 return -5.;
267
268 Float_t maxval = -FLT_MAX;
269
270 for (UInt_t i=1; i<fNumPixels; i++)
271 {
272 const MCerPhotPix &pix = (*this)[i];
273 if (!pix.IsPixelUsed())
274 continue;
275
276 Float_t testval = pix.GetNumPhotons()/pix.GetErrorPhot();
277 if (testval > maxval)
278 maxval = testval;
279 }
280
281 return maxval;
282}
283
284// --------------------------------------------------------------------------
285//
286// get the minimum of error
287// If you specify a geometry the number of photons is weighted with the
288// area of the pixel
289//
290Float_t MCerPhotEvt::GetErrorPhotMin(const MGeomCam *geom) const
291{
292 if (fNumPixels <= 0)
293 return 50.;
294
295 Float_t minval = FLT_MAX;
296
297 for (UInt_t i=1; i<fNumPixels; i++)
298 {
299 const MCerPhotPix &pix = (*this)[i];
300 if (!pix.IsPixelUsed())
301 continue;
302
303 Float_t testval = pix.GetErrorPhot();
304
305 if (geom)
306 testval *= geom->GetPixRatio(pix.GetPixId());
307
308 if (testval < minval)
309 minval = testval;
310 }
311 return minval;
312}
313
314// --------------------------------------------------------------------------
315//
316// get the maximum ratio of photons/error
317// If you specify a geometry the number of photons is weighted with the
318// area of the pixel
319//
320Float_t MCerPhotEvt::GetErrorPhotMax(const MGeomCam *geom) const
321{
322 if (fNumPixels <= 0)
323 return 50.;
324
325 Float_t maxval = -FLT_MAX;
326
327 for (UInt_t i=1; i<fNumPixels; i++)
328 {
329 const MCerPhotPix &pix = (*this)[i];
330 if (!pix.IsPixelUsed())
331 continue;
332
333 Float_t testval = pix.GetErrorPhot();
334
335 if (geom)
336 testval *= geom->GetPixRatio(pix.GetPixId());
337
338 if (testval > maxval)
339 maxval = testval;
340 }
341 return maxval;
342}
343
344// --------------------------------------------------------------------------
345//
346// Return a pointer to the pixel with the requested id. NULL if it doesn't
347// exist.
348//
349MCerPhotPix *MCerPhotEvt::GetPixById(int id) const
350{
351 TIter Next(fPixels);
352 MCerPhotPix *pix = NULL;
353
354 while ((pix=(MCerPhotPix*)Next()))
355 if (pix->GetPixId()==id)
356 return pix;
357
358 return NULL;
359}
360
361void MCerPhotEvt::Scale(Double_t f)
362{
363 fPixels->ForEach(MCerPhotPix, Scale)(f);
364}
365
366void MCerPhotEvt::RemoveUnusedPixels()
367{
368 TIter Next(fPixels);
369 MCerPhotPix *pix = NULL;
370
371 while ((pix=(MCerPhotPix*)Next()))
372 if (!pix->IsPixelUsed())
373 fPixels->Remove(pix);
374
375 fPixels->Compress();
376 fNumPixels=fPixels->GetEntriesFast();
377}
Note: See TracBrowser for help on using the repository browser.