| 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): Thomas Bretz 12/2000 <mailto:tbretz@uni-sw.gwdg.de>
|
|---|
| 19 | ! Author(s): Harald Kornmayer 1/2001
|
|---|
| 20 | ! Author(s): Rudolf Bock 10/2001 <mailto:Rudolf.Bock@cern.ch>
|
|---|
| 21 | ! Author(s): Wolfgang Wittek 6/2002 <mailto:wittek@mppmu.mpg.de>
|
|---|
| 22 | !
|
|---|
| 23 | ! Copyright: MAGIC Software Development, 2000-2002
|
|---|
| 24 | !
|
|---|
| 25 | !
|
|---|
| 26 | \* ======================================================================== */
|
|---|
| 27 |
|
|---|
| 28 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 29 | //
|
|---|
| 30 | // MHillas
|
|---|
| 31 | //
|
|---|
| 32 | // Storage Container for image parameters
|
|---|
| 33 | //
|
|---|
| 34 | // basic image parameters
|
|---|
| 35 | //
|
|---|
| 36 | // Version 1:
|
|---|
| 37 | // ----------
|
|---|
| 38 | // fLength [mm] major axis of ellipse
|
|---|
| 39 | // fWidth [mm] minor axis
|
|---|
| 40 | // fDelta [rad] angle of major axis with x-axis
|
|---|
| 41 | // by definition the major axis is pointing into
|
|---|
| 42 | // the hemisphere x>0, thus -pi/2 < delta < pi/2
|
|---|
| 43 | // fSize [#CerPhot] total sum of pixels
|
|---|
| 44 | // fMeanX [mm] x of center of ellipse
|
|---|
| 45 | // fMeanY [mm] y of center of ellipse
|
|---|
| 46 | //
|
|---|
| 47 | // Version 2:
|
|---|
| 48 | // ----------
|
|---|
| 49 | // fNumCorePixels number of pixels called core
|
|---|
| 50 | // fNumUsedPixels number of pixels which survived the cleaning
|
|---|
| 51 | //
|
|---|
| 52 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 53 | #include "MHillas.h"
|
|---|
| 54 |
|
|---|
| 55 | #include <fstream.h>
|
|---|
| 56 |
|
|---|
| 57 | #include <TEllipse.h>
|
|---|
| 58 |
|
|---|
| 59 | #include "MGeomPix.h"
|
|---|
| 60 | #include "MGeomCam.h"
|
|---|
| 61 |
|
|---|
| 62 | #include "MCerPhotPix.h"
|
|---|
| 63 | #include "MCerPhotEvt.h"
|
|---|
| 64 |
|
|---|
| 65 | #include "MLog.h"
|
|---|
| 66 | #include "MLogManip.h"
|
|---|
| 67 |
|
|---|
| 68 | ClassImp(MHillas);
|
|---|
| 69 |
|
|---|
| 70 | // --------------------------------------------------------------------------
|
|---|
| 71 | //
|
|---|
| 72 | // Default constructor.
|
|---|
| 73 | //
|
|---|
| 74 | MHillas::MHillas(const char *name, const char *title) : fEllipse(NULL)
|
|---|
| 75 | {
|
|---|
| 76 | fName = name ? name : "MHillas";
|
|---|
| 77 | fTitle = title ? title : "Storage container for image parameters of one event";
|
|---|
| 78 |
|
|---|
| 79 | Reset();
|
|---|
| 80 | // FIXME: (intelligent) initialization of values missing
|
|---|
| 81 |
|
|---|
| 82 | fEllipse = new TEllipse;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | // --------------------------------------------------------------------------
|
|---|
| 86 | //
|
|---|
| 87 | // Destructor. Deletes the TEllipse if one exists.
|
|---|
| 88 | //
|
|---|
| 89 | MHillas::~MHillas()
|
|---|
| 90 | {
|
|---|
| 91 | Clear();
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | // --------------------------------------------------------------------------
|
|---|
| 95 | //
|
|---|
| 96 | // Initializes the values with defaults. For the default values see the
|
|---|
| 97 | // source code.
|
|---|
| 98 | //
|
|---|
| 99 | void MHillas::Reset()
|
|---|
| 100 | {
|
|---|
| 101 | fLength = -1;
|
|---|
| 102 | fWidth = -1;
|
|---|
| 103 | fDelta = 0;
|
|---|
| 104 |
|
|---|
| 105 | fSize = -1;
|
|---|
| 106 | fMeanX = -1;
|
|---|
| 107 | fMeanY = -1;
|
|---|
| 108 |
|
|---|
| 109 | fNumUsedPixels = -1;
|
|---|
| 110 | fNumCorePixels = -1;
|
|---|
| 111 |
|
|---|
| 112 | Clear();
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | // --------------------------------------------------------------------------
|
|---|
| 116 | //
|
|---|
| 117 | // Print the hillas Parameters to *fLog
|
|---|
| 118 | //
|
|---|
| 119 | void MHillas::Print(Option_t *) const
|
|---|
| 120 | {
|
|---|
| 121 | Double_t atg = atan2(fMeanY, fMeanX)*kRad2Deg;
|
|---|
| 122 |
|
|---|
| 123 | if (atg<0)
|
|---|
| 124 | atg += 180;
|
|---|
| 125 |
|
|---|
| 126 | *fLog << all;
|
|---|
| 127 | *fLog << "Basic Image Parameters (" << GetName() << ")" << endl;
|
|---|
| 128 | *fLog << " - Length [mm] = " << fLength << endl;
|
|---|
| 129 | *fLog << " - Width [mm] = " << fWidth << endl;
|
|---|
| 130 | *fLog << " - Delta [deg] = " << fDelta*kRad2Deg << endl;
|
|---|
| 131 | *fLog << " - Size [1] = " << fSize << " #CherPhot" << endl;
|
|---|
| 132 | *fLog << " - Meanx [mm] = " << fMeanX << endl;
|
|---|
| 133 | *fLog << " - Meany [mm] = " << fMeanY << endl;
|
|---|
| 134 | *fLog << " - atg(y/x) [deg] = " << atg << endl;
|
|---|
| 135 | *fLog << " - Used Pixels [#] = " << fNumUsedPixels << " Pixels" << endl;
|
|---|
| 136 | *fLog << " - Core Pixels [#] = " << fNumCorePixels << " Pixels" << endl;
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | /*
|
|---|
| 140 | // -----------------------------------------------------------
|
|---|
| 141 | //
|
|---|
| 142 | // call the Paint function of the Ellipse if a TEllipse exists
|
|---|
| 143 | //
|
|---|
| 144 | void MHillas::Paint(Option_t *)
|
|---|
| 145 | {
|
|---|
| 146 | fEllipse->SetLineWidth(2);
|
|---|
| 147 | fEllipse->PaintEllipse(fMeanX, fMeanY, fLength, fWidth,
|
|---|
| 148 | 0, 360, fDelta*kRad2Deg+180);
|
|---|
| 149 | }
|
|---|
| 150 | */
|
|---|
| 151 |
|
|---|
| 152 | // --------------------------------------------------------------------------
|
|---|
| 153 | //
|
|---|
| 154 | // Instead of adding MHillas itself to the Pad
|
|---|
| 155 | // (s. AppendPad in TObject) we create an ellipse,
|
|---|
| 156 | // which is added to the Pad by its Draw function
|
|---|
| 157 | // You can remove it by deleting the Ellipse Object
|
|---|
| 158 | // (s. Clear() )
|
|---|
| 159 | //
|
|---|
| 160 | void MHillas::Draw(Option_t *opt)
|
|---|
| 161 | {
|
|---|
| 162 |
|
|---|
| 163 | Clear();
|
|---|
| 164 |
|
|---|
| 165 | if (fLength<0 || fWidth<0)
|
|---|
| 166 | return;
|
|---|
| 167 |
|
|---|
| 168 | fEllipse = new TEllipse(fMeanX, fMeanY, fLength, fWidth,
|
|---|
| 169 | 0, 360, fDelta*kRad2Deg+180);
|
|---|
| 170 |
|
|---|
| 171 | fEllipse->SetLineWidth(2);
|
|---|
| 172 | fEllipse->Draw();
|
|---|
| 173 |
|
|---|
| 174 | /*
|
|---|
| 175 | fEllipse->SetPhimin();
|
|---|
| 176 | fEllipse->SetPhimax();
|
|---|
| 177 | fEllipse->SetR1(fLength);
|
|---|
| 178 | fEllipse->SetR2(fWidth);
|
|---|
| 179 | fEllipse->SetTheta(fDelta*kRad2Deg+180);
|
|---|
| 180 | fEllipse->SetX1(fMeanX);
|
|---|
| 181 | fEllipse->SetY1(fMeanY);
|
|---|
| 182 |
|
|---|
| 183 | fEllipse->SetLineWidth(2);
|
|---|
| 184 | fEllipse->PaintEllipse(fMeanX, fMeanY, fLength, fWidth,
|
|---|
| 185 | 0, 360, fDelta*kRad2Deg+180);
|
|---|
| 186 |
|
|---|
| 187 | AppendPad(opt);
|
|---|
| 188 |
|
|---|
| 189 | // This is from TH1
|
|---|
| 190 | TString opt = option;
|
|---|
| 191 | opt.ToLower();
|
|---|
| 192 | if (gPad && !opt.Contains("same")) {
|
|---|
| 193 | //the following statement is necessary in case one attempts to draw
|
|---|
| 194 | //a temporary histogram already in the current pad
|
|---|
| 195 | if (TestBit(kCanDelete)) gPad->GetListOfPrimitives()->Remove(this);
|
|---|
| 196 | gPad->Clear();
|
|---|
| 197 | }
|
|---|
| 198 | */
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | // --------------------------------------------------------------------------
|
|---|
| 202 | //
|
|---|
| 203 | // If a TEllipse object exists it is deleted
|
|---|
| 204 | //
|
|---|
| 205 | void MHillas::Clear(Option_t *)
|
|---|
| 206 | {
|
|---|
| 207 | if (!fEllipse)
|
|---|
| 208 | return;
|
|---|
| 209 |
|
|---|
| 210 | delete fEllipse;
|
|---|
| 211 |
|
|---|
| 212 | fEllipse = NULL;
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 | // --------------------------------------------------------------------------
|
|---|
| 217 | //
|
|---|
| 218 | // Calculate the image parameters from a Cherenkov photon event
|
|---|
| 219 | // assuming Cher.photons/pixel and pixel coordinates are given
|
|---|
| 220 | // In case you don't call Calc from within an eventloop make sure, that
|
|---|
| 221 | // you call the Reset member function before.
|
|---|
| 222 | //
|
|---|
| 223 | Bool_t MHillas::Calc(const MGeomCam &geom, const MCerPhotEvt &evt)
|
|---|
| 224 | {
|
|---|
| 225 | const UInt_t npixevt = evt.GetNumPixels();
|
|---|
| 226 |
|
|---|
| 227 | //
|
|---|
| 228 | // sanity check
|
|---|
| 229 | //
|
|---|
| 230 | if (npixevt <= 2)
|
|---|
| 231 | {
|
|---|
| 232 | *fLog << warn << "MHillas::Calc: Event has less than two pixels... skipped." << endl;
|
|---|
| 233 | return kFALSE;
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | //
|
|---|
| 237 | // calculate mean value of pixel coordinates and fSize
|
|---|
| 238 | // -----------------------------------------------------
|
|---|
| 239 | //
|
|---|
| 240 | // Because this are only simple sums of roughly 600 values
|
|---|
| 241 | // with an accuracy less than three digits there should not
|
|---|
| 242 | // be any need to use double precision (Double_t) for the
|
|---|
| 243 | // calculation of fMeanX, fMeanY and fSize.
|
|---|
| 244 | //
|
|---|
| 245 | fMeanX = 0;
|
|---|
| 246 | fMeanY = 0;
|
|---|
| 247 | fSize = 0;
|
|---|
| 248 |
|
|---|
| 249 | fNumUsedPixels = 0;
|
|---|
| 250 | fNumCorePixels = 0;
|
|---|
| 251 |
|
|---|
| 252 | for (UInt_t i=0; i<npixevt; i++)
|
|---|
| 253 | {
|
|---|
| 254 | const MCerPhotPix &pix = evt[i];
|
|---|
| 255 |
|
|---|
| 256 | if (!pix.IsPixelUsed())
|
|---|
| 257 | continue;
|
|---|
| 258 |
|
|---|
| 259 | const MGeomPix &gpix = geom[pix.GetPixId()];
|
|---|
| 260 |
|
|---|
| 261 | const Float_t nphot = pix.GetNumPhotons();
|
|---|
| 262 |
|
|---|
| 263 | if (nphot==0)
|
|---|
| 264 | *fLog << warn << GetDescriptor() << ": Pixel #" << pix.GetPixId() << " has no photons." << endl;
|
|---|
| 265 |
|
|---|
| 266 | fSize += nphot; // [counter]
|
|---|
| 267 | fMeanX += nphot * gpix.GetX(); // [mm]
|
|---|
| 268 | fMeanY += nphot * gpix.GetY(); // [mm]
|
|---|
| 269 |
|
|---|
| 270 | if (pix.IsPixelCore())
|
|---|
| 271 | fNumCorePixels++;
|
|---|
| 272 |
|
|---|
| 273 | fNumUsedPixels++;
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | //
|
|---|
| 277 | // sanity checks
|
|---|
| 278 | //
|
|---|
| 279 | if (fSize==0)
|
|---|
| 280 | {
|
|---|
| 281 | //*fLog << inf << GetDescriptor() << ": Event has zero cerenkov photons... skipped." << endl;
|
|---|
| 282 | return kFALSE;
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | if (fNumUsedPixels<3)
|
|---|
| 286 | {
|
|---|
| 287 | //*fLog << inf << GetDescriptor() << ": Event has less than 3 used pixels... skipped." << endl;
|
|---|
| 288 | return kFALSE;
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 | fMeanX /= fSize; // [mm]
|
|---|
| 292 | fMeanY /= fSize; // [mm]
|
|---|
| 293 |
|
|---|
| 294 | //
|
|---|
| 295 | // calculate 2nd moments
|
|---|
| 296 | // ---------------------
|
|---|
| 297 | //
|
|---|
| 298 | // To make sure that the more complicated sum is evaluated as
|
|---|
| 299 | // accurate as possible (because it is needed for more
|
|---|
| 300 | // complicated calculations (see below) we calculate it using
|
|---|
| 301 | // double prcision.
|
|---|
| 302 | //
|
|---|
| 303 | Double_t corrxx=0; // [m^2]
|
|---|
| 304 | Double_t corrxy=0; // [m^2]
|
|---|
| 305 | Double_t corryy=0; // [m^2]
|
|---|
| 306 |
|
|---|
| 307 | for (UInt_t i=0; i<npixevt; i++)
|
|---|
| 308 | {
|
|---|
| 309 | const MCerPhotPix &pix = evt[i];
|
|---|
| 310 |
|
|---|
| 311 | if (!pix.IsPixelUsed())
|
|---|
| 312 | continue;
|
|---|
| 313 |
|
|---|
| 314 | const MGeomPix &gpix = geom[pix.GetPixId()];
|
|---|
| 315 |
|
|---|
| 316 | const Float_t dx = gpix.GetX() - fMeanX; // [mm]
|
|---|
| 317 | const Float_t dy = gpix.GetY() - fMeanY; // [mm]
|
|---|
| 318 |
|
|---|
| 319 | const Float_t nphot = pix.GetNumPhotons(); // [#phot]
|
|---|
| 320 |
|
|---|
| 321 | corrxx += nphot * dx*dx; // [mm^2]
|
|---|
| 322 | corrxy += nphot * dx*dy; // [mm^2]
|
|---|
| 323 | corryy += nphot * dy*dy; // [mm^2]
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | //
|
|---|
| 327 | // If corrxy=0 (which should never happen, because fSize>0) we
|
|---|
| 328 | // cannot calculate Length and Width. The calculation failed
|
|---|
| 329 | // and returns kFALSE
|
|---|
| 330 | // In reallity it is almost impossible to have a distribution
|
|---|
| 331 | // of cerenkov photons in the used pixels which is exactly symmetric
|
|---|
| 332 | // along one of the axis.
|
|---|
| 333 | //
|
|---|
| 334 | if (corrxy==0)
|
|---|
| 335 | {
|
|---|
| 336 | *fLog << inf << GetDescriptor() << ": Event has CorrXY==0... skipped." << endl;
|
|---|
| 337 | return kFALSE;
|
|---|
| 338 | }
|
|---|
| 339 |
|
|---|
| 340 | //
|
|---|
| 341 | // calculate the basic Hillas parameters: orientation and size of axes
|
|---|
| 342 | // -------------------------------------------------------------------
|
|---|
| 343 | //
|
|---|
| 344 | // fDelta is the angle between the major axis of the ellipse and
|
|---|
| 345 | // the x axis. It is independent of the position of the ellipse
|
|---|
| 346 | // in the camera it has values between -pi/2 and pi/2 degrees
|
|---|
| 347 | //
|
|---|
| 348 | const Double_t d0 = corryy - corrxx;
|
|---|
| 349 | const Double_t d1 = corrxy*2;
|
|---|
| 350 | const Double_t d2 = d0 + sqrt(d0*d0 + d1*d1);
|
|---|
| 351 | const Double_t tand = d2 / d1;
|
|---|
| 352 |
|
|---|
| 353 | fDelta = atan(tand);
|
|---|
| 354 |
|
|---|
| 355 | const Double_t s2 = tand*tand+1;
|
|---|
| 356 | const Double_t s = sqrt(s2);
|
|---|
| 357 |
|
|---|
| 358 | fCosDelta = 1.0/s; // need these in derived classes
|
|---|
| 359 | fSinDelta = tand/s; // like MHillasExt
|
|---|
| 360 |
|
|---|
| 361 | Double_t axis1 = (tand*tand*corryy + d2 + corrxx)/s2/fSize;
|
|---|
| 362 | Double_t axis2 = (tand*tand*corrxx - d2 + corryy)/s2/fSize;
|
|---|
| 363 |
|
|---|
| 364 | //
|
|---|
| 365 | // fLength^2 is the second moment along the major axis of the ellipse
|
|---|
| 366 | // fWidth^2 is the second moment along the minor axis of the ellipse
|
|---|
| 367 | //
|
|---|
| 368 | // From the algorithm we get: fWidth <= fLength is always true
|
|---|
| 369 | //
|
|---|
| 370 | // very small numbers can get negative by rounding
|
|---|
| 371 | //
|
|---|
| 372 | fLength = axis1<0 ? 0 : sqrt(axis1); // [mm]
|
|---|
| 373 | fWidth = axis2<0 ? 0 : sqrt(axis2); // [mm]
|
|---|
| 374 |
|
|---|
| 375 | SetReadyToSave();
|
|---|
| 376 |
|
|---|
| 377 | return kTRUE;
|
|---|
| 378 | }
|
|---|
| 379 |
|
|---|
| 380 | // --------------------------------------------------------------------------
|
|---|
| 381 | //
|
|---|
| 382 | /*
|
|---|
| 383 | void MHillas::AsciiRead(ifstream &fin)
|
|---|
| 384 | {
|
|---|
| 385 | fin >> fLength;
|
|---|
| 386 | fin >> fWidth;
|
|---|
| 387 | fin >> fDelta;
|
|---|
| 388 | fin >> fSize;
|
|---|
| 389 | fin >> fMeanX;
|
|---|
| 390 | fin >> fMeanY;
|
|---|
| 391 | }
|
|---|
| 392 | */
|
|---|
| 393 | // --------------------------------------------------------------------------
|
|---|
| 394 | /*
|
|---|
| 395 | void MHillas::AsciiWrite(ofstream &fout) const
|
|---|
| 396 | {
|
|---|
| 397 | fout << fLength << " ";
|
|---|
| 398 | fout << fWidth << " ";
|
|---|
| 399 | fout << fDelta << " ";
|
|---|
| 400 | fout << fSize << " ";
|
|---|
| 401 | fout << fMeanX << " ";
|
|---|
| 402 | fout << fMeanY;
|
|---|
| 403 | }
|
|---|
| 404 | */ |
|---|