| 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, 10/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 19 | ! Author(s): Hendrik Bartko, 08/2004 <mailto:hbartko@mppmu.mpg.de>
|
|---|
| 20 | !
|
|---|
| 21 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 22 | !
|
|---|
| 23 | !
|
|---|
| 24 | \* ======================================================================== */
|
|---|
| 25 |
|
|---|
| 26 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 27 | //
|
|---|
| 28 | // MCameraData
|
|---|
| 29 | //
|
|---|
| 30 | // This is a generalized class storing camera data. For example the cleaning
|
|---|
| 31 | // level for the image cleaning is one possibility.
|
|---|
| 32 | //
|
|---|
| 33 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 34 | #include "MCameraData.h"
|
|---|
| 35 |
|
|---|
| 36 | #include "MMath.h"
|
|---|
| 37 |
|
|---|
| 38 | #include "MLog.h"
|
|---|
| 39 | #include "MLogManip.h"
|
|---|
| 40 |
|
|---|
| 41 | #include "MGeomCam.h"
|
|---|
| 42 | #include "MGeomPix.h"
|
|---|
| 43 |
|
|---|
| 44 | #include "MPedPhotCam.h"
|
|---|
| 45 | #include "MPedPhotPix.h"
|
|---|
| 46 |
|
|---|
| 47 | #include "MSignalCam.h"
|
|---|
| 48 | #include "MSignalPix.h"
|
|---|
| 49 |
|
|---|
| 50 | #include "MSigmabar.h"
|
|---|
| 51 |
|
|---|
| 52 | ClassImp(MCameraData);
|
|---|
| 53 |
|
|---|
| 54 | using namespace std;
|
|---|
| 55 |
|
|---|
| 56 | // --------------------------------------------------------------------------
|
|---|
| 57 | //
|
|---|
| 58 | // Creates a MSignalPix object for each pixel in the event
|
|---|
| 59 | //
|
|---|
| 60 | MCameraData::MCameraData(const char *name, const char *title)
|
|---|
| 61 | {
|
|---|
| 62 | fName = name ? name : "MCameraData";
|
|---|
| 63 | fTitle = title ? title : "Generalized storage container for camera contents";
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | /*
|
|---|
| 67 | // --------------------------------------------------------------------------
|
|---|
| 68 | //
|
|---|
| 69 | // This is not yet implemented like it should.
|
|---|
| 70 | //
|
|---|
| 71 |
|
|---|
| 72 | void MCameraData::Draw(Option_t* option)
|
|---|
| 73 | {
|
|---|
| 74 | //
|
|---|
| 75 | // FIXME!!! Here the Draw function of the CamDisplay
|
|---|
| 76 | // should be called to add the CamDisplay to the Pad.
|
|---|
| 77 | // The drawing should be done in MCamDisplay::Paint
|
|---|
| 78 | //
|
|---|
| 79 |
|
|---|
| 80 | // MGeomCam *geom = fType ? new MGeomCamMagic : new MGeomCamCT1;
|
|---|
| 81 | // MCamDisplay *disp = new MCamDisplay(geom);
|
|---|
| 82 | // delete geom;
|
|---|
| 83 | // disp->DrawPhotNum(this);
|
|---|
| 84 | }
|
|---|
| 85 | */
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 | // --------------------------------------------------------------------------
|
|---|
| 89 | //
|
|---|
| 90 | // Function to calculate the cleaning level for all pixels in a given event
|
|---|
| 91 | // as the ratio between the measured photons and the pedestal rms.
|
|---|
| 92 | // In order to do the image cleaning on average in the same photon flux
|
|---|
| 93 | // (reconstructed photons per pixel area) for the inner and outer pixels,
|
|---|
| 94 | // a correction factor is applied to the outer pixels (see TDAS 02-14).
|
|---|
| 95 | // The correction factor assumes the ideal case that the pedestal rms
|
|---|
| 96 | // scales with the inverse square root of the pixel area.
|
|---|
| 97 | //
|
|---|
| 98 | // FIXME: Should the check noise<=0 be replaced by MBadPixels?
|
|---|
| 99 | //
|
|---|
| 100 | void MCameraData::CalcCleaningLevel(const MSignalCam &evt, const MPedPhotCam &cam,
|
|---|
| 101 | const MGeomCam &geom)
|
|---|
| 102 | {
|
|---|
| 103 | const Int_t n = geom.GetNumPixels();
|
|---|
| 104 |
|
|---|
| 105 | // Reset arrays
|
|---|
| 106 | fData.Set(n);
|
|---|
| 107 | fData.Reset();
|
|---|
| 108 |
|
|---|
| 109 | fValidity.Set(n);
|
|---|
| 110 | fValidity.Reset();
|
|---|
| 111 |
|
|---|
| 112 | const Int_t entries = evt.GetNumPixels();
|
|---|
| 113 |
|
|---|
| 114 | // calculate cleaning levels
|
|---|
| 115 | for (Int_t idx=0; idx<entries; idx++)
|
|---|
| 116 | {
|
|---|
| 117 | const MSignalPix &pix = evt[idx];
|
|---|
| 118 |
|
|---|
| 119 | const Float_t noise = cam[idx].GetRms();
|
|---|
| 120 |
|
|---|
| 121 | if (noise<=0) // fData[idx]=0, fValidity[idx]=0
|
|---|
| 122 | continue;
|
|---|
| 123 |
|
|---|
| 124 | //
|
|---|
| 125 | // We calculate a correction factor which accounts for the
|
|---|
| 126 | // fact that pixels have different size (see TDAS 02-14).
|
|---|
| 127 | //
|
|---|
| 128 | fData[idx] = pix.GetNumPhotons() * geom.GetPixRatioSqrt(idx) / noise;
|
|---|
| 129 | fValidity[idx] = 1;
|
|---|
| 130 | }
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | // --------------------------------------------------------------------------
|
|---|
| 134 | //
|
|---|
| 135 | // Function to calculate the cleaning level for all pixels in a given event
|
|---|
| 136 | // as the ratio between the measured photons and the pedestal rms.
|
|---|
| 137 | // In order to do the image cleaning on average in the same photon flux
|
|---|
| 138 | // (reconstructed photons per pixel area) for the inner and outer pixels,
|
|---|
| 139 | // a correction factor is applied to the outer pixels (see TDAS 02-14).
|
|---|
| 140 | // The correction factor takes the actual average pedestal RMS of the
|
|---|
| 141 | // inner and outer pixels into account.
|
|---|
| 142 | //
|
|---|
| 143 | // FIXME: Should the check noise<=0 be replaced by MBadPixels?
|
|---|
| 144 | //
|
|---|
| 145 | void MCameraData::CalcCleaningLevel2(const MSignalCam &evt, const MPedPhotCam &cam,
|
|---|
| 146 | const MGeomCam &geom)
|
|---|
| 147 | {
|
|---|
| 148 | const Int_t n = geom.GetNumPixels();
|
|---|
| 149 |
|
|---|
| 150 | // reset arrays
|
|---|
| 151 | fData.Set(n);
|
|---|
| 152 | fData.Reset();
|
|---|
| 153 |
|
|---|
| 154 | fValidity.Set(n);
|
|---|
| 155 | fValidity.Reset();
|
|---|
| 156 |
|
|---|
| 157 | // check validity of rms with area index 0
|
|---|
| 158 | const Float_t anoise0 = cam.GetArea(0).GetRms();
|
|---|
| 159 | if (anoise0<=0)
|
|---|
| 160 | return;
|
|---|
| 161 |
|
|---|
| 162 | // calculate cleaning levels
|
|---|
| 163 | const Int_t entries = evt.GetNumPixels();
|
|---|
| 164 | for (Int_t idx=0; idx<entries; idx++)
|
|---|
| 165 | {
|
|---|
| 166 | const MSignalPix &pix = evt[idx];
|
|---|
| 167 |
|
|---|
| 168 | const Float_t noise = cam[idx].GetRms();
|
|---|
| 169 |
|
|---|
| 170 | if (noise<=0) // fData[idx]=0, fValidity[idx]=0
|
|---|
| 171 | continue;
|
|---|
| 172 |
|
|---|
| 173 | //
|
|---|
| 174 | // We calculate a correction factor which accounts for the
|
|---|
| 175 | // fact that pixels have different size (see TDAS 02-14).
|
|---|
| 176 | // We also take into account that the RMS does not scale
|
|---|
| 177 | // with the square root of the pixel area.
|
|---|
| 178 | //
|
|---|
| 179 | const UInt_t aidx = geom[idx].GetAidx();
|
|---|
| 180 | const Float_t ratio = cam.GetArea(aidx).GetRms()/anoise0;
|
|---|
| 181 |
|
|---|
| 182 | fData[idx] = pix.GetNumPhotons() * geom.GetPixRatio(idx) * ratio / noise;
|
|---|
| 183 | fValidity[idx] = 1;
|
|---|
| 184 | }
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 | void MCameraData::CalcCleaningLevel(const MSignalCam &evt, const MSigmabar &sgb,
|
|---|
| 189 | const MGeomCam &geom)
|
|---|
| 190 | {
|
|---|
| 191 | CalcCleaningLevel(evt, sgb.GetSigmabarInner(), geom);
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | void MCameraData::CalcCleaningLevel(const MSignalCam &evt, Double_t noise,
|
|---|
| 195 | const MGeomCam &geom)
|
|---|
| 196 | {
|
|---|
| 197 | const Int_t n = geom.GetNumPixels();
|
|---|
| 198 |
|
|---|
| 199 | // reset arrays
|
|---|
| 200 | fData.Set(n);
|
|---|
| 201 | fData.Reset();
|
|---|
| 202 |
|
|---|
| 203 | fValidity.Set(n);
|
|---|
| 204 | fValidity.Reset();
|
|---|
| 205 |
|
|---|
| 206 | // check validity of noise
|
|---|
| 207 | if (noise<=0)
|
|---|
| 208 | return;
|
|---|
| 209 |
|
|---|
| 210 | // calculate cleaning levels
|
|---|
| 211 | const Int_t entries = evt.GetNumPixels();
|
|---|
| 212 | for (Int_t idx=0; idx<entries; idx++)
|
|---|
| 213 | {
|
|---|
| 214 | const MSignalPix &pix = evt[idx];
|
|---|
| 215 |
|
|---|
| 216 | //
|
|---|
| 217 | // We calculate a correction factor which accounts for the
|
|---|
| 218 | // fact that pixels have different size (see TDAS 02-14).
|
|---|
| 219 | //
|
|---|
| 220 | fData[idx] = pix.GetNumPhotons() * geom.GetPixRatio(idx) / noise;
|
|---|
| 221 | fValidity[idx] = 1;
|
|---|
| 222 | }
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | // --------------------------------------------------------------------------
|
|---|
| 226 | //
|
|---|
| 227 | // Function to calculate the cleaning level for all pixels in a given event
|
|---|
| 228 | // as the ratio between the reconstructed number of photons per area of an
|
|---|
| 229 | // inner pixel and the average pedestal RMS of the inner pixels (democratic
|
|---|
| 230 | // image cleaning, see TDAS 02-14).
|
|---|
| 231 | //
|
|---|
| 232 | // FIXME: Should the check noise<=0 be replaced by MBadPixels?
|
|---|
| 233 | //
|
|---|
| 234 | void MCameraData::CalcCleaningLevelDemocratic(const MSignalCam &evt, const MPedPhotCam &cam,
|
|---|
| 235 | const MGeomCam &geom)
|
|---|
| 236 | {
|
|---|
| 237 | const Int_t n = geom.GetNumPixels();
|
|---|
| 238 |
|
|---|
| 239 | // reset arrays
|
|---|
| 240 | fData.Set(n);
|
|---|
| 241 | fData.Reset();
|
|---|
| 242 |
|
|---|
| 243 | fValidity.Set(n);
|
|---|
| 244 | fValidity.Reset();
|
|---|
| 245 |
|
|---|
| 246 | // check validity of rms with area index 0
|
|---|
| 247 | const Float_t noise0 = cam.GetArea(0).GetRms();
|
|---|
| 248 | if (noise0<=0)
|
|---|
| 249 | return;
|
|---|
| 250 |
|
|---|
| 251 | // calculate cleaning levels
|
|---|
| 252 | const Int_t entries = evt.GetNumPixels();
|
|---|
| 253 | for (Int_t idx=0; idx<entries; idx++)
|
|---|
| 254 | {
|
|---|
| 255 | const MSignalPix &pix = evt[idx];
|
|---|
| 256 |
|
|---|
| 257 | const Float_t noise = cam[idx].GetRms();
|
|---|
| 258 |
|
|---|
| 259 | if (noise<=0)
|
|---|
| 260 | continue;
|
|---|
| 261 |
|
|---|
| 262 | //
|
|---|
| 263 | // We calculate a correction factor which accounts for the
|
|---|
| 264 | // fact that pixels have different size (see TDAS 02-14).
|
|---|
| 265 | //
|
|---|
| 266 | fData[idx] = pix.GetNumPhotons() * geom.GetPixRatio(idx) / noise0;
|
|---|
| 267 | fValidity[idx] = 1;
|
|---|
| 268 | }
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 | // --------------------------------------------------------------------------
|
|---|
| 272 | //
|
|---|
| 273 | // Function to calculate the cleaning level for all pixels in a given event.
|
|---|
| 274 | // The level is the probability that the signal is a real signal (taking
|
|---|
| 275 | // the signal height and the fluctuation of the background into account)
|
|---|
| 276 | // times one minus the probability that the signal is a background
|
|---|
| 277 | // fluctuation (calculated from the time spread of arrival times
|
|---|
| 278 | // around the pixel with the highest signal)
|
|---|
| 279 | //
|
|---|
| 280 | // FIXME: Should the check noise<=0 be replaced by MBadPixels?
|
|---|
| 281 | //
|
|---|
| 282 | void MCameraData::CalcCleaningProbability(const MSignalCam &evt, const MPedPhotCam &pcam,
|
|---|
| 283 | const MGeomCam &geom)
|
|---|
| 284 | {
|
|---|
| 285 | const Int_t n = geom.GetNumPixels();
|
|---|
| 286 |
|
|---|
| 287 | // Reset arrays
|
|---|
| 288 | fData.Set(n);
|
|---|
| 289 | fData.Reset();
|
|---|
| 290 |
|
|---|
| 291 | fValidity.Set(n);
|
|---|
| 292 | fValidity.Reset();
|
|---|
| 293 |
|
|---|
| 294 | // check validity of noise
|
|---|
| 295 | const Float_t anoise0 = pcam.GetArea(0).GetRms();
|
|---|
| 296 | if (anoise0<=0)
|
|---|
| 297 | return;
|
|---|
| 298 |
|
|---|
| 299 | const Int_t entries = evt.GetNumPixels();
|
|---|
| 300 |
|
|---|
| 301 | // Find pixel with max signal
|
|---|
| 302 | Int_t maxidx = 0;
|
|---|
| 303 |
|
|---|
| 304 | // Find pixel entry with maximum signal
|
|---|
| 305 | for (Int_t i=0; i<entries; i++)
|
|---|
| 306 | {
|
|---|
| 307 | const Double_t s0 = evt[i].GetNumPhotons() * geom.GetPixRatio(i);
|
|---|
| 308 | const Double_t s1 = evt[maxidx].GetNumPhotons() * geom.GetPixRatio(maxidx);
|
|---|
| 309 | if (s0>s1)
|
|---|
| 310 | maxidx = i;
|
|---|
| 311 | }
|
|---|
| 312 |
|
|---|
| 313 | const Double_t timemean = evt[maxidx].GetArrivalTime();
|
|---|
| 314 | const Double_t timerms = 0.75; //[slices] rms time spread around highest pixel
|
|---|
| 315 |
|
|---|
| 316 | // calculate cleaning levels
|
|---|
| 317 | for (Int_t idx=0; idx<entries; idx++)
|
|---|
| 318 | {
|
|---|
| 319 | const MSignalPix &spix = evt[idx];
|
|---|
| 320 |
|
|---|
| 321 | const Float_t rms = pcam[idx].GetRms();
|
|---|
| 322 | if (rms<=0) // fData[idx]=0, fValidity[idx]=0
|
|---|
| 323 | continue;
|
|---|
| 324 |
|
|---|
| 325 | fValidity[idx]=1;
|
|---|
| 326 |
|
|---|
| 327 | // get signal and arrival time
|
|---|
| 328 | const UInt_t aidx = geom[idx].GetAidx();
|
|---|
| 329 | const Float_t ratio = pcam.GetArea(aidx).GetRms()/anoise0;
|
|---|
| 330 |
|
|---|
| 331 | const Double_t signal = spix.GetNumPhotons() * geom.GetPixRatio(idx) * ratio / rms;
|
|---|
| 332 | const Double_t time = evt[idx].GetArrivalTime();
|
|---|
| 333 |
|
|---|
| 334 | // if signal<0 the probability is equal 0
|
|---|
| 335 | if (signal<0)
|
|---|
| 336 | continue;
|
|---|
| 337 |
|
|---|
| 338 | // Just for convinience for easy readybility
|
|---|
| 339 | const Double_t means = 0;
|
|---|
| 340 | const Double_t meant = timemean;
|
|---|
| 341 |
|
|---|
| 342 | const Double_t sigmas = rms;
|
|---|
| 343 | const Double_t sigmat = timerms;
|
|---|
| 344 |
|
|---|
| 345 | // Get probabilities
|
|---|
| 346 | const Double_t psignal = MMath::GaussProb(signal, sigmas, means);
|
|---|
| 347 | const Double_t pbckgnd = MMath::GaussProb(time, sigmat, meant);
|
|---|
| 348 |
|
|---|
| 349 | // Set probability
|
|---|
| 350 | fData[idx] = psignal*(1-pbckgnd);
|
|---|
| 351 | fValidity[idx] = 1;
|
|---|
| 352 |
|
|---|
| 353 | // Make sure, that we don't run into trouble because of
|
|---|
| 354 | // a little numerical uncertanty
|
|---|
| 355 | if (fData[idx]>1)
|
|---|
| 356 | fData[idx]=1;
|
|---|
| 357 | if (fData[idx]<0)
|
|---|
| 358 | fData[idx]=0;
|
|---|
| 359 | }
|
|---|
| 360 | }
|
|---|
| 361 |
|
|---|
| 362 | // --------------------------------------------------------------------------
|
|---|
| 363 | //
|
|---|
| 364 | // Function to calculate the cleaning level for all pixels in a given event.
|
|---|
| 365 | // The level is the absolute number of photons times the area-ratio.
|
|---|
| 366 | //
|
|---|
| 367 | void MCameraData::CalcCleaningAbsolute(const MSignalCam &evt, const MGeomCam &geom)
|
|---|
| 368 | {
|
|---|
| 369 | const Int_t n = geom.GetNumPixels();
|
|---|
| 370 |
|
|---|
| 371 | // Reset arrays
|
|---|
| 372 | fData.Set(n);
|
|---|
| 373 | fData.Reset();
|
|---|
| 374 |
|
|---|
| 375 | fValidity.Set(n);
|
|---|
| 376 | fValidity.Reset();
|
|---|
| 377 |
|
|---|
| 378 | const Int_t entries = evt.GetNumPixels();
|
|---|
| 379 |
|
|---|
| 380 | // calculate cleaning levels
|
|---|
| 381 | for (Int_t idx=0; idx<entries; idx++)
|
|---|
| 382 | {
|
|---|
| 383 | const MSignalPix &spix = evt[idx];
|
|---|
| 384 |
|
|---|
| 385 | // Set probability
|
|---|
| 386 | fData[idx] = spix.GetNumPhotons() * geom.GetPixRatio(idx);
|
|---|
| 387 | fValidity[idx] = 1;
|
|---|
| 388 | }
|
|---|
| 389 | }
|
|---|
| 390 |
|
|---|
| 391 | // --------------------------------------------------------------------------
|
|---|
| 392 | //
|
|---|
| 393 | // Returns the contents of the pixel.
|
|---|
| 394 | //
|
|---|
| 395 | Bool_t MCameraData::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
|
|---|
| 396 | {
|
|---|
| 397 | if (idx<0 || idx>=fData.GetSize())
|
|---|
| 398 | return kFALSE;
|
|---|
| 399 |
|
|---|
| 400 | val = fData[idx];
|
|---|
| 401 | return fValidity[idx];
|
|---|
| 402 | }
|
|---|
| 403 |
|
|---|
| 404 | void MCameraData::DrawPixelContent(Int_t num) const
|
|---|
| 405 | {
|
|---|
| 406 | *fLog << warn << "MCameraData::DrawPixelContent - not available." << endl;
|
|---|
| 407 | }
|
|---|
| 408 |
|
|---|
| 409 | void MCameraData::Print(Option_t *o) const
|
|---|
| 410 | {
|
|---|
| 411 | MParContainer::Print(o);
|
|---|
| 412 | *fLog << "Size = " << fData.GetSize() << endl;
|
|---|
| 413 | for (int i=0; i<fData.GetSize(); i++)
|
|---|
| 414 | cout << i << ": " << fData[i] << endl;
|
|---|
| 415 | }
|
|---|