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

Last change on this file since 6215 was 5331, checked in by mase, 20 years ago
*** empty log message ***
File size: 8.9 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! Markus Meyer 10/2004 <mailto:meyer@astro.uni-wuerzburg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MMuonSearchPar
29//
30// Storage Container for muon
31//
32// This class is the container for muon parameters. Actually, the calculation
33// is done here. Muons are searched by fitting the image with a circle.
34// (This function will be called by using the class of MMuonSearchParCalc.)
35// This container especially holds the information of the results of the
36// search (fit of a image by a circle).
37//
38// In order to use further information of muons such as the width of arcs,
39// the arc length along it, the muons size. Use the infomation stored in
40// MMuonCalibPar. The information will be available by using the task of
41// MMuonCalibParCalc.
42//
43//
44// --- How to search muons ---
45// (This information is a little bit technical. You can skip to read if you
46// don't need the technical information.)
47//
48// 1. A temporal center position of a circle is determined by using
49// the Hillas parameters. Assumed that the center position will be on the
50// line which is perpendicular to the longitudinal image axis and the
51// distance from the gravity center of the image to the center position of
52// a ring is approximately 1 deg. (corresponding to the Cherenkov angle.).
53// Therefore, we will have two candidates of the center positions.
54// 2. Find the ring radius which gives the minimum RMS between the camera
55// images and the estimated circle.
56// 3. Select one temporal position which gives smaller RMS as a true temporal
57// center position.
58// 4. Changing the center position of a circle on the camera plane from the
59// determined temporal center position, find the position which gives the
60// minimum RMS of the fit.
61//
62//
63// --- Remark ---
64// This method to search for muons is not fully optimized yet. However,
65// it is good idea to use the temporal estimated center position from
66// the Hillas parameters in order to reduce time to search. In addition,
67// This method is faster than the MINUIT.
68//
69//
70// Input Containers:
71// [MGeomCam]
72// [MHillas]
73// [MCerPhotEvt]
74//
75/////////////////////////////////////////////////////////////////////////////
76#include "MMuonSearchPar.h"
77
78#include <fstream>
79
80#include "MLog.h"
81#include "MLogManip.h"
82#include "MHillas.h"
83#include "MGeomCam.h"
84#include "MGeomPix.h"
85#include "MCerPhotEvt.h"
86#include "MCerPhotPix.h"
87
88using namespace std;
89
90ClassImp(MMuonSearchPar);
91
92// --------------------------------------------------------------------------
93//
94// Default constructor.
95//
96MMuonSearchPar::MMuonSearchPar(const char *name, const char *title)
97{
98 fName = name ? name : "MMuonSearchPar";
99 fTitle = title ? title : "Muon search parameters";
100}
101
102// --------------------------------------------------------------------------
103//
104void MMuonSearchPar::Reset()
105{
106 fRadius = -1.;
107 fDeviation = -1.;
108 fCenterX = 0.;
109 fCenterY = 0.;
110 fNoMuon = kFALSE;
111}
112
113// --------------------------------------------------------------------------
114//
115// Get the tempolary center of a ring from the Hillas parameters.
116// Two candidates of the position is returened.
117//
118void MMuonSearchPar::CalcTempCenter(const MHillas &hillas,
119 Float_t &xtmp1, Float_t &ytmp1, Float_t &xtmp2, Float_t &ytmp2)
120{
121 Float_t a,dx,dy;
122 Float_t tmp_r = 300.; // assume that the temporal cherenkov angle is 1 deg. (300 mm).
123
124 a = TMath::Tan(hillas.GetDelta());
125
126 dx = a/TMath::Sqrt(tmp_r+a*a)/3.;
127 dy = -tmp_r/TMath::Sqrt(1+a*a)/3.;
128
129 xtmp1 = hillas.GetMeanX() + dx;
130 ytmp1 = hillas.GetMeanY() + dy;
131 xtmp2 = hillas.GetMeanX() - dx;
132 ytmp2 = hillas.GetMeanY() - dy;
133}
134
135// --------------------------------------------------------------------------
136//
137// This function gives you the ring radius fitted best to the camera image
138// and its RMS for the input position.
139//
140Bool_t MMuonSearchPar::CalcRadius(const MGeomCam &geom, const MCerPhotEvt &evt,
141 Float_t x, Float_t y, Float_t &r, Float_t &sigma)
142{
143 Float_t mean_r=0., dev_r=0., sums=0., tmp=0.;
144
145 const Int_t entries = evt.GetNumPixels();
146
147 for (Int_t i=0; i<entries; i++ ){
148 const MCerPhotPix &pix = evt[i];
149
150 if (!pix.IsPixelUsed())
151 continue;
152
153 const MGeomPix &gpix = geom[pix.GetPixId()];
154
155 tmp=TMath::Sqrt((gpix.GetX()-x)*(gpix.GetX()-x)
156 +(gpix.GetY()-y)*(gpix.GetY()-y));
157
158 mean_r += pix.GetNumPhotons()*tmp;
159 dev_r += pix.GetNumPhotons()*tmp*tmp;
160 sums += pix.GetNumPhotons();
161 }
162
163 if(sums<1.E-10)
164 return kFALSE;
165
166 r = mean_r/sums;
167
168 if(dev_r/sums-(r)*(r)<1.E-10)
169 return kFALSE;
170
171 sigma = TMath::Sqrt(dev_r/sums-(r)*(r));
172
173 return kTRUE;
174}
175
176// --------------------------------------------------------------------------
177//
178// This function finds the center position of the circle which gives minimum
179// RMS of the fit, changing the center position of the circle.
180//
181void MMuonSearchPar::CalcMinimumDeviation
182( const MGeomCam &geom, const MCerPhotEvt &evt, Float_t x, Float_t y,
183 Float_t xcog, Float_t ycog, Float_t sigma, Float_t &opt_rad,
184 Float_t &new_sigma, Float_t &newx, Float_t &newy )
185{
186 Float_t delta = 3.; // 3 mm (1/10 of an inner pixel size) Step to move.
187 Float_t rad_tmp,sig_tmp;
188 Float_t r2;
189
190 while(1)
191 {
192 r2=(xcog-x)*(xcog-x)+(ycog-y)*(ycog-y);
193 // Exit if the new estimated radius is above 2 deg. (600 mm).
194 if(r2 > 360000.)
195 {
196 new_sigma=sigma;
197 opt_rad=rad_tmp;
198 newx=x;
199 newy=y;
200 fNoMuon = kTRUE;
201 break;
202 }
203 if(CalcRadius(geom,evt,x,y+delta,rad_tmp,sig_tmp))
204 {
205 if(sig_tmp<sigma)
206 {
207 sigma=sig_tmp;
208 opt_rad=rad_tmp;
209 y=y+delta;
210 continue;
211 }
212 }
213 if(CalcRadius(geom,evt,x-delta,y,rad_tmp,sig_tmp))
214 {
215 if(sig_tmp<sigma)
216 {
217 sigma=sig_tmp;
218 opt_rad=rad_tmp;
219 x=x-delta;
220 continue;
221 }
222 }
223 if(CalcRadius(geom,evt,x+delta,y,rad_tmp,sig_tmp))
224 {
225 if(sig_tmp<sigma)
226 {
227 sigma=sig_tmp;
228 opt_rad=rad_tmp;
229 x=x+delta;
230 continue;
231 }
232 }
233 if(CalcRadius(geom,evt,x,y-delta,rad_tmp,sig_tmp))
234 {
235 if(sig_tmp<sigma)
236 {
237 sigma=sig_tmp;
238 opt_rad=rad_tmp;
239 y=y-delta;
240 continue;
241 }
242 }
243 new_sigma=sigma;
244 newx=x;
245 newy=y;
246 break;
247 }
248}
249
250// --------------------------------------------------------------------------
251//
252// Calculation of muon parameters
253//
254void MMuonSearchPar::Calc
255(const MGeomCam &geom, const MCerPhotEvt &evt, const MHillas &hillas)
256{
257 Reset();
258
259 Float_t xtmp1,xtmp2,ytmp1,ytmp2;
260 Float_t rad,dev,rad2,dev2;
261 Float_t opt_rad,new_sigma,newx,newy;
262
263 // gets temporaly center
264 CalcTempCenter(hillas,xtmp1,ytmp1,xtmp2,ytmp2);
265
266 // determine which position will be the true position. Here mainly
267 // the curvature of a muon arc is relied on.
268 CalcRadius(geom, evt, xtmp1,ytmp1,rad,dev);
269 CalcRadius(geom, evt, xtmp2,ytmp2,rad2,dev2);
270 if(dev2<dev){
271 xtmp1=xtmp2; ytmp1=ytmp2; dev=dev2; rad=rad2;
272 }
273
274 // find the best fit.
275 CalcMinimumDeviation(geom, evt, xtmp1,ytmp1,hillas.GetMeanX(),
276 hillas.GetMeanY(), dev, opt_rad, new_sigma,
277 newx, newy);
278
279 fRadius = opt_rad;
280 fDeviation = new_sigma;
281
282 fCenterX = newx;
283 fCenterY = newy;
284
285 SetReadyToSave();
286}
287
288void MMuonSearchPar::Print(Option_t *) const
289{
290 *fLog << all;
291 *fLog << "Muon Parameters (" << GetName() << ")" << 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 << "Muon Parameters (" << GetName() << ")" << 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
Note: See TracBrowser for help on using the repository browser.