source: trunk/MagicSoft/Mars/manalysis/MHillas.cc@ 701

Last change on this file since 701 was 701, checked in by tbretz, 24 years ago
fixed some minor errors in Hillas calculation
  • Property svn:executable set to *
File size: 4.4 KB
Line 
1/////////////////////////////////////////////////////////////////////////////
2// //
3// MHillas //
4// //
5// Storage Container for the Hillas parameter //
6// //
7// FIXME: Here everybody should find an explanation of the parameters //
8// //
9/////////////////////////////////////////////////////////////////////////////
10#include "MHillas.h"
11
12#include <TEllipse.h>
13
14#include "MCerPhotEvt.h"
15#include "MCerPhotPix.h"
16#include "MGeomCam.h"
17
18#include "MLog.h"
19
20ClassImp(MHillas)
21
22 MHillas::MHillas(const char *name, const char *title) : fEllipse(NULL)
23{
24 *fName = name ? name : "MHillas";
25 *fTitle = title ? title : "Storage container for Hillas parameter of one event";
26
27 // FIXME: Initialization of values missing
28}
29
30MHillas::~MHillas()
31{
32 Clear();
33}
34
35void MHillas::Print(Option_t *)
36{
37 *fLog << "Hillas Parameter:" << endl;
38 *fLog << " - Alpha = " << fAlpha << endl;
39 *fLog << " - Width = " << fWidth << endl;
40 *fLog << " - Length = " << fLength << endl;
41 *fLog << " - Dist = " << fDist << endl;
42}
43
44void MHillas::Draw(Option_t *)
45{
46 //
47 // Instead of adding MHillas itself to the Pad
48 // (s. AppendPad in TObject) we create an ellipse,
49 // which is added to the Pad by it's Draw function
50 // You can remove it by deleting the Ellipse Object
51 // (s. Clear() )
52 //
53
54 Clear();
55
56 fEllipse = new TEllipse(cos(fTheta)*fDist, sin(fTheta)*fDist,
57 fLength, fWidth,
58 0, 360, fTheta*kRad2Deg+fAlpha-180);
59
60 fEllipse->SetLineWidth(2);
61 fEllipse->Draw();
62}
63
64void MHillas::Clear(Option_t *)
65{
66 if (!fEllipse)
67 return;
68
69 delete fEllipse;
70
71 fEllipse = NULL;
72}
73
74void MHillas::Calc(MGeomCam &geom, MCerPhotEvt &evt)
75{
76 const UInt_t nevt = evt.GetNumPixels();
77
78 //
79 // calculate mean valu of pixels
80 //
81 float xmean =0;
82 float ymean =0;
83
84 fSize = 0;
85
86 for (UInt_t i=0; i<nevt; i++)
87 {
88 const MCerPhotPix &pix = evt[i];
89
90 if (!pix.IsPixelUsed())
91 continue;
92
93 const MGeomPix &gpix = geom[pix.GetPixId()];
94
95 const float nphot = pix.GetNumPhotons();
96
97 fSize += nphot;
98 xmean += nphot * gpix.GetX(); // [mm]
99 ymean += nphot * gpix.GetY(); // [mm]
100 }
101
102 xmean /= fSize; // [mm]
103 ymean /= fSize; // [mm]
104
105 //
106 // calculate sdev
107 //
108 float sigmaxx=0;
109 float sigmaxy=0;
110 float sigmayy=0;
111
112 for (UInt_t i=0; i<nevt; i++)
113 {
114 const MCerPhotPix &pix = evt[i];
115
116 if (!pix.IsPixelUsed())
117 continue;
118
119 const MGeomPix &gpix = geom[pix.GetPixId()];
120
121 const float dx = gpix.GetX() - xmean;
122 const float dy = gpix.GetY() - ymean;
123
124 const float nphot = pix.GetNumPhotons();
125
126 sigmaxx += nphot * dx*dx; // [mm^2]
127 sigmaxy += nphot * dx*dy; // [mm^2]
128 sigmayy += nphot * dy*dy; // [mm^2]
129 }
130
131 //
132 // check for orientation
133 //
134 const float theta = atan(sigmaxy/(sigmaxx-sigmayy)*2)/2;
135
136 float c = cos(theta); // [1]
137 float s = sin(theta); // [1]
138
139 //
140 // resolve four-fold ambiguity of solution
141 //
142 float axis1 = 2.0*c*s*sigmaxy + c*c*sigmaxx + s*s*sigmayy; // [mm^2]
143 float axis2 = -2.0*c*s*sigmaxy + s*s*sigmaxx + c*c*sigmayy; // [mm^2]
144
145 axis1 /= fSize; // [mm^2]
146 axis2 /= fSize; // [mm^2]
147
148 //
149 // check for numerical negatives
150 //
151 if (axis1 < 0) axis1=0;
152 if (axis2 < 0) axis2=0;
153
154 //
155 // check the rotation of the axis (maybe turn by 90ø)
156 //
157 const int rotation = axis1<axis2;
158
159 fLength = rotation ? sqrt(axis2) : sqrt(axis1); // [mm]
160 fWidth = rotation ? sqrt(axis1) : sqrt(axis2); // [mm]
161
162 fAlpha = rotation ?
163 fabs(atan((-xmean*c - ymean*s)/(c*ymean - s*xmean))) :
164 fabs(atan(( ymean*c - xmean*s)/(c*xmean + s*ymean))) ;
165
166 // [deg]
167
168 fAlpha *= kRad2Deg; // [deg]
169
170 fDist = sqrt(xmean*xmean + ymean*ymean); // [mm]
171
172 fTheta = atan(ymean/xmean); // [rad]
173 if (xmean<0) fTheta += kPI; // [rad]
174}
Note: See TracBrowser for help on using the repository browser.