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

Last change on this file since 5210 was 5210, 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, in this class,
33// muons are searched by fitting the image with a circle. (This function will
34// be called by using the class of MMuonSearchParCalc.) This container
35// especially holds the information of the results of the search (fit of
36// 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#include "MBinning.h"
88
89using namespace std;
90
91ClassImp(MMuonSearchPar);
92
93// --------------------------------------------------------------------------
94//
95// Default constructor.
96//
97MMuonSearchPar::MMuonSearchPar(const char *name, const char *title)
98{
99 fName = name ? name : "MMuonSearchPar";
100 fTitle = title ? title : "Muon search parameters";
101}
102
103// --------------------------------------------------------------------------
104//
105void MMuonSearchPar::Reset()
106{
107 fRadius = -1.;
108 fDeviation = -1.;
109 fCenterX = 0.;
110 fCenterY = 0.;
111 fNoMuon = kFALSE;
112}
113
114// --------------------------------------------------------------------------
115//
116// Get the tempolary center of a ring from the Hillas parameters.
117// Two candidates of the position is returened.
118//
119void MMuonSearchPar::CalcTempCenter(const MHillas &hillas,
120 Float_t *xtmp1, Float_t *ytmp1, Float_t *xtmp2, Float_t *ytmp2)
121{
122 Float_t a,dx,dy;
123 Float_t tmp_r = 300.; // assume that the temporal cherenkov angle is 1 deg. (300 mm).
124
125 a = TMath::Tan(hillas.GetDelta());
126
127 dx = a/TMath::Sqrt(tmp_r+a*a)/3.;
128 dy = -tmp_r/TMath::Sqrt(1+a*a)/3.;
129
130 *xtmp1 = hillas.GetMeanX() + dx;
131 *ytmp1 = hillas.GetMeanY() + dy;
132 *xtmp2 = hillas.GetMeanX() - dx;
133 *ytmp2 = hillas.GetMeanY() - dy;
134}
135
136// --------------------------------------------------------------------------
137//
138// This function gives you the ring radius fitted best to the camera image
139// and its RMS for the input position.
140//
141Bool_t MMuonSearchPar::CalcRadius(const MGeomCam &geom, const MCerPhotEvt &evt,
142 Float_t x, Float_t y, Float_t *r, Float_t *sigma)
143{
144 Float_t mean_r=0., dev_r=0., sums=0., tmp=0.;
145
146 const Int_t entries = evt.GetNumPixels();
147
148 for (Int_t i=0; i<entries; i++ ){
149 const MCerPhotPix &pix = evt[i];
150
151 if (!pix.IsPixelUsed())
152 continue;
153
154 const MGeomPix &gpix = geom[pix.GetPixId()];
155
156 tmp=TMath::Sqrt((gpix.GetX()-x)*(gpix.GetX()-x)
157 +(gpix.GetY()-y)*(gpix.GetY()-y));
158
159 mean_r += pix.GetNumPhotons()*tmp;
160 dev_r += pix.GetNumPhotons()*tmp*tmp;
161 sums += pix.GetNumPhotons();
162 }
163
164 if(sums<1.E-10)
165 return kFALSE;
166
167 *r = mean_r/sums;
168
169 if(dev_r/sums-(*r)*(*r)<1.E-10)
170 return kFALSE;
171
172 *sigma = TMath::Sqrt(dev_r/sums-(*r)*(*r));
173
174 return kTRUE;
175}
176
177// --------------------------------------------------------------------------
178//
179// This function finds the center position of the circle which gives minimum
180// RMS of the fit, changing the center position of the circle.
181//
182void MMuonSearchPar::CalcMinimumDeviation
183( const MGeomCam &geom, const MCerPhotEvt &evt, Float_t x, Float_t y,
184 Float_t xcog, Float_t ycog, Float_t sigma, Float_t *opt_rad,
185 Float_t *new_sigma, Float_t *newx, Float_t *newy )
186{
187 Float_t delta = 3.; // 3 mm (1/10 of an inner pixel size) Step to move.
188 Float_t rad_tmp,sig_tmp;
189 Float_t r2;
190
191 while(1)
192 {
193 r2=(xcog-x)*(xcog-x)+(ycog-y)*(ycog-y);
194 // Exit if the new estimated radius is above 2 deg. (600 mm).
195 if(r2 > 360000.)
196 {
197 *new_sigma=sigma;
198 *opt_rad=rad_tmp;
199 *newx=x; *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; *opt_rad=rad_tmp;
208 y=y+delta;
209 continue;
210 }
211 }
212 if(CalcRadius(geom,evt,x-delta,y,&rad_tmp,&sig_tmp))
213 {
214 if(sig_tmp<sigma)
215 {
216 sigma=sig_tmp; *opt_rad=rad_tmp;
217 x=x-delta;
218 continue;
219 }
220 }
221 if(CalcRadius(geom,evt,x+delta,y,&rad_tmp,&sig_tmp))
222 {
223 if(sig_tmp<sigma)
224 {
225 sigma=sig_tmp; *opt_rad=rad_tmp;
226 x=x+delta;
227 continue;
228 }
229 }
230 if(CalcRadius(geom,evt,x,y-delta,&rad_tmp,&sig_tmp))
231 {
232 if(sig_tmp<sigma)
233 {
234 sigma=sig_tmp; *opt_rad=rad_tmp;
235 y=y-delta;
236 continue;
237 }
238 }
239 *new_sigma=sigma;
240 *newx=x; *newy=y;
241 break;
242 }
243}
244
245// --------------------------------------------------------------------------
246//
247// Calculation of muon parameters
248//
249void MMuonSearchPar::Calc
250(const MGeomCam &geom, const MCerPhotEvt &evt, const MHillas &hillas)
251{
252 Reset();
253
254 Float_t xtmp1,xtmp2,ytmp1,ytmp2;
255 Float_t rad,dev,rad2,dev2;
256 Float_t opt_rad,new_sigma,newx,newy;
257
258 // gets temporaly center
259 CalcTempCenter(hillas,&xtmp1,&ytmp1,&xtmp2,&ytmp2);
260
261 // determine which position will be the true position. Here mainly
262 // the curvature of a muon arc is relied on.
263 CalcRadius(geom, evt, xtmp1,ytmp1,&rad,&dev);
264 CalcRadius(geom, evt, xtmp2,ytmp2,&rad2,&dev2);
265 if(dev2<dev){
266 xtmp1=xtmp2; ytmp1=ytmp2; dev=dev2; rad=rad2;
267 }
268
269 // find the best fit.
270 CalcMinimumDeviation(geom, evt, xtmp1,ytmp1,hillas.GetMeanX(),hillas.GetMeanY(),
271 dev, &opt_rad, &new_sigma, &newx, &newy);
272
273 fRadius = opt_rad;
274 fDeviation = new_sigma;
275
276 fCenterX = newx;
277 fCenterY = newy;
278
279 SetReadyToSave();
280}
281
282void MMuonSearchPar::Print(Option_t *) const
283{
284 *fLog << all;
285 *fLog << "Muon Parameters (" << GetName() << ")" << endl;
286 *fLog << " - Est. Radius [mm] = " << fRadius << endl;
287 *fLog << " - Deviation [mm] = " << fDeviation << endl;
288 *fLog << " - Center Pos. X [mm] = " << fCenterX << endl;
289 *fLog << " - Center Pos. Y [mm] = " << fCenterY << endl;
290}
291
292void MMuonSearchPar::Print(const MGeomCam &geom, Option_t *) const
293{
294 *fLog << all;
295 *fLog << "Muon Parameters (" << GetName() << ")" << endl;
296 *fLog << " - Est. Radius [deg.] = " << fRadius*geom.GetConvMm2Deg() << endl;
297 *fLog << " - Deviation [deg.] = " << fDeviation*geom.GetConvMm2Deg() << endl;
298 *fLog << " - Center Pos. X [deg.] = " << fCenterX*geom.GetConvMm2Deg() << endl;
299 *fLog << " - Center Pos. Y [deg.] = " << fCenterY*geom.GetConvMm2Deg() << endl;
300}
301
302
303
Note: See TracBrowser for help on using the repository browser.