source: branches/MarsMoreSimulationTruth/mgui/MCamEvent.cc@ 20115

Last change on this file since 20115 was 12928, checked in by tbretz, 13 years ago
Fixed median calculation.
File size: 3.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, 6/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MCamEvent
28//
29// A base class describing an event in the camera.
30//
31// If GetPixelContent returns kFALSE, it must not touch 'val'.
32//
33// You can derive a class in addition to TObject from MCamEvent, too.
34//
35// MCamEvent MUST be after TObject:
36// ALLOWED: class MyClass : public TObject, public MCamEvent
37// FORBIDDEN: class MyClass : public MCamEvent, public TObject
38//
39//////////////////////////////////////////////////////////////////////////////
40#include "MCamEvent.h"
41
42#include <TMath.h>
43
44#include "MGeomCam.h"
45#include "MArrayD.h"
46
47ClassImp(MCamEvent);
48
49// --------------------------------------------------------------------------
50//
51// You can overwrite this function if you want the container to be
52// initialized by MGeomApply with the geometry. If it is not overloaded
53// it calls InitSize with the corresponding pixel number. If this information
54// is enough for you it is enough to overload InitSize.
55//
56void MCamEvent::Init(const MGeomCam &geom)
57{
58 InitSize(geom.GetNumPixels());
59}
60
61// --------------------------------------------------------------------------
62//
63// Return the median of all corresponding GetPixelContent
64//
65Double_t MCamEvent::GetCameraMedian(const MGeomCam &cam, Int_t type) const
66{
67 Int_t num = 0;
68
69 MArrayD arr(cam.GetNumPixels());
70 for (unsigned int i=0; i<cam.GetNumPixels(); i++)
71 {
72 Double_t val;
73 if (!GetPixelContent(val, i, cam, type))
74 continue;
75
76 arr[num++] = val;
77 }
78
79 return TMath::Median(num, arr.GetArray());
80}
81
82// --------------------------------------------------------------------------
83//
84// Return the mean of all corresponding GetPixelContent
85//
86Double_t MCamEvent::GetCameraMean(const MGeomCam &cam, Int_t type) const
87{
88 return GetCameraStat(cam, type)[0];
89}
90
91// --------------------------------------------------------------------------
92//
93// Return the rms of all corresponding GetPixelContent
94//
95Double_t MCamEvent::GetCameraRMS(const MGeomCam &cam, Int_t type) const
96{
97 return GetCameraStat(cam, type)[1];
98}
99
100// --------------------------------------------------------------------------
101//
102// Return the rms of all corresponding GetPixelContent
103//
104TArrayD MCamEvent::GetCameraStat(const MGeomCam &cam, Int_t type) const
105{
106 Int_t num = 0;
107 Double_t sum = 0;
108 Double_t sq = 0;
109
110 for (unsigned int i=0; i<cam.GetNumPixels(); i++)
111 {
112 Double_t val;
113 if (!GetPixelContent(val, i, cam, type))
114 continue;
115
116 sum += val;
117 sq += val;
118 num ++;
119 }
120
121 if (num==0)
122 return 0;
123
124 sum /= num;
125 sq /= num;
126
127 TArrayD stat(2);
128 stat[0] = sum;
129 stat[1] = TMath::Sqrt(sq-sum*sum);
130 return stat;
131}
Note: See TracBrowser for help on using the repository browser.