| 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): Abelardo Moralejo, 12/2003 <mailto:moralejo@pd.infn.it>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2003
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MMcCalibrationUpdate
|
|---|
| 28 | //
|
|---|
| 29 | // This task looks for the ìnformation about FADC pedestals in
|
|---|
| 30 | // MMcFadcHeader and translates it to the pedestal mean and rms (in adc counts).
|
|---|
| 31 | // If not already existing in the parameter list, an MCalibrationCam object
|
|---|
| 32 | // is created, with the conversion factor between photons and ADC counts is
|
|---|
| 33 | // set to 1 to allow the analysis to proceed.
|
|---|
| 34 | //
|
|---|
| 35 | // Then it creates and fills also the MPedPhotCam object containing the pedestal
|
|---|
| 36 | // mean and rms in units of photons.
|
|---|
| 37 | //
|
|---|
| 38 | // Input Containers:
|
|---|
| 39 | // MMcFadcHeader
|
|---|
| 40 | // MRawRunHeader
|
|---|
| 41 | // [MCalibrationCam] (if it existed previously)
|
|---|
| 42 | //
|
|---|
| 43 | // Output Containers:
|
|---|
| 44 | // MPedPhotCam
|
|---|
| 45 | // [MCalibrationCam] (if it did not exist previously)
|
|---|
| 46 | //
|
|---|
| 47 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 48 | #include "MMcCalibrationUpdate.h"
|
|---|
| 49 |
|
|---|
| 50 | #include "MParList.h"
|
|---|
| 51 |
|
|---|
| 52 | #include "MLog.h"
|
|---|
| 53 | #include "MLogManip.h"
|
|---|
| 54 |
|
|---|
| 55 | #include "MCalibrationChargePix.h"
|
|---|
| 56 | #include "MCalibrationChargeCam.h"
|
|---|
| 57 |
|
|---|
| 58 | #include "MCalibrationQEPix.h"
|
|---|
| 59 | #include "MCalibrationQECam.h"
|
|---|
| 60 |
|
|---|
| 61 | #include "MExtractedSignalCam.h"
|
|---|
| 62 | #include "MExtractedSignalPix.h"
|
|---|
| 63 | #include "MGeomCam.h"
|
|---|
| 64 | #include "MPedPhotCam.h"
|
|---|
| 65 | #include "MPedPhotPix.h"
|
|---|
| 66 |
|
|---|
| 67 | #include "MRawRunHeader.h"
|
|---|
| 68 | #include "MMcRunHeader.hxx"
|
|---|
| 69 | #include "MMcFadcHeader.hxx"
|
|---|
| 70 |
|
|---|
| 71 | ClassImp(MMcCalibrationUpdate);
|
|---|
| 72 |
|
|---|
| 73 | using namespace std;
|
|---|
| 74 |
|
|---|
| 75 | MMcCalibrationUpdate::MMcCalibrationUpdate(const char *name, const char *title)
|
|---|
| 76 | {
|
|---|
| 77 | fName = name ? name : "MMcCalibrationUpdate";
|
|---|
| 78 | fTitle = title ? title : "Write MC pedestals and conversion factors into MCalibration Container";
|
|---|
| 79 |
|
|---|
| 80 | fADC2PhInner = 1.;
|
|---|
| 81 | fADC2PhOuter = 1.;
|
|---|
| 82 |
|
|---|
| 83 | fAmplitude = -1.;
|
|---|
| 84 | fAmplitudeOuter = -1.;
|
|---|
| 85 | fConversionHiLo = -1.;
|
|---|
| 86 |
|
|---|
| 87 | fFillCalibrationCam = kTRUE;
|
|---|
| 88 | fOuterPixelsGainScaling = kTRUE;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | // --------------------------------------------------------------------------
|
|---|
| 92 | //
|
|---|
| 93 | // Check for the run type. Return kTRUE if it is a MC run or if there
|
|---|
| 94 | // is no MC run header (old camera files) kFALSE in case of a different
|
|---|
| 95 | // run type
|
|---|
| 96 | //
|
|---|
| 97 | Bool_t MMcCalibrationUpdate::CheckRunType(MParList *pList) const
|
|---|
| 98 | {
|
|---|
| 99 | const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
|---|
| 100 | if (!run)
|
|---|
| 101 | {
|
|---|
| 102 | *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
|
|---|
| 103 | return kTRUE;
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | return run->IsMonteCarloRun();
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | // --------------------------------------------------------------------------
|
|---|
| 110 | //
|
|---|
| 111 | // Make sure, that there is an MCalibrationCam Object in the Parameter List.
|
|---|
| 112 | //
|
|---|
| 113 | Int_t MMcCalibrationUpdate::PreProcess(MParList *pList)
|
|---|
| 114 | {
|
|---|
| 115 | fCalCam = (MCalibrationChargeCam*) pList->FindObject(AddSerialNumber("MCalibrationChargeCam"));
|
|---|
| 116 | if (!fCalCam)
|
|---|
| 117 | {
|
|---|
| 118 | fCalCam = (MCalibrationChargeCam*) pList->FindCreateObj(AddSerialNumber("MCalibrationChargeCam"));
|
|---|
| 119 | if (!fCalCam)
|
|---|
| 120 | return kFALSE;
|
|---|
| 121 | }
|
|---|
| 122 | else
|
|---|
| 123 | {
|
|---|
| 124 | fFillCalibrationCam = kFALSE;
|
|---|
| 125 | *fLog << inf << AddSerialNumber("MCalibrationChargeCam") << " already exists... " << endl;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | fQECam = (MCalibrationQECam*) pList->FindObject(AddSerialNumber("MCalibrationQECam"));
|
|---|
| 129 | if (!fQECam)
|
|---|
| 130 | {
|
|---|
| 131 | fQECam = (MCalibrationQECam*) pList->FindCreateObj(AddSerialNumber("MCalibrationQECam"));
|
|---|
| 132 | if (!fQECam)
|
|---|
| 133 | return kFALSE;
|
|---|
| 134 | }
|
|---|
| 135 | else
|
|---|
| 136 | {
|
|---|
| 137 | fFillQECam = kFALSE;
|
|---|
| 138 | *fLog << inf << AddSerialNumber("MCalibrationQECam") << " already exists... " << endl;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 | fPedPhotCam = (MPedPhotCam*) pList->FindCreateObj(AddSerialNumber("MPedPhotCam"));
|
|---|
| 143 | if (!fPedPhotCam)
|
|---|
| 144 | return kFALSE;
|
|---|
| 145 |
|
|---|
| 146 | fSignalCam = (MExtractedSignalCam*) pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
|
|---|
| 147 | if (!fSignalCam)
|
|---|
| 148 | {
|
|---|
| 149 | *fLog << err << AddSerialNumber("MExtractedSignalCam") << " not found... aborting." << endl;
|
|---|
| 150 | return kFALSE;
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | return kTRUE;
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | // --------------------------------------------------------------------------
|
|---|
| 157 | //
|
|---|
| 158 | // Check for the runtype.
|
|---|
| 159 | // Search for MGeomCam and MMcFadcHeader.
|
|---|
| 160 | // Fill the MCalibrationCam object.
|
|---|
| 161 | //
|
|---|
| 162 | Bool_t MMcCalibrationUpdate::ReInit(MParList *pList)
|
|---|
| 163 | {
|
|---|
| 164 | //
|
|---|
| 165 | // If it is no MC file skip this function...
|
|---|
| 166 | //
|
|---|
| 167 | if (!CheckRunType(pList))
|
|---|
| 168 | {
|
|---|
| 169 | *fLog << inf << "This is no MC file... skipping." << endl;
|
|---|
| 170 | return kTRUE;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | //
|
|---|
| 174 | // Now check the existence of all necessary containers.
|
|---|
| 175 | //
|
|---|
| 176 | fGeom = (MGeomCam*) pList->FindObject(AddSerialNumber("MGeomCam"));
|
|---|
| 177 | if (!fGeom)
|
|---|
| 178 | {
|
|---|
| 179 | *fLog << err << AddSerialNumber("MGeomCam") << " not found... aborting." << endl;
|
|---|
| 180 | return kFALSE;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | fHeaderFadc = (MMcFadcHeader*)pList->FindObject(AddSerialNumber("MMcFadcHeader"));
|
|---|
| 184 | if (!fHeaderFadc)
|
|---|
| 185 | {
|
|---|
| 186 | *fLog << err << AddSerialNumber("MMcFadcHeader") << " not found... aborting." << endl;
|
|---|
| 187 | return kFALSE;
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | MMcRunHeader* mcrunh = (MMcRunHeader*) pList->FindObject("MMcRunHeader");
|
|---|
| 191 |
|
|---|
| 192 | //
|
|---|
| 193 | // Initialize Fadc simulation parameters:
|
|---|
| 194 | //
|
|---|
| 195 | if (fAmplitude < 0)
|
|---|
| 196 | {
|
|---|
| 197 | fAmplitude = fHeaderFadc->GetAmplitud();
|
|---|
| 198 | if (mcrunh->GetCamVersion() > 60)
|
|---|
| 199 | {
|
|---|
| 200 | fAmplitudeOuter = fHeaderFadc->GetAmplitudOuter();
|
|---|
| 201 | fConversionHiLo = fHeaderFadc->GetLow2HighGain();
|
|---|
| 202 | }
|
|---|
| 203 | else // old MC files, camera < v0.7
|
|---|
| 204 | {
|
|---|
| 205 | fAmplitudeOuter = fAmplitude;
|
|---|
| 206 | fConversionHiLo = 1; // dummy value
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | }
|
|---|
| 210 | else // Check that following files have all the same FADC parameters
|
|---|
| 211 | {
|
|---|
| 212 | if ( fabs(fHeaderFadc->GetAmplitud()-fAmplitude) > 1.e-6 )
|
|---|
| 213 | {
|
|---|
| 214 | *fLog << err << "Parameters of MMcFadcHeader are not the same for all files... aborting." << endl;
|
|---|
| 215 | return kFALSE;
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | if (mcrunh->GetCamVersion() > 60) // old MC files, camera < v0.7
|
|---|
| 219 | {
|
|---|
| 220 | if( fabs(fHeaderFadc->GetAmplitudOuter()-fAmplitudeOuter) > 1.e-6 ||
|
|---|
| 221 | fabs(fConversionHiLo-fHeaderFadc->GetLow2HighGain()) > 1.e-6 )
|
|---|
| 222 | {
|
|---|
| 223 | *fLog << err << "Parameters of MMcFadcHeader are not the same for all files... aborting." << endl;
|
|---|
| 224 | return kFALSE;
|
|---|
| 225 | }
|
|---|
| 226 | }
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 | //
|
|---|
| 232 | // If MCalibrationCam already existed in the parameter list before
|
|---|
| 233 | // MMcCalibrationUpdate::PreProcess was executed (from a
|
|---|
| 234 | // previous calibration loop) we must not fill it, hence nothing
|
|---|
| 235 | // else has to be done in ReInit:
|
|---|
| 236 | //
|
|---|
| 237 | if (!fFillCalibrationCam)
|
|---|
| 238 | return kTRUE;
|
|---|
| 239 |
|
|---|
| 240 | //
|
|---|
| 241 | // Set the ADC to photons conversion factor for outer pixels.
|
|---|
| 242 | // One can choose not to apply the known (in MC) gain factor between
|
|---|
| 243 | // inner and outer pixels, (fOuterPixelsGainScaling = kFALSE),
|
|---|
| 244 | // which may be useful for display purposes.
|
|---|
| 245 | //
|
|---|
| 246 |
|
|---|
| 247 | if (fOuterPixelsGainScaling)
|
|---|
| 248 | fADC2PhOuter = fADC2PhInner * (fAmplitude / fAmplitudeOuter);
|
|---|
| 249 | else
|
|---|
| 250 | fADC2PhOuter = fADC2PhInner;
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 | const int num = fCalCam->GetSize();
|
|---|
| 254 |
|
|---|
| 255 | fCalCam->SetFFactorMethodValid ( kTRUE );
|
|---|
| 256 | fQECam->SetFFactorMethodValid ( kTRUE );
|
|---|
| 257 | fQECam->SetBlindPixelMethodValid ( kTRUE );
|
|---|
| 258 | fQECam->SetCombinedMethodValid ( kTRUE );
|
|---|
| 259 | fQECam->SetPINDiodeMethodValid ( kTRUE );
|
|---|
| 260 |
|
|---|
| 261 | for (int i=0; i<num; i++)
|
|---|
| 262 | {
|
|---|
| 263 | MCalibrationChargePix &calpix = (MCalibrationChargePix&)(*fCalCam)[i];
|
|---|
| 264 |
|
|---|
| 265 | calpix.SetFFactorMethodValid();
|
|---|
| 266 |
|
|---|
| 267 | calpix.SetConversionHiLo(fConversionHiLo);
|
|---|
| 268 | calpix.SetConversionHiLoErr(0.); // FIXME ?
|
|---|
| 269 |
|
|---|
| 270 | //
|
|---|
| 271 | // Write conversion factor ADC to photo-electrons (different for inner
|
|---|
| 272 | // and outer pixels).
|
|---|
| 273 | //
|
|---|
| 274 | Float_t adc2phot = (fGeom->GetPixRatio(i) < fGeom->GetPixRatio(0))?
|
|---|
| 275 | fADC2PhOuter : fADC2PhInner;
|
|---|
| 276 |
|
|---|
| 277 | //
|
|---|
| 278 | // FIXME: This has now to be split into a adc2phe part and a phe2phot (==QE) part
|
|---|
| 279 | //
|
|---|
| 280 | const Float_t qe = MCalibrationQEPix::gkDefaultAverageQE;
|
|---|
| 281 | calpix.SetMeanConvFADC2Phe(adc2phot*qe); // here, the FADC to phe part should go.
|
|---|
| 282 | calpix.SetMeanConvFADC2PheVar(0.);
|
|---|
| 283 | calpix.SetMeanFFactorFADC2Phot(0.);
|
|---|
| 284 |
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 | return kTRUE;
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 | // --------------------------------------------------------------------------
|
|---|
| 293 | //
|
|---|
| 294 | // Fill the MCerPhotPed object
|
|---|
| 295 | //
|
|---|
| 296 | Int_t MMcCalibrationUpdate::Process()
|
|---|
| 297 | {
|
|---|
| 298 | const int num = fCalCam->GetSize();
|
|---|
| 299 |
|
|---|
| 300 | for (int i=0; i<num; i++)
|
|---|
| 301 | {
|
|---|
| 302 | MExtractedSignalPix &sigpix = (*fSignalCam)[i];
|
|---|
| 303 |
|
|---|
| 304 | //
|
|---|
| 305 | // ped mean and rms per pixel, in ADC counts, according to signal
|
|---|
| 306 | // calculation (hi or low gain and number of integrated slices):
|
|---|
| 307 | //
|
|---|
| 308 | const Float_t pedestmean = sigpix.IsLoGainUsed()?
|
|---|
| 309 | fSignalCam->GetNumUsedLoGainFADCSlices()*fHeaderFadc->GetPedestal(i) :
|
|---|
| 310 | fSignalCam->GetNumUsedHiGainFADCSlices()*fHeaderFadc->GetPedestal(i);
|
|---|
| 311 |
|
|---|
| 312 | //
|
|---|
| 313 | // In some cases, depending on the camera simulation parameters, one can
|
|---|
| 314 | // have very little or no noise in the FADC. In the case the rms of
|
|---|
| 315 | // pedestal is zero, the pixel will be cleaned out later in the image
|
|---|
| 316 | // cleaning. To avoid this problem,we set a default value of 0.01 ADC
|
|---|
| 317 | // counts for the RMS per slice:
|
|---|
| 318 | //
|
|---|
| 319 | const Double_t used = (Double_t)(sigpix.IsLoGainUsed() ?
|
|---|
| 320 | fSignalCam->GetNumUsedLoGainFADCSlices() :
|
|---|
| 321 | fSignalCam->GetNumUsedHiGainFADCSlices());
|
|---|
| 322 |
|
|---|
| 323 | const Float_t rms0 = sigpix.IsLoGainUsed() ?
|
|---|
| 324 | fHeaderFadc->GetPedestalRmsLow(i) :
|
|---|
| 325 | fHeaderFadc->GetPedestalRmsHigh(i);
|
|---|
| 326 |
|
|---|
| 327 | const Float_t pedestrms = TMath::Sqrt(used) * (rms0>0 ? rms0 : 0.01);
|
|---|
| 328 |
|
|---|
| 329 | //
|
|---|
| 330 | // Write mean pedestal and pedestal rms per pixel
|
|---|
| 331 | // in number of photons:
|
|---|
| 332 | //
|
|---|
| 333 | MPedPhotPix &pedpix = (*fPedPhotCam)[i];
|
|---|
| 334 |
|
|---|
| 335 | MCalibrationChargePix &calpix = (MCalibrationChargePix&)(*fCalCam)[i];
|
|---|
| 336 | // MCalibrationQEPix &qepix = (MCalibrationQEPix&) (*fQECam) [i];
|
|---|
| 337 |
|
|---|
| 338 | Float_t qe = MCalibrationQEPix::gkDefaultAverageQE;
|
|---|
| 339 | Float_t adc2phot = calpix.GetMeanConvFADC2Phe() / qe;
|
|---|
| 340 | Float_t hi2lo = calpix.GetConversionHiLo();
|
|---|
| 341 |
|
|---|
| 342 | if (sigpix.IsLoGainUsed())
|
|---|
| 343 | pedpix.Set(adc2phot*hi2lo*pedestmean, adc2phot*hi2lo*pedestrms);
|
|---|
| 344 | else
|
|---|
| 345 | pedpix.Set(adc2phot*pedestmean, adc2phot*pedestrms);
|
|---|
| 346 |
|
|---|
| 347 | }
|
|---|
| 348 |
|
|---|
| 349 | return kTRUE;
|
|---|
| 350 | }
|
|---|