source: trunk/MagicSoft/Mars/mmuon/MMuonSearchPar.cc@ 7367

Last change on this file since 7367 was 7367, checked in by tbretz, 19 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): Keiichi Mase 10/2004 <mailto:mase@mppmu.mpg.de>
19! Author(s): Markus Meyer 10/2004 <mailto:meyer@astro.uni-wuerzburg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2005
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MMuonSearchPar
29//
30// Storage Container for muon
31//
32// This class is the container for muon parameters. The calculation
33// of Radius and center of the ring is done here.
34// Muons are searched by fitting the image with a circle.
35//
36// In order to use further information of muons such as the width of arcs,
37// the size of the fraction of the ring and the muons size, use the
38// infomation stored in
39//
40// MMuonCalibPar.
41//
42// The information will be available by using the task of
43//
44// MMuonCalibParCalc.
45//
46// Version 2:
47// ----------
48// + Float_t fTime; // Mean arrival time of core pixels
49// + Float_t fTimeRms; // Rms of arrival time of core pixels
50//
51// Input Containers:
52// MGeomCam
53// MHillas
54// MSignalCam
55//
56/////////////////////////////////////////////////////////////////////////////
57#include "MMuonSearchPar.h"
58
59#include <TMinuit.h>
60#include <TEllipse.h>
61
62#include "MLog.h"
63#include "MLogManip.h"
64
65#include "MHillas.h"
66
67#include "MGeomCam.h"
68#include "MGeomPix.h"
69
70#include "MSignalPix.h"
71#include "MSignalCam.h"
72
73using namespace std;
74
75ClassImp(MMuonSearchPar);
76
77// --------------------------------------------------------------------------
78//
79// Default constructor.
80//
81MMuonSearchPar::MMuonSearchPar(const char *name, const char *title)
82{
83 fName = name ? name : "MMuonSearchPar";
84 fTitle = title ? title : "Parameters to find Muons";
85}
86
87// --------------------------------------------------------------------------
88//
89void MMuonSearchPar::Reset()
90{
91 fRadius = -1;
92 fDeviation = -1;
93 fCenterX = 0;
94 fCenterY = 0;
95 fTime = 0;
96 fTimeRms = -1;
97}
98
99// --------------------------------------------------------------------------
100//
101// This is a wrapper function to have direct access to the data members
102// in the function calculating the minimization value.
103//
104void MMuonSearchPar::fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
105{
106 const MMuonSearchPar *optim = (MMuonSearchPar*)gMinuit->GetObjectFit();
107 f = optim->Fcn(par);
108}
109
110// --------------------------------------------------------------------------
111//
112// This function gives you the ring radius fitted best to the camera image
113// and its RMS for the input position.
114//
115Double_t MMuonSearchPar::Fcn(Double_t *par) const
116{
117 const Int_t entries = fSignal.GetSize();
118
119 Double_t meanr=0;
120 Double_t devr =0;
121 Double_t sums =0;
122
123 // It seems that the loop is easy enough for a compiler optimization.
124 // Using pointer arithmetics doesn't improve the speed of the fit.
125 for (Int_t i=0; i<entries; i++ )
126 {
127 Double_t tmp = TMath::Hypot(fX[i]-par[0], fY[i]-par[1]);
128
129 sums += fSignal[i];
130 meanr += fSignal[i] * tmp;
131 devr += fSignal[i] * tmp*tmp;
132 }
133
134 par[2] = meanr/sums;
135 par[3] = devr/sums - par[2]*par[2];
136
137 return par[3];
138}
139
140// --------------------------------------------------------------------------
141//
142// This function finds the center position of the circle which gives minimum
143// RMS of the fit, changing the center position of the circle.
144//
145void MMuonSearchPar::CalcMinimumDeviation(const MGeomCam &geom,
146 const MSignalCam &evt,
147 Double_t &x, Double_t &y,
148 Double_t &sigma, Double_t &radius)
149{
150 // ------- Make a temporaray copy of the signal ---------
151 // ------- and calculate arrival time parameters --------
152 const Int_t n = geom.GetNumPixels();
153
154 fSignal.Set(n);
155 fX.Set(n);
156 fY.Set(n);
157
158 Int_t p=0;
159 Int_t q=0;
160
161 Float_t mean=0;
162 Float_t sq =0;
163
164 for (int i=0; i<n; i++)
165 {
166 const MSignalPix &pix = evt[i];
167
168 if (pix.IsPixelUsed())
169 {
170 fSignal[p] = pix.GetNumPhotons();
171
172 fX[p] = geom[i].GetX();
173 fY[p] = geom[i].GetY();
174 p++;
175
176 //timing
177 if (!pix.IsPixelCore())
178 continue;
179
180 mean += pix.GetArrivalTime();
181 sq += pix.GetArrivalTime()*pix.GetArrivalTime();
182 q++;
183 }
184 }
185
186 mean /= q;
187 sq /= q;
188
189 fTime = mean;
190 fTimeRms = TMath::Sqrt(sq-mean*mean);
191
192 fSignal.Set(p);
193
194
195 // ----------------- Setup and call minuit -------------------
196 const Float_t delta = 30.; // 3 mm (1/10 of an inner pixel size) Step to move.
197 const Double_t r = geom.GetMaxRadius()*2;
198
199 // Save gMinuit
200 TMinuit *minsave = gMinuit;
201
202 // Initialize TMinuit with 4 parameters
203 TMinuit minuit;
204 minuit.SetPrintLevel(-1); // Switch off printing
205 minuit.Command("set nowarn"); // Switch off warning
206 // Define Parameters
207 minuit.DefineParameter(0, "x", x, delta, -r, r);
208 minuit.DefineParameter(1, "y", y, delta, -r, r);
209 minuit.DefineParameter(2, "r", 0, 1, 0, 0);
210 minuit.DefineParameter(3, "sigma", 0, 1, 0, 0);
211 // Fix return parameters
212 minuit.FixParameter(2);
213 minuit.FixParameter(3);
214 // Setup Minuit for 'this' and use fit function fcn
215 minuit.SetObjectFit(this);
216 minuit.SetFCN(fcn);
217
218 // Perform Simplex minimization
219 Int_t err;
220 Double_t tmp[2] = { 0, 0 };
221 minuit.mnexcm("simplex", tmp, 2, err);
222
223 // Get resulting parameters
224 Double_t error;
225 minuit.GetParameter(0, x, error);
226 minuit.GetParameter(1, y, error);
227 minuit.GetParameter(2, radius, error);
228 minuit.GetParameter(3, sigma, error);
229
230 sigma = sigma>0 ? TMath::Sqrt(sigma) : 0;
231
232 gMinuit = minsave;
233}
234
235// --------------------------------------------------------------------------
236//
237// Calculation of muon parameters
238//
239void MMuonSearchPar::Calc(const MGeomCam &geom, const MSignalCam &evt,
240 const MHillas &hillas)
241{
242 Double_t x = hillas.GetMeanX();
243 Double_t y = hillas.GetMeanY();
244
245 // -------------------------------------------------
246 // Keiichi suggested trying to precalculate the Muon
247 // center a bit better, but it neither improves the
248 // fit result nor the speed
249 //
250 // const Float_t tmpr = 300.; // assume that the temporal cherenkov angle is 1 deg. (300 mm).
251 //
252 // const Double_t a = TMath::Tan(hillas.GetDelta());
253 //
254 // const Double_t dx = a/TMath::Sqrt(tmpr+a*a)/3.;
255 // const Double_t dy = -tmpr/TMath::Sqrt(1+a*a)/3.;
256 //
257 // Double_t par1[] = { x+dx, y+dy, 0, 0 };
258 // Double_t par2[] = { x-dx, y-dy, 0, 0 };
259 //
260 // const Double_t dev1 = MMuonSearchPar::Fcn(par1);
261 // const Double_t dev2 = MMuonSearchPar::Fcn(par2);
262 //
263 // if (dev1<dev2)
264 // {
265 // x += dx;
266 // y += dy;
267 // }
268 // else
269 // {
270 // x -= dx;
271 // y -= dy;
272 // }
273 // -------------------------------------------------
274
275 Double_t sigma, rad;
276
277 // find the best fit.
278 CalcMinimumDeviation(geom, evt, x, y, sigma, rad);
279
280 fCenterX = x;
281 fCenterY = y;
282 fRadius = rad;
283 fDeviation = sigma;
284
285 //SetReadyToSave();
286}
287
288void MMuonSearchPar::Print(Option_t *) const
289{
290 *fLog << all;
291 *fLog << GetDescriptor() << endl;
292 *fLog << " - Est. Radius [mm] = " << fRadius << endl;
293 *fLog << " - Deviation [mm] = " << fDeviation << endl;
294 *fLog << " - Center Pos. X [mm] = " << fCenterX << endl;
295 *fLog << " - Center Pos. Y [mm] = " << fCenterY << endl;
296}
297
298void MMuonSearchPar::Print(const MGeomCam &geom, Option_t *) const
299{
300 *fLog << all;
301 *fLog << GetDescriptor() << endl;
302 *fLog << " - Est. Radius [deg] = " << fRadius*geom.GetConvMm2Deg() << endl;
303 *fLog << " - Deviation [deg] = " << fDeviation*geom.GetConvMm2Deg() << endl;
304 *fLog << " - Center Pos. X [deg] = " << fCenterX*geom.GetConvMm2Deg() << endl;
305 *fLog << " - Center Pos. Y [deg] = " << fCenterY*geom.GetConvMm2Deg() << endl;
306}
307
308// --------------------------------------------------------------------------
309//
310// Paint the ellipse corresponding to the parameters
311//
312void MMuonSearchPar::Paint(Option_t *opt)
313{
314 if (fRadius<180 || fRadius>400 || fDeviation>45)
315 return;
316
317 TEllipse e1(fCenterX, fCenterY, fRadius-fDeviation, fRadius-fDeviation);
318 TEllipse e2(fCenterX, fCenterY, fRadius+fDeviation, fRadius+fDeviation);
319 e1.SetLineWidth(1);
320 e2.SetLineWidth(1);
321 e1.SetLineColor(kYellow);
322 e2.SetLineColor(kYellow);
323 e1.Paint();
324 e2.Paint();
325}
Note: See TracBrowser for help on using the repository browser.