| 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 (harald@mppmu.mpg.de)
|
|---|
| 20 | !
|
|---|
| 21 | ! Copyright: MAGIC Software Development, 2000-2001
|
|---|
| 22 | !
|
|---|
| 23 | !
|
|---|
| 24 | \* ======================================================================== */
|
|---|
| 25 |
|
|---|
| 26 | #include "MCerPhotEvt.h"
|
|---|
| 27 |
|
|---|
| 28 | #include <math.h>
|
|---|
| 29 | #include <limits.h>
|
|---|
| 30 | #include <fstream>
|
|---|
| 31 |
|
|---|
| 32 | #include <TCanvas.h>
|
|---|
| 33 |
|
|---|
| 34 | #include "MLog.h"
|
|---|
| 35 |
|
|---|
| 36 | #include "MGeomCam.h"
|
|---|
| 37 |
|
|---|
| 38 | ClassImp(MCerPhotEvt);
|
|---|
| 39 |
|
|---|
| 40 | using namespace std;
|
|---|
| 41 |
|
|---|
| 42 | // --------------------------------------------------------------------------
|
|---|
| 43 | //
|
|---|
| 44 | // Creates a MCerPhotPix object for each pixel in the event
|
|---|
| 45 | //
|
|---|
| 46 | MCerPhotEvt::MCerPhotEvt(const char *name, const char *title) : fNumPixels(0)
|
|---|
| 47 | {
|
|---|
| 48 | fName = name ? name : "MCerPhotEvt";
|
|---|
| 49 | fTitle = title ? title : "(Number of Photon)-Event Information";
|
|---|
| 50 |
|
|---|
| 51 | fPixels = new TClonesArray("MCerPhotPix", 0);
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | // --------------------------------------------------------------------------
|
|---|
| 55 | //
|
|---|
| 56 | // This is not yet implemented like it should.
|
|---|
| 57 | //
|
|---|
| 58 | void MCerPhotEvt::Draw(Option_t* option)
|
|---|
| 59 | {
|
|---|
| 60 | //
|
|---|
| 61 | // FIXME!!! Here the Draw function of the CamDisplay
|
|---|
| 62 | // should be called to add the CamDisplay to the Pad.
|
|---|
| 63 | // The drawing should be done in MCamDisplay::Paint
|
|---|
| 64 | //
|
|---|
| 65 |
|
|---|
| 66 | // MGeomCam *geom = fType ? new MGeomCamMagic : new MGeomCamCT1;
|
|---|
| 67 | // MCamDisplay *disp = new MCamDisplay(geom);
|
|---|
| 68 | // delete geom;
|
|---|
| 69 | // disp->DrawPhotNum(this);
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | // --------------------------------------------------------------------------
|
|---|
| 73 | //
|
|---|
| 74 | // reset counter and delete netries in list.
|
|---|
| 75 | //
|
|---|
| 76 | void MCerPhotEvt::Reset()
|
|---|
| 77 | {
|
|---|
| 78 | fNumPixels = 0;
|
|---|
| 79 | // fPixels->Delete();
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | void MCerPhotEvt::FixSize()
|
|---|
| 83 | {
|
|---|
| 84 | if (fPixels->GetEntriesFast() == (Int_t)fNumPixels)
|
|---|
| 85 | return;
|
|---|
| 86 |
|
|---|
| 87 | fPixels->ExpandCreateFast(fNumPixels);
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | // --------------------------------------------------------------------------
|
|---|
| 91 | //
|
|---|
| 92 | // Dump the cerenkov photon event to *fLog
|
|---|
| 93 | //
|
|---|
| 94 | void MCerPhotEvt::Print(Option_t *) const
|
|---|
| 95 | {
|
|---|
| 96 | const Int_t entries = fPixels->GetEntries();
|
|---|
| 97 |
|
|---|
| 98 | *fLog << GetDescriptor() << dec << endl;
|
|---|
| 99 | *fLog << " Number of Pixels: " << fNumPixels << "(" << entries << ")" << endl;
|
|---|
| 100 |
|
|---|
| 101 | for (Int_t i=0; i<entries; i++ )
|
|---|
| 102 | (*this)[i].Print();
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | // --------------------------------------------------------------------------
|
|---|
| 106 | //
|
|---|
| 107 | // Checks if in the pixel list is an entry with pixel id
|
|---|
| 108 | //
|
|---|
| 109 | Bool_t MCerPhotEvt::IsPixelExisting(Int_t id) const
|
|---|
| 110 | {
|
|---|
| 111 | const Int_t entries = fPixels->GetEntries();
|
|---|
| 112 |
|
|---|
| 113 | for (Int_t i=0; i<entries; i++)
|
|---|
| 114 | {
|
|---|
| 115 | if (id == (*this)[i].GetPixId())
|
|---|
| 116 | return kTRUE;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | return kFALSE;
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | // --------------------------------------------------------------------------
|
|---|
| 123 | //
|
|---|
| 124 | // Checks if in the pixel list is an entry with pixel id
|
|---|
| 125 | //
|
|---|
| 126 | Bool_t MCerPhotEvt::IsPixelUsed(Int_t id) const
|
|---|
| 127 | {
|
|---|
| 128 | const Int_t entries = fPixels->GetEntries();
|
|---|
| 129 |
|
|---|
| 130 | for (Int_t i=0; i<entries; i++)
|
|---|
| 131 | {
|
|---|
| 132 | const MCerPhotPix &pix = (*this)[i];
|
|---|
| 133 | if (!pix.IsPixelUsed())
|
|---|
| 134 | continue;
|
|---|
| 135 |
|
|---|
| 136 | if (id == pix.GetPixId() && pix.IsPixelUsed())
|
|---|
| 137 | return kTRUE;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | return kFALSE;
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | // --------------------------------------------------------------------------
|
|---|
| 144 | //
|
|---|
| 145 | // Checks if in the pixel list is an entry with pixel id
|
|---|
| 146 | //
|
|---|
| 147 | Bool_t MCerPhotEvt::IsPixelCore(Int_t id) const
|
|---|
| 148 | {
|
|---|
| 149 | const Int_t entries = fPixels->GetEntries();
|
|---|
| 150 |
|
|---|
| 151 | for (Int_t i=0; i<entries; i++)
|
|---|
| 152 | {
|
|---|
| 153 | const MCerPhotPix &pix = (*this)[i];
|
|---|
| 154 | if (!pix.IsPixelUsed())
|
|---|
| 155 | continue;
|
|---|
| 156 |
|
|---|
| 157 | if (id == pix.GetPixId() && pix.IsPixelCore())
|
|---|
| 158 | return kTRUE;
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | return kFALSE;
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | // --------------------------------------------------------------------------
|
|---|
| 165 | //
|
|---|
| 166 | // get the minimum number of photons of all valid pixels in the list
|
|---|
| 167 | // If you specify a geometry the number of photons is weighted with the
|
|---|
| 168 | // area of the pixel
|
|---|
| 169 | //
|
|---|
| 170 | Float_t MCerPhotEvt::GetNumPhotonsMin(const MGeomCam *geom) const
|
|---|
| 171 | {
|
|---|
| 172 | if (fNumPixels <= 0)
|
|---|
| 173 | return -5.;
|
|---|
| 174 |
|
|---|
| 175 | const UInt_t n = geom->GetNumPixels();
|
|---|
| 176 |
|
|---|
| 177 | Float_t minval = FLT_MAX;
|
|---|
| 178 |
|
|---|
| 179 | for (UInt_t i=1; i<fNumPixels; i++)
|
|---|
| 180 | {
|
|---|
| 181 | const MCerPhotPix &pix = (*this)[i];
|
|---|
| 182 | if (!pix.IsPixelUsed())
|
|---|
| 183 | continue;
|
|---|
| 184 |
|
|---|
| 185 | const UInt_t id = pix.GetPixId();
|
|---|
| 186 | if (id>=n)
|
|---|
| 187 | continue;
|
|---|
| 188 |
|
|---|
| 189 | Float_t testval = pix.GetNumPhotons();
|
|---|
| 190 |
|
|---|
| 191 | if (geom)
|
|---|
| 192 | testval *= geom->GetPixRatio(id);
|
|---|
| 193 |
|
|---|
| 194 | if (testval < minval)
|
|---|
| 195 | minval = testval;
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | return minval;
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | // --------------------------------------------------------------------------
|
|---|
| 202 | //
|
|---|
| 203 | // get the maximum number of photons of all valid pixels in the list
|
|---|
| 204 | // If you specify a geometry the number of photons is weighted with the
|
|---|
| 205 | // area of the pixel
|
|---|
| 206 | //
|
|---|
| 207 | Float_t MCerPhotEvt::GetNumPhotonsMax(const MGeomCam *geom) const
|
|---|
| 208 | {
|
|---|
| 209 | if (fNumPixels <= 0)
|
|---|
| 210 | return 50.;
|
|---|
| 211 |
|
|---|
| 212 | const UInt_t n = geom->GetNumPixels();
|
|---|
| 213 |
|
|---|
| 214 | Float_t maxval = -FLT_MAX;
|
|---|
| 215 |
|
|---|
| 216 | for (UInt_t i=1; i<fNumPixels; i++)
|
|---|
| 217 | {
|
|---|
| 218 | const MCerPhotPix &pix = (*this)[i];
|
|---|
| 219 | if (!pix.IsPixelUsed())
|
|---|
| 220 | continue;
|
|---|
| 221 |
|
|---|
| 222 | const UInt_t id = pix.GetPixId();
|
|---|
| 223 | if (id>=n)
|
|---|
| 224 | continue;
|
|---|
| 225 |
|
|---|
| 226 | Float_t testval = pix.GetNumPhotons();
|
|---|
| 227 | if (geom)
|
|---|
| 228 | testval *= geom->GetPixRatio(id);
|
|---|
| 229 |
|
|---|
| 230 | if (testval > maxval)
|
|---|
| 231 | maxval = testval;
|
|---|
| 232 | }
|
|---|
| 233 | return maxval;
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | // --------------------------------------------------------------------------
|
|---|
| 237 | //
|
|---|
| 238 | // get the minimum ratio of photons/error
|
|---|
| 239 | //
|
|---|
| 240 | Float_t MCerPhotEvt::GetRatioMin(const MGeomCam *geom) const
|
|---|
| 241 | {
|
|---|
| 242 | if (fNumPixels <= 0)
|
|---|
| 243 | return -5.;
|
|---|
| 244 |
|
|---|
| 245 | Float_t minval = (*this)[0].GetNumPhotons()/(*this)[0].GetErrorPhot();
|
|---|
| 246 |
|
|---|
| 247 | for (UInt_t i=1; i<fNumPixels; i++)
|
|---|
| 248 | {
|
|---|
| 249 | const MCerPhotPix &pix = (*this)[i];
|
|---|
| 250 | if (!pix.IsPixelUsed())
|
|---|
| 251 | continue;
|
|---|
| 252 |
|
|---|
| 253 | Float_t testval = pix.GetNumPhotons()/pix.GetErrorPhot();
|
|---|
| 254 | if (geom)
|
|---|
| 255 | testval *= TMath::Sqrt(geom->GetPixRatio(pix.GetPixId()));
|
|---|
| 256 |
|
|---|
| 257 | if (testval < minval)
|
|---|
| 258 | minval = testval;
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | return minval;
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | // --------------------------------------------------------------------------
|
|---|
| 265 | //
|
|---|
| 266 | // get the maximum ratio of photons/error
|
|---|
| 267 | //
|
|---|
| 268 | Float_t MCerPhotEvt::GetRatioMax(const MGeomCam *geom) const
|
|---|
| 269 | {
|
|---|
| 270 | if (fNumPixels <= 0)
|
|---|
| 271 | return -5.;
|
|---|
| 272 |
|
|---|
| 273 | Float_t maxval = -FLT_MAX;
|
|---|
| 274 |
|
|---|
| 275 | for (UInt_t i=1; i<fNumPixels; i++)
|
|---|
| 276 | {
|
|---|
| 277 | const MCerPhotPix &pix = (*this)[i];
|
|---|
| 278 | if (!pix.IsPixelUsed())
|
|---|
| 279 | continue;
|
|---|
| 280 |
|
|---|
| 281 | Float_t testval = pix.GetNumPhotons()/pix.GetErrorPhot();
|
|---|
| 282 | if (geom)
|
|---|
| 283 | testval *= TMath::Sqrt(geom->GetPixRatio(pix.GetPixId()));
|
|---|
| 284 |
|
|---|
| 285 | if (testval > maxval)
|
|---|
| 286 | maxval = testval;
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 | return maxval;
|
|---|
| 290 | }
|
|---|
| 291 |
|
|---|
| 292 | // --------------------------------------------------------------------------
|
|---|
| 293 | //
|
|---|
| 294 | // get the minimum of error
|
|---|
| 295 | // If you specify a geometry the number of photons is weighted with the
|
|---|
| 296 | // area of the pixel
|
|---|
| 297 | //
|
|---|
| 298 | Float_t MCerPhotEvt::GetErrorPhotMin(const MGeomCam *geom) const
|
|---|
| 299 | {
|
|---|
| 300 | if (fNumPixels <= 0)
|
|---|
| 301 | return 50.;
|
|---|
| 302 |
|
|---|
| 303 | Float_t minval = FLT_MAX;
|
|---|
| 304 |
|
|---|
| 305 | for (UInt_t i=1; i<fNumPixels; i++)
|
|---|
| 306 | {
|
|---|
| 307 | const MCerPhotPix &pix = (*this)[i];
|
|---|
| 308 | if (!pix.IsPixelUsed())
|
|---|
| 309 | continue;
|
|---|
| 310 |
|
|---|
| 311 | Float_t testval = pix.GetErrorPhot();
|
|---|
| 312 |
|
|---|
| 313 | if (geom)
|
|---|
| 314 | testval *= geom->GetPixRatio(pix.GetPixId());
|
|---|
| 315 |
|
|---|
| 316 | if (testval < minval)
|
|---|
| 317 | minval = testval;
|
|---|
| 318 | }
|
|---|
| 319 | return minval;
|
|---|
| 320 | }
|
|---|
| 321 |
|
|---|
| 322 | // --------------------------------------------------------------------------
|
|---|
| 323 | //
|
|---|
| 324 | // get the maximum ratio of photons/error
|
|---|
| 325 | // If you specify a geometry the number of photons is weighted with the
|
|---|
| 326 | // area of the pixel
|
|---|
| 327 | //
|
|---|
| 328 | Float_t MCerPhotEvt::GetErrorPhotMax(const MGeomCam *geom) const
|
|---|
| 329 | {
|
|---|
| 330 | if (fNumPixels <= 0)
|
|---|
| 331 | return 50.;
|
|---|
| 332 |
|
|---|
| 333 | Float_t maxval = -FLT_MAX;
|
|---|
| 334 |
|
|---|
| 335 | for (UInt_t i=1; i<fNumPixels; i++)
|
|---|
| 336 | {
|
|---|
| 337 | const MCerPhotPix &pix = (*this)[i];
|
|---|
| 338 | if (!pix.IsPixelUsed())
|
|---|
| 339 | continue;
|
|---|
| 340 |
|
|---|
| 341 | Float_t testval = pix.GetErrorPhot();
|
|---|
| 342 |
|
|---|
| 343 | if (geom)
|
|---|
| 344 | testval *= geom->GetPixRatio(pix.GetPixId());
|
|---|
| 345 |
|
|---|
| 346 | if (testval > maxval)
|
|---|
| 347 | maxval = testval;
|
|---|
| 348 | }
|
|---|
| 349 | return maxval;
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 | // --------------------------------------------------------------------------
|
|---|
| 353 | //
|
|---|
| 354 | // Return a pointer to the pixel with the requested id. NULL if it doesn't
|
|---|
| 355 | // exist.
|
|---|
| 356 | //
|
|---|
| 357 | MCerPhotPix *MCerPhotEvt::GetPixById(int id) const
|
|---|
| 358 | {
|
|---|
| 359 | TIter Next(fPixels);
|
|---|
| 360 | MCerPhotPix *pix = NULL;
|
|---|
| 361 |
|
|---|
| 362 | while ((pix=(MCerPhotPix*)Next()))
|
|---|
| 363 | if (pix->GetPixId()==id)
|
|---|
| 364 | return pix;
|
|---|
| 365 |
|
|---|
| 366 | return NULL;
|
|---|
| 367 | }
|
|---|
| 368 |
|
|---|
| 369 | void MCerPhotEvt::Scale(Double_t f)
|
|---|
| 370 | {
|
|---|
| 371 | fPixels->ForEach(MCerPhotPix, Scale)(f);
|
|---|
| 372 | }
|
|---|
| 373 |
|
|---|
| 374 | void MCerPhotEvt::RemoveUnusedPixels()
|
|---|
| 375 | {
|
|---|
| 376 | TIter Next(fPixels);
|
|---|
| 377 | MCerPhotPix *pix = NULL;
|
|---|
| 378 |
|
|---|
| 379 | while ((pix=(MCerPhotPix*)Next()))
|
|---|
| 380 | if (!pix->IsPixelUsed())
|
|---|
| 381 | fPixels->Remove(pix);
|
|---|
| 382 |
|
|---|
| 383 | fPixels->Compress();
|
|---|
| 384 | fNumPixels=fPixels->GetEntriesFast();
|
|---|
| 385 | }
|
|---|
| 386 |
|
|---|
| 387 | // --------------------------------------------------------------------------
|
|---|
| 388 | //
|
|---|
| 389 | // Returns, depending on the type flag:
|
|---|
| 390 | //
|
|---|
| 391 | // 0: Number of Photons*PixRatio
|
|---|
| 392 | // 1: Error*sqrt(PixRatio)
|
|---|
| 393 | // 2: Cleaning level = Num Photons*sqrt(PixRatio)/Error
|
|---|
| 394 | // 3: Number of Photons
|
|---|
| 395 | // 4: Error
|
|---|
| 396 | //
|
|---|
| 397 | Bool_t MCerPhotEvt::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
|
|---|
| 398 | {
|
|---|
| 399 | MCerPhotPix *pix = GetPixById(idx);
|
|---|
| 400 | if (!pix || !pix->IsPixelUsed())
|
|---|
| 401 | return kFALSE;
|
|---|
| 402 |
|
|---|
| 403 | const Double_t ratio = cam.GetPixRatio(idx);
|
|---|
| 404 |
|
|---|
| 405 | switch (type)
|
|---|
| 406 | {
|
|---|
| 407 | case 1:
|
|---|
| 408 | val = pix->GetErrorPhot()*TMath::Sqrt(ratio);
|
|---|
| 409 | return kTRUE;
|
|---|
| 410 | case 2:
|
|---|
| 411 | if (pix->GetErrorPhot()<=0)
|
|---|
| 412 | return kFALSE;
|
|---|
| 413 | val = pix->GetNumPhotons()*TMath::Sqrt(ratio)/pix->GetErrorPhot();
|
|---|
| 414 | return kTRUE;
|
|---|
| 415 | case 3:
|
|---|
| 416 | val = pix->GetNumPhotons();
|
|---|
| 417 | break;
|
|---|
| 418 | case 4:
|
|---|
| 419 | val = pix->GetErrorPhot();
|
|---|
| 420 | break;
|
|---|
| 421 | default:
|
|---|
| 422 | val = pix->GetNumPhotons()*ratio;
|
|---|
| 423 | return kTRUE;
|
|---|
| 424 | }
|
|---|
| 425 | return kTRUE;
|
|---|
| 426 | }
|
|---|