| 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): Markus Gaug 01/2004 <mailto:markus@ifae.es>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MExtractPedestal
|
|---|
| 28 | //
|
|---|
| 29 | // Pedestal Extractor base class
|
|---|
| 30 | //
|
|---|
| 31 | // Input Containers:
|
|---|
| 32 | // MRawEvtData
|
|---|
| 33 | // MRawRunHeader
|
|---|
| 34 | // MRawEvtHeader
|
|---|
| 35 | // MGeomCam
|
|---|
| 36 | // MPedestalCam
|
|---|
| 37 | //
|
|---|
| 38 | // Output Containers:
|
|---|
| 39 | // MPedestalCam
|
|---|
| 40 | //
|
|---|
| 41 | // This class should be used for pedestal extractors with the following facilities:
|
|---|
| 42 | // a) Standardized calculation of AB-noise, mean pedestals and RMS
|
|---|
| 43 | // b) Standardized treatment of area- and sector averaged pedestals values
|
|---|
| 44 | // c) Possibility to use a signal extractor to be applied on the pedestals
|
|---|
| 45 | // d) Possibility to handle two MPedestalCams: one for the signal extractor and
|
|---|
| 46 | // a second to be filled during the pedestal calculating process.
|
|---|
| 47 | //
|
|---|
| 48 | // ad a): Every calculated value is referred to one FADC slice (e.g. Mean pedestal per slice),
|
|---|
| 49 | // RMS per slice.
|
|---|
| 50 | // MExtractPedestal applies the following formula (1):
|
|---|
| 51 | //
|
|---|
| 52 | // Pedestal per slice = sum(x_i) / n / slices
|
|---|
| 53 | // PedRMS per slice = Sqrt( ( sum(x_i^2) - sum(x_i)^2/n ) / n-1 / slices )
|
|---|
| 54 | // AB-Offset per slice = (sumAB0 - sumAB1) / n / slices
|
|---|
| 55 | //
|
|---|
| 56 | // where x_i is the sum of "slices" FADC slices and sum means the sum over all
|
|---|
| 57 | // events. "n" is the number of events, "slices" is the number of summed FADC samples.
|
|---|
| 58 | //
|
|---|
| 59 | // Note that the slice-to-slice fluctuations are not Gaussian, but Poissonian, thus
|
|---|
| 60 | // asymmetric and they are correlated.
|
|---|
| 61 | //
|
|---|
| 62 | // It is important to know that the Pedestal per slice and PedRMS per slice depend
|
|---|
| 63 | // on the number of used FADC slices, as seen in the following plots:
|
|---|
| 64 | //
|
|---|
| 65 | //Begin_Html
|
|---|
| 66 | /*
|
|---|
| 67 | <img src="images/PedestalStudyInner.gif">
|
|---|
| 68 | */
|
|---|
| 69 | //End_Html
|
|---|
| 70 | //
|
|---|
| 71 | //Begin_Html
|
|---|
| 72 | /*
|
|---|
| 73 | <img src="images/PedestalStudyOuter.gif">
|
|---|
| 74 | */
|
|---|
| 75 | //End_Html
|
|---|
| 76 | //
|
|---|
| 77 | // The plots show the inner and outer pixels, respectivly and have the following meaning:
|
|---|
| 78 | //
|
|---|
| 79 | // 1) The calculated mean pedestal per slice (from MPedCalcPedRun)
|
|---|
| 80 | // 2) The fitted mean pedestal per slice (from MHPedestalCam)
|
|---|
| 81 | // 3) The calculated pedestal RMS per slice (from MPedCalcPedRun)
|
|---|
| 82 | // 4) The fitted sigma of the pedestal distribution per slice
|
|---|
| 83 | // (from MHPedestalCam)
|
|---|
| 84 | // 5) The relative difference between calculation and histogram fit
|
|---|
| 85 | // for the mean
|
|---|
| 86 | // 6) The relative difference between calculation and histogram fit
|
|---|
| 87 | // for the sigma or RMS, respectively.
|
|---|
| 88 | //
|
|---|
| 89 | // The calculated means do not change significantly except for the case of 2 slices,
|
|---|
| 90 | // however the RMS changes from 5.7 per slice in the case of 2 extracted slices
|
|---|
| 91 | // to 8.3 per slice in the case of 26 extracted slices. This change is very significant.
|
|---|
| 92 | //
|
|---|
| 93 | // ad b) Every calculated value is referred to one FADC slice and one (averaged) pixel,
|
|---|
| 94 | // (e.g. Mean Pedestal per area index per slice per pixel, etc. )
|
|---|
| 95 | //
|
|---|
| 96 | // MExtractPedestal applies the following formula (2):
|
|---|
| 97 | //
|
|---|
| 98 | // Averaged Pedestal per slice = sum(x_i) / n / slices / n_pix
|
|---|
| 99 | // PedRMS per slice = Sqrt( ( sum(x_i^2) - sum(x_i)^2/n ) / n-1 / slices / n_pix )
|
|---|
| 100 | // AB-Offset per slice = (sumAB0 - sumAB1) / n / slices / n_pix
|
|---|
| 101 | //
|
|---|
| 102 | // where x_i is the sum of "slices" FADC slices and sum means the sum over all
|
|---|
| 103 | // events and all concerned pixels.
|
|---|
| 104 | // "n" is the number of events, "slices" is the number of summed FADC samples and
|
|---|
| 105 | // "n_pix" is the number of pixels belonging to the specific area index or camera sector.
|
|---|
| 106 | //
|
|---|
| 107 | // Calculating these averaged event-by-event values is very important to trace coherent
|
|---|
| 108 | // fluctuations. An example is given in the following plots:
|
|---|
| 109 | //
|
|---|
| 110 | //Begin_Html
|
|---|
| 111 | /*
|
|---|
| 112 | <img src="images/PedestalOscillations.gif">
|
|---|
| 113 | */
|
|---|
| 114 | //End_Html
|
|---|
| 115 | //
|
|---|
| 116 | // The plots show the extracted pedestals of the inner pixels (obtained
|
|---|
| 117 | // with MHPedestalCam), averaged on an event-by-event basis from
|
|---|
| 118 | // run 13428 with switched off camera LV.
|
|---|
| 119 | // The meaning of the four plots is:
|
|---|
| 120 | //
|
|---|
| 121 | // 1) The distribution of the averaged pedestals
|
|---|
| 122 | // 2) The averaged pedestals vs. time.
|
|---|
| 123 | // One can see clearly the oscillation pattern
|
|---|
| 124 | // 3) The fourier transform of the averaged pedestals vs. time.
|
|---|
| 125 | // One can see clearly a peak at a certain frequency
|
|---|
| 126 | // 4) The projection of the fourier components with the non-exponential
|
|---|
| 127 | // (and therefore significant) outlier.
|
|---|
| 128 | //
|
|---|
| 129 | // ad c) Many signal extractors, especially those using a sliding window
|
|---|
| 130 | // have biases and their resolutions for zero-signals do not agree
|
|---|
| 131 | // with the pedestal RMS. For the F-Factor method in the calibration
|
|---|
| 132 | // and the image cleaning, however, both have to be known and measured.
|
|---|
| 133 | //
|
|---|
| 134 | // For this reason, a signal extractor can be handed over to the
|
|---|
| 135 | // pedestal extractor and applied on the pedestal events with the
|
|---|
| 136 | // function SetExtractor().
|
|---|
| 137 | // The results will get stored in an MPedestalCam.
|
|---|
| 138 | //
|
|---|
| 139 | // Note that only extractors deriving from MExtractTimeAndCharge
|
|---|
| 140 | // can be used.
|
|---|
| 141 | //
|
|---|
| 142 | // ad d) The signal extractors themselves need a pedestal to be subtracted
|
|---|
| 143 | // from the FADC slices.
|
|---|
| 144 | // If the user wishes that the pededestals do not get overwritten by
|
|---|
| 145 | // the results from the signal extractor, a different named MPedestalCam
|
|---|
| 146 | // can be created with the function: SetNamePedestalOut().
|
|---|
| 147 | //
|
|---|
| 148 | // See also: MPedestalCam, MPedestalPix, MPedCalcPedRun, MPedCalcFromLoGain
|
|---|
| 149 | //
|
|---|
| 150 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 151 | #include "MExtractPedestal.h"
|
|---|
| 152 |
|
|---|
| 153 | #include "MParList.h"
|
|---|
| 154 |
|
|---|
| 155 | #include "MLog.h"
|
|---|
| 156 | #include "MLogManip.h"
|
|---|
| 157 |
|
|---|
| 158 | #include "MRawRunHeader.h"
|
|---|
| 159 | #include "MRawEvtHeader.h"
|
|---|
| 160 | #include "MRawEvtPixelIter.h"
|
|---|
| 161 | #include "MRawEvtData.h"
|
|---|
| 162 |
|
|---|
| 163 | #include "MPedestalPix.h"
|
|---|
| 164 | #include "MPedestalCam.h"
|
|---|
| 165 |
|
|---|
| 166 | #include "MGeomPix.h"
|
|---|
| 167 | #include "MGeomCam.h"
|
|---|
| 168 |
|
|---|
| 169 | #include "MTaskEnv.h"
|
|---|
| 170 | #include "MExtractTimeAndCharge.h"
|
|---|
| 171 |
|
|---|
| 172 | ClassImp(MExtractPedestal);
|
|---|
| 173 |
|
|---|
| 174 | using namespace std;
|
|---|
| 175 |
|
|---|
| 176 | const TString MExtractPedestal::fgNamePedestalCam = "MPedestalCam";
|
|---|
| 177 |
|
|---|
| 178 | // --------------------------------------------------------------------------
|
|---|
| 179 | //
|
|---|
| 180 | // Default constructor:
|
|---|
| 181 | //
|
|---|
| 182 | // Sets:
|
|---|
| 183 | // - all pointers to NULL
|
|---|
| 184 | //
|
|---|
| 185 | // Calls:
|
|---|
| 186 | // - AddToBranchList("fHiGainPixId");
|
|---|
| 187 | // - AddToBranchList("fHiGainFadcSamples");
|
|---|
| 188 | // - Clear()
|
|---|
| 189 | //
|
|---|
| 190 | MExtractPedestal::MExtractPedestal(const char *name, const char *title)
|
|---|
| 191 | : fRandomCalculation(kTRUE), fGeom(NULL), fPedestalsIn(NULL), fPedestalsOut(NULL),
|
|---|
| 192 | fExtractor(NULL), fExtractWinFirst(0), fExtractWinSize(0)
|
|---|
| 193 | {
|
|---|
| 194 | fName = name ? name : "MExtractPedestal";
|
|---|
| 195 | fTitle = title ? title : "Base class to calculate pedestals";
|
|---|
| 196 |
|
|---|
| 197 | AddToBranchList("fHiGainPixId");
|
|---|
| 198 | AddToBranchList("fLoGainPixId");
|
|---|
| 199 | AddToBranchList("fHiGainFadcSamples");
|
|---|
| 200 | AddToBranchList("fLoGainFadcSamples");
|
|---|
| 201 |
|
|---|
| 202 | SetPedestalUpdate(kTRUE);
|
|---|
| 203 |
|
|---|
| 204 | SetNamePedestalCamIn();
|
|---|
| 205 | SetNamePedestalCamOut();
|
|---|
| 206 | SetNumDump();
|
|---|
| 207 |
|
|---|
| 208 | Clear();
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | void MExtractPedestal::ResetArrays()
|
|---|
| 212 | {
|
|---|
| 213 | // Reset contents of arrays.
|
|---|
| 214 | fSumx.Reset();
|
|---|
| 215 | fSumx2.Reset();
|
|---|
| 216 | fSumAB0.Reset();
|
|---|
| 217 | fSumAB1.Reset();
|
|---|
| 218 | fAreaSumx.Reset();
|
|---|
| 219 | fAreaSumx2.Reset();
|
|---|
| 220 | fAreaSumAB0.Reset();
|
|---|
| 221 | fAreaSumAB1.Reset();
|
|---|
| 222 | fAreaFilled.Reset();
|
|---|
| 223 | fAreaValid.Reset();
|
|---|
| 224 | fSectorSumx.Reset();
|
|---|
| 225 | fSectorSumx2.Reset();
|
|---|
| 226 | fSectorSumAB0.Reset();
|
|---|
| 227 | fSectorSumAB1.Reset();
|
|---|
| 228 | fSectorFilled.Reset();
|
|---|
| 229 | fSectorValid.Reset();
|
|---|
| 230 |
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | // --------------------------------------------------------------------------
|
|---|
| 234 | //
|
|---|
| 235 | // Resets Arrays:
|
|---|
| 236 | //
|
|---|
| 237 | // Sets:
|
|---|
| 238 | // - fRawEvt to NULL
|
|---|
| 239 | // - fRunHeader to NULL
|
|---|
| 240 | // - fEvtHeader to NULL
|
|---|
| 241 | // - fPedestalsIn to NULL
|
|---|
| 242 | // - fPedestalsOut to NULL
|
|---|
| 243 | //
|
|---|
| 244 | void MExtractPedestal::Clear(const Option_t *o)
|
|---|
| 245 | {
|
|---|
| 246 |
|
|---|
| 247 | fRawEvt = NULL;
|
|---|
| 248 | fRunHeader = NULL;
|
|---|
| 249 | fEvtHeader = NULL;
|
|---|
| 250 |
|
|---|
| 251 | // If the size is yet set, set the size
|
|---|
| 252 | if (fSumx.GetSize()>0)
|
|---|
| 253 | ResetArrays();
|
|---|
| 254 |
|
|---|
| 255 | }
|
|---|
| 256 |
|
|---|
| 257 | // --------------------------------------------------------------------------
|
|---|
| 258 | //
|
|---|
| 259 | // Checks:
|
|---|
| 260 | // - if a window is odd
|
|---|
| 261 | //
|
|---|
| 262 | Bool_t MExtractPedestal::SetExtractWindow(UShort_t windowf, UShort_t windows)
|
|---|
| 263 | {
|
|---|
| 264 |
|
|---|
| 265 | Bool_t rc = kTRUE;
|
|---|
| 266 |
|
|---|
| 267 | const Int_t odd = windows & 0x1;
|
|---|
| 268 |
|
|---|
| 269 | if (odd)
|
|---|
| 270 | {
|
|---|
| 271 | *fLog << warn << GetDescriptor();
|
|---|
| 272 | *fLog << " - WARNING: Window size in SetExtraxtWindow has to be even... ";
|
|---|
| 273 | *fLog << " raising from " << windows << " to ";
|
|---|
| 274 | windows += 1;
|
|---|
| 275 | *fLog << windows << "!" << endl;
|
|---|
| 276 | rc = kFALSE;
|
|---|
| 277 | }
|
|---|
| 278 |
|
|---|
| 279 | if (windows==0)
|
|---|
| 280 | {
|
|---|
| 281 | *fLog << warn << GetDescriptor();
|
|---|
| 282 | *fLog << " - WARNING: Window size in SetExtraxtWindow has to be > 0... adjusting to 2!" << endl;
|
|---|
| 283 | windows = 2;
|
|---|
| 284 | rc = kFALSE;
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | fExtractWinSize = windows;
|
|---|
| 288 | fExtractWinFirst = windowf;
|
|---|
| 289 | fExtractWinLast = fExtractWinFirst+fExtractWinSize-1;
|
|---|
| 290 |
|
|---|
| 291 | return rc;
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 | // --------------------------------------------------------------------------
|
|---|
| 295 | //
|
|---|
| 296 | // Look for the following input containers:
|
|---|
| 297 | //
|
|---|
| 298 | // - MRawEvtData
|
|---|
| 299 | // - MRawRunHeader
|
|---|
| 300 | // - MRawEvtHeader
|
|---|
| 301 | // - MGeomCam
|
|---|
| 302 | //
|
|---|
| 303 | // The following output containers are also searched and created if
|
|---|
| 304 | // they were not found:
|
|---|
| 305 | //
|
|---|
| 306 | // - MPedestalCam with the name fPedContainerName
|
|---|
| 307 | //
|
|---|
| 308 | Int_t MExtractPedestal::PreProcess(MParList *pList)
|
|---|
| 309 | {
|
|---|
| 310 |
|
|---|
| 311 | Clear();
|
|---|
| 312 |
|
|---|
| 313 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
|
|---|
| 314 | if (!fRawEvt)
|
|---|
| 315 | {
|
|---|
| 316 | *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
|
|---|
| 317 | return kFALSE;
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 | fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
|
|---|
| 321 | if (!fRunHeader)
|
|---|
| 322 | {
|
|---|
| 323 | *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
|
|---|
| 324 | return kFALSE;
|
|---|
| 325 | }
|
|---|
| 326 |
|
|---|
| 327 | fEvtHeader = (MRawEvtHeader*)pList->FindObject(AddSerialNumber("MRawEvtHeader"));
|
|---|
| 328 | if (!fEvtHeader)
|
|---|
| 329 | {
|
|---|
| 330 | *fLog << err << AddSerialNumber("MRawEvtHeader") << " not found... aborting." << endl;
|
|---|
| 331 | return kFALSE;
|
|---|
| 332 | }
|
|---|
| 333 |
|
|---|
| 334 | fGeom = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
|
|---|
| 335 | if (!fGeom)
|
|---|
| 336 | {
|
|---|
| 337 | *fLog << err << AddSerialNumber("MGeomCam") << " not found... aborting." << endl;
|
|---|
| 338 | return kFALSE;
|
|---|
| 339 | }
|
|---|
| 340 |
|
|---|
| 341 | if (fExtractor && !fPedestalsIn)
|
|---|
| 342 | {
|
|---|
| 343 | fPedestalsIn = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedestalCamIn), "MPedestalCam");
|
|---|
| 344 | if (!fPedestalsIn)
|
|---|
| 345 | {
|
|---|
| 346 | *fLog << err << AddSerialNumber(fNamePedestalCamIn) << " not found... aborting." << endl;
|
|---|
| 347 | return kFALSE;
|
|---|
| 348 | }
|
|---|
| 349 | }
|
|---|
| 350 |
|
|---|
| 351 | if (!fPedestalsOut)
|
|---|
| 352 | {
|
|---|
| 353 | fPedestalsOut = (MPedestalCam*)pList->FindCreateObj("MPedestalCam", AddSerialNumber(fNamePedestalCamOut));
|
|---|
| 354 | if (!fPedestalsOut)
|
|---|
| 355 | return kFALSE;
|
|---|
| 356 | }
|
|---|
| 357 |
|
|---|
| 358 | *fLog << inf;
|
|---|
| 359 | Print();
|
|---|
| 360 |
|
|---|
| 361 | // FIMXE: MUST call fExtractor->PreProcess()???
|
|---|
| 362 | return kTRUE;
|
|---|
| 363 | }
|
|---|
| 364 |
|
|---|
| 365 | Int_t MExtractPedestal::Process()
|
|---|
| 366 | {
|
|---|
| 367 | if (fExtractor)
|
|---|
| 368 | fExtractor->SetNoiseCalculation(fRandomCalculation);
|
|---|
| 369 |
|
|---|
| 370 | const Int_t rc = Calc();
|
|---|
| 371 |
|
|---|
| 372 | if (fExtractor)
|
|---|
| 373 | fExtractor->SetNoiseCalculation(kFALSE);
|
|---|
| 374 |
|
|---|
| 375 | return rc;
|
|---|
| 376 | }
|
|---|
| 377 |
|
|---|
| 378 | // ---------------------------------------------------------------------------------
|
|---|
| 379 | //
|
|---|
| 380 | // Sets the size (from MPedestalCam::GetSize() ) and resets the following arrays:
|
|---|
| 381 | // - fSumx
|
|---|
| 382 | // - fSumx2
|
|---|
| 383 | // - fSumAB0
|
|---|
| 384 | // - fSumAB1
|
|---|
| 385 | // - fAreaSumx
|
|---|
| 386 | // - fAreaSumx2
|
|---|
| 387 | // - fAreaSumAB0
|
|---|
| 388 | // - fAreaSumAB1
|
|---|
| 389 | // - fAreaFilled
|
|---|
| 390 | // - fAreaValid
|
|---|
| 391 | // - fSectorSumx
|
|---|
| 392 | // - fSectorSumx2
|
|---|
| 393 | // - fSectorSumAB0
|
|---|
| 394 | // - fSectorSumAB1
|
|---|
| 395 | // - fSectorFilled
|
|---|
| 396 | // - fSectorValid
|
|---|
| 397 | //
|
|---|
| 398 | Bool_t MExtractPedestal::ReInit(MParList *pList)
|
|---|
| 399 | {
|
|---|
| 400 | // If the size is not yet set, set the size
|
|---|
| 401 | if (fSumx.GetSize()==0)
|
|---|
| 402 | {
|
|---|
| 403 | const Int_t npixels = fPedestalsOut->GetSize();
|
|---|
| 404 | const Int_t areas = fPedestalsOut->GetNumAverageArea();
|
|---|
| 405 | const Int_t sectors = fPedestalsOut->GetNumAverageSector();
|
|---|
| 406 |
|
|---|
| 407 | fSumx. Set(npixels);
|
|---|
| 408 | fSumx2. Set(npixels);
|
|---|
| 409 | fSumAB0.Set(npixels);
|
|---|
| 410 | fSumAB1.Set(npixels);
|
|---|
| 411 |
|
|---|
| 412 | fAreaSumx. Set(areas);
|
|---|
| 413 | fAreaSumx2. Set(areas);
|
|---|
| 414 | fAreaSumAB0.Set(areas);
|
|---|
| 415 | fAreaSumAB1.Set(areas);
|
|---|
| 416 | fAreaFilled.Set(areas);
|
|---|
| 417 | fAreaValid .Set(areas);
|
|---|
| 418 |
|
|---|
| 419 | fSectorSumx. Set(sectors);
|
|---|
| 420 | fSectorSumx2. Set(sectors);
|
|---|
| 421 | fSectorSumAB0.Set(sectors);
|
|---|
| 422 | fSectorSumAB1.Set(sectors);
|
|---|
| 423 | fSectorFilled.Set(sectors);
|
|---|
| 424 | fSectorValid .Set(sectors);
|
|---|
| 425 |
|
|---|
| 426 | for (Int_t i=0; i<npixels; i++)
|
|---|
| 427 | {
|
|---|
| 428 | const UInt_t aidx = (*fGeom)[i].GetAidx();
|
|---|
| 429 | const UInt_t sector = (*fGeom)[i].GetSector();
|
|---|
| 430 |
|
|---|
| 431 | fAreaValid [aidx] ++;
|
|---|
| 432 | fSectorValid[sector]++;
|
|---|
| 433 | }
|
|---|
| 434 | }
|
|---|
| 435 |
|
|---|
| 436 | if (fExtractor)
|
|---|
| 437 | {
|
|---|
| 438 | if (!fExtractor->InitArrays())
|
|---|
| 439 | return kFALSE;
|
|---|
| 440 |
|
|---|
| 441 | SetExtractWindow(fExtractor->GetHiGainFirst(), (Int_t)TMath::Nint(fExtractor->GetNumHiGainSamples()));
|
|---|
| 442 | }
|
|---|
| 443 |
|
|---|
| 444 | return kTRUE;
|
|---|
| 445 | }
|
|---|
| 446 |
|
|---|
| 447 | Int_t MExtractPedestal::PostProcess()
|
|---|
| 448 | {
|
|---|
| 449 | fPedestalsIn = NULL;
|
|---|
| 450 | return kTRUE;
|
|---|
| 451 | }
|
|---|
| 452 |
|
|---|
| 453 |
|
|---|
| 454 | // --------------------------------------------------------------------------
|
|---|
| 455 | //
|
|---|
| 456 | // The following resources are available:
|
|---|
| 457 | // ExtractWindowFirst: 15
|
|---|
| 458 | // ExtractWindowSize: 6
|
|---|
| 459 | // NumEventsDump: 500
|
|---|
| 460 | // PedestalUpdate: yes
|
|---|
| 461 | // RandomCalculation: yes
|
|---|
| 462 | //
|
|---|
| 463 | Int_t MExtractPedestal::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
|---|
| 464 | {
|
|---|
| 465 | Bool_t rc=kFALSE;
|
|---|
| 466 |
|
|---|
| 467 | // find resource for numeventsdump
|
|---|
| 468 | if (IsEnvDefined(env, prefix, "NumEventsDump", print))
|
|---|
| 469 | {
|
|---|
| 470 | SetNumEventsDump(GetEnvValue(env, prefix, "NumEventsDump", (Int_t)fNumEventsDump));
|
|---|
| 471 | rc = kTRUE;
|
|---|
| 472 | }
|
|---|
| 473 |
|
|---|
| 474 | // find resource for numeventsdump
|
|---|
| 475 | if (IsEnvDefined(env, prefix, "NumAreasDump", print))
|
|---|
| 476 | {
|
|---|
| 477 | SetNumAreasDump(GetEnvValue(env, prefix, "NumAreasDump", (Int_t)fNumAreasDump));
|
|---|
| 478 | rc = kTRUE;
|
|---|
| 479 | }
|
|---|
| 480 |
|
|---|
| 481 | // find resource for numeventsdump
|
|---|
| 482 | if (IsEnvDefined(env, prefix, "NumSectorsDump", print))
|
|---|
| 483 | {
|
|---|
| 484 | SetNumSectorsDump(GetEnvValue(env, prefix, "NumSectorsDump", (Int_t)fNumSectorsDump));
|
|---|
| 485 | rc = kTRUE;
|
|---|
| 486 | }
|
|---|
| 487 |
|
|---|
| 488 | // find resource for pedestal update
|
|---|
| 489 | if (IsEnvDefined(env, prefix, "PedestalUpdate", print))
|
|---|
| 490 | {
|
|---|
| 491 | SetPedestalUpdate(GetEnvValue(env, prefix, "PedestalUpdate", fPedestalUpdate));
|
|---|
| 492 | rc = kTRUE;
|
|---|
| 493 | }
|
|---|
| 494 |
|
|---|
| 495 | // find resource for random calculation
|
|---|
| 496 | if (IsEnvDefined(env, prefix, "RandomCalculation", print))
|
|---|
| 497 | {
|
|---|
| 498 | SetRandomCalculation(GetEnvValue(env, prefix, "RandomCalculation", fRandomCalculation));
|
|---|
| 499 | rc = kTRUE;
|
|---|
| 500 | }
|
|---|
| 501 |
|
|---|
| 502 | // Find resources for ExtractWindow
|
|---|
| 503 | Int_t ef = fExtractWinFirst;
|
|---|
| 504 | Int_t es = fExtractWinSize;
|
|---|
| 505 | if (IsEnvDefined(env, prefix, "ExtractWinFirst", print))
|
|---|
| 506 | {
|
|---|
| 507 | ef = GetEnvValue(env, prefix, "ExtractWinFirst", ef);
|
|---|
| 508 | rc = kTRUE;
|
|---|
| 509 | }
|
|---|
| 510 | if (IsEnvDefined(env, prefix, "ExtractWinSize", print))
|
|---|
| 511 | {
|
|---|
| 512 | es = GetEnvValue(env, prefix, "ExtractWinSize", es);
|
|---|
| 513 | rc = kTRUE;
|
|---|
| 514 | }
|
|---|
| 515 |
|
|---|
| 516 | SetExtractWindow(ef,es);
|
|---|
| 517 |
|
|---|
| 518 | // find resource for MPedestalCam
|
|---|
| 519 | if (IsEnvDefined(env, prefix, "NamePedestalCamIn", print))
|
|---|
| 520 | {
|
|---|
| 521 | SetNamePedestalCamIn(GetEnvValue(env, prefix, "NamePedestalCamIn", fNamePedestalCamIn));
|
|---|
| 522 | rc = kTRUE;
|
|---|
| 523 | }
|
|---|
| 524 |
|
|---|
| 525 | if (IsEnvDefined(env, prefix, "NamePedestalCamOut", print))
|
|---|
| 526 | {
|
|---|
| 527 | SetNamePedestalCamOut(GetEnvValue(env, prefix, "NamePedestalCamOut", fNamePedestalCamOut));
|
|---|
| 528 | rc = kTRUE;
|
|---|
| 529 | }
|
|---|
| 530 |
|
|---|
| 531 | return rc;
|
|---|
| 532 | }
|
|---|
| 533 |
|
|---|
| 534 | // ---------------------------------------------------------------------------------
|
|---|
| 535 | //
|
|---|
| 536 | // Calculates for pixel "idx":
|
|---|
| 537 | //
|
|---|
| 538 | // Ped per slice = sum / n / fExtractWinSize;
|
|---|
| 539 | // RMS per slice = sqrt { (sum2 - sum*sum/n) / (n-1) / fExtractWinSize }
|
|---|
| 540 | // ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / n / fExtractWinSize;
|
|---|
| 541 | //
|
|---|
| 542 | // Stores the results in MPedestalCam[pixid]
|
|---|
| 543 | //
|
|---|
| 544 | void MExtractPedestal::CalcPixResults(const UInt_t nevts, const UInt_t pixid)
|
|---|
| 545 | {
|
|---|
| 546 | const Float_t sum = fSumx[pixid];
|
|---|
| 547 | const Float_t sum2 = fSumx2[pixid];
|
|---|
| 548 |
|
|---|
| 549 | // 1. Calculate the mean of the sums:
|
|---|
| 550 | Float_t ped = sum/nevts;
|
|---|
| 551 |
|
|---|
| 552 | // 2. Calculate the Variance of the sums:
|
|---|
| 553 | Float_t var = (sum2-sum*sum/nevts)/(nevts-1.);
|
|---|
| 554 |
|
|---|
| 555 | // 3. Calculate the amplitude of the 150MHz "AB" noise
|
|---|
| 556 | Float_t abOffs = (fSumAB0[pixid] - fSumAB1[pixid]) / nevts;
|
|---|
| 557 |
|
|---|
| 558 | // 4. Scale the mean, variance and AB-noise to the number of slices:
|
|---|
| 559 | ped /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
|---|
| 560 | var /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
|---|
| 561 | abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
|---|
| 562 |
|
|---|
| 563 | // 5. Calculate the RMS from the Variance:
|
|---|
| 564 | const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
|
|---|
| 565 |
|
|---|
| 566 | (*fPedestalsOut)[pixid].Set(ped, rms, abOffs, nevts);
|
|---|
| 567 | }
|
|---|
| 568 |
|
|---|
| 569 | // ---------------------------------------------------------------------------------
|
|---|
| 570 | //
|
|---|
| 571 | // Calculates for area idx "aidx" with "napix" valid pixels:
|
|---|
| 572 | //
|
|---|
| 573 | // Ped per slice = sum / nevts / fExtractWinSize / napix;
|
|---|
| 574 | // RMS per slice = sqrt { (sum2 - sum*sum/nevts) / (nevts-1) / fExtractWinSize / napix }
|
|---|
| 575 | // ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / nevts / fExtractWinSize / napix;
|
|---|
| 576 | //
|
|---|
| 577 | // Stores the results in MPedestalCam::GetAverageArea(aidx)
|
|---|
| 578 | //
|
|---|
| 579 | void MExtractPedestal::CalcAreaResults(const UInt_t nevts, const UInt_t napix, const UInt_t aidx)
|
|---|
| 580 | {
|
|---|
| 581 | const Float_t sum = fAreaSumx[aidx];
|
|---|
| 582 | const Float_t sum2 = fAreaSumx2[aidx];
|
|---|
| 583 |
|
|---|
| 584 | // 1. Calculate the mean of the sums:
|
|---|
| 585 | Float_t ped = sum/nevts;
|
|---|
| 586 |
|
|---|
| 587 | // 2. Calculate the Variance of the sums:
|
|---|
| 588 | Float_t var = (sum2-sum*sum/nevts)/(nevts-1.);
|
|---|
| 589 |
|
|---|
| 590 | // 3. Calculate the amplitude of the 150MHz "AB" noise
|
|---|
| 591 | Float_t abOffs = (fAreaSumAB0[aidx] - fAreaSumAB1[aidx]) / nevts;
|
|---|
| 592 |
|
|---|
| 593 | // 4. Scale the mean, variance and AB-noise to the number of slices:
|
|---|
| 594 | ped /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
|---|
| 595 | var /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
|---|
| 596 | abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
|---|
| 597 |
|
|---|
| 598 | // 5. Scale the mean, variance and AB-noise to the number of pixels:
|
|---|
| 599 | ped /= napix;
|
|---|
| 600 | var /= napix;
|
|---|
| 601 | abOffs /= napix;
|
|---|
| 602 |
|
|---|
| 603 | // 6. Calculate the RMS from the Variance:
|
|---|
| 604 | const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
|
|---|
| 605 |
|
|---|
| 606 | fPedestalsOut->GetAverageArea(aidx).Set(ped, rms, abOffs, nevts);
|
|---|
| 607 | }
|
|---|
| 608 |
|
|---|
| 609 | // ---------------------------------------------------------------------------------
|
|---|
| 610 | //
|
|---|
| 611 | // Calculates for sector idx "sector" with "nspix" valid pixels:
|
|---|
| 612 | //
|
|---|
| 613 | // Ped per slice = sum / nevts / fExtractWinSize / nspix;
|
|---|
| 614 | // RMS per slice = sqrt { (sum2 - sum*sum/nevts) / (nevts-1) / fExtractWinSize / nspix }
|
|---|
| 615 | // ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / nevts / fExtractWinSize / nspix;
|
|---|
| 616 | //
|
|---|
| 617 | // Stores the results in MPedestalCam::GetAverageSector(sector)
|
|---|
| 618 | //
|
|---|
| 619 | void MExtractPedestal::CalcSectorResults(const UInt_t nevts, const UInt_t nspix, const UInt_t sector)
|
|---|
| 620 | {
|
|---|
| 621 | const Float_t sum = fSectorSumx[sector];
|
|---|
| 622 | const Float_t sum2 = fSectorSumx2[sector];
|
|---|
| 623 |
|
|---|
| 624 | // 1. Calculate the mean of the sums:
|
|---|
| 625 | Float_t ped = sum/nevts;
|
|---|
| 626 |
|
|---|
| 627 | // 2. Calculate the Variance of the sums:
|
|---|
| 628 | Float_t var = (sum2-sum*sum/nevts)/(nevts-1.);
|
|---|
| 629 |
|
|---|
| 630 | // 3. Calculate the amplitude of the 150MHz "AB" noise
|
|---|
| 631 | Float_t abOffs = (fSectorSumAB0[sector] - fSectorSumAB1[sector]) / nevts;
|
|---|
| 632 |
|
|---|
| 633 | // 4. Scale the mean, variance and AB-noise to the number of slices:
|
|---|
| 634 | ped /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
|---|
| 635 | var /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
|---|
| 636 | abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize;
|
|---|
| 637 |
|
|---|
| 638 | // 5. Scale the mean, variance and AB-noise to the number of pixels:
|
|---|
| 639 | ped /= nspix;
|
|---|
| 640 | var /= nspix;
|
|---|
| 641 | abOffs /= nspix;
|
|---|
| 642 |
|
|---|
| 643 | // 6. Calculate the RMS from the Variance:
|
|---|
| 644 | const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
|
|---|
| 645 |
|
|---|
| 646 | fPedestalsOut->GetAverageSector(sector).Set(ped, rms, abOffs, nevts);
|
|---|
| 647 | }
|
|---|
| 648 |
|
|---|
| 649 | void MExtractPedestal::Print(Option_t *o) const
|
|---|
| 650 | {
|
|---|
| 651 | *fLog << GetDescriptor() << ":" << endl;
|
|---|
| 652 | *fLog << "Name of input MPedestalCam: " << (fPedestalsIn?fPedestalsIn->GetName():fNamePedestalCamIn.Data()) << " (" << fPedestalsIn << ")" << endl;
|
|---|
| 653 | *fLog << "Name of output MPedestalCam: " << (fPedestalsOut?fPedestalsOut->GetName():fNamePedestalCamOut.Data()) << " (" << fPedestalsOut << ")" << endl;
|
|---|
| 654 | *fLog << "Pedestal Update is " << (fPedestalUpdate?"on":"off") << endl;
|
|---|
| 655 | if (fPedestalUpdate)
|
|---|
| 656 | {
|
|---|
| 657 | *fLog << "Num evts for pedestal calc: " << fNumEventsDump << endl;
|
|---|
| 658 | *fLog << "Num evts for avg.areas calc: " << fNumAreasDump << endl;
|
|---|
| 659 | *fLog << "Num evts for avg.sector calc: " << fNumSectorsDump << endl;
|
|---|
| 660 | }
|
|---|
| 661 | if (fExtractor)
|
|---|
| 662 | {
|
|---|
| 663 | *fLog << "Extractor used: " << fExtractor->ClassName() << " (";
|
|---|
| 664 | *fLog << (fRandomCalculation?"":"non-") << "random)" << endl;
|
|---|
| 665 | }
|
|---|
| 666 | }
|
|---|