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

Last change on this file since 2172 was 2147, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 9.3 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 MGeomCam *geom) 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 (geom)
253 testval *= TMath::Sqrt(geom->GetPixRatio(pix.GetPixId()));
254
255 if (testval < minval)
256 minval = testval;
257 }
258
259 return minval;
260}
261
262// --------------------------------------------------------------------------
263//
264// get the maximum ratio of photons/error
265//
266Float_t MCerPhotEvt::GetRatioMax(const MGeomCam *geom) const
267{
268 if (fNumPixels <= 0)
269 return -5.;
270
271 Float_t maxval = -FLT_MAX;
272
273 for (UInt_t i=1; i<fNumPixels; i++)
274 {
275 const MCerPhotPix &pix = (*this)[i];
276 if (!pix.IsPixelUsed())
277 continue;
278
279 Float_t testval = pix.GetNumPhotons()/pix.GetErrorPhot();
280 if (geom)
281 testval *= TMath::Sqrt(geom->GetPixRatio(pix.GetPixId()));
282
283 if (testval > maxval)
284 maxval = testval;
285 }
286
287 return maxval;
288}
289
290// --------------------------------------------------------------------------
291//
292// get the minimum of error
293// If you specify a geometry the number of photons is weighted with the
294// area of the pixel
295//
296Float_t MCerPhotEvt::GetErrorPhotMin(const MGeomCam *geom) const
297{
298 if (fNumPixels <= 0)
299 return 50.;
300
301 Float_t minval = FLT_MAX;
302
303 for (UInt_t i=1; i<fNumPixels; i++)
304 {
305 const MCerPhotPix &pix = (*this)[i];
306 if (!pix.IsPixelUsed())
307 continue;
308
309 Float_t testval = pix.GetErrorPhot();
310
311 if (geom)
312 testval *= geom->GetPixRatio(pix.GetPixId());
313
314 if (testval < minval)
315 minval = testval;
316 }
317 return minval;
318}
319
320// --------------------------------------------------------------------------
321//
322// get the maximum ratio of photons/error
323// If you specify a geometry the number of photons is weighted with the
324// area of the pixel
325//
326Float_t MCerPhotEvt::GetErrorPhotMax(const MGeomCam *geom) const
327{
328 if (fNumPixels <= 0)
329 return 50.;
330
331 Float_t maxval = -FLT_MAX;
332
333 for (UInt_t i=1; i<fNumPixels; i++)
334 {
335 const MCerPhotPix &pix = (*this)[i];
336 if (!pix.IsPixelUsed())
337 continue;
338
339 Float_t testval = pix.GetErrorPhot();
340
341 if (geom)
342 testval *= geom->GetPixRatio(pix.GetPixId());
343
344 if (testval > maxval)
345 maxval = testval;
346 }
347 return maxval;
348}
349
350// --------------------------------------------------------------------------
351//
352// Return a pointer to the pixel with the requested id. NULL if it doesn't
353// exist.
354//
355MCerPhotPix *MCerPhotEvt::GetPixById(int id) const
356{
357 TIter Next(fPixels);
358 MCerPhotPix *pix = NULL;
359
360 while ((pix=(MCerPhotPix*)Next()))
361 if (pix->GetPixId()==id)
362 return pix;
363
364 return NULL;
365}
366
367void MCerPhotEvt::Scale(Double_t f)
368{
369 fPixels->ForEach(MCerPhotPix, Scale)(f);
370}
371
372void MCerPhotEvt::RemoveUnusedPixels()
373{
374 TIter Next(fPixels);
375 MCerPhotPix *pix = NULL;
376
377 while ((pix=(MCerPhotPix*)Next()))
378 if (!pix->IsPixelUsed())
379 fPixels->Remove(pix);
380
381 fPixels->Compress();
382 fNumPixels=fPixels->GetEntriesFast();
383}
Note: See TracBrowser for help on using the repository browser.