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