| 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): Markus Gaug 09/2003 <mailto:markus@ifae.es>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2001
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MCalibrationCalc
|
|---|
| 28 | //
|
|---|
| 29 | // Task to calculate the calibration conversion factors from the FADC
|
|---|
| 30 | // time slices. The integrated time slices have to be delivered by an
|
|---|
| 31 | // MExtractedSignalCam. The pedestals by an MPedestalCam.
|
|---|
| 32 | //
|
|---|
| 33 | // The output container MCalibrationCam holds one entry of type MCalibrationPix
|
|---|
| 34 | // for every pixel. It is filled in the following way:
|
|---|
| 35 | //
|
|---|
| 36 | // ProProcess: Search for MPedestalCam, MExtractedSignalCam
|
|---|
| 37 | // Initialize MCalibrationCam
|
|---|
| 38 | // Initialize pulser light wavelength
|
|---|
| 39 | //
|
|---|
| 40 | // ReInit: MCalibrationCam::InitSize(NumPixels) is called which allocates
|
|---|
| 41 | // memory in a TClonesArray of type MCalibrationPix
|
|---|
| 42 | // Initialize number of used FADC slices
|
|---|
| 43 | // Optionally exclude pixels from calibration
|
|---|
| 44 | //
|
|---|
| 45 | // Process: Every MCalibrationPix holds a histogram class,
|
|---|
| 46 | // MHCalibrationPixel which itself hold histograms of type:
|
|---|
| 47 | // HCharge(npix) (distribution of summed FADC time slice
|
|---|
| 48 | // entries)
|
|---|
| 49 | // HTime(npix) (distribution of position of maximum)
|
|---|
| 50 | // HChargevsN(npix) (distribution of charges vs. event number.
|
|---|
| 51 | //
|
|---|
| 52 | // PostProcess: All histograms HCharge(npix) are fitted to a Gaussian
|
|---|
| 53 | // All histograms HTime(npix) are fitted to a Gaussian
|
|---|
| 54 | // The histogram HBlindPixelCharge (blind pixel) is fitted to
|
|---|
| 55 | // a single PhE fit
|
|---|
| 56 | //
|
|---|
| 57 | // The histograms of the PIN Diode are fitted to Gaussians
|
|---|
| 58 | //
|
|---|
| 59 | // Fits can be excluded via the commands:
|
|---|
| 60 | // MalibrationCam::SkipBlindPixelFits() (skip all blind
|
|---|
| 61 | // pixel fits)
|
|---|
| 62 | // MalibrationCam::SkipPinDiodeFits() (skip all PIN Diode
|
|---|
| 63 | // fits)
|
|---|
| 64 | //
|
|---|
| 65 | // Hi-Gain vs. Lo-Gain Calibration (very memory-intensive)
|
|---|
| 66 | // can be skipped with the command:
|
|---|
| 67 | // MalibrationCam::SkipHiLoGainCalibration()
|
|---|
| 68 | //
|
|---|
| 69 | // Input Containers:
|
|---|
| 70 | // MRawEvtData
|
|---|
| 71 | // MPedestalCam
|
|---|
| 72 | // MExtractedSignalCam
|
|---|
| 73 | //
|
|---|
| 74 | // Output Containers:
|
|---|
| 75 | // MCalibrationCam
|
|---|
| 76 | //
|
|---|
| 77 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 78 | #include "MCalibrationCalc.h"
|
|---|
| 79 |
|
|---|
| 80 | // FXIME: Usage of fstream is a preliminary workaround!
|
|---|
| 81 | #include <fstream>
|
|---|
| 82 |
|
|---|
| 83 | // FXIME: This has to be removed!!!! (YES, WHEN WE HAVE ACCESS TO THE DATABASE!!!!!)
|
|---|
| 84 | #include "MCalibrationConfig.h"
|
|---|
| 85 |
|
|---|
| 86 | #include <TSystem.h>
|
|---|
| 87 | #include <TH1.h>
|
|---|
| 88 |
|
|---|
| 89 | #include "MLog.h"
|
|---|
| 90 | #include "MLogManip.h"
|
|---|
| 91 |
|
|---|
| 92 | #include "MParList.h"
|
|---|
| 93 |
|
|---|
| 94 | #include "MGeomCam.h"
|
|---|
| 95 | #include "MRawRunHeader.h"
|
|---|
| 96 | #include "MRawEvtPixelIter.h"
|
|---|
| 97 |
|
|---|
| 98 | #include "MPedestalCam.h"
|
|---|
| 99 | #include "MPedestalPix.h"
|
|---|
| 100 |
|
|---|
| 101 | #include "MCalibrationCam.h"
|
|---|
| 102 | #include "MCalibrationPix.h"
|
|---|
| 103 |
|
|---|
| 104 | #include "MExtractedSignalCam.h"
|
|---|
| 105 | #include "MExtractedSignalPix.h"
|
|---|
| 106 |
|
|---|
| 107 | #include "MCalibrationBlindPix.h"
|
|---|
| 108 | #include "MCalibrationPINDiode.h"
|
|---|
| 109 |
|
|---|
| 110 | ClassImp(MCalibrationCalc);
|
|---|
| 111 |
|
|---|
| 112 | using namespace std;
|
|---|
| 113 |
|
|---|
| 114 | const UInt_t MCalibrationCalc::fBlindPixelId = 559;
|
|---|
| 115 | const UInt_t MCalibrationCalc::fPINDiodeId = 9999;
|
|---|
| 116 | const Byte_t MCalibrationCalc::fgSaturationLimit = 254;
|
|---|
| 117 | const Int_t MCalibrationCalc::fgBlindPixelFirst = 3;
|
|---|
| 118 | const Int_t MCalibrationCalc::fgBlindPixelLast = 14;
|
|---|
| 119 | const Int_t MCalibrationCalc::fgBlindPixelSinglePheCut = 400;
|
|---|
| 120 |
|
|---|
| 121 | // --------------------------------------------------------------------------
|
|---|
| 122 | //
|
|---|
| 123 | // Default constructor.
|
|---|
| 124 | //
|
|---|
| 125 | MCalibrationCalc::MCalibrationCalc(const char *name, const char *title)
|
|---|
| 126 | : fPedestals(NULL), fCalibrations(NULL), fSignals(NULL),
|
|---|
| 127 | fRawEvt(NULL), fRunHeader(NULL), fEvtTime(NULL)
|
|---|
| 128 | {
|
|---|
| 129 |
|
|---|
| 130 | fName = name ? name : "MCalibrationCalc";
|
|---|
| 131 | fTitle = title ? title : "Task to calculate the calibration constants and MCalibrationCam ";
|
|---|
| 132 |
|
|---|
| 133 | AddToBranchList("MRawEvtData.fHiGainPixId");
|
|---|
| 134 | AddToBranchList("MRawEvtData.fLoGainPixId");
|
|---|
| 135 | AddToBranchList("MRawEvtData.fHiGainFadcSamples");
|
|---|
| 136 | AddToBranchList("MRawEvtData.fLoGainFadcSamples");
|
|---|
| 137 |
|
|---|
| 138 | Clear();
|
|---|
| 139 | SetBlindPixelRange();
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | void MCalibrationCalc::Clear(const Option_t *o)
|
|---|
| 143 | {
|
|---|
| 144 |
|
|---|
| 145 | SETBIT(fFlags, kUseBlindPixelFit);
|
|---|
| 146 | SETBIT(fFlags, kUseQualityChecks);
|
|---|
| 147 | SETBIT(fFlags, kHiLoGainCalibration);
|
|---|
| 148 |
|
|---|
| 149 | CLRBIT(fFlags, kHiGainOverFlow);
|
|---|
| 150 | CLRBIT(fFlags, kLoGainOverFlow);
|
|---|
| 151 | // As long as we don't have the PIN Diode:
|
|---|
| 152 | CLRBIT(fFlags, kUsePinDiodeFit);
|
|---|
| 153 |
|
|---|
| 154 | fBlindPixelFirst = 0;
|
|---|
| 155 | fBlindPixelLast = 0;
|
|---|
| 156 |
|
|---|
| 157 | fNumBlindPixelSinglePhe = 0;
|
|---|
| 158 | fNumBlindPixelPedestal = 0;
|
|---|
| 159 |
|
|---|
| 160 | fNumHiGainSamples = 0;
|
|---|
| 161 | fNumLoGainSamples = 0;
|
|---|
| 162 | fConversionHiLo = 0;
|
|---|
| 163 | fNumExcludedPixels = 0;
|
|---|
| 164 |
|
|---|
| 165 | fColor = kECT1;
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | void MCalibrationCalc::SetBlindPixelRange(Int_t first, Int_t last)
|
|---|
| 169 | {
|
|---|
| 170 |
|
|---|
| 171 | fBlindPixelFirst = first;
|
|---|
| 172 | fBlindPixelLast = last;
|
|---|
| 173 |
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 | MCalibrationBlindPix *MCalibrationCalc::GetBlindPixel() const
|
|---|
| 178 | {
|
|---|
| 179 | return fCalibrations->GetBlindPixel();
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | MCalibrationPINDiode *MCalibrationCalc::GetPINDiode() const
|
|---|
| 183 | {
|
|---|
| 184 | return fCalibrations->GetPINDiode();
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | // --------------------------------------------------------------------------
|
|---|
| 188 | //
|
|---|
| 189 | // The PreProcess searches for the following input containers:
|
|---|
| 190 | // - MRawEvtData
|
|---|
| 191 | // - MPedestalCam
|
|---|
| 192 | //
|
|---|
| 193 | // The following output containers are also searched and created if
|
|---|
| 194 | // they were not found:
|
|---|
| 195 | //
|
|---|
| 196 | // - MHCalibrationBlindPixel
|
|---|
| 197 | // - MCalibrationCam
|
|---|
| 198 | //
|
|---|
| 199 | // The following output containers are only searched, but not created
|
|---|
| 200 | //
|
|---|
| 201 | // - MTime
|
|---|
| 202 | //
|
|---|
| 203 | Int_t MCalibrationCalc::PreProcess(MParList *pList)
|
|---|
| 204 | {
|
|---|
| 205 |
|
|---|
| 206 | fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
|---|
| 207 | if (!fRawEvt)
|
|---|
| 208 | {
|
|---|
| 209 | *fLog << err << dbginf << "MRawEvtData not found... aborting." << endl;
|
|---|
| 210 | return kFALSE;
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
|---|
| 214 | if (!runheader)
|
|---|
| 215 | *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
|
|---|
| 216 | else
|
|---|
| 217 | if (runheader->GetRunType() == kRTMonteCarlo)
|
|---|
| 218 | {
|
|---|
| 219 | return kTRUE;
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | fCalibrations = (MCalibrationCam*)pList->FindCreateObj("MCalibrationCam");
|
|---|
| 223 | if (!fCalibrations)
|
|---|
| 224 | {
|
|---|
| 225 | *fLog << err << dbginf << "MCalibrationCam could not be created ... aborting." << endl;
|
|---|
| 226 | return kFALSE;
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | fEvtTime = (MTime*)pList->FindObject("MTime");
|
|---|
| 230 |
|
|---|
| 231 | switch (fColor)
|
|---|
| 232 | {
|
|---|
| 233 | case kEBlue:
|
|---|
| 234 | fCalibrations->SetColor(MCalibrationCam::kECBlue);
|
|---|
| 235 | break;
|
|---|
| 236 | case kEGreen:
|
|---|
| 237 | fCalibrations->SetColor(MCalibrationCam::kECGreen);
|
|---|
| 238 | break;
|
|---|
| 239 | case kEUV:
|
|---|
| 240 | fCalibrations->SetColor(MCalibrationCam::kECUV);
|
|---|
| 241 | break;
|
|---|
| 242 | case kECT1:
|
|---|
| 243 | fCalibrations->SetColor(MCalibrationCam::kECCT1);
|
|---|
| 244 | break;
|
|---|
| 245 | default:
|
|---|
| 246 | fCalibrations->SetColor(MCalibrationCam::kECCT1);
|
|---|
| 247 | }
|
|---|
| 248 |
|
|---|
| 249 | fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
|
|---|
| 250 | if (!fPedestals)
|
|---|
| 251 | {
|
|---|
| 252 | *fLog << err << dbginf << "Cannot find MPedestalCam ... aborting" << endl;
|
|---|
| 253 | return kFALSE;
|
|---|
| 254 | }
|
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 | fSignals = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
|
|---|
| 258 | if (!fSignals)
|
|---|
| 259 | {
|
|---|
| 260 | *fLog << err << dbginf << "Cannot find MExtractedSignalCam ... aborting" << endl;
|
|---|
| 261 | return kFALSE;
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | return kTRUE;
|
|---|
| 265 | }
|
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 | // --------------------------------------------------------------------------
|
|---|
| 269 | //
|
|---|
| 270 | // The ReInit searches for the following input containers:
|
|---|
| 271 | // - MRawRunHeader
|
|---|
| 272 | //
|
|---|
| 273 | Bool_t MCalibrationCalc::ReInit(MParList *pList )
|
|---|
| 274 | {
|
|---|
| 275 |
|
|---|
| 276 | fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
|---|
| 277 | if (!fRunHeader)
|
|---|
| 278 | {
|
|---|
| 279 | *fLog << err << dbginf << ": MRawRunHeader not found... aborting." << endl;
|
|---|
| 280 | return kFALSE;
|
|---|
| 281 | }
|
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 | MGeomCam *cam = (MGeomCam*)pList->FindObject("MGeomCam");
|
|---|
| 285 | if (!cam)
|
|---|
| 286 | {
|
|---|
| 287 | *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
|
|---|
| 288 | return kFALSE;
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 | fCalibrations->SetGeomCam(cam);
|
|---|
| 293 |
|
|---|
| 294 | fNumHiGainSamples = fSignals->GetNumUsedHiGainFADCSlices();
|
|---|
| 295 | fNumLoGainSamples = fSignals->GetNumUsedLoGainFADCSlices();
|
|---|
| 296 | fSqrtHiGainSamples = TMath::Sqrt((Float_t)fNumHiGainSamples);
|
|---|
| 297 |
|
|---|
| 298 | UInt_t npixels = cam->GetNumPixels();
|
|---|
| 299 |
|
|---|
| 300 | for (UInt_t i=0; i<npixels; i++)
|
|---|
| 301 | {
|
|---|
| 302 |
|
|---|
| 303 | MCalibrationPix &pix = (*fCalibrations)[i];
|
|---|
| 304 | pix.DefinePixId(i);
|
|---|
| 305 |
|
|---|
| 306 | pix.SetAbsTimeBordersHiGain(fSignals->GetFirstUsedSliceHiGain(),
|
|---|
| 307 | fSignals->GetLastUsedSliceHiGain());
|
|---|
| 308 | pix.SetAbsTimeBordersLoGain(fSignals->GetFirstUsedSliceLoGain(),
|
|---|
| 309 | fSignals->GetLastUsedSliceLoGain());
|
|---|
| 310 |
|
|---|
| 311 | if (!TESTBIT(fFlags,kUseQualityChecks))
|
|---|
| 312 | pix.SetExcludeQualityCheck();
|
|---|
| 313 |
|
|---|
| 314 | // Exclude the blind pixel and the PIN Diode from normal pixel calibration:
|
|---|
| 315 | if (i == fBlindPixelId)
|
|---|
| 316 | pix.SetExcluded();
|
|---|
| 317 |
|
|---|
| 318 | if (i == fPINDiodeId)
|
|---|
| 319 | pix.SetExcluded();
|
|---|
| 320 |
|
|---|
| 321 | }
|
|---|
| 322 |
|
|---|
| 323 | //
|
|---|
| 324 | // Look for file to exclude pixels from analysis
|
|---|
| 325 | //
|
|---|
| 326 | if (!fExcludedPixelsFile.IsNull())
|
|---|
| 327 | {
|
|---|
| 328 |
|
|---|
| 329 | fExcludedPixelsFile = gSystem->ExpandPathName(fExcludedPixelsFile.Data());
|
|---|
| 330 |
|
|---|
| 331 | //
|
|---|
| 332 | // Initialize reading the file
|
|---|
| 333 | //
|
|---|
| 334 | ifstream in(fExcludedPixelsFile.Data(),ios::in);
|
|---|
| 335 |
|
|---|
| 336 | if (in)
|
|---|
| 337 | {
|
|---|
| 338 | *fLog << inf << "Use excluded pixels from file: '" << fExcludedPixelsFile.Data() << "'" << endl;
|
|---|
| 339 | //
|
|---|
| 340 | // Read the file and count the number of entries
|
|---|
| 341 | //
|
|---|
| 342 | UInt_t pixel = 0;
|
|---|
| 343 |
|
|---|
| 344 | while (++fNumExcludedPixels)
|
|---|
| 345 | {
|
|---|
| 346 |
|
|---|
| 347 | in >> pixel;
|
|---|
| 348 |
|
|---|
| 349 | if (!in.good())
|
|---|
| 350 | break;
|
|---|
| 351 | //
|
|---|
| 352 | // Check for out of range
|
|---|
| 353 | //
|
|---|
| 354 | if (pixel > npixels)
|
|---|
| 355 | {
|
|---|
| 356 | *fLog << warn << "WARNING: To be excluded pixel: " << pixel
|
|---|
| 357 | << " is out of range " << endl;
|
|---|
| 358 | continue;
|
|---|
| 359 | }
|
|---|
| 360 | //
|
|---|
| 361 | // Exclude pixel
|
|---|
| 362 | //
|
|---|
| 363 | MCalibrationPix &pix = (*fCalibrations)[pixel];
|
|---|
| 364 | pix.SetExcluded();
|
|---|
| 365 |
|
|---|
| 366 | *fLog << GetDescriptor() << inf << ": Exclude Pixel: " << pixel << endl;
|
|---|
| 367 |
|
|---|
| 368 | }
|
|---|
| 369 |
|
|---|
| 370 | if (--fNumExcludedPixels == 0)
|
|---|
| 371 | *fLog << warn << "WARNING: File '" << fExcludedPixelsFile.Data()
|
|---|
| 372 | << "'" << " is empty " << endl;
|
|---|
| 373 | else
|
|---|
| 374 | fCalibrations->SetNumPixelsExcluded(fNumExcludedPixels);
|
|---|
| 375 |
|
|---|
| 376 | }
|
|---|
| 377 | else
|
|---|
| 378 | *fLog << warn << dbginf << "Cannot open file '" << fExcludedPixelsFile.Data() << "'" << endl;
|
|---|
| 379 | }
|
|---|
| 380 |
|
|---|
| 381 | return kTRUE;
|
|---|
| 382 | }
|
|---|
| 383 |
|
|---|
| 384 |
|
|---|
| 385 | // --------------------------------------------------------------------------
|
|---|
| 386 | //
|
|---|
| 387 | // Calculate the integral of the FADC time slices and store them as a new
|
|---|
| 388 | // pixel in the MCerPhotEvt container.
|
|---|
| 389 | //
|
|---|
| 390 | Int_t MCalibrationCalc::Process()
|
|---|
| 391 | {
|
|---|
| 392 |
|
|---|
| 393 | //
|
|---|
| 394 | // Initialize pointers to blind pixel, PIN Diode and individual pixels
|
|---|
| 395 | //
|
|---|
| 396 | MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
|
|---|
| 397 | MCalibrationPINDiode &pindiode = *(fCalibrations->GetPINDiode());
|
|---|
| 398 |
|
|---|
| 399 | MRawEvtPixelIter pixel(fRawEvt);
|
|---|
| 400 |
|
|---|
| 401 | //
|
|---|
| 402 | // Create a loop to fill the calibration histograms
|
|---|
| 403 | // Search for: a signal in MExtractedSignalCam
|
|---|
| 404 | // Fill histograms with:
|
|---|
| 405 | // charge
|
|---|
| 406 | // charge vs. event nr.
|
|---|
| 407 | //
|
|---|
| 408 | while (pixel.Next())
|
|---|
| 409 | {
|
|---|
| 410 |
|
|---|
| 411 | const UInt_t pixid = pixel.GetPixelId();
|
|---|
| 412 |
|
|---|
| 413 | MCalibrationPix &pix = (*fCalibrations)[pixid];
|
|---|
| 414 |
|
|---|
| 415 | MExtractedSignalPix &sig = (*fSignals)[pixid];
|
|---|
| 416 |
|
|---|
| 417 | const Float_t sumhi = sig.GetExtractedSignalHiGain();
|
|---|
| 418 | const Float_t sumlo = sig.GetExtractedSignalLoGain();
|
|---|
| 419 |
|
|---|
| 420 | Float_t abstime = 0.;
|
|---|
| 421 | #if 0
|
|---|
| 422 | Float_t reltime = 0.;
|
|---|
| 423 |
|
|---|
| 424 | if (TESTBIT(fFlags,kUseTimes))
|
|---|
| 425 | {
|
|---|
| 426 |
|
|---|
| 427 | //
|
|---|
| 428 | // Have a look in MArrivalTime,
|
|---|
| 429 | // otherwise search the position of maximum bin
|
|---|
| 430 | // in MRawEvtData
|
|---|
| 431 | //
|
|---|
| 432 | if (fArrivalTime)
|
|---|
| 433 | {
|
|---|
| 434 | abstime = (*fArrivalTime)[pixid];
|
|---|
| 435 | reltime = abstime - (*fArrivalTime)[1];
|
|---|
| 436 | }
|
|---|
| 437 |
|
|---|
| 438 | else
|
|---|
| 439 | {
|
|---|
| 440 | if (pixid == 1)
|
|---|
| 441 | referencetime = (Float_t)pixel.GetIdxMaxHiGainSample();
|
|---|
| 442 | if (sig.IsLoGainUsed())
|
|---|
| 443 | {
|
|---|
| 444 | abstime = (Float_t)pixel.GetIdxMaxLoGainSample();
|
|---|
| 445 | // reltime = abstime - referencetime;
|
|---|
| 446 | }
|
|---|
| 447 | else
|
|---|
| 448 | {
|
|---|
| 449 | abstime = (Float_t)pixel.GetIdxMaxHiGainSample();
|
|---|
| 450 | // reltime = abstime - referencetime;
|
|---|
| 451 | }
|
|---|
| 452 | // }
|
|---|
| 453 | // } /* if Use Times */
|
|---|
| 454 |
|
|---|
| 455 | #endif
|
|---|
| 456 | switch(pixid)
|
|---|
| 457 | {
|
|---|
| 458 |
|
|---|
| 459 | case fBlindPixelId:
|
|---|
| 460 |
|
|---|
| 461 | if (TESTBIT(fFlags,kUseBlindPixelFit))
|
|---|
| 462 | {
|
|---|
| 463 |
|
|---|
| 464 | Byte_t *ptr = pixel.GetHiGainSamples();
|
|---|
| 465 |
|
|---|
| 466 | Int_t blindpixelsumhi = 0;
|
|---|
| 467 | Int_t blindpixelsumlo = 0;
|
|---|
| 468 | //
|
|---|
| 469 | // We need a dedicated signal extractor for the blind pixel
|
|---|
| 470 | //
|
|---|
| 471 | Int_t diff = 0;
|
|---|
| 472 | Int_t last = fBlindPixelLast;
|
|---|
| 473 | Int_t first = fBlindPixelFirst;
|
|---|
| 474 |
|
|---|
| 475 | if (last > 15)
|
|---|
| 476 | {
|
|---|
| 477 | diff = last - 15;
|
|---|
| 478 | last = 15;
|
|---|
| 479 | }
|
|---|
| 480 |
|
|---|
| 481 | Byte_t *start = ptr + first - 1;
|
|---|
| 482 | Byte_t *end = ptr + last - 1;
|
|---|
| 483 |
|
|---|
| 484 | ptr = start;
|
|---|
| 485 |
|
|---|
| 486 | Int_t sum = 0;
|
|---|
| 487 |
|
|---|
| 488 | while (ptr<=end)
|
|---|
| 489 | {
|
|---|
| 490 | sum += *ptr;
|
|---|
| 491 | ptr++;
|
|---|
| 492 | }
|
|---|
| 493 |
|
|---|
| 494 | if (diff > 0)
|
|---|
| 495 | {
|
|---|
| 496 | ptr = pixel.GetLoGainSamples();
|
|---|
| 497 | end = ptr + diff - 1;
|
|---|
| 498 |
|
|---|
| 499 | while (ptr<=end)
|
|---|
| 500 | {
|
|---|
| 501 | sum += *ptr;
|
|---|
| 502 | ptr++;
|
|---|
| 503 | }
|
|---|
| 504 | }
|
|---|
| 505 |
|
|---|
| 506 | blindpixelsumhi = sum;
|
|---|
| 507 |
|
|---|
| 508 | ptr = pixel.GetLoGainSamples();
|
|---|
| 509 |
|
|---|
| 510 | start = ptr + fBlindPixelFirst - 1;
|
|---|
| 511 | end = ptr + fBlindPixelLast;
|
|---|
| 512 |
|
|---|
| 513 | ptr = start;
|
|---|
| 514 |
|
|---|
| 515 | sum = 0;
|
|---|
| 516 |
|
|---|
| 517 | while (++ptr<end)
|
|---|
| 518 | sum += *ptr;
|
|---|
| 519 |
|
|---|
| 520 | blindpixelsumlo = sum;
|
|---|
| 521 |
|
|---|
| 522 | // if (!CalcSignalBlindPixel(hiptr, blindpixelsumhi))
|
|---|
| 523 | // return kFALSE;
|
|---|
| 524 |
|
|---|
| 525 | if (!blindpixel.FillCharge(blindpixelsumhi))
|
|---|
| 526 | *fLog << warn <<
|
|---|
| 527 | "Overflow or Underflow occurred filling Blind Pixel sum = " << blindpixelsumhi << endl;
|
|---|
| 528 |
|
|---|
| 529 | // Byte_t *loptr = pixel.GetLoGainSamples();
|
|---|
| 530 | // CalcSignalBlindPixel(loptr, blindpixelsumlo);
|
|---|
| 531 |
|
|---|
| 532 | blindpixel.FillGraphs(blindpixelsumhi,blindpixelsumlo);
|
|---|
| 533 |
|
|---|
| 534 | TH1I *hist;
|
|---|
| 535 |
|
|---|
| 536 | if (blindpixelsumhi > fBlindPixelSinglePheCut)
|
|---|
| 537 | {
|
|---|
| 538 | hist = (blindpixel.GetHist())->GetHSinglePheFADCSlices();
|
|---|
| 539 | fNumBlindPixelSinglePhe++;
|
|---|
| 540 | }
|
|---|
| 541 | else
|
|---|
| 542 | {
|
|---|
| 543 | hist = (blindpixel.GetHist())->GetHPedestalFADCSlices();
|
|---|
| 544 | fNumBlindPixelPedestal++;
|
|---|
| 545 | }
|
|---|
| 546 |
|
|---|
| 547 | ptr = pixel.GetHiGainSamples();
|
|---|
| 548 | for (Int_t i=1;i<16;i++)
|
|---|
| 549 | hist->Fill(i,*ptr++);
|
|---|
| 550 |
|
|---|
| 551 | ptr = pixel.GetLoGainSamples();
|
|---|
| 552 | for (Int_t i=16;i<31;i++)
|
|---|
| 553 | hist->Fill(i,*ptr++);
|
|---|
| 554 |
|
|---|
| 555 | } /* if use blind pixel */
|
|---|
| 556 |
|
|---|
| 557 | break;
|
|---|
| 558 | case fPINDiodeId:
|
|---|
| 559 |
|
|---|
| 560 | if (TESTBIT(fFlags,kUsePinDiodeFit))
|
|---|
| 561 | {
|
|---|
| 562 |
|
|---|
| 563 | if (!pindiode.FillCharge(sumhi))
|
|---|
| 564 | *fLog << warn
|
|---|
| 565 | << "Overflow or Underflow occurred filling PINDiode: sum = "
|
|---|
| 566 | << sumhi << endl;
|
|---|
| 567 |
|
|---|
| 568 | if (!pindiode.FillAbsTime(abstime))
|
|---|
| 569 | *fLog << warn
|
|---|
| 570 | << "Overflow or Underflow occurred filling PINDiode abs. time = "
|
|---|
| 571 | << abstime << endl;
|
|---|
| 572 |
|
|---|
| 573 | if (!pindiode.FillGraphs(sumhi,sumlo))
|
|---|
| 574 | *fLog << warn
|
|---|
| 575 | << "Overflow or Underflow occurred filling PINDiode: eventnr = " << endl;
|
|---|
| 576 |
|
|---|
| 577 | } /* if use PIN Diode */
|
|---|
| 578 |
|
|---|
| 579 | // break;
|
|---|
| 580 |
|
|---|
| 581 | default:
|
|---|
| 582 |
|
|---|
| 583 | if (pix.IsExcluded())
|
|---|
| 584 | continue;
|
|---|
| 585 |
|
|---|
| 586 | pix.FillGraphs(sumhi,sumlo);
|
|---|
| 587 |
|
|---|
| 588 | if (sig.IsLoGainUsed())
|
|---|
| 589 | {
|
|---|
| 590 |
|
|---|
| 591 | if (!pix.FillChargeLoGain(sumlo))
|
|---|
| 592 | *fLog << warn << "Could not fill Lo Gain Charge of pixel: " << pixid
|
|---|
| 593 | << " signal = " << sumlo << endl;
|
|---|
| 594 |
|
|---|
| 595 | if (!pix.FillAbsTimeLoGain(abstime))
|
|---|
| 596 | *fLog << warn << "Could not fill Lo Gain Abs. Time of pixel: "
|
|---|
| 597 | << pixid << " time = " << abstime << endl;
|
|---|
| 598 | /*
|
|---|
| 599 | if (!pix.FillRelTimeLoGain(reltime))
|
|---|
| 600 | *fLog << warn << "Could not fill Lo Gain Rel. Time of pixel: "
|
|---|
| 601 | << pixid << " time = " << reltime << endl;
|
|---|
| 602 | */
|
|---|
| 603 | } /* if (sig.IsLoGainUsed()) */
|
|---|
| 604 | else
|
|---|
| 605 | {
|
|---|
| 606 | if (!pix.FillChargeHiGain(sumhi))
|
|---|
| 607 | *fLog << warn << "Could not fill Hi Gain Charge of pixel: " << pixid
|
|---|
| 608 | << " signal = " << sumhi << endl;
|
|---|
| 609 |
|
|---|
| 610 | if (!pix.FillAbsTimeHiGain(abstime))
|
|---|
| 611 | *fLog << warn << "Could not fill Hi Gain Abs. Time of pixel: "
|
|---|
| 612 | << pixid << " time = " << abstime << endl;
|
|---|
| 613 | /*
|
|---|
| 614 | if (!pix.FillRelTimeHiGain(reltime))
|
|---|
| 615 | *fLog << warn << "Could not fill Hi Gain Rel. Time of pixel: "
|
|---|
| 616 | << pixid << " time = " << reltime << endl;
|
|---|
| 617 | */
|
|---|
| 618 | } /* else (sig.IsLoGainUsed()) */
|
|---|
| 619 | break;
|
|---|
| 620 |
|
|---|
| 621 | } /* switch(pixid) */
|
|---|
| 622 |
|
|---|
| 623 | } /* while (pixel.Next()) */
|
|---|
| 624 |
|
|---|
| 625 | return kTRUE;
|
|---|
| 626 | }
|
|---|
| 627 |
|
|---|
| 628 | Int_t MCalibrationCalc::PostProcess()
|
|---|
| 629 | {
|
|---|
| 630 |
|
|---|
| 631 | *fLog << inf << endl;
|
|---|
| 632 |
|
|---|
| 633 | *fLog << inf << GetDescriptor() << ": Cut Histogram Edges" << endl;
|
|---|
| 634 |
|
|---|
| 635 | //
|
|---|
| 636 | // Cut edges to make fits and viewing of the hists easier
|
|---|
| 637 | //
|
|---|
| 638 | fCalibrations->CutEdges();
|
|---|
| 639 |
|
|---|
| 640 | //
|
|---|
| 641 | // Fit the blind pixel
|
|---|
| 642 | //
|
|---|
| 643 | if (TESTBIT(fFlags,kUseBlindPixelFit))
|
|---|
| 644 | {
|
|---|
| 645 | //
|
|---|
| 646 | // Get pointer to blind pixel
|
|---|
| 647 | //
|
|---|
| 648 | MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
|
|---|
| 649 |
|
|---|
| 650 | *fLog << inf << GetDescriptor() << ": Fitting the Blind Pixel" << endl;
|
|---|
| 651 |
|
|---|
| 652 | //
|
|---|
| 653 | // retrieve mean and sigma of the blind pixel pedestal,
|
|---|
| 654 | // so that we can use it for the fit
|
|---|
| 655 | //
|
|---|
| 656 | Float_t pedestal;
|
|---|
| 657 | Float_t pederr;
|
|---|
| 658 | Float_t pedsigma;
|
|---|
| 659 | Float_t pedsigmaerr;
|
|---|
| 660 |
|
|---|
| 661 | const ULong_t nentries = fPedestals->GetTotalEntries();
|
|---|
| 662 | const Int_t nslices = fBlindPixelLast-fBlindPixelFirst+1;
|
|---|
| 663 | const Float_t sqrslice = TMath::Sqrt((Float_t)nslices);
|
|---|
| 664 | //
|
|---|
| 665 | // retrieve the pedestal pix of the blind pixel
|
|---|
| 666 | //
|
|---|
| 667 | if (fPedestals->GetHistSize() > fBlindPixelId)
|
|---|
| 668 | {
|
|---|
| 669 | MHPedestalPixel &pedhist = (*fPedestals)(fBlindPixelId);
|
|---|
| 670 | pedestal = pedhist.GetChargeMean()*nslices;
|
|---|
| 671 | pederr = pedhist.GetChargeMeanErr()*nslices;
|
|---|
| 672 | //
|
|---|
| 673 | // Fitted sigma: 1. one sqrt(Nr. slices) for the division which is not
|
|---|
| 674 | // not appropriate: sigma(real)/slice = GetSigma*sqrt(nslices)
|
|---|
| 675 | // 2. another sqrt(Nr. slices) to calculate back to number
|
|---|
| 676 | // of slices
|
|---|
| 677 | //
|
|---|
| 678 | pedsigma = pedhist.GetChargeSigma()*nslices;
|
|---|
| 679 | pedsigmaerr = pedhist.GetChargeSigmaErr()*nslices;
|
|---|
| 680 | }
|
|---|
| 681 | else
|
|---|
| 682 | {
|
|---|
| 683 | MPedestalPix &pedpix = (*fPedestals)[fBlindPixelId];
|
|---|
| 684 | pedestal = pedpix.GetPedestal()*nslices;
|
|---|
| 685 | pederr = pedpix.GetPedestalRms()*nslices/nentries;
|
|---|
| 686 | pedsigma = pedpix.GetPedestalRms()*sqrslice;
|
|---|
| 687 | pedsigmaerr = pederr/2.;
|
|---|
| 688 | }
|
|---|
| 689 | //
|
|---|
| 690 | // retrieve the histogram containers
|
|---|
| 691 | //
|
|---|
| 692 | MHCalibrationBlindPixel *hist = blindpixel.GetHist();
|
|---|
| 693 |
|
|---|
| 694 | hist->SetMeanPedestal(pedestal);
|
|---|
| 695 | hist->SetMeanPedestalErr(pederr);
|
|---|
| 696 | hist->SetSigmaPedestal(pedsigma);
|
|---|
| 697 | hist->SetSigmaPedestalErr(pedsigmaerr);
|
|---|
| 698 |
|
|---|
| 699 | if (!blindpixel.FitCharge())
|
|---|
| 700 | {
|
|---|
| 701 | *fLog << warn << "Could not fit the blind pixel! " << endl;
|
|---|
| 702 | *fLog << warn << "Setting bit kBlindPixelMethodValid to FALSE in MCalibrationCam" << endl;
|
|---|
| 703 | fCalibrations->SetBlindPixelMethodValid(kFALSE);
|
|---|
| 704 | }
|
|---|
| 705 | else
|
|---|
| 706 | fCalibrations->SetBlindPixelMethodValid(kTRUE);
|
|---|
| 707 |
|
|---|
| 708 | if (blindpixel.CheckOscillations())
|
|---|
| 709 | fCalibrations->SetBlindPixelMethodValid(kFALSE);
|
|---|
| 710 |
|
|---|
| 711 | TH1I *sphehist = hist->GetHSinglePheFADCSlices();
|
|---|
| 712 | TH1I *pedhist = hist->GetHPedestalFADCSlices();
|
|---|
| 713 |
|
|---|
| 714 | if (fNumBlindPixelSinglePhe > 1)
|
|---|
| 715 | sphehist->Scale(1./fNumBlindPixelSinglePhe);
|
|---|
| 716 | if (fNumBlindPixelPedestal > 1)
|
|---|
| 717 | pedhist->Scale(1./fNumBlindPixelPedestal);
|
|---|
| 718 |
|
|---|
| 719 | blindpixel.DrawClone();
|
|---|
| 720 | }
|
|---|
| 721 | else
|
|---|
| 722 | *fLog << inf << GetDescriptor() << ": Skipping Blind Pixel Fit " << endl;
|
|---|
| 723 |
|
|---|
| 724 | *fLog << err << "total: " << GetNumExecutions() << " sphe: " << fNumBlindPixelSinglePhe << " ped: " << fNumBlindPixelPedestal << endl;
|
|---|
| 725 |
|
|---|
| 726 |
|
|---|
| 727 | *fLog << inf << GetDescriptor() << ": Fitting the Normal Pixels" << endl;
|
|---|
| 728 |
|
|---|
| 729 | //
|
|---|
| 730 | // loop over the pedestal events and check if we have calibration
|
|---|
| 731 | //
|
|---|
| 732 | for (Int_t pixid=0; pixid<fPedestals->GetSize(); pixid++)
|
|---|
| 733 | {
|
|---|
| 734 |
|
|---|
| 735 | MCalibrationPix &pix = (*fCalibrations)[pixid];
|
|---|
| 736 |
|
|---|
| 737 | //
|
|---|
| 738 | // Check if the pixel has been excluded from the fits
|
|---|
| 739 | //
|
|---|
| 740 | if (pix.IsExcluded())
|
|---|
| 741 | continue;
|
|---|
| 742 |
|
|---|
| 743 | //
|
|---|
| 744 | // get the pedestals
|
|---|
| 745 | //
|
|---|
| 746 | const Float_t ped = (*fPedestals)[pixid].GetPedestal();
|
|---|
| 747 | const Float_t prms = (*fPedestals)[pixid].GetPedestalRms();
|
|---|
| 748 |
|
|---|
| 749 | //
|
|---|
| 750 | // set them in the calibration camera
|
|---|
| 751 | //
|
|---|
| 752 | pix.SetPedestal(ped,prms,(Float_t)fNumHiGainSamples,(Float_t)fNumLoGainSamples);
|
|---|
| 753 |
|
|---|
| 754 | //
|
|---|
| 755 | // perform the Gauss fits to the charges
|
|---|
| 756 | //
|
|---|
| 757 | pix.FitCharge();
|
|---|
| 758 |
|
|---|
| 759 | //
|
|---|
| 760 | // check also for oscillations
|
|---|
| 761 | //
|
|---|
| 762 | pix.CheckOscillations();
|
|---|
| 763 |
|
|---|
| 764 | }
|
|---|
| 765 |
|
|---|
| 766 | if (TESTBIT(fFlags,kUseBlindPixelFit) && fCalibrations->IsBlindPixelMethodValid())
|
|---|
| 767 | {
|
|---|
| 768 | if (!fCalibrations->CalcFluxInsidePlexiglass())
|
|---|
| 769 | {
|
|---|
| 770 | *fLog << err
|
|---|
| 771 | << "Could not calculate the number of photons from the blind pixel " << endl;
|
|---|
| 772 | *fLog << err
|
|---|
| 773 | << "You can try to calibrate using the MCalibrationCalc::SkipBlindPixelFit()" << endl;
|
|---|
| 774 | fCalibrations->SetBlindPixelMethodValid(kFALSE);
|
|---|
| 775 | }
|
|---|
| 776 | }
|
|---|
| 777 | else
|
|---|
| 778 | *fLog << inf << GetDescriptor() << ": Skipping Blind Pixel Calibration! " << endl;
|
|---|
| 779 |
|
|---|
| 780 |
|
|---|
| 781 | if (TESTBIT(fFlags,kUsePinDiodeFit) && fCalibrations->IsPINDiodeMethodValid())
|
|---|
| 782 | {
|
|---|
| 783 | if (!fCalibrations->CalcFluxOutsidePlexiglass())
|
|---|
| 784 | {
|
|---|
| 785 | *fLog << err
|
|---|
| 786 | << "Could not calculate the number of photons from the blind pixel " << endl;
|
|---|
| 787 | *fLog << err
|
|---|
| 788 | << "You can try to calibrate using the MCalibrationCalc::SkipPINDiodeFit()" << endl;
|
|---|
| 789 | fCalibrations->SetPINDiodeMethodValid(kFALSE);
|
|---|
| 790 | }
|
|---|
| 791 | }
|
|---|
| 792 | else
|
|---|
| 793 | *fLog << inf << GetDescriptor() << ": Skipping PIN Diode Calibration! " << endl;
|
|---|
| 794 |
|
|---|
| 795 | fCalibrations->SetReadyToSave();
|
|---|
| 796 |
|
|---|
| 797 | return kTRUE;
|
|---|
| 798 | }
|
|---|
| 799 |
|
|---|
| 800 |
|
|---|
| 801 | Bool_t MCalibrationCalc::CalcSignalBlindPixel(Byte_t *ptr, Float_t &signal) const
|
|---|
| 802 | {
|
|---|
| 803 |
|
|---|
| 804 | Byte_t *newptr = ptr;
|
|---|
| 805 | Byte_t *start = ptr + fBlindPixelFirst-1;
|
|---|
| 806 | Byte_t *end = ptr + fBlindPixelLast;
|
|---|
| 807 |
|
|---|
| 808 | Byte_t sum = 0;
|
|---|
| 809 | Int_t sat = 0;
|
|---|
| 810 |
|
|---|
| 811 | newptr = start;
|
|---|
| 812 |
|
|---|
| 813 | while (ptr<end)
|
|---|
| 814 | {
|
|---|
| 815 | sum += *ptr;
|
|---|
| 816 | if (*ptr++ >= fgSaturationLimit)
|
|---|
| 817 | sat++;
|
|---|
| 818 | }
|
|---|
| 819 |
|
|---|
| 820 | if (sat)
|
|---|
| 821 | {
|
|---|
| 822 | *fLog << err << "HI Gain Saturation occurred in the blind pixel! "
|
|---|
| 823 | << " Do not know yet how to treat this ... aborting " << endl;
|
|---|
| 824 | *fLog << err << "If you need absolutely any other kind of calibration, "
|
|---|
| 825 | << " use SkipBlindPixelFit() " << endl;
|
|---|
| 826 | return kFALSE;
|
|---|
| 827 | }
|
|---|
| 828 |
|
|---|
| 829 | signal = (Float_t)sum;
|
|---|
| 830 |
|
|---|
| 831 | return kTRUE;
|
|---|
| 832 | }
|
|---|