| 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 | ! Markus Gaug 02/2004 <mailto:markus@ifae.es>
|
|---|
| 20 | !
|
|---|
| 21 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 22 | !
|
|---|
| 23 | !
|
|---|
| 24 | \* ======================================================================== */
|
|---|
| 25 |
|
|---|
| 26 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 27 | // //
|
|---|
| 28 | // MPedestalCam //
|
|---|
| 29 | // //
|
|---|
| 30 | // Hold the Pedestal information for all pixels in the camera //
|
|---|
| 31 | // //
|
|---|
| 32 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 33 | #include "MPedestalCam.h"
|
|---|
| 34 | #include "MPedestalPix.h"
|
|---|
| 35 |
|
|---|
| 36 | #include <TClonesArray.h>
|
|---|
| 37 |
|
|---|
| 38 | #include "MLog.h"
|
|---|
| 39 | #include "MLogManip.h"
|
|---|
| 40 |
|
|---|
| 41 | #include "MParList.h"
|
|---|
| 42 |
|
|---|
| 43 | #include "MGeomCam.h"
|
|---|
| 44 |
|
|---|
| 45 | ClassImp(MPedestalCam);
|
|---|
| 46 |
|
|---|
| 47 | using namespace std;
|
|---|
| 48 |
|
|---|
| 49 | // --------------------------------------------------------------------------
|
|---|
| 50 | //
|
|---|
| 51 | // Default constructor.
|
|---|
| 52 | //
|
|---|
| 53 | // Creates a TClonesArray of MPedestalPix containers, initialized to 1 entry, destinated
|
|---|
| 54 | // to hold one container per pixel. Later, a call to MPedestalCam::InitSize()
|
|---|
| 55 | // has to be performed (in MGeomApply).
|
|---|
| 56 | //
|
|---|
| 57 | // Creates a TClonesArray of MPedestalPix containers, initialized to 1 entry, destinated
|
|---|
| 58 | // to hold one container per pixel AREA. Later, a call to MPedestalCam::InitAreas()
|
|---|
| 59 | // has to be performed (in MGeomApply).
|
|---|
| 60 | //
|
|---|
| 61 | // Creates a TClonesArray of MPedestalPix containers, initialized to 1 entry, destinated
|
|---|
| 62 | // to hold one container per camera SECTOR. Later, a call to MPedestalCam::InitSectors()
|
|---|
| 63 | // has to be performed (in MGeomApply).
|
|---|
| 64 | //
|
|---|
| 65 | MPedestalCam::MPedestalCam(const char *name, const char *title)
|
|---|
| 66 | : fTotalEntries(0)
|
|---|
| 67 | {
|
|---|
| 68 | fName = name ? name : "MPedestalCam";
|
|---|
| 69 | fTitle = title ? title : "Storage container for all Pedestal Information in the camera";
|
|---|
| 70 |
|
|---|
| 71 | fArray = new TClonesArray("MPedestalPix", 1);
|
|---|
| 72 | fAverageAreas = new TClonesArray("MPedestalPix", 1);
|
|---|
| 73 | fAverageSectors = new TClonesArray("MPedestalPix", 1);
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | // --------------------------------------------------------------------------
|
|---|
| 77 | //
|
|---|
| 78 | // Deletes the following TClonesArray's of MPedestalPix containers (if exist):
|
|---|
| 79 | // - fArray
|
|---|
| 80 | // - fAverageAreas
|
|---|
| 81 | // - fAverageSectors
|
|---|
| 82 | //
|
|---|
| 83 | MPedestalCam::~MPedestalCam()
|
|---|
| 84 | {
|
|---|
| 85 | delete fArray;
|
|---|
| 86 | delete fAverageAreas;
|
|---|
| 87 | delete fAverageSectors;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | // --------------------------------------------------------------------------
|
|---|
| 91 | //
|
|---|
| 92 | // Set the size of the camera
|
|---|
| 93 | //
|
|---|
| 94 | void MPedestalCam::InitSize(const UInt_t i)
|
|---|
| 95 | {
|
|---|
| 96 | fArray->ExpandCreate(i);
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | // -------------------------------------------------------------------
|
|---|
| 100 | //
|
|---|
| 101 | // Calls TClonesArray::ExpandCreate() for:
|
|---|
| 102 | // - fAverageAreas
|
|---|
| 103 | //
|
|---|
| 104 | void MPedestalCam::InitAverageAreas(const UInt_t i)
|
|---|
| 105 | {
|
|---|
| 106 | fAverageAreas->ExpandCreate(i);
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | // -------------------------------------------------------------------
|
|---|
| 110 | //
|
|---|
| 111 | // Calls TClonesArray::ExpandCreate() for:
|
|---|
| 112 | // - fAverageSectors
|
|---|
| 113 | //
|
|---|
| 114 | void MPedestalCam::InitAverageSectors(const UInt_t i)
|
|---|
| 115 | {
|
|---|
| 116 | fAverageSectors->ExpandCreate(i);
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | // -------------------------------------------------------------------
|
|---|
| 120 | //
|
|---|
| 121 | // Calls:
|
|---|
| 122 | // - InitSize()
|
|---|
| 123 | // - InitAverageAreas()
|
|---|
| 124 | // - InitAverageSectors()
|
|---|
| 125 | //
|
|---|
| 126 | void MPedestalCam::Init(const MGeomCam &geom)
|
|---|
| 127 | {
|
|---|
| 128 | InitSize (geom.GetNumPixels() );
|
|---|
| 129 | InitAverageAreas (geom.GetNumAreas() );
|
|---|
| 130 | InitAverageSectors(geom.GetNumSectors());
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | // --------------------------------------------------------------------------
|
|---|
| 134 | //
|
|---|
| 135 | // This function returns the current size of the TClonesArray
|
|---|
| 136 | // independently if the MPedestalPix is filled with values or not.
|
|---|
| 137 | //
|
|---|
| 138 | // Get the size of the MPedestalCam
|
|---|
| 139 | //
|
|---|
| 140 | Int_t MPedestalCam::GetSize() const
|
|---|
| 141 | {
|
|---|
| 142 | return fArray->GetEntriesFast();
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | // --------------------------------------------------------------------------
|
|---|
| 146 | //
|
|---|
| 147 | // Returns the current size of the TClonesArray fAverageAreas
|
|---|
| 148 | // independently if the MPedestalPix is filled with values or not.
|
|---|
| 149 | //
|
|---|
| 150 | const Int_t MPedestalCam::GetAverageAreas() const
|
|---|
| 151 | {
|
|---|
| 152 | return fAverageAreas->GetEntriesFast();
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | // --------------------------------------------------------------------------
|
|---|
| 156 | //
|
|---|
| 157 | // Returns the current size of the TClonesArray fAverageSectors
|
|---|
| 158 | // independently if the MPedestalPix is filled with values or not.
|
|---|
| 159 | //
|
|---|
| 160 | const Int_t MPedestalCam::GetAverageSectors() const
|
|---|
| 161 | {
|
|---|
| 162 | return fAverageSectors->GetEntriesFast();
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | // --------------------------------------------------------------------------
|
|---|
| 166 | //
|
|---|
| 167 | // Get i-th pixel (pixel number)
|
|---|
| 168 | //
|
|---|
| 169 | MPedestalPix &MPedestalCam::operator[](Int_t i)
|
|---|
| 170 | {
|
|---|
| 171 | return *static_cast<MPedestalPix*>(fArray->UncheckedAt(i));
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | // --------------------------------------------------------------------------
|
|---|
| 175 | //
|
|---|
| 176 | // Get i-th pixel (pixel number)
|
|---|
| 177 | //
|
|---|
| 178 | const MPedestalPix &MPedestalCam::operator[](Int_t i) const
|
|---|
| 179 | {
|
|---|
| 180 | return *static_cast<MPedestalPix*>(fArray->UncheckedAt(i));
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | // --------------------------------------------------------------------------
|
|---|
| 184 | //
|
|---|
| 185 | // Get i-th average pixel (area number)
|
|---|
| 186 | //
|
|---|
| 187 | MPedestalPix &MPedestalCam::GetAverageArea(UInt_t i)
|
|---|
| 188 | {
|
|---|
| 189 | return *static_cast<MPedestalPix*>(fAverageAreas->UncheckedAt(i));
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | // --------------------------------------------------------------------------
|
|---|
| 193 | //
|
|---|
| 194 | // Get i-th average pixel (area number)
|
|---|
| 195 | //
|
|---|
| 196 | const MPedestalPix &MPedestalCam::GetAverageArea(UInt_t i) const
|
|---|
| 197 | {
|
|---|
| 198 | return *static_cast<MPedestalPix*>(fAverageAreas->UncheckedAt(i));
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | // --------------------------------------------------------------------------
|
|---|
| 202 | //
|
|---|
| 203 | // Get i-th average pixel (sector number)
|
|---|
| 204 | //
|
|---|
| 205 | MPedestalPix &MPedestalCam::GetAverageSector(UInt_t i)
|
|---|
| 206 | {
|
|---|
| 207 | return *static_cast<MPedestalPix*>(fAverageSectors->UncheckedAt(i));
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | // --------------------------------------------------------------------------
|
|---|
| 211 | //
|
|---|
| 212 | // Get i-th average pixel (sector number)
|
|---|
| 213 | //
|
|---|
| 214 | const MPedestalPix &MPedestalCam::GetAverageSector(UInt_t i) const
|
|---|
| 215 | {
|
|---|
| 216 | return *static_cast<MPedestalPix*>(fAverageSectors->UncheckedAt(i));
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | // --------------------------------------
|
|---|
| 220 | //
|
|---|
| 221 | // Calls the ForEach macro for the TClonesArray fArray with the argument Clear()
|
|---|
| 222 | //
|
|---|
| 223 | // Loops over the fAverageAreas, calling the function Clear() for
|
|---|
| 224 | // every entry in fAverageAreas
|
|---|
| 225 | //
|
|---|
| 226 | // Loops over the fAverageSectors, calling the function Clear() for
|
|---|
| 227 | // every entry in fAverageSectors
|
|---|
| 228 | //
|
|---|
| 229 | void MPedestalCam::Clear(Option_t *o)
|
|---|
| 230 | {
|
|---|
| 231 | fArray->ForEach(TObject, Clear)();
|
|---|
| 232 |
|
|---|
| 233 | //
|
|---|
| 234 | // another ForEach does not compile, thus have to do the loop ourselves:
|
|---|
| 235 | //
|
|---|
| 236 | for (Int_t i=0;i<GetAverageAreas();i++)
|
|---|
| 237 | fAverageAreas[i].Clear();
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 | //
|
|---|
| 241 | // another ForEach does not compile, thus have to do the loop ourselves:
|
|---|
| 242 | //
|
|---|
| 243 | for (Int_t i=0;i<GetAverageSectors();i++)
|
|---|
| 244 | fAverageSectors[i].Clear();
|
|---|
| 245 |
|
|---|
| 246 | fTotalEntries = 0;
|
|---|
| 247 | }
|
|---|
| 248 |
|
|---|
| 249 | void MPedestalCam::Print(Option_t *o) const
|
|---|
| 250 | {
|
|---|
| 251 | *fLog << all << GetDescriptor() << ":" << endl;
|
|---|
| 252 | int id = 0;
|
|---|
| 253 |
|
|---|
| 254 | TIter Next(fArray);
|
|---|
| 255 | MPedestalPix *pix;
|
|---|
| 256 | while ((pix=(MPedestalPix*)Next()))
|
|---|
| 257 | {
|
|---|
| 258 | id++;
|
|---|
| 259 |
|
|---|
| 260 | if (!pix->IsValid())
|
|---|
| 261 | continue;
|
|---|
| 262 |
|
|---|
| 263 | *fLog << id-1 << ": ";
|
|---|
| 264 | *fLog << pix->GetPedestal() << " " << pix->GetPedestalRms() << endl;
|
|---|
| 265 | }
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | Float_t MPedestalCam::GetPedestalMin(const MGeomCam *geom) const
|
|---|
| 269 | {
|
|---|
| 270 | if (fArray->GetEntries() <= 0)
|
|---|
| 271 | return 50.;
|
|---|
| 272 |
|
|---|
| 273 | Float_t minval = (*this)[0].GetPedestalRms();
|
|---|
| 274 |
|
|---|
| 275 | for (Int_t i=1; i<fArray->GetEntries(); i++)
|
|---|
| 276 | {
|
|---|
| 277 | const MPedestalPix &pix = (*this)[i];
|
|---|
| 278 |
|
|---|
| 279 | Float_t testval = pix.GetPedestalRms();
|
|---|
| 280 |
|
|---|
| 281 | if (geom)
|
|---|
| 282 | testval *= geom->GetPixRatio(i);
|
|---|
| 283 |
|
|---|
| 284 | if (testval < minval)
|
|---|
| 285 | minval = testval;
|
|---|
| 286 | }
|
|---|
| 287 | return minval;
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | Float_t MPedestalCam::GetPedestalMax(const MGeomCam *geom) const
|
|---|
| 291 | {
|
|---|
| 292 | if (fArray->GetEntries() <= 0)
|
|---|
| 293 | return 50.;
|
|---|
| 294 |
|
|---|
| 295 | Float_t maxval = (*this)[0].GetPedestalRms();
|
|---|
| 296 |
|
|---|
| 297 | for (Int_t i=1; i<fArray->GetEntries(); i++)
|
|---|
| 298 | {
|
|---|
| 299 | const MPedestalPix &pix = (*this)[i];
|
|---|
| 300 |
|
|---|
| 301 | Float_t testval = pix.GetPedestalRms();
|
|---|
| 302 |
|
|---|
| 303 | if (geom)
|
|---|
| 304 | testval *= geom->GetPixRatio(i);
|
|---|
| 305 |
|
|---|
| 306 | if (testval > maxval)
|
|---|
| 307 | maxval = testval;
|
|---|
| 308 | }
|
|---|
| 309 | return maxval;
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | Bool_t MPedestalCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
|
|---|
| 313 | {
|
|---|
| 314 |
|
|---|
| 315 | if (GetSize() <= idx)
|
|---|
| 316 | return kFALSE;
|
|---|
| 317 |
|
|---|
| 318 | const Float_t ped = (*this)[idx].GetPedestal();
|
|---|
| 319 | const Float_t rms = (*this)[idx].GetPedestalRms();
|
|---|
| 320 |
|
|---|
| 321 | const Float_t pederr = rms/TMath::Sqrt((Float_t)fTotalEntries);
|
|---|
| 322 | const Float_t rmserr = rms/TMath::Sqrt((Float_t)fTotalEntries)/2.;
|
|---|
| 323 |
|
|---|
| 324 | switch (type)
|
|---|
| 325 | {
|
|---|
| 326 | case 0:
|
|---|
| 327 | val = ped;
|
|---|
| 328 | break;
|
|---|
| 329 | case 1:
|
|---|
| 330 | val = pederr;
|
|---|
| 331 | break;
|
|---|
| 332 | case 2:
|
|---|
| 333 | val = rms;
|
|---|
| 334 | break;
|
|---|
| 335 | case 3:
|
|---|
| 336 | val = rmserr;
|
|---|
| 337 | break;
|
|---|
| 338 | default:
|
|---|
| 339 | return kFALSE;
|
|---|
| 340 | }
|
|---|
| 341 | return kTRUE;
|
|---|
| 342 | }
|
|---|
| 343 |
|
|---|
| 344 | void MPedestalCam::DrawPixelContent(Int_t idx) const
|
|---|
| 345 | {
|
|---|
| 346 | *fLog << warn << "MPedestalCam::DrawPixelContent - not available." << endl;
|
|---|
| 347 | }
|
|---|