| 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 "MCalibrationPix.h"
|
|---|
| 56 | #include "MCalibrationCam.h"
|
|---|
| 57 | #include "MExtractedSignalCam.h"
|
|---|
| 58 | #include "MExtractedSignalPix.h"
|
|---|
| 59 | #include "MGeomCam.h"
|
|---|
| 60 | #include "MPedPhotCam.h"
|
|---|
| 61 | #include "MPedPhotPix.h"
|
|---|
| 62 |
|
|---|
| 63 | #include "MRawRunHeader.h"
|
|---|
| 64 | #include "MMcFadcHeader.hxx"
|
|---|
| 65 |
|
|---|
| 66 | ClassImp(MMcCalibrationUpdate);
|
|---|
| 67 |
|
|---|
| 68 | using namespace std;
|
|---|
| 69 |
|
|---|
| 70 | MMcCalibrationUpdate::MMcCalibrationUpdate(const char *name, const char *title)
|
|---|
| 71 | {
|
|---|
| 72 | fName = name ? name : "MMcCalibrationUpdate";
|
|---|
| 73 | fTitle = title ? title : "Write MC pedestals and conversion factors into MCalibration Container";
|
|---|
| 74 |
|
|---|
| 75 | fADC2PhInner = 1.;
|
|---|
| 76 | fADC2PhOuter = 1.;
|
|---|
| 77 |
|
|---|
| 78 | fAmplitude = -1.;
|
|---|
| 79 | fAmplitudeOuter = -1.;
|
|---|
| 80 | fConversionHiLo = -1.;
|
|---|
| 81 |
|
|---|
| 82 | fFillCalibrationCam = kTRUE;
|
|---|
| 83 |
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | // --------------------------------------------------------------------------
|
|---|
| 87 | //
|
|---|
| 88 | // Check for the run type. Return kTRUE if it is a MC run or if there
|
|---|
| 89 | // is no MC run header (old camera files) kFALSE in case of a different
|
|---|
| 90 | // run type
|
|---|
| 91 | //
|
|---|
| 92 | Bool_t MMcCalibrationUpdate::CheckRunType(MParList *pList) const
|
|---|
| 93 | {
|
|---|
| 94 | const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
|---|
| 95 | if (!run)
|
|---|
| 96 | {
|
|---|
| 97 | *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
|
|---|
| 98 | return kTRUE;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | return run->GetRunType() == kRTMonteCarlo;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | // --------------------------------------------------------------------------
|
|---|
| 105 | //
|
|---|
| 106 | // Make sure, that there is an MCalibrationCam Object in the Parameter List.
|
|---|
| 107 | //
|
|---|
| 108 | Int_t MMcCalibrationUpdate::PreProcess(MParList *pList)
|
|---|
| 109 | {
|
|---|
| 110 | fCalCam = (MCalibrationCam*) pList->FindObject(AddSerialNumber("MCalibrationCam"));
|
|---|
| 111 | if ( !fCalCam )
|
|---|
| 112 | {
|
|---|
| 113 | *fLog << inf << dbginf << AddSerialNumber("MCalibrationCam") << " does not exist... Creating." << endl;
|
|---|
| 114 |
|
|---|
| 115 | fCalCam = (MCalibrationCam*) pList->FindCreateObj(AddSerialNumber("MCalibrationCam"));
|
|---|
| 116 | if ( !fCalCam )
|
|---|
| 117 | {
|
|---|
| 118 | *fLog << err << dbginf << "Cannot create " << AddSerialNumber("MCalibrationCam") << "... aborting." << endl;
|
|---|
| 119 | return kFALSE;
|
|---|
| 120 | }
|
|---|
| 121 | }
|
|---|
| 122 | else
|
|---|
| 123 | {
|
|---|
| 124 | fFillCalibrationCam = kFALSE;
|
|---|
| 125 | *fLog << inf << AddSerialNumber("MCalibrationCam") << " already exists... " << endl;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | fPedPhotCam = (MPedPhotCam*) pList->FindCreateObj(AddSerialNumber("MPedPhotCam"));
|
|---|
| 129 | if ( ! fPedPhotCam)
|
|---|
| 130 | {
|
|---|
| 131 | *fLog << err << dbginf << "Cannot create " << AddSerialNumber("MPedPhotCam") << "... aborting." << endl;
|
|---|
| 132 | return kFALSE;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | fSignalCam = (MExtractedSignalCam*) pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
|
|---|
| 136 | if ( ! fSignalCam)
|
|---|
| 137 | {
|
|---|
| 138 | *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MExtractedSignalCam") << "... aborting." << endl;
|
|---|
| 139 | return kFALSE;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | return kTRUE;
|
|---|
| 143 |
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | // --------------------------------------------------------------------------
|
|---|
| 147 | //
|
|---|
| 148 | // Check for the runtype.
|
|---|
| 149 | // Search for MGeomCam and MMcFadcHeader.
|
|---|
| 150 | // Fill the MCalibrationCam object.
|
|---|
| 151 | //
|
|---|
| 152 | Bool_t MMcCalibrationUpdate::ReInit(MParList *pList)
|
|---|
| 153 | {
|
|---|
| 154 | //
|
|---|
| 155 | // If it is no MC file skip this function...
|
|---|
| 156 | //
|
|---|
| 157 | if (!CheckRunType(pList))
|
|---|
| 158 | {
|
|---|
| 159 | *fLog << inf << "This is no MC file... skipping." << endl;
|
|---|
| 160 | return kTRUE;
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | //
|
|---|
| 164 | // Now check the existence of all necessary containers.
|
|---|
| 165 | //
|
|---|
| 166 |
|
|---|
| 167 | fGeom = (MGeomCam*) pList->FindObject(AddSerialNumber("MGeomCam"));
|
|---|
| 168 | if ( ! fGeom )
|
|---|
| 169 | {
|
|---|
| 170 | *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MGeomCam") << "... aborting." << endl;
|
|---|
| 171 | return kFALSE;
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | fHeaderFadc = (MMcFadcHeader*)pList->FindObject(AddSerialNumber("MMcFadcHeader"));
|
|---|
| 175 | if (!fHeaderFadc)
|
|---|
| 176 | {
|
|---|
| 177 | *fLog << err << dbginf << AddSerialNumber("MMcFadcHeader") << " not found... aborting." << endl;
|
|---|
| 178 | return kFALSE;
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | //
|
|---|
| 182 | // Initialize Fadc simulation parameters:
|
|---|
| 183 | //
|
|---|
| 184 | if ( fAmplitude < 0. )
|
|---|
| 185 | {
|
|---|
| 186 | fAmplitude = fHeaderFadc->GetAmplitud();
|
|---|
| 187 | fAmplitudeOuter = fHeaderFadc->GetAmplitudOuter();
|
|---|
| 188 | fConversionHiLo = fHeaderFadc->GetLow2HighGain();
|
|---|
| 189 | }
|
|---|
| 190 | else // Check that following files have all the same FADC parameters
|
|---|
| 191 | {
|
|---|
| 192 | if ( fabs(fHeaderFadc->GetAmplitud()-fAmplitude) > 1.e-6 ||
|
|---|
| 193 | fabs(fHeaderFadc->GetAmplitudOuter()-fAmplitudeOuter) > 1.e-6 ||
|
|---|
| 194 | fabs(fConversionHiLo-fHeaderFadc->GetLow2HighGain()) > 1.e-6 )
|
|---|
| 195 | {
|
|---|
| 196 | *fLog << err << endl << endl << dbginf << "Parameters of MMcFadcHeader are not the same for all the read files. Aborting..." << endl << endl;
|
|---|
| 197 | return kFALSE;
|
|---|
| 198 | }
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | //
|
|---|
| 202 | // If MCalibrationCam already existed in the parameter list before
|
|---|
| 203 | // MMcCalibrationUpdate::PreProcess was executed (from a
|
|---|
| 204 | // previous calibration loop) we must not fill it, hence nothing
|
|---|
| 205 | // else has to be done in ReInit:
|
|---|
| 206 | //
|
|---|
| 207 | if ( !fFillCalibrationCam )
|
|---|
| 208 | return kTRUE;
|
|---|
| 209 |
|
|---|
| 210 | //
|
|---|
| 211 | // Set the ADC to photons conversion factor for outer pixels:
|
|---|
| 212 | //
|
|---|
| 213 | fADC2PhOuter = fADC2PhInner * (fAmplitude / fAmplitudeOuter);
|
|---|
| 214 |
|
|---|
| 215 | const int num = fCalCam->GetSize();
|
|---|
| 216 |
|
|---|
| 217 | fCalCam->SetBlindPixelMethodValid(kTRUE);
|
|---|
| 218 |
|
|---|
| 219 | for (int i=0; i<num; i++)
|
|---|
| 220 | {
|
|---|
| 221 | MCalibrationPix &calpix = (*fCalCam)[i];
|
|---|
| 222 |
|
|---|
| 223 | calpix.SetBlindPixelMethodValid();
|
|---|
| 224 | calpix.SetChargeFitValid();
|
|---|
| 225 | calpix.SetTimeFitValid();
|
|---|
| 226 |
|
|---|
| 227 | calpix.SetConversionHiLo(fConversionHiLo);
|
|---|
| 228 | calpix.SetConversionHiLoError(0.); // FIXME ?
|
|---|
| 229 |
|
|---|
| 230 | //
|
|---|
| 231 | // Write conversion factor ADC to photons (different for inner
|
|---|
| 232 | // and outer pixels).
|
|---|
| 233 | //
|
|---|
| 234 |
|
|---|
| 235 | Float_t adc2phot = (fGeom->GetPixRatio(i) < fGeom->GetPixRatio(0))?
|
|---|
| 236 | fADC2PhOuter : fADC2PhInner;
|
|---|
| 237 |
|
|---|
| 238 | calpix.SetConversionBlindPixelMethod(adc2phot, 0., 0.);
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 | return kTRUE;
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 | // --------------------------------------------------------------------------
|
|---|
| 247 | //
|
|---|
| 248 | // Fill the MCerPhotPed object
|
|---|
| 249 | //
|
|---|
| 250 | Int_t MMcCalibrationUpdate::Process()
|
|---|
| 251 | {
|
|---|
| 252 | const int num = fCalCam->GetSize();
|
|---|
| 253 |
|
|---|
| 254 | for (int i=0; i<num; i++)
|
|---|
| 255 | {
|
|---|
| 256 | MExtractedSignalPix &sigpix = (*fSignalCam)[i];
|
|---|
| 257 |
|
|---|
| 258 | //
|
|---|
| 259 | // ped mean and rms per pixel, in ADC counts, according to signal
|
|---|
| 260 | // calculation (hi or low gain and number of integrated slices):
|
|---|
| 261 | //
|
|---|
| 262 | const Float_t pedestmean = sigpix.IsLoGainUsed()?
|
|---|
| 263 | fSignalCam->GetNumUsedLoGainFADCSlices()*fHeaderFadc->GetPedestal(i) :
|
|---|
| 264 | fSignalCam->GetNumUsedHiGainFADCSlices()*fHeaderFadc->GetPedestal(i);
|
|---|
| 265 |
|
|---|
| 266 | //
|
|---|
| 267 | // In some cases, depending on the camera simulation parameters, one can
|
|---|
| 268 | // have very little or no noise in the FADC. In the case the rms of
|
|---|
| 269 | // pedestal is zero, the pixel will be cleaned out later in the image
|
|---|
| 270 | // cleaning. To avoid this problem,we set a default value of 0.01 ADC
|
|---|
| 271 | // counts for the RMS per slice:
|
|---|
| 272 | //
|
|---|
| 273 |
|
|---|
| 274 | const Float_t pedestrms = sigpix.IsLoGainUsed()?
|
|---|
| 275 | sqrt((Double_t)(fSignalCam->GetNumUsedLoGainFADCSlices())) *
|
|---|
| 276 | (fHeaderFadc->GetPedestalRmsLow(i)>0.? fHeaderFadc->GetPedestalRmsLow(i): 0.01)
|
|---|
| 277 | :
|
|---|
| 278 | sqrt((Double_t)(fSignalCam->GetNumUsedHiGainFADCSlices())) *
|
|---|
| 279 | (fHeaderFadc->GetPedestalRmsHigh(i)>0.? fHeaderFadc->GetPedestalRmsHigh(i) : 0.01);
|
|---|
| 280 |
|
|---|
| 281 | //
|
|---|
| 282 | // Write mean pedestal and pedestal rms per pixel
|
|---|
| 283 | // in number of photons:
|
|---|
| 284 | //
|
|---|
| 285 | MPedPhotPix &pedpix = (*fPedPhotCam)[i];
|
|---|
| 286 |
|
|---|
| 287 | MCalibrationPix &calpix = (*fCalCam)[i];
|
|---|
| 288 | Float_t adc2phot = calpix.GetMeanConversionBlindPixelMethod();
|
|---|
| 289 | Float_t hi2lo = calpix.GetConversionHiLo();
|
|---|
| 290 |
|
|---|
| 291 | if (sigpix.IsLoGainUsed())
|
|---|
| 292 | pedpix.Set(adc2phot*hi2lo*pedestmean,
|
|---|
| 293 | adc2phot*hi2lo*pedestrms);
|
|---|
| 294 | else
|
|---|
| 295 | pedpix.Set(adc2phot*pedestmean, adc2phot*pedestrms);
|
|---|
| 296 |
|
|---|
| 297 | }
|
|---|
| 298 |
|
|---|
| 299 | return kTRUE;
|
|---|
| 300 | }
|
|---|