| 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): Javier Lopez 12/2003 <mailto:jlopez@ifae.es>
|
|---|
| 19 | ! Author(s): Javier Rico 01/2004 <mailto:jrico@ifae.es>
|
|---|
| 20 | ! Author(s): Wolfgang Wittek 02/2004 <mailto:wittek@mppmu.mpg.de>
|
|---|
| 21 | ! Author(s): Markus Gaug 04/2004 <mailto:markus@ifae.es>
|
|---|
| 22 | ! Author(s): Hendrik Bartko 08/2004 <mailto:hbartko@mppmu.mpg.de>
|
|---|
| 23 | ! Author(s): Thomas Bretz 08/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 24 | !
|
|---|
| 25 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 26 | !
|
|---|
| 27 | !
|
|---|
| 28 | \* ======================================================================== */
|
|---|
| 29 |
|
|---|
| 30 | ///////////////////////////////////////////////////////////////////////////////////
|
|---|
| 31 | //
|
|---|
| 32 | // MCalibrateData
|
|---|
| 33 | //
|
|---|
| 34 | // This task takes the integrated charge from MExtractedSignal and applies
|
|---|
| 35 | // the calibration constants from MCalibrationCam to convert the summed FADC
|
|---|
| 36 | // slices into photons. The number of photons obtained is stored in MCerPhotEvt.
|
|---|
| 37 | // Optionally, the calibration of pedestals from an MPedestalCam container into
|
|---|
| 38 | // an MPedPhotCam container can be chosen with the member functions
|
|---|
| 39 | // SetPedestalType(). Default is 'kRun', i.e. calibration of pedestals from a
|
|---|
| 40 | // dedicated pedestal run.
|
|---|
| 41 | // In case, the chosen pedestal type is kRun or kEvent, in ReInit() the MPedPhotCam
|
|---|
| 42 | // container is filled using the information from MPedestalCam, MExtractedSignalCam,
|
|---|
| 43 | // MCalibrationChargeCam and MCalibrationQECam
|
|---|
| 44 | //
|
|---|
| 45 | // Selection of different calibration methods is allowed through the
|
|---|
| 46 | // SetCalibrationMode() member function (default: kFfactor)
|
|---|
| 47 | //
|
|---|
| 48 | // The calibration modes which exclude non-valid pixels are the following:
|
|---|
| 49 | //
|
|---|
| 50 | // kFfactor: calibrates using the F-Factor method
|
|---|
| 51 | // kBlindpixel: calibrates using the BlindPixel method
|
|---|
| 52 | // kBlindpixel: calibrates using the BlindPixel method
|
|---|
| 53 | // kFlatCharge: perform a charge flat-flatfielding. Outer pixels are area-corrected.
|
|---|
| 54 | // kDummy: calibrates with fixed conversion factors of 1 and errors of 0.
|
|---|
| 55 | //
|
|---|
| 56 | // The calibration modes which include all pixels regardless of their validity is:
|
|---|
| 57 | //
|
|---|
| 58 | // kNone: calibrates with fixed conversion factors of 1 and errors of 0.
|
|---|
| 59 | //
|
|---|
| 60 | // Use the kDummy and kNone methods ONLY FOR DEBUGGING!
|
|---|
| 61 | //
|
|---|
| 62 | //
|
|---|
| 63 | // This class can calibrate data and/or pedestals. To switch off calibration of data
|
|---|
| 64 | // set the Calibration Mode to kSkip. To switch on pedestal calibration call either
|
|---|
| 65 | // SetPedestalFlag(MCalibrateData::kRun) (calibration is done once in ReInit)
|
|---|
| 66 | // SetPedestalFlag(MCalibrateData::kEvent) (calibration is done for each event)
|
|---|
| 67 | //
|
|---|
| 68 | // By calling AddPedestal() you can control the name of the
|
|---|
| 69 | // MPedestalCam and/or MPedPhotCam container which is used.
|
|---|
| 70 | //
|
|---|
| 71 | // Assume you want to calibrate "MPedestalCam" once and "MPedestalFromLoGain" [MPedestalCam]
|
|---|
| 72 | // event-by-event, so:
|
|---|
| 73 | // MCalibrateData cal1;
|
|---|
| 74 | // cal1.SetCalibrationMode(MCalibrateData::kSkip);
|
|---|
| 75 | // cal1.SetPedestalFlag(MCalibrateData::kRun);
|
|---|
| 76 | // MCalibrateData cal2;
|
|---|
| 77 | // cal2.SetCalibrationMode(MCalibrateData::kSkip);
|
|---|
| 78 | // cal2.AddPedestal("FromLoGain");
|
|---|
| 79 | // cal2.SetPedestalFlag(MCalibrateData::kEvent);
|
|---|
| 80 | //
|
|---|
| 81 | //
|
|---|
| 82 | // Input Containers:
|
|---|
| 83 | // [MPedestalCam]
|
|---|
| 84 | // [MExtractedSignalCam]
|
|---|
| 85 | // [MCalibrationChargeCam]
|
|---|
| 86 | // [MCalibrationQECam]
|
|---|
| 87 | // MBadPixelsCam
|
|---|
| 88 | //
|
|---|
| 89 | // Output Containers:
|
|---|
| 90 | // [MPedPhotCam]
|
|---|
| 91 | // [MCerPhotEvt]
|
|---|
| 92 | //
|
|---|
| 93 | // See also: MJCalibration, MJPedestal, MJExtractSignal, MJExtractCalibTest
|
|---|
| 94 | //
|
|---|
| 95 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 96 | #include "MCalibrateData.h"
|
|---|
| 97 |
|
|---|
| 98 | #include <fstream>
|
|---|
| 99 |
|
|---|
| 100 | #include <TEnv.h>
|
|---|
| 101 |
|
|---|
| 102 | #include "MLog.h"
|
|---|
| 103 | #include "MLogManip.h"
|
|---|
| 104 |
|
|---|
| 105 | #include "MParList.h"
|
|---|
| 106 | #include "MH.h"
|
|---|
| 107 |
|
|---|
| 108 | #include "MGeomCam.h"
|
|---|
| 109 |
|
|---|
| 110 | #include "MPedestalCam.h"
|
|---|
| 111 | #include "MPedestalPix.h"
|
|---|
| 112 |
|
|---|
| 113 | #include "MCalibrationChargeCam.h"
|
|---|
| 114 | #include "MCalibrationChargePix.h"
|
|---|
| 115 |
|
|---|
| 116 | #include "MCalibrationQECam.h"
|
|---|
| 117 | #include "MCalibrationQEPix.h"
|
|---|
| 118 |
|
|---|
| 119 | #include "MExtractedSignalCam.h"
|
|---|
| 120 | #include "MExtractedSignalPix.h"
|
|---|
| 121 |
|
|---|
| 122 | #include "MPedPhotCam.h"
|
|---|
| 123 | #include "MPedPhotPix.h"
|
|---|
| 124 |
|
|---|
| 125 | #include "MBadPixelsCam.h"
|
|---|
| 126 | #include "MBadPixelsPix.h"
|
|---|
| 127 |
|
|---|
| 128 | #include "MCerPhotEvt.h"
|
|---|
| 129 |
|
|---|
| 130 | ClassImp(MCalibrateData);
|
|---|
| 131 |
|
|---|
| 132 | using namespace std;
|
|---|
| 133 |
|
|---|
| 134 | // --------------------------------------------------------------------------
|
|---|
| 135 | //
|
|---|
| 136 | // Default constructor.
|
|---|
| 137 | //
|
|---|
| 138 | // Sets all pointers to NULL
|
|---|
| 139 | //
|
|---|
| 140 | // Initializes:
|
|---|
| 141 | // - fCalibrationMode to kDefault
|
|---|
| 142 | // - fPedestalFlag to kNo
|
|---|
| 143 | //
|
|---|
| 144 | MCalibrateData::MCalibrateData(CalibrationMode_t calmode,const char *name, const char *title)
|
|---|
| 145 | : fGeomCam(NULL), fBadPixels(NULL), fCalibrations(NULL),
|
|---|
| 146 | fQEs(NULL), fSignals(NULL), fCerPhotEvt(NULL), fPedestalFlag(kNo)
|
|---|
| 147 | {
|
|---|
| 148 |
|
|---|
| 149 | fName = name ? name : "MCalibrateData";
|
|---|
| 150 | fTitle = title ? title : "Task to calculate the number of photons in one event";
|
|---|
| 151 |
|
|---|
| 152 | SetCalibrationMode(calmode);
|
|---|
| 153 |
|
|---|
| 154 | fNamesPedestal.SetOwner();
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | void MCalibrateData::AddPedestal(const char *name)
|
|---|
| 158 | {
|
|---|
| 159 | TString ped(name);
|
|---|
| 160 | TString pho(name);
|
|---|
| 161 | ped.Prepend("MPedestal");
|
|---|
| 162 | pho.Prepend("MPedPhot");
|
|---|
| 163 |
|
|---|
| 164 | fNamesPedestal.Add(new TNamed(ped, pho));
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | void MCalibrateData::AddPedestal(const char *pedestal, const char *pedphot)
|
|---|
| 168 | {
|
|---|
| 169 | fNamesPedestal.Add(new TNamed(pedestal, pedphot));
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | // --------------------------------------------------------------------------
|
|---|
| 173 | //
|
|---|
| 174 | // The PreProcess searches for the following input containers:
|
|---|
| 175 | //
|
|---|
| 176 | // - MGeomCam
|
|---|
| 177 | // - MPedestalCam
|
|---|
| 178 | // - MCalibrationChargeCam
|
|---|
| 179 | // - MCalibrationQECam
|
|---|
| 180 | // - MExtractedSignalCam
|
|---|
| 181 | // - MBadPixelsCam
|
|---|
| 182 | //
|
|---|
| 183 | // The following output containers are also searched and created if
|
|---|
| 184 | // they were not found:
|
|---|
| 185 | //
|
|---|
| 186 | // - MPedPhotCam
|
|---|
| 187 | // - MCerPhotEvt
|
|---|
| 188 | //
|
|---|
| 189 | Int_t MCalibrateData::PreProcess(MParList *pList)
|
|---|
| 190 | {
|
|---|
| 191 | // input containers
|
|---|
| 192 |
|
|---|
| 193 | fBadPixels = (MBadPixelsCam*)pList->FindObject(AddSerialNumber("MBadPixelsCam"));
|
|---|
| 194 | if (!fBadPixels)
|
|---|
| 195 | {
|
|---|
| 196 | *fLog << err << AddSerialNumber("MBadPixelsCam") << " not found ... aborting" << endl;
|
|---|
| 197 | return kFALSE;
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | fSignals = 0;
|
|---|
| 201 | fCerPhotEvt = 0;
|
|---|
| 202 | if (fCalibrationMode>kSkip)
|
|---|
| 203 | {
|
|---|
| 204 | fSignals = (MExtractedSignalCam*)pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
|
|---|
| 205 | if (!fSignals)
|
|---|
| 206 | {
|
|---|
| 207 | *fLog << err << AddSerialNumber("MExtractedSignalCam") << " not found ... aborting" << endl;
|
|---|
| 208 | return kFALSE;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj(AddSerialNumber("MCerPhotEvt"));
|
|---|
| 212 | if (!fCerPhotEvt)
|
|---|
| 213 | return kFALSE;
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | fCalibrations = 0;
|
|---|
| 217 | fQEs = 0;
|
|---|
| 218 | if (fCalibrationMode>kNone)
|
|---|
| 219 | {
|
|---|
| 220 | fCalibrations = (MCalibrationChargeCam*)pList->FindObject(AddSerialNumber("MCalibrationChargeCam"));
|
|---|
| 221 | if (!fCalibrations)
|
|---|
| 222 | {
|
|---|
| 223 | *fLog << err << AddSerialNumber("MCalibrationChargeCam") << " not found ... aborting." << endl;
|
|---|
| 224 | return kFALSE;
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | fQEs = (MCalibrationQECam*)pList->FindObject(AddSerialNumber("MCalibrationQECam"));
|
|---|
| 228 | if (!fQEs)
|
|---|
| 229 | {
|
|---|
| 230 | *fLog << err << AddSerialNumber("MCalibrationQECam") << " not found ... aborting." << endl;
|
|---|
| 231 | return kFALSE;
|
|---|
| 232 | }
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | if (fNamesPedestal.GetSize()>0 && fPedestalFlag==kNo)
|
|---|
| 236 | {
|
|---|
| 237 | *fLog << warn << "Pedestal list contains entries, but mode is set to kNo... setting to kEvent." << endl;
|
|---|
| 238 | fPedestalFlag = kEvent;
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | if (fPedestalFlag)
|
|---|
| 242 | {
|
|---|
| 243 | if (fNamesPedestal.GetSize()==0)
|
|---|
| 244 | {
|
|---|
| 245 | *fLog << inf << "No container names specified... using default: MPedestalCam and MPedPhotCam." << endl;
|
|---|
| 246 | AddPedestal();
|
|---|
| 247 | }
|
|---|
| 248 |
|
|---|
| 249 | fPedestalCams.Clear();
|
|---|
| 250 | fPedPhotCams.Clear();
|
|---|
| 251 |
|
|---|
| 252 | TIter Next(&fNamesPedestal);
|
|---|
| 253 | TObject *o=0;
|
|---|
| 254 | while ((o=Next()))
|
|---|
| 255 | {
|
|---|
| 256 | TObject *pedcam = pList->FindObject(AddSerialNumber(o->GetName()), "MPedestalCam");
|
|---|
| 257 | if (!pedcam)
|
|---|
| 258 | {
|
|---|
| 259 | *fLog << err << AddSerialNumber(o->GetName()) << " [MPedestalCam] not found ... aborting" << endl;
|
|---|
| 260 | return kFALSE;
|
|---|
| 261 | }
|
|---|
| 262 | TObject *pedphot = pList->FindCreateObj("MPedPhotCam", AddSerialNumber(o->GetTitle()));
|
|---|
| 263 | if (!pedphot)
|
|---|
| 264 | return kFALSE;
|
|---|
| 265 |
|
|---|
| 266 | fPedestalCams.Add(pedcam);
|
|---|
| 267 | fPedPhotCams.Add(pedphot);
|
|---|
| 268 | }
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 | return kTRUE;
|
|---|
| 272 | }
|
|---|
| 273 |
|
|---|
| 274 | // --------------------------------------------------------------------------
|
|---|
| 275 | //
|
|---|
| 276 | // The ReInit searches for the following input containers:
|
|---|
| 277 | //
|
|---|
| 278 | // - MGeomCam
|
|---|
| 279 | //
|
|---|
| 280 | // Check for validity of the selected calibration method, switch to a
|
|---|
| 281 | // different one in case of need
|
|---|
| 282 | //
|
|---|
| 283 | // Fill the MPedPhotCam container using the information from MPedestalCam,
|
|---|
| 284 | // MExtractedSignalCam and MCalibrationCam
|
|---|
| 285 | //
|
|---|
| 286 | Bool_t MCalibrateData::ReInit(MParList *pList)
|
|---|
| 287 | {
|
|---|
| 288 | fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
|
|---|
| 289 | if (!fGeomCam)
|
|---|
| 290 | {
|
|---|
| 291 | *fLog << err << "No MGeomCam found... aborting." << endl;
|
|---|
| 292 | return kFALSE;
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | // Sizes might have changed
|
|---|
| 296 | if (fPedestalFlag)
|
|---|
| 297 | {
|
|---|
| 298 | TIter Next(&fPedestalCams);
|
|---|
| 299 | MPedestalCam *cam=0;
|
|---|
| 300 | while ((cam=(MPedestalCam*)Next()))
|
|---|
| 301 | if ((Int_t)cam->GetSize() != fSignals->GetSize())
|
|---|
| 302 | {
|
|---|
| 303 | *fLog << err << "Size mismatch of " << cam->GetDescriptor() << " and MCalibrationCam... abort." << endl;
|
|---|
| 304 | return kFALSE;
|
|---|
| 305 | }
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | if(fCalibrationMode == kBlindPixel && !fQEs->IsBlindPixelMethodValid())
|
|---|
| 309 | {
|
|---|
| 310 | *fLog << warn << "Blind pixel calibration method not valid, switching to F-factor method" << endl;
|
|---|
| 311 | fCalibrationMode = kFfactor;
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 | if(fCalibrationMode == kPinDiode && !fQEs->IsPINDiodeMethodValid())
|
|---|
| 315 | {
|
|---|
| 316 | *fLog << warn << "PIN diode calibration method not valid, switching to F-factor method" << endl;
|
|---|
| 317 | fCalibrationMode = kFfactor;
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 | if(fCalibrationMode == kCombined && !fQEs->IsCombinedMethodValid())
|
|---|
| 321 | {
|
|---|
| 322 | *fLog << warn << "Combined calibration method not valid, switching to F-factor method" << endl;
|
|---|
| 323 | fCalibrationMode = kFfactor;
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | //
|
|---|
| 327 | // output information or warnings:
|
|---|
| 328 | //
|
|---|
| 329 | switch(fCalibrationMode)
|
|---|
| 330 | {
|
|---|
| 331 | case kBlindPixel:
|
|---|
| 332 | break;
|
|---|
| 333 | case kFfactor:
|
|---|
| 334 | break;
|
|---|
| 335 | case kPinDiode:
|
|---|
| 336 | *fLog << err << "PIN Diode Calibration mode not yet available!" << endl;
|
|---|
| 337 | return kFALSE;
|
|---|
| 338 | break;
|
|---|
| 339 | case kCombined:
|
|---|
| 340 | *fLog << err << "Combined Calibration mode not yet available!" << endl;
|
|---|
| 341 | return kFALSE;
|
|---|
| 342 | break;
|
|---|
| 343 | case kFlatCharge:
|
|---|
| 344 | *fLog << warn << "WARNING - Flat-fielding charges - only for muon calibration!" << endl;
|
|---|
| 345 | break;
|
|---|
| 346 | case kDummy:
|
|---|
| 347 | *fLog << warn << "WARNING - Dummy calibration, no calibration applied!" << endl;
|
|---|
| 348 | break;
|
|---|
| 349 | case kNone:
|
|---|
| 350 | *fLog << warn << "WARNING - No calibration applied!" << endl;
|
|---|
| 351 | break;
|
|---|
| 352 | default:
|
|---|
| 353 | *fLog << warn << "WARNING - Calibration mode value (" << fCalibrationMode << ") not known" << endl;
|
|---|
| 354 | return kFALSE;
|
|---|
| 355 | }
|
|---|
| 356 |
|
|---|
| 357 | if (TestPedestalFlag(kRun))
|
|---|
| 358 | Calibrate(kFALSE, kTRUE);
|
|---|
| 359 |
|
|---|
| 360 | return kTRUE;
|
|---|
| 361 | }
|
|---|
| 362 |
|
|---|
| 363 | // --------------------------------------------------------------------------
|
|---|
| 364 | //
|
|---|
| 365 | // Get conversion factor and its error from MCalibrationCam
|
|---|
| 366 | //
|
|---|
| 367 | Bool_t MCalibrateData::GetConversionFactor(UInt_t pixidx, Float_t &hiloconv, Float_t &hiloconverr,
|
|---|
| 368 | Float_t &calibConv, Float_t &calibConvVar,
|
|---|
| 369 | Float_t &calibFFactor) const
|
|---|
| 370 | {
|
|---|
| 371 | //
|
|---|
| 372 | // For the moment, we use only a dummy zenith for the calibration:
|
|---|
| 373 | //
|
|---|
| 374 | const Float_t zenith = -1.;
|
|---|
| 375 |
|
|---|
| 376 | hiloconv = 1.;
|
|---|
| 377 | hiloconverr = 0.;
|
|---|
| 378 | calibConv = 1.;
|
|---|
| 379 | calibConvVar = 0.;
|
|---|
| 380 | calibFFactor = 0.;
|
|---|
| 381 |
|
|---|
| 382 | Float_t calibQE = 1.;
|
|---|
| 383 | Float_t calibQEVar = 0.;
|
|---|
| 384 |
|
|---|
| 385 | if(fCalibrationMode!=kNone)
|
|---|
| 386 | {
|
|---|
| 387 | MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCalibrations)[pixidx];
|
|---|
| 388 |
|
|---|
| 389 | hiloconv = pix.GetConversionHiLo ();
|
|---|
| 390 | hiloconverr= pix.GetConversionHiLoErr();
|
|---|
| 391 |
|
|---|
| 392 | if ((*fBadPixels)[pixidx].IsUnsuitable())
|
|---|
| 393 | return kFALSE;
|
|---|
| 394 |
|
|---|
| 395 | calibConv = pix.GetMeanConvFADC2Phe();
|
|---|
| 396 | calibConvVar = pix.GetMeanConvFADC2PheVar();
|
|---|
| 397 | calibFFactor = pix.GetMeanFFactorFADC2Phot();
|
|---|
| 398 |
|
|---|
| 399 | MCalibrationQEPix &qe = (MCalibrationQEPix&) (*fQEs)[pixidx];
|
|---|
| 400 |
|
|---|
| 401 | switch(fCalibrationMode)
|
|---|
| 402 | {
|
|---|
| 403 | case kFlatCharge:
|
|---|
| 404 | {
|
|---|
| 405 | MCalibrationChargePix &avpix = (MCalibrationChargePix&)fCalibrations->GetAverageArea(0);
|
|---|
| 406 | calibConv = avpix.GetMean() / (pix.GetMean() * fGeomCam->GetPixRatio(pixidx));
|
|---|
| 407 | calibConvVar = (avpix.GetMeanRelVar() + pix.GetMeanRelVar()) * calibConv * calibConv;
|
|---|
| 408 | if (pix.IsFFactorMethodValid())
|
|---|
| 409 | {
|
|---|
| 410 | const Float_t convmin1 = qe.GetQECascadesFFactor(zenith)/pix.GetMeanConvFADC2Phe();
|
|---|
| 411 | if (convmin1 > 0)
|
|---|
| 412 | calibFFactor *= TMath::Sqrt(convmin1);
|
|---|
| 413 | else
|
|---|
| 414 | calibFFactor = -1.;
|
|---|
| 415 | }
|
|---|
| 416 | }
|
|---|
| 417 | break;
|
|---|
| 418 |
|
|---|
| 419 | case kBlindPixel:
|
|---|
| 420 | if (!qe.IsBlindPixelMethodValid())
|
|---|
| 421 | return kFALSE;
|
|---|
| 422 | calibQE = qe.GetQECascadesBlindPixel ( zenith );
|
|---|
| 423 | calibQEVar = qe.GetQECascadesBlindPixelVar( zenith );
|
|---|
| 424 | break;
|
|---|
| 425 |
|
|---|
| 426 | case kPinDiode:
|
|---|
| 427 | if (!qe.IsPINDiodeMethodValid())
|
|---|
| 428 | return kFALSE;
|
|---|
| 429 | calibQE = qe.GetQECascadesPINDiode ( zenith );
|
|---|
| 430 | calibQEVar = qe.GetQECascadesPINDiodeVar( zenith );
|
|---|
| 431 | break;
|
|---|
| 432 |
|
|---|
| 433 | case kFfactor:
|
|---|
| 434 | if (!pix.IsFFactorMethodValid())
|
|---|
| 435 | return kFALSE;
|
|---|
| 436 | calibQE = qe.GetQECascadesFFactor ( zenith );
|
|---|
| 437 | calibQEVar = qe.GetQECascadesFFactorVar( zenith );
|
|---|
| 438 | break;
|
|---|
| 439 |
|
|---|
| 440 | case kCombined:
|
|---|
| 441 | if (!qe.IsCombinedMethodValid())
|
|---|
| 442 | return kFALSE;
|
|---|
| 443 | calibQE = qe.GetQECascadesCombined ( zenith );
|
|---|
| 444 | calibQEVar = qe.GetQECascadesCombinedVar( zenith );
|
|---|
| 445 | break;
|
|---|
| 446 |
|
|---|
| 447 | case kDummy:
|
|---|
| 448 | hiloconv = 1.;
|
|---|
| 449 | hiloconverr = 0.;
|
|---|
| 450 | break;
|
|---|
| 451 | } /* switch calibration mode */
|
|---|
| 452 | } /* if(fCalibrationMode!=kNone) */
|
|---|
| 453 | else
|
|---|
| 454 | {
|
|---|
| 455 | calibConv = 1./fGeomCam->GetPixRatio(pixidx);
|
|---|
| 456 | }
|
|---|
| 457 |
|
|---|
| 458 | calibConv /= calibQE;
|
|---|
| 459 |
|
|---|
| 460 | if (calibConv != 0. && calibQE != 0.)
|
|---|
| 461 | {
|
|---|
| 462 | // Now doing:
|
|---|
| 463 | // calibConvVar = calibConvVar/(calibConv*calibConv) + calibQEVar/(calibQE*calibQE);
|
|---|
| 464 | // calibConvVar *= (calibConv*calibConv);
|
|---|
| 465 | calibConvVar += calibQEVar*(calibConv*calibConv)/(calibQE*calibQE);
|
|---|
| 466 | }
|
|---|
| 467 |
|
|---|
| 468 | return kTRUE;
|
|---|
| 469 | }
|
|---|
| 470 |
|
|---|
| 471 | Int_t MCalibrateData::Calibrate(Bool_t data, Bool_t pedestal) const
|
|---|
| 472 | {
|
|---|
| 473 | if (!data && !pedestal)
|
|---|
| 474 | return kTRUE;
|
|---|
| 475 |
|
|---|
| 476 | const UInt_t npix = fSignals->GetSize();
|
|---|
| 477 | const Float_t slices = fSignals->GetNumUsedHiGainFADCSlices();
|
|---|
| 478 | const Float_t sqrtslices = TMath::Sqrt(slices);
|
|---|
| 479 |
|
|---|
| 480 | Float_t hiloconv;
|
|---|
| 481 | Float_t hiloconverr;
|
|---|
| 482 | Float_t calibConv;
|
|---|
| 483 | Float_t calibConvErr;
|
|---|
| 484 | Float_t calibFFactor;
|
|---|
| 485 |
|
|---|
| 486 | UInt_t skip = 0;
|
|---|
| 487 | for (UInt_t pixidx=0; pixidx<npix; pixidx++)
|
|---|
| 488 | {
|
|---|
| 489 | if (!GetConversionFactor(pixidx, hiloconv, hiloconverr,
|
|---|
| 490 | calibConv, calibConvErr, calibFFactor))
|
|---|
| 491 | {
|
|---|
| 492 | skip++;
|
|---|
| 493 | continue;
|
|---|
| 494 | }
|
|---|
| 495 |
|
|---|
| 496 | if (data)
|
|---|
| 497 | {
|
|---|
| 498 | const MExtractedSignalPix &sig = (*fSignals)[pixidx];
|
|---|
| 499 |
|
|---|
| 500 | Float_t signal = 0;
|
|---|
| 501 | Float_t signalErr = 0.;
|
|---|
| 502 |
|
|---|
| 503 | if (sig.IsLoGainUsed())
|
|---|
| 504 | {
|
|---|
| 505 | signal = sig.GetExtractedSignalLoGain()*hiloconv;
|
|---|
| 506 | signalErr = signal*hiloconverr;
|
|---|
| 507 | }
|
|---|
| 508 | else
|
|---|
| 509 | {
|
|---|
| 510 | if (sig.GetExtractedSignalHiGain() <= 9999.)
|
|---|
| 511 | signal = sig.GetExtractedSignalHiGain();
|
|---|
| 512 | }
|
|---|
| 513 |
|
|---|
| 514 | const Float_t nphot = signal*calibConv;
|
|---|
| 515 | const Float_t nphotErr = calibFFactor*TMath::Sqrt(TMath::Abs(nphot));
|
|---|
| 516 |
|
|---|
| 517 | //
|
|---|
| 518 | // The following part is the commented first version of the error calculation
|
|---|
| 519 | // Contact Markus Gaug for questions (or wait for the next documentation update...)
|
|---|
| 520 | //
|
|---|
| 521 | /*
|
|---|
| 522 | nphotErr = signal > 0 ? signalErr*signalErr / (signal * signal) : 0.
|
|---|
| 523 | + calibConv > 0 ? calibConvVar / (calibConv * calibConv ) : 0.;
|
|---|
| 524 | nphotErr = TMath::Sqrt(nphotErr) * nphot;
|
|---|
| 525 | */
|
|---|
| 526 |
|
|---|
| 527 | MCerPhotPix *cpix = fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
|
|---|
| 528 |
|
|---|
| 529 | if (sig.GetNumHiGainSaturated() > 0)
|
|---|
| 530 | cpix->SetPixelHGSaturated();
|
|---|
| 531 |
|
|---|
| 532 | if (sig.GetNumLoGainSaturated() > 0)
|
|---|
| 533 | cpix->SetPixelSaturated();
|
|---|
| 534 | }
|
|---|
| 535 |
|
|---|
| 536 | if (pedestal)
|
|---|
| 537 | {
|
|---|
| 538 | /*
|
|---|
| 539 | // pedestals/(used FADC slices) in [ADC] counts
|
|---|
| 540 | const Float_t pedes = (*fPedestalMean)[pixidx].GetPedestal() * slices;
|
|---|
| 541 | const Float_t pedrms = (*fPedestalRms)[pixidx].GetPedestalRms() * sqrtslices;
|
|---|
| 542 |
|
|---|
| 543 | //
|
|---|
| 544 | // pedestals/(used FADC slices) in [number of photons]
|
|---|
| 545 | //
|
|---|
| 546 | const Float_t pedphot = pedes * calibConv;
|
|---|
| 547 | const Float_t pedphotrms = pedrms * calibConv;
|
|---|
| 548 |
|
|---|
| 549 | (*fPedPhot)[pixidx].Set(pedphot, pedphotrms);
|
|---|
| 550 | */
|
|---|
| 551 | TIter NextPed(&fPedestalCams);
|
|---|
| 552 | TIter NextPhot(&fPedPhotCams);
|
|---|
| 553 |
|
|---|
| 554 | MPedestalCam *pedestal = 0;
|
|---|
| 555 | MPedPhotCam *pedphot = 0;
|
|---|
| 556 |
|
|---|
| 557 | while ((pedestal=(MPedestalCam*)NextPed()) &&
|
|---|
| 558 | (pedphot =(MPedPhotCam*)NextPhot()))
|
|---|
| 559 | {
|
|---|
| 560 | // pedestals/(used FADC slices) in [ADC] counts
|
|---|
| 561 | const Float_t pedes = (*pedestal)[pixidx].GetPedestal() * slices;
|
|---|
| 562 | const Float_t pedrms = (*pedestal)[pixidx].GetPedestalRms() * sqrtslices;
|
|---|
| 563 |
|
|---|
| 564 | // pedestals/(used FADC slices) in [number of photons]
|
|---|
| 565 | const Float_t mean = pedes * calibConv;
|
|---|
| 566 | const Float_t rms = pedrms * calibConv;
|
|---|
| 567 |
|
|---|
| 568 | (*pedphot)[pixidx].Set(mean, rms);
|
|---|
| 569 | pedphot->SetReadyToSave();
|
|---|
| 570 | }
|
|---|
| 571 | }
|
|---|
| 572 | }
|
|---|
| 573 |
|
|---|
| 574 | if (skip>npix*0.9)
|
|---|
| 575 | {
|
|---|
| 576 | *fLog << warn << "WARNING - GetConversionFactor has skipped more than 90% of the pixels... skip." << endl;
|
|---|
| 577 | return kCONTINUE;
|
|---|
| 578 | }
|
|---|
| 579 |
|
|---|
| 580 | if (data)
|
|---|
| 581 | {
|
|---|
| 582 | fCerPhotEvt->FixSize();
|
|---|
| 583 | fCerPhotEvt->SetReadyToSave();
|
|---|
| 584 | }
|
|---|
| 585 | return kTRUE;
|
|---|
| 586 | }
|
|---|
| 587 |
|
|---|
| 588 | // --------------------------------------------------------------------------
|
|---|
| 589 | //
|
|---|
| 590 | // Apply the calibration factors to the extracted signal according to the
|
|---|
| 591 | // selected calibration method
|
|---|
| 592 | //
|
|---|
| 593 | Int_t MCalibrateData::Process()
|
|---|
| 594 | {
|
|---|
| 595 | /*
|
|---|
| 596 | if (fCalibrations->GetNumPixels() != (UInt_t)fSignals->GetSize())
|
|---|
| 597 | {
|
|---|
| 598 | // FIXME: MExtractedSignal must be of variable size -
|
|---|
| 599 | // like MCerPhotEvt - because we must be able
|
|---|
| 600 | // to reduce size by zero supression
|
|---|
| 601 | // For the moment this check could be done in ReInit...
|
|---|
| 602 | *fLog << err << "MExtractedSignal and MCalibrationCam have different sizes... abort." << endl;
|
|---|
| 603 | return kFALSE;
|
|---|
| 604 | }
|
|---|
| 605 | */
|
|---|
| 606 |
|
|---|
| 607 | return Calibrate(fCalibrationMode!=kSkip, TestPedestalFlag(kEvent));
|
|---|
| 608 | }
|
|---|
| 609 |
|
|---|
| 610 | // --------------------------------------------------------------------------
|
|---|
| 611 | //
|
|---|
| 612 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
|---|
| 613 | // to a macro. In the original root implementation it is used to write
|
|---|
| 614 | // gui elements to a macro-file.
|
|---|
| 615 | //
|
|---|
| 616 | void MCalibrateData::StreamPrimitive(ofstream &out) const
|
|---|
| 617 | {
|
|---|
| 618 | out << " " << ClassName() << " " << GetUniqueName() << "(\"";
|
|---|
| 619 | out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
|
|---|
| 620 |
|
|---|
| 621 | if (TestPedestalFlag(kEvent))
|
|---|
| 622 | out << " " << GetUniqueName() << ".EnablePedestalType(MCalibrateData::kEvent)" << endl;
|
|---|
| 623 | if (TestPedestalFlag(kRun))
|
|---|
| 624 | out << " " << GetUniqueName() << ".EnablePedestalType(MCalibrateData::kRun)" << endl;
|
|---|
| 625 |
|
|---|
| 626 | if (fCalibrationMode != kDefault)
|
|---|
| 627 | {
|
|---|
| 628 | out << " " << GetUniqueName() << ".SetCalibrationMode(MCalibrateData::";
|
|---|
| 629 | switch (fCalibrationMode)
|
|---|
| 630 | {
|
|---|
| 631 | case kSkip: out << "kSkip"; break;
|
|---|
| 632 | case kNone: out << "kNone"; break;
|
|---|
| 633 | case kFlatCharge: out << "kFlatCharge"; break;
|
|---|
| 634 | case kBlindPixel: out << "kBlindPixel"; break;
|
|---|
| 635 | case kFfactor: out << "kFfactor"; break;
|
|---|
| 636 | case kPinDiode: out << "kPinDiode"; break;
|
|---|
| 637 | case kCombined: out << "kCombined"; break;
|
|---|
| 638 | case kDummy: out << "kDummy"; break;
|
|---|
| 639 | default: out << (int)fCalibrationMode; break;
|
|---|
| 640 | }
|
|---|
| 641 | out << ")" << endl;
|
|---|
| 642 | }
|
|---|
| 643 |
|
|---|
| 644 | TIter Next(&fNamesPedestal);
|
|---|
| 645 | TObject *o=0;
|
|---|
| 646 | while ((o=Next()))
|
|---|
| 647 | {
|
|---|
| 648 | out << " " << GetUniqueName() << ".AddPedestal(\"";
|
|---|
| 649 | out << o->GetName() << "\", \"" << o->GetTitle() << "\");" << endl;
|
|---|
| 650 | }
|
|---|
| 651 | }
|
|---|
| 652 |
|
|---|
| 653 | // --------------------------------------------------------------------------
|
|---|
| 654 | //
|
|---|
| 655 | // Read the setup from a TEnv, eg:
|
|---|
| 656 | // MJPedestal.MCalibrateDate.PedestalFlag: no,run,event
|
|---|
| 657 | // MJPedestal.MCalibrateDate.CalibrationMode: skip,none,flatcharge,blindpixel,ffactor,pindiode,combined,dummy,default
|
|---|
| 658 | //
|
|---|
| 659 | Int_t MCalibrateData::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
|---|
| 660 | {
|
|---|
| 661 | Bool_t rc = kFALSE;
|
|---|
| 662 | if (IsEnvDefined(env, prefix, "PedestalFlag", print))
|
|---|
| 663 | {
|
|---|
| 664 | rc = kTRUE;
|
|---|
| 665 | TString s = GetEnvValue(env, prefix, "PedestalFlag", "");
|
|---|
| 666 | s.ToLower();
|
|---|
| 667 | if (s.BeginsWith("no"))
|
|---|
| 668 | SetPedestalFlag(kNo);
|
|---|
| 669 | if (s.BeginsWith("run"))
|
|---|
| 670 | SetPedestalFlag(kRun);
|
|---|
| 671 | if (s.BeginsWith("event"))
|
|---|
| 672 | SetPedestalFlag(kEvent);
|
|---|
| 673 | }
|
|---|
| 674 |
|
|---|
| 675 | if (IsEnvDefined(env, prefix, "CalibrationMode", print))
|
|---|
| 676 | {
|
|---|
| 677 | rc = kTRUE;
|
|---|
| 678 | TString s = GetEnvValue(env, prefix, "CalibrationMode", "");
|
|---|
| 679 | s.ToLower();
|
|---|
| 680 | if (s.BeginsWith("skip"))
|
|---|
| 681 | SetCalibrationMode(kSkip);
|
|---|
| 682 | if (s.BeginsWith("none"))
|
|---|
| 683 | SetCalibrationMode(kNone);
|
|---|
| 684 | if (s.BeginsWith("flatcharge"))
|
|---|
| 685 | SetCalibrationMode(kFlatCharge);
|
|---|
| 686 | if (s.BeginsWith("blindpixel"))
|
|---|
| 687 | SetCalibrationMode(kBlindPixel);
|
|---|
| 688 | if (s.BeginsWith("ffactor"))
|
|---|
| 689 | SetCalibrationMode(kFfactor);
|
|---|
| 690 | if (s.BeginsWith("pindiode"))
|
|---|
| 691 | SetCalibrationMode(kPinDiode);
|
|---|
| 692 | if (s.BeginsWith("combined"))
|
|---|
| 693 | SetCalibrationMode(kCombined);
|
|---|
| 694 | if (s.BeginsWith("dummy"))
|
|---|
| 695 | SetCalibrationMode(kDummy);
|
|---|
| 696 | if (s.BeginsWith("default"))
|
|---|
| 697 | SetCalibrationMode();
|
|---|
| 698 | }
|
|---|
| 699 |
|
|---|
| 700 | return rc;
|
|---|
| 701 | }
|
|---|