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

Last change on this file since 7062 was 7009, checked in by meyer, 20 years ago
*** empty log message ***
File size: 8.1 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//
47// Input Containers:
48// MGeomCam
49// MHillas
50// MSignalCam
51//
52/////////////////////////////////////////////////////////////////////////////
53#include "MMuonSearchPar.h"
54
55#include <TMinuit.h>
56
57#include "MLog.h"
58#include "MLogManip.h"
59
60#include "MHillas.h"
61
62#include "MGeomCam.h"
63#include "MGeomPix.h"
64
65#include "MSignalPix.h"
66#include "MSignalCam.h"
67
68using namespace std;
69
70ClassImp(MMuonSearchPar);
71
72// --------------------------------------------------------------------------
73//
74// Default constructor.
75//
76MMuonSearchPar::MMuonSearchPar(const char *name, const char *title)
77{
78 fName = name ? name : "MMuonSearchPar";
79 fTitle = title ? title : "Muon search parameters";
80}
81
82// --------------------------------------------------------------------------
83//
84void MMuonSearchPar::Reset()
85{
86 fRadius = -1;
87 fDeviation = -1;
88 fCenterX = 0;
89 fCenterY = 0;
90}
91
92// --------------------------------------------------------------------------
93//
94// This is a wrapper function to have direct access to the data members
95// in the function calculating the minimization value.
96//
97void MMuonSearchPar::fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
98{
99 const MMuonSearchPar *optim = (MMuonSearchPar*)gMinuit->GetObjectFit();
100 f = optim->Fcn(par);
101}
102
103// --------------------------------------------------------------------------
104//
105// This function gives you the ring radius fitted best to the camera image
106// and its RMS for the input position.
107//
108Double_t MMuonSearchPar::Fcn(Double_t *par) const
109{
110 const Int_t entries = fSignal.GetSize();
111
112 Double_t meanr=0;
113 Double_t devr =0;
114 Double_t sums =0;
115
116 // It seems that the loop is easy enough for a compiler optimization.
117 // Using pointer arithmetics doesn't improve the speed of the fit.
118 for (Int_t i=0; i<entries; i++ )
119 {
120 Double_t tmp = TMath::Hypot(fX[i]-par[0], fY[i]-par[1]);
121
122 sums += fSignal[i];
123 meanr += fSignal[i] * tmp;
124 devr += fSignal[i] * tmp*tmp;
125 }
126
127 par[2] = meanr/sums;
128 par[3] = devr/sums - par[2]*par[2];
129
130 return par[3];
131}
132
133// --------------------------------------------------------------------------
134//
135// This function finds the center position of the circle which gives minimum
136// RMS of the fit, changing the center position of the circle.
137//
138void MMuonSearchPar::CalcMinimumDeviation(const MGeomCam &geom,
139 const MSignalCam &evt,
140 Double_t &x, Double_t &y,
141 Double_t &sigma, Double_t &radius)
142{
143 // ------- Make a temporaray copy of the signal ---------
144 const Int_t n = geom.GetNumPixels();
145
146 fSignal.Set(n);
147 fX.Set(n);
148 fY.Set(n);
149
150 Int_t p=0;
151 for (int i=0; i<n; i++)
152 {
153 const MSignalPix &pix = evt[i];
154 if (pix.IsPixelUsed())
155 {
156 fSignal[p] = pix.GetNumPhotons();
157
158 fX[p] = geom[i].GetX();
159 fY[p] = geom[i].GetY();
160 p++;
161 }
162 }
163 fSignal.Set(p);
164
165
166 // ----------------- Setup and call minuit -------------------
167 const Float_t delta = 30.; // 3 mm (1/10 of an inner pixel size) Step to move.
168 const Double_t r = geom.GetMaxRadius()*2;
169
170 // Save gMinuit
171 TMinuit *minsave = gMinuit;
172
173 // Initialize TMinuit with 4 parameters
174 TMinuit minuit;
175 minuit.SetPrintLevel(-1); // Switch off printing
176 minuit.Command("set nowarn"); // Switch off warning
177 // Define Parameters
178 minuit.DefineParameter(0, "x", x, delta, -r, r);
179 minuit.DefineParameter(1, "y", y, delta, -r, r);
180 minuit.DefineParameter(2, "r", 0, 1, 0, 0);
181 minuit.DefineParameter(3, "sigma", 0, 1, 0, 0);
182 // Fix return parameters
183 minuit.FixParameter(2);
184 minuit.FixParameter(3);
185 // Setup Minuit for 'this' and use fit function fcn
186 minuit.SetObjectFit(this);
187 minuit.SetFCN(fcn);
188
189 // Perform Simplex minimization
190 Int_t err;
191 Double_t tmp[2] = { 0, 0 };
192 minuit.mnexcm("simplex", tmp, 2, err);
193
194 // Get resulting parameters
195 Double_t error;
196 minuit.GetParameter(0, x, error);
197 minuit.GetParameter(1, y, error);
198 minuit.GetParameter(2, radius, error);
199 minuit.GetParameter(3, sigma, error);
200
201 sigma = sigma>0 ? TMath::Sqrt(sigma) : 0;
202
203 gMinuit = minsave;
204}
205
206// --------------------------------------------------------------------------
207//
208// Calculation of muon parameters
209//
210void MMuonSearchPar::Calc(const MGeomCam &geom, const MSignalCam &evt,
211 const MHillas &hillas)
212{
213 Double_t x = hillas.GetMeanX();
214 Double_t y = hillas.GetMeanY();
215
216 // -------------------------------------------------
217 // Keiichi suggested trying to precalculate the Muon
218 // center a bit better, but it neither improves the
219 // fit result nor the speed
220 //
221 // const Float_t tmpr = 300.; // assume that the temporal cherenkov angle is 1 deg. (300 mm).
222 //
223 // const Double_t a = TMath::Tan(hillas.GetDelta());
224 //
225 // const Double_t dx = a/TMath::Sqrt(tmpr+a*a)/3.;
226 // const Double_t dy = -tmpr/TMath::Sqrt(1+a*a)/3.;
227 //
228 // Double_t par1[] = { x+dx, y+dy, 0, 0 };
229 // Double_t par2[] = { x-dx, y-dy, 0, 0 };
230 //
231 // const Double_t dev1 = MMuonSearchPar::Fcn(par1);
232 // const Double_t dev2 = MMuonSearchPar::Fcn(par2);
233 //
234 // if (dev1<dev2)
235 // {
236 // x += dx;
237 // y += dy;
238 // }
239 // else
240 // {
241 // x -= dx;
242 // y -= dy;
243 // }
244 // -------------------------------------------------
245
246 Double_t sigma, rad;
247
248 // find the best fit.
249 CalcMinimumDeviation(geom, evt, x, y, sigma, rad);
250
251 fCenterX = x;
252 fCenterY = y;
253 fRadius = rad;
254 fDeviation = sigma;
255
256 //SetReadyToSave();
257}
258
259void MMuonSearchPar::Print(Option_t *) const
260{
261 *fLog << all;
262 *fLog << "Muon Parameters (" << GetName() << ")" << endl;
263 *fLog << " - Est. Radius [mm] = " << fRadius << endl;
264 *fLog << " - Deviation [mm] = " << fDeviation << endl;
265 *fLog << " - Center Pos. X [mm] = " << fCenterX << endl;
266 *fLog << " - Center Pos. Y [mm] = " << fCenterY << endl;
267}
268
269void MMuonSearchPar::Print(const MGeomCam &geom, Option_t *) const
270{
271 *fLog << all;
272 *fLog << "Muon Parameters (" << GetName() << ")" << endl;
273 *fLog << " - Est. Radius [deg] = " << fRadius*geom.GetConvMm2Deg() << endl;
274 *fLog << " - Deviation [deg] = " << fDeviation*geom.GetConvMm2Deg() << endl;
275 *fLog << " - Center Pos. X [deg] = " << fCenterX*geom.GetConvMm2Deg() << endl;
276 *fLog << " - Center Pos. Y [deg] = " << fCenterY*geom.GetConvMm2Deg() << endl;
277}
Note: See TracBrowser for help on using the repository browser.