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

Last change on this file since 1289 was 1218, checked in by tbretz, 23 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 8.8 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
20! Author(s): Rudolf Bock 10/2001 <mailto:Rudolf.Bock@cern.ch>
21!
22! Copyright: MAGIC Software Development, 2000-2002
23!
24!
25\* ======================================================================== */
26
27/////////////////////////////////////////////////////////////////////////////
28//
29// MHillas
30//
31// Storage Container for image parameters
32//
33// basic image parameters
34// fLength major axis of ellipse
35// fWidth minor axis
36// fDelta angle of major axis wrt x-axis
37// fSize total sum of pixels
38// fMeanX x of center of ellipse
39// fMeanY y of center of ellipse
40//
41/////////////////////////////////////////////////////////////////////////////
42#include "MHillas.h"
43
44#include <fstream.h>
45
46#include <TEllipse.h>
47
48#include "MGeomPix.h"
49#include "MGeomCam.h"
50
51#include "MCerPhotPix.h"
52#include "MCerPhotEvt.h"
53
54#include "MLog.h"
55#include "MLogManip.h"
56
57ClassImp(MHillas);
58
59// --------------------------------------------------------------------------
60//
61// Default constructor.
62//
63MHillas::MHillas(const char *name, const char *title) : fEllipse(NULL)
64{
65 fName = name ? name : "MHillas";
66 fTitle = title ? title : "Storage container for image parameters of one event";
67
68 Reset();
69 // FIXME: (intelligent) initialization of values missing
70
71 fEllipse = new TEllipse;
72}
73
74// --------------------------------------------------------------------------
75//
76// Destructor. Deletes the TEllipse if one exists.
77//
78MHillas::~MHillas()
79{
80 Clear();
81}
82
83// --------------------------------------------------------------------------
84//
85void MHillas::Reset()
86{
87 fLength = 0;
88 fWidth = 0;
89 fDelta = 0;
90 fSize = 0;
91 fMeanX = 0;
92 fMeanY = 0;
93
94 Clear();
95}
96
97// --------------------------------------------------------------------------
98//
99// Print the hillas Parameters to *fLog
100//
101void MHillas::Print(Option_t *) const
102{
103 Double_t atg = atan2(fMeanY, fMeanX)*kRad2Deg;
104
105 if (atg<0)
106 atg += 180;
107
108 *fLog << all;
109 *fLog << "Basic Image Parameters (" << GetName() << ")" << endl;
110 *fLog << " - Length [mm] = " << fLength << endl;
111 *fLog << " - Width [mm] = " << fWidth << endl;
112 *fLog << " - Meanx [mm] = " << fMeanX << endl;
113 *fLog << " - Meany [mm] = " << fMeanY << endl;
114 *fLog << " - Delta [deg] = " << fDelta*kRad2Deg << endl;
115 *fLog << " - atg(y/x) [deg] = " << atg << endl;
116 *fLog << " - Size [1] = " << fSize << " #CherPhot" << endl;
117}
118
119/*
120// -----------------------------------------------------------
121//
122// call the Paint function of the Ellipse if a TEllipse exists
123//
124void MHillas::Paint(Option_t *)
125{
126 fEllipse->SetLineWidth(2);
127 fEllipse->PaintEllipse(fMeanX, fMeanY, fLength, fWidth,
128 0, 360, fDelta*kRad2Deg+180);
129}
130*/
131
132// --------------------------------------------------------------------------
133//
134// Instead of adding MHillas itself to the Pad
135// (s. AppendPad in TObject) we create an ellipse,
136// which is added to the Pad by its Draw function
137// You can remove it by deleting the Ellipse Object
138// (s. Clear() )
139//
140void MHillas::Draw(Option_t *opt)
141{
142
143 Clear();
144
145 fEllipse = new TEllipse(fMeanX, fMeanY, fLength, fWidth,
146 0, 360, fDelta*kRad2Deg+180);
147
148 fEllipse->SetLineWidth(2);
149 fEllipse->Draw();
150
151 /*
152 fEllipse->SetPhimin();
153 fEllipse->SetPhimax();
154 fEllipse->SetR1(fLength);
155 fEllipse->SetR2(fWidth);
156 fEllipse->SetTheta(fDelta*kRad2Deg+180);
157 fEllipse->SetX1(fMeanX);
158 fEllipse->SetY1(fMeanY);
159
160 fEllipse->SetLineWidth(2);
161 fEllipse->PaintEllipse(fMeanX, fMeanY, fLength, fWidth,
162 0, 360, fDelta*kRad2Deg+180);
163
164 AppendPad(opt);
165
166 // This is from TH1
167 TString opt = option;
168 opt.ToLower();
169 if (gPad && !opt.Contains("same")) {
170 //the following statement is necessary in case one attempts to draw
171 //a temporary histogram already in the current pad
172 if (TestBit(kCanDelete)) gPad->GetListOfPrimitives()->Remove(this);
173 gPad->Clear();
174 }
175 */
176}
177
178// --------------------------------------------------------------------------
179//
180// If a TEllipse object exists it is deleted
181//
182void MHillas::Clear(Option_t *)
183{
184 if (!fEllipse)
185 return;
186
187 delete fEllipse;
188
189 fEllipse = NULL;
190}
191
192
193// --------------------------------------------------------------------------
194//
195// Calculate the image parameters from a Cherenkov photon event
196// assuming Cher.photons/pixel and pixel coordinates are given
197//
198Bool_t MHillas::Calc(const MGeomCam &geom, const MCerPhotEvt &evt)
199{
200 // FIXME: MHillas::Calc is rather slow at the moment because it loops
201 // unnecessarily over all pixels in all its loops (s.MImgCleanStd)
202 // The speed could be improved very much by using Hash-Tables
203 // (linked lists, see THashTable and THashList, too)
204 //
205
206 const UInt_t npixevt = evt.GetNumPixels();
207
208 //
209 // sanity check
210 //
211 if (npixevt <= 2)
212 return kFALSE;
213
214 //
215 // calculate mean value of pixel coordinates and fSize
216 // -----------------------------------------------------
217 //
218 fMeanX = 0;
219 fMeanY = 0;
220 fSize = 0;
221
222 //
223 // FIXME! npix should be retrieved from MCerPhotEvt
224 //
225 UShort_t npix=0;
226 for (UInt_t i=0; i<npixevt; i++)
227 {
228 const MCerPhotPix &pix = evt[i];
229
230 if (!pix.IsPixelUsed())
231 continue;
232
233 const MGeomPix &gpix = geom[pix.GetPixId()];
234
235 const float nphot = pix.GetNumPhotons();
236
237 fSize += nphot; // [counter]
238 fMeanX += nphot * gpix.GetX(); // [mm]
239 fMeanY += nphot * gpix.GetY(); // [mm]
240
241 npix++;
242 }
243
244 //
245 // sanity check
246 //
247 if (fSize==0 || npix<=2)
248 return kFALSE;
249
250 fMeanX /= fSize; // [mm]
251 fMeanY /= fSize; // [mm]
252
253 //
254 // calculate 2nd moments
255 // -------------------
256 //
257 float corrxx=0; // [m^2]
258 float corrxy=0; // [m^2]
259 float corryy=0; // [m^2]
260
261 for (UInt_t i=0; i<npixevt; i++)
262 {
263 const MCerPhotPix &pix = evt[i];
264
265 if (!pix.IsPixelUsed())
266 continue;
267
268 const MGeomPix &gpix = geom[pix.GetPixId()];
269 const float dx = gpix.GetX() - fMeanX; // [mm]
270 const float dy = gpix.GetY() - fMeanY; // [mm]
271
272 const float nphot = pix.GetNumPhotons(); // [#phot]
273
274 corrxx += nphot * dx*dx; // [mm^2]
275 corrxy += nphot * dx*dy; // [mm^2]
276 corryy += nphot * dy*dy; // [mm^2]
277 }
278
279 //
280 // calculate the basic Hillas parameters: orientation and size of axes
281 // -------------------------------------------------------------------
282 //
283 const float d = corryy - corrxx;
284
285 fDelta = atan2(d + sqrt(d*d + corrxy*corrxy*4), corrxy*2);
286
287 fCosDelta = cos(fDelta); // need these in derived classes
288 fSinDelta = sin(fDelta); // like MHillasExt
289
290 float axis1 = ( fCosDelta*fSinDelta*corrxy*2 + fCosDelta*fCosDelta*corrxx + fSinDelta*fSinDelta*corryy) / fSize; // [mm^2]
291 float axis2 = (-fCosDelta*fSinDelta*corrxy*2 + fSinDelta*fSinDelta*corrxx + fCosDelta*fCosDelta*corryy) / fSize; // [mm^2]
292
293 // very small numbers can get negative by rounding
294 if (axis1 < 0) axis1=0;
295 if (axis2 < 0) axis2=0;
296
297 fLength = sqrt(axis1); // [mm]
298 fWidth = sqrt(axis2); // [mm]
299
300 SetReadyToSave();
301
302 return kTRUE;
303}
304
305// --------------------------------------------------------------------------
306//
307void MHillas::AsciiRead(ifstream &fin)
308{
309 fin >> fLength;
310 fin >> fWidth;
311 fin >> fDelta;
312 fin >> fSize;
313 fin >> fMeanX;
314 fin >> fMeanY;
315}
316
317// --------------------------------------------------------------------------
318/*
319void MHillas::AsciiWrite(ofstream &fout) const
320{
321 fout << fLength << " ";
322 fout << fWidth << " ";
323 fout << fDelta << " ";
324 fout << fSize << " ";
325 fout << fMeanX << " ";
326 fout << fMeanY;
327}
328*/
Note: See TracBrowser for help on using the repository browser.