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