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