| 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 | ! Modified by: Javier Rico 01/2004 <mailto:jrico@ifae.es>
|
|---|
| 20 | ! Wolfgang Wittek 02/2004 <mailto:wittek@mppmu.mpg.de>
|
|---|
| 21 | !
|
|---|
| 22 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 23 | !
|
|---|
| 24 | !
|
|---|
| 25 | \* ======================================================================== */
|
|---|
| 26 |
|
|---|
| 27 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 28 | //
|
|---|
| 29 | // MCalibrateData
|
|---|
| 30 | //
|
|---|
| 31 | // This task takes the integrated charge from MExtractedSignal and apply
|
|---|
| 32 | // the calibration constants from MCalibraitionCam to the charge. Then
|
|---|
| 33 | // stores number of photons obtained in MCerPhotEvt. Selection of different
|
|---|
| 34 | // calibration methods is allowed through SetCalibrationMode member function
|
|---|
| 35 | //
|
|---|
| 36 | // in ReInit the MPedPhotCam container is filled using the information from
|
|---|
| 37 | // MPedestalCam, MExtractedSignalCam and MCalibrationCam
|
|---|
| 38 | //
|
|---|
| 39 | // Input Containers:
|
|---|
| 40 | // MPedestalCam
|
|---|
| 41 | // MExtractedSingalCam
|
|---|
| 42 | // MCalibrationCam
|
|---|
| 43 | //
|
|---|
| 44 | // Output Containers:
|
|---|
| 45 | // MPedPhotCam
|
|---|
| 46 | // MCerPhotEvt
|
|---|
| 47 | //
|
|---|
| 48 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 49 | #include "MCalibrateData.h"
|
|---|
| 50 | #include "MCalibrationConfig.h"
|
|---|
| 51 |
|
|---|
| 52 | #include "MLog.h"
|
|---|
| 53 | #include "MLogManip.h"
|
|---|
| 54 |
|
|---|
| 55 | #include "MParList.h"
|
|---|
| 56 | #include "MH.h"
|
|---|
| 57 |
|
|---|
| 58 | #include "MGeomCam.h"
|
|---|
| 59 |
|
|---|
| 60 | #include "MPedestalCam.h"
|
|---|
| 61 | #include "MPedestalPix.h"
|
|---|
| 62 |
|
|---|
| 63 | #include "MCalibrationCam.h"
|
|---|
| 64 | #include "MCalibrationPix.h"
|
|---|
| 65 |
|
|---|
| 66 | #include "MExtractedSignalCam.h"
|
|---|
| 67 | #include "MExtractedSignalPix.h"
|
|---|
| 68 |
|
|---|
| 69 | #include "MPedPhotCam.h"
|
|---|
| 70 | #include "MPedPhotPix.h"
|
|---|
| 71 |
|
|---|
| 72 | #include "MCerPhotEvt.h"
|
|---|
| 73 |
|
|---|
| 74 | ClassImp(MCalibrateData);
|
|---|
| 75 |
|
|---|
| 76 | using namespace std;
|
|---|
| 77 | // --------------------------------------------------------------------------
|
|---|
| 78 | //
|
|---|
| 79 | // Default constructor.
|
|---|
| 80 | //
|
|---|
| 81 | MCalibrateData::MCalibrateData(CalibrationMode_t calmode,const char *name, const char *title) : fCalibrationMode(calmode)
|
|---|
| 82 | {
|
|---|
| 83 | fName = name ? name : "MCalibrateData";
|
|---|
| 84 | fTitle = title ? title : "Task to calculate the number of photons in one event";
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | // --------------------------------------------------------------------------
|
|---|
| 88 | //
|
|---|
| 89 | // The PreProcess searches for the following input containers:
|
|---|
| 90 | // - MGeomCam
|
|---|
| 91 | // - MPedestalCam
|
|---|
| 92 | // - MCalibrationCam
|
|---|
| 93 | // - MExtractedSignalCam
|
|---|
| 94 | //
|
|---|
| 95 | // The following output containers are also searched and created if
|
|---|
| 96 | // they were not found:
|
|---|
| 97 | //
|
|---|
| 98 | // - MPedPhotCam
|
|---|
| 99 | // - MCerPhotEvt
|
|---|
| 100 | //
|
|---|
| 101 | Int_t MCalibrateData::PreProcess(MParList *pList)
|
|---|
| 102 | {
|
|---|
| 103 | fPedestal = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
|
|---|
| 104 | if (!fPedestal)
|
|---|
| 105 | {
|
|---|
| 106 | *fLog << err << AddSerialNumber("MPedestalCam") << " not found ... aborting" << endl;
|
|---|
| 107 | return kFALSE;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | fSignals = (MExtractedSignalCam*)pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
|
|---|
| 111 | if (!fSignals)
|
|---|
| 112 | {
|
|---|
| 113 | *fLog << err << AddSerialNumber("MExtractedSignalCam") << " not found ... aborting" << endl;
|
|---|
| 114 | return kFALSE;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | if(fCalibrationMode>kNone)
|
|---|
| 118 | {
|
|---|
| 119 | fCalibrations = (MCalibrationCam*)pList->FindObject(AddSerialNumber("MCalibrationCam"));
|
|---|
| 120 | if (!fCalibrations)
|
|---|
| 121 | {
|
|---|
| 122 | *fLog << err << AddSerialNumber("MCalibrationCam") << " not found ... aborting." << endl;
|
|---|
| 123 | return kFALSE;
|
|---|
| 124 | }
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | fPedPhot = (MPedPhotCam*)pList->FindCreateObj(AddSerialNumber("MPedPhotCam"));
|
|---|
| 128 | if (!fPedPhot)
|
|---|
| 129 | return kFALSE;
|
|---|
| 130 |
|
|---|
| 131 | fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj(AddSerialNumber("MCerPhotEvt"));
|
|---|
| 132 | if (!fCerPhotEvt)
|
|---|
| 133 | return kFALSE;
|
|---|
| 134 |
|
|---|
| 135 | return kTRUE;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | // --------------------------------------------------------------------------
|
|---|
| 139 | //
|
|---|
| 140 | // Check for validity of the selected calibration method, switch to a
|
|---|
| 141 | // different one in case of need
|
|---|
| 142 | //
|
|---|
| 143 | // fill the MPedPhotCam container using the information from MPedestalCam,
|
|---|
| 144 | // MExtractedSignalCam and MCalibrationCam
|
|---|
| 145 | //
|
|---|
| 146 | //
|
|---|
| 147 | Bool_t MCalibrateData::ReInit(MParList *pList)
|
|---|
| 148 | {
|
|---|
| 149 |
|
|---|
| 150 | if(fCalibrationMode == kBlindPixel && !fCalibrations->IsBlindPixelMethodValid())
|
|---|
| 151 | {
|
|---|
| 152 | *fLog << warn << GetDescriptor() << "Warning: Blind pixel calibration method not valid, switching to F-factor method" << endl;
|
|---|
| 153 | fCalibrationMode = kFfactor;
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | if(fCalibrationMode == kPinDiode && !fCalibrations->IsPINDiodeMethodValid())
|
|---|
| 157 | {
|
|---|
| 158 | *fLog << warn << GetDescriptor() << "Warning: PIN diode calibration method not valid, switching to F-factor method" << endl;
|
|---|
| 159 | fCalibrationMode = kFfactor;
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | //---------------------------------------------
|
|---|
| 163 | // fill MPedPhot container using the informations from
|
|---|
| 164 | // MPedestalCam, MExtractedSignalCam and MCalibrationCam
|
|---|
| 165 |
|
|---|
| 166 | fNumUsedHiGainFADCSlices = fSignals->GetNumUsedHiGainFADCSlices();
|
|---|
| 167 |
|
|---|
| 168 | // is pixid equal to pixidx ?
|
|---|
| 169 | if (fPedestal->GetSize() != fSignals->GetSize())
|
|---|
| 170 | {
|
|---|
| 171 | *fLog << err << "MCalibrateData::ReInit(); sizes of MPedestalCam and MCalibrationCam are different"
|
|---|
| 172 | << endl;
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | *fLog << all << "MCalibrateData::ReInit(); fill MPedPhotCam container"
|
|---|
| 176 | << endl;
|
|---|
| 177 | *fLog << all << " fNumUsedHiGainADCSlices = "
|
|---|
| 178 | << fNumUsedHiGainFADCSlices << endl;
|
|---|
| 179 | *fLog << all << " pixid, calibrationConversionFactor, ped, pedRMS, pedphot, pedphotRMS :"
|
|---|
| 180 | << endl;
|
|---|
| 181 | for (Int_t pixid=0; pixid<fPedestal->GetSize(); pixid++)
|
|---|
| 182 | {
|
|---|
| 183 | const MPedestalPix &ped = (*fPedestal)[pixid];
|
|---|
| 184 |
|
|---|
| 185 | // pedestals/(used FADC slices) in [ADC] counts
|
|---|
| 186 | Float_t pedes = ped.GetPedestal() * fNumUsedHiGainFADCSlices;
|
|---|
| 187 | Float_t pedrms = ped.GetPedestalRms() * sqrt(fNumUsedHiGainFADCSlices);
|
|---|
| 188 |
|
|---|
| 189 | //----------------------------------
|
|---|
| 190 | // get photon/ADC conversion factor
|
|---|
| 191 |
|
|---|
| 192 | Float_t hiloconv;
|
|---|
| 193 | Float_t hiloconverr;
|
|---|
| 194 | Float_t calibrationConversionFactor;
|
|---|
| 195 | Float_t calibrationConversionFactorError;
|
|---|
| 196 |
|
|---|
| 197 | if ( !GetConversionFactor(pixid, hiloconv, hiloconverr,
|
|---|
| 198 | calibrationConversionFactor, calibrationConversionFactorError) )
|
|---|
| 199 | continue;
|
|---|
| 200 |
|
|---|
| 201 | //----------------------------------
|
|---|
| 202 |
|
|---|
| 203 | // pedestals/(used FADC slices) in [number of photons]
|
|---|
| 204 | Float_t pedphot = pedes * calibrationConversionFactor;
|
|---|
| 205 | Float_t pedphotrms = pedrms * calibrationConversionFactor;
|
|---|
| 206 |
|
|---|
| 207 | (*fPedPhot)[pixid].Set(pedphot, pedphotrms);
|
|---|
| 208 |
|
|---|
| 209 | *fLog << all << pixid << ", " << calibrationConversionFactor << ", "
|
|---|
| 210 | << ped.GetPedestal() << ", " << ped.GetPedestalRms() << ", "
|
|---|
| 211 | << pedphot << ", " << pedphotrms << endl;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | //---------------------------------------------
|
|---|
| 215 |
|
|---|
| 216 | fPedPhot->SetReadyToSave();
|
|---|
| 217 |
|
|---|
| 218 | return kTRUE;
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | // --------------------------------------------------------------------------
|
|---|
| 222 | //
|
|---|
| 223 | // Get conversion factor and its error from MCalibrationCam
|
|---|
| 224 | //
|
|---|
| 225 | //
|
|---|
| 226 | Bool_t MCalibrateData::GetConversionFactor(UInt_t pixidx,
|
|---|
| 227 | Float_t &hiloconv, Float_t &hiloconverr,
|
|---|
| 228 | Float_t &calibrationConversionFactor, Float_t &calibrationConversionFactorError)
|
|---|
| 229 | {
|
|---|
| 230 | hiloconv = 1.;
|
|---|
| 231 | hiloconverr = 0.;
|
|---|
| 232 | calibrationConversionFactor = 1.;
|
|---|
| 233 | calibrationConversionFactorError = 0.;
|
|---|
| 234 |
|
|---|
| 235 | if(fCalibrationMode!=kNone)
|
|---|
| 236 | {
|
|---|
| 237 | MCalibrationPix &pix = (*fCalibrations)[pixidx];
|
|---|
| 238 |
|
|---|
| 239 | if (!pix.IsChargeValid())
|
|---|
| 240 | return kFALSE;
|
|---|
| 241 |
|
|---|
| 242 | hiloconv = pix.GetConversionHiLo();
|
|---|
| 243 | hiloconverr= pix.GetConversionHiLoError();
|
|---|
| 244 |
|
|---|
| 245 | switch(fCalibrationMode)
|
|---|
| 246 | {
|
|---|
| 247 | case kBlindPixel:
|
|---|
| 248 | calibrationConversionFactor = pix.GetMeanConversionBlindPixelMethod();
|
|---|
| 249 | calibrationConversionFactorError = pix.GetErrorConversionBlindPixelMethod();
|
|---|
| 250 | break;
|
|---|
| 251 | case kFfactor:
|
|---|
| 252 | calibrationConversionFactor = pix.GetMeanConversionFFactorMethod();
|
|---|
| 253 | calibrationConversionFactorError = pix.GetErrorConversionFFactorMethod();
|
|---|
| 254 | break;
|
|---|
| 255 | default:
|
|---|
| 256 | *fLog << warn << "MCalibrateData::GetConversionFactor; Warning: Calibration mode value ("<<fCalibrationMode<<") not known" << endl;
|
|---|
| 257 | break;
|
|---|
| 258 | }
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | return kTRUE;
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | // --------------------------------------------------------------------------
|
|---|
| 265 | //
|
|---|
| 266 | // Apply the calibration factors to the extracted signal according to the
|
|---|
| 267 | // selected calibration method
|
|---|
| 268 | //
|
|---|
| 269 | Int_t MCalibrateData::Process()
|
|---|
| 270 | {
|
|---|
| 271 | /*
|
|---|
| 272 | if (fCalibrations->GetNumPixels() != (UInt_t)fSignals->GetSize())
|
|---|
| 273 | {
|
|---|
| 274 | // FIXME: MExtractedSignal must be of variable size -
|
|---|
| 275 | // like MCerPhotEvt - because we must be able
|
|---|
| 276 | // to reduce size by zero supression
|
|---|
| 277 | // For the moment this check could be done in ReInit...
|
|---|
| 278 | *fLog << err << "MExtractedSignal and MCalibrationCam have different sizes... abort." << endl;
|
|---|
| 279 | return kFALSE;
|
|---|
| 280 | }
|
|---|
| 281 | */
|
|---|
| 282 |
|
|---|
| 283 | UInt_t npix = fSignals->GetSize();
|
|---|
| 284 |
|
|---|
| 285 | Float_t hiloconv;
|
|---|
| 286 | Float_t hiloconverr;
|
|---|
| 287 | Float_t calibrationConversionFactor;
|
|---|
| 288 | Float_t calibrationConversionFactorError;
|
|---|
| 289 |
|
|---|
| 290 | for (UInt_t pixidx=0; pixidx<npix; pixidx++)
|
|---|
| 291 | {
|
|---|
| 292 | if ( !GetConversionFactor(pixidx, hiloconv, hiloconverr,
|
|---|
| 293 | calibrationConversionFactor, calibrationConversionFactorError) )
|
|---|
| 294 | continue;
|
|---|
| 295 |
|
|---|
| 296 | MExtractedSignalPix &sig = (*fSignals)[pixidx];
|
|---|
| 297 |
|
|---|
| 298 | Float_t signal;
|
|---|
| 299 | Float_t signalErr = 0.;
|
|---|
| 300 | Float_t nphot,nphotErr;
|
|---|
| 301 |
|
|---|
| 302 | if (sig.IsLoGainUsed())
|
|---|
| 303 | {
|
|---|
| 304 | signal = sig.GetExtractedSignalLoGain()*hiloconv;
|
|---|
| 305 | signalErr = signal*hiloconverr;
|
|---|
| 306 | }
|
|---|
| 307 | else
|
|---|
| 308 | {
|
|---|
| 309 | if (sig.GetExtractedSignalHiGain() > 9999.)
|
|---|
| 310 | {
|
|---|
| 311 | signal = 0.;
|
|---|
| 312 | signalErr = 0.;
|
|---|
| 313 | }
|
|---|
| 314 | else
|
|---|
| 315 | signal = sig.GetExtractedSignalHiGain();
|
|---|
| 316 | }
|
|---|
| 317 |
|
|---|
| 318 | nphot = signal*calibrationConversionFactor;
|
|---|
| 319 | nphotErr = signal*calibrationConversionFactorError
|
|---|
| 320 | *signal*calibrationConversionFactorError
|
|---|
| 321 | +signalErr*calibrationConversionFactor
|
|---|
| 322 | *signalErr*calibrationConversionFactor;
|
|---|
| 323 |
|
|---|
| 324 | nphotErr = TMath::Sqrt(nphotErr);
|
|---|
| 325 |
|
|---|
| 326 | MCerPhotPix *cpix = fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
|
|---|
| 327 |
|
|---|
| 328 | if (sig.GetNumLoGainSaturated() > 0)
|
|---|
| 329 | cpix->SetPixelSaturated();
|
|---|
| 330 | }
|
|---|
| 331 |
|
|---|
| 332 | fCerPhotEvt->FixSize();
|
|---|
| 333 | fCerPhotEvt->SetReadyToSave();
|
|---|
| 334 |
|
|---|
| 335 | return kTRUE;
|
|---|
| 336 | }
|
|---|