| 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 | !
|
|---|
| 21 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 22 | !
|
|---|
| 23 | !
|
|---|
| 24 | \* ======================================================================== */
|
|---|
| 25 |
|
|---|
| 26 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 27 | //
|
|---|
| 28 | // MCalibrate
|
|---|
| 29 | //
|
|---|
| 30 | // This task takes the integrated charge from MExtractedSignal and apply
|
|---|
| 31 | // the calibration constants from MCalibraitionCam to the charge. Then
|
|---|
| 32 | // stores number of photons obtained in MCerPhotEvt. Selection of different
|
|---|
| 33 | // calibration methods is allowed through SetCalibrationMode member function
|
|---|
| 34 | //
|
|---|
| 35 | // Input Containers:
|
|---|
| 36 | // MExtractedSingal
|
|---|
| 37 | // MCalibrationCam
|
|---|
| 38 | //
|
|---|
| 39 | // Output Containers:
|
|---|
| 40 | // MCerPhotEvt
|
|---|
| 41 | //
|
|---|
| 42 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 43 | #include "MCalibrate.h"
|
|---|
| 44 | #include "MCalibrationConfig.h"
|
|---|
| 45 |
|
|---|
| 46 | #include "MLog.h"
|
|---|
| 47 | #include "MLogManip.h"
|
|---|
| 48 |
|
|---|
| 49 | #include "MParList.h"
|
|---|
| 50 | #include "MH.h"
|
|---|
| 51 |
|
|---|
| 52 | #include "MGeomCam.h"
|
|---|
| 53 |
|
|---|
| 54 | #include "MCalibrationCam.h"
|
|---|
| 55 | #include "MCalibrationPix.h"
|
|---|
| 56 |
|
|---|
| 57 | #include "MExtractedSignalCam.h"
|
|---|
| 58 | #include "MExtractedSignalPix.h"
|
|---|
| 59 |
|
|---|
| 60 | #include "MCerPhotEvt.h"
|
|---|
| 61 |
|
|---|
| 62 | ClassImp(MCalibrate);
|
|---|
| 63 |
|
|---|
| 64 | using namespace std;
|
|---|
| 65 | // --------------------------------------------------------------------------
|
|---|
| 66 | //
|
|---|
| 67 | // Default constructor.
|
|---|
| 68 | //
|
|---|
| 69 | MCalibrate::MCalibrate(CalibrationMode_t calmode,const char *name, const char *title) : fCalibrationMode(calmode)
|
|---|
| 70 | {
|
|---|
| 71 | fName = name ? name : "MCalibrate";
|
|---|
| 72 | fTitle = title ? title : "Task to calculate the number of photons in one event";
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | // --------------------------------------------------------------------------
|
|---|
| 76 | //
|
|---|
| 77 | // The PreProcess searches for the following input containers:
|
|---|
| 78 | // - MGeomCam
|
|---|
| 79 | // - MCalibrationCam
|
|---|
| 80 | // - MExtractedSignalCam
|
|---|
| 81 | //
|
|---|
| 82 | // The following output containers are also searched and created if
|
|---|
| 83 | // they were not found:
|
|---|
| 84 | //
|
|---|
| 85 | // - MCerPhotEvt
|
|---|
| 86 | //
|
|---|
| 87 | Int_t MCalibrate::PreProcess(MParList *pList)
|
|---|
| 88 | {
|
|---|
| 89 |
|
|---|
| 90 | fSignals = (MExtractedSignalCam*)pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
|
|---|
| 91 |
|
|---|
| 92 | if (!fSignals)
|
|---|
| 93 | {
|
|---|
| 94 | *fLog << err << AddSerialNumber("MExtractedSignalCam") << " not found ... aborting" << endl;
|
|---|
| 95 | return kFALSE;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | if(fCalibrationMode>kNone)
|
|---|
| 99 | {
|
|---|
| 100 |
|
|---|
| 101 | fCalibrations = (MCalibrationCam*)pList->FindObject(AddSerialNumber("MCalibrationCam"));
|
|---|
| 102 | if (!fCalibrations)
|
|---|
| 103 | {
|
|---|
| 104 | *fLog << err << AddSerialNumber("MCalibrationCam") << " not found ... aborting." << endl;
|
|---|
| 105 | return kFALSE;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj(AddSerialNumber("MCerPhotEvt"));
|
|---|
| 111 | if (!fCerPhotEvt)
|
|---|
| 112 | return kFALSE;
|
|---|
| 113 |
|
|---|
| 114 | return kTRUE;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | // --------------------------------------------------------------------------
|
|---|
| 118 | //
|
|---|
| 119 | // Check for validity of the selected calibration method, switch to a
|
|---|
| 120 | // different one in case of need
|
|---|
| 121 | //
|
|---|
| 122 | Bool_t MCalibrate::ReInit(MParList *pList)
|
|---|
| 123 | {
|
|---|
| 124 |
|
|---|
| 125 | if(fCalibrationMode == kBlindPixel && !fCalibrations->IsBlindPixelMethodValid())
|
|---|
| 126 | {
|
|---|
| 127 | *fLog << warn << GetDescriptor() << "Warning: Blind pixel calibration method not valid, switching to F-factor method" << endl;
|
|---|
| 128 | fCalibrationMode = kFfactor;
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | if(fCalibrationMode == kPinDiode && !fCalibrations->IsPINDiodeMethodValid())
|
|---|
| 132 | {
|
|---|
| 133 | *fLog << warn << GetDescriptor() << "Warning: PIN diode calibration method not valid, switching to F-factor method" << endl;
|
|---|
| 134 | fCalibrationMode = kFfactor;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | switch(fCalibrationMode)
|
|---|
| 138 | {
|
|---|
| 139 | case kBlindPixel:
|
|---|
| 140 | break;
|
|---|
| 141 | case kFfactor:
|
|---|
| 142 | break;
|
|---|
| 143 | case kPinDiode:
|
|---|
| 144 | *fLog << err << GetDescriptor()
|
|---|
| 145 | << ": PIN Diode Calibration mode not yet available " << endl;
|
|---|
| 146 | return kFALSE;
|
|---|
| 147 | break;
|
|---|
| 148 | case kCombined:
|
|---|
| 149 | *fLog << err << GetDescriptor()
|
|---|
| 150 | << ": Combined Calibration mode not yet available " << endl;
|
|---|
| 151 | return kFALSE;
|
|---|
| 152 | break;
|
|---|
| 153 | case kDummy:
|
|---|
| 154 | *fLog << warn << GetDescriptor()
|
|---|
| 155 | << ": WARNING: Dummy calibration, no calibration applied!!" << endl;
|
|---|
| 156 | break;
|
|---|
| 157 | default:
|
|---|
| 158 | *fLog << warn << GetDescriptor()
|
|---|
| 159 | << ": WARNING: Calibration mode value ("
|
|---|
| 160 | <<fCalibrationMode<<") not known" << endl;
|
|---|
| 161 | return kFALSE;
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | return kTRUE;
|
|---|
| 165 | }
|
|---|
| 166 | // --------------------------------------------------------------------------
|
|---|
| 167 | //
|
|---|
| 168 | // Apply the calibration factors to the extracted signal according to the
|
|---|
| 169 | // selected calibration method
|
|---|
| 170 | //
|
|---|
| 171 | Int_t MCalibrate::Process()
|
|---|
| 172 | {
|
|---|
| 173 | /*
|
|---|
| 174 | if (fCalibrations->GetNumPixels() != (UInt_t)fSignals->GetSize())
|
|---|
| 175 | {
|
|---|
| 176 | // FIXME: MExtractedSignal must be of variable size -
|
|---|
| 177 | // like MCerPhotEvt - because we must be able
|
|---|
| 178 | // to reduce size by zero supression
|
|---|
| 179 | // For the moment this check could be done in ReInit...
|
|---|
| 180 | *fLog << err << "MExtractedSignal and MCalibrationCam have different sizes... abort." << endl;
|
|---|
| 181 | return kFALSE;
|
|---|
| 182 | }
|
|---|
| 183 | */
|
|---|
| 184 |
|
|---|
| 185 | UInt_t npix = fSignals->GetSize();
|
|---|
| 186 |
|
|---|
| 187 | Float_t hiloconv = 1.;
|
|---|
| 188 | Float_t hiloconverr= 0.;
|
|---|
| 189 | Float_t calibrationConversionFactor = 1.;
|
|---|
| 190 | Float_t calibrationConversionFactorError = 0.;
|
|---|
| 191 |
|
|---|
| 192 | for (UInt_t pixidx=0; pixidx<npix; pixidx++)
|
|---|
| 193 | {
|
|---|
| 194 | if(fCalibrationMode!=kNone)
|
|---|
| 195 | {
|
|---|
| 196 | MCalibrationPix &pix = (*fCalibrations)[pixidx];
|
|---|
| 197 |
|
|---|
| 198 | if (!pix.IsChargeValid())
|
|---|
| 199 | continue;
|
|---|
| 200 |
|
|---|
| 201 | hiloconv = pix.GetConversionHiLo();
|
|---|
| 202 | hiloconverr= pix.GetConversionHiLoError();
|
|---|
| 203 |
|
|---|
| 204 | switch(fCalibrationMode)
|
|---|
| 205 | {
|
|---|
| 206 | case kBlindPixel:
|
|---|
| 207 | calibrationConversionFactor = pix.GetMeanConversionBlindPixelMethod();
|
|---|
| 208 | calibrationConversionFactorError = pix.GetErrorConversionBlindPixelMethod();
|
|---|
| 209 | break;
|
|---|
| 210 | case kPinDiode:
|
|---|
| 211 | calibrationConversionFactor = pix.GetMeanConversionPINDiodeMethod();
|
|---|
| 212 | calibrationConversionFactorError = pix.GetErrorConversionPINDiodeMethod();
|
|---|
| 213 | break;
|
|---|
| 214 | case kFfactor:
|
|---|
| 215 | calibrationConversionFactor = pix.GetMeanConversionFFactorMethod();
|
|---|
| 216 | calibrationConversionFactorError = pix.GetErrorConversionFFactorMethod();
|
|---|
| 217 | break;
|
|---|
| 218 | case kCombined:
|
|---|
| 219 | calibrationConversionFactor = pix.GetMeanConversionCombinedMethod();
|
|---|
| 220 | calibrationConversionFactorError = pix.GetErrorConversionCombinedMethod();
|
|---|
| 221 | break;
|
|---|
| 222 | case kDummy:
|
|---|
| 223 | calibrationConversionFactor = 1.;
|
|---|
| 224 | calibrationConversionFactorError = 0.;
|
|---|
| 225 | break;
|
|---|
| 226 | }
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | MExtractedSignalPix &sig = (*fSignals)[pixidx];
|
|---|
| 230 |
|
|---|
| 231 | Float_t signal;
|
|---|
| 232 | Float_t signalErr = 0.;
|
|---|
| 233 | Float_t nphot,nphotErr;
|
|---|
| 234 |
|
|---|
| 235 | if (sig.IsLoGainUsed())
|
|---|
| 236 | {
|
|---|
| 237 | signal = sig.GetExtractedSignalLoGain()*hiloconv;
|
|---|
| 238 | signalErr = signal*hiloconverr;
|
|---|
| 239 | }
|
|---|
| 240 | else
|
|---|
| 241 | {
|
|---|
| 242 | if (sig.GetExtractedSignalHiGain() > 9999.)
|
|---|
| 243 | {
|
|---|
| 244 | signal = 0.;
|
|---|
| 245 | signalErr = 0.;
|
|---|
| 246 | }
|
|---|
| 247 | else
|
|---|
| 248 | signal = sig.GetExtractedSignalHiGain();
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | nphot = signal*calibrationConversionFactor;
|
|---|
| 252 | nphotErr = signal*calibrationConversionFactorError
|
|---|
| 253 | *signal*calibrationConversionFactorError
|
|---|
| 254 | +signalErr*calibrationConversionFactor
|
|---|
| 255 | *signalErr*calibrationConversionFactor;
|
|---|
| 256 |
|
|---|
| 257 | nphotErr = TMath::Sqrt(nphotErr);
|
|---|
| 258 |
|
|---|
| 259 | MCerPhotPix *cpix = fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
|
|---|
| 260 |
|
|---|
| 261 | if (sig.GetNumLoGainSaturated() > 0)
|
|---|
| 262 | cpix->SetPixelSaturated();
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 | fCerPhotEvt->FixSize();
|
|---|
| 266 | fCerPhotEvt->SetReadyToSave();
|
|---|
| 267 |
|
|---|
| 268 | return kTRUE;
|
|---|
| 269 | }
|
|---|