| 1 | /* ======================================================================== *\ | 
|---|
| 2 | ! $Name: not supported by cvs2svn $:$Id: MExtractPedestal.cc,v 1.28 2007-03-05 15:54:55 tbretz Exp $ | 
|---|
| 3 | ! -------------------------------------------------------------------------- | 
|---|
| 4 | ! | 
|---|
| 5 | ! * | 
|---|
| 6 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction | 
|---|
| 7 | ! * Software. It is distributed to you in the hope that it can be a useful | 
|---|
| 8 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes. | 
|---|
| 9 | ! * It is distributed WITHOUT ANY WARRANTY. | 
|---|
| 10 | ! * | 
|---|
| 11 | ! * Permission to use, copy, modify and distribute this software and its | 
|---|
| 12 | ! * documentation for any purpose is hereby granted without fee, | 
|---|
| 13 | ! * provided that the above copyright notice appear in all copies and | 
|---|
| 14 | ! * that both that copyright notice and this permission notice appear | 
|---|
| 15 | ! * in supporting documentation. It is provided "as is" without express | 
|---|
| 16 | ! * or implied warranty. | 
|---|
| 17 | ! * | 
|---|
| 18 | ! | 
|---|
| 19 | ! | 
|---|
| 20 | !   Author(s): Markus Gaug 01/2004 <mailto:markus@ifae.es> | 
|---|
| 21 | !   Author(s): Thomas Bretz 01/2004 <mailto:tbretz@astro.uni-wuerzburg.de> | 
|---|
| 22 | ! | 
|---|
| 23 | !   Copyright: MAGIC Software Development, 2000-2006 | 
|---|
| 24 | ! | 
|---|
| 25 | ! | 
|---|
| 26 | \* ======================================================================== */ | 
|---|
| 27 |  | 
|---|
| 28 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 29 | // | 
|---|
| 30 | //   MExtractPedestal | 
|---|
| 31 | // | 
|---|
| 32 | //  Pedestal Extractor base class | 
|---|
| 33 | // | 
|---|
| 34 | //  Input Containers: | 
|---|
| 35 | //   MRawEvtData | 
|---|
| 36 | //   MRawRunHeader | 
|---|
| 37 | //   MRawEvtHeader | 
|---|
| 38 | //   MGeomCam | 
|---|
| 39 | //   MPedestalCam | 
|---|
| 40 | // | 
|---|
| 41 | //  Output Containers: | 
|---|
| 42 | //   MPedestalCam | 
|---|
| 43 | // | 
|---|
| 44 | //  This class should be used for pedestal extractors with the following facilities: | 
|---|
| 45 | //  a) Standardized calculation of AB-noise, mean pedestals and RMS | 
|---|
| 46 | //  b) Standardized treatment of area- and sector averaged pedestals values | 
|---|
| 47 | //  c) Possibility to use a signal extractor to be applied on the pedestals | 
|---|
| 48 | //  d) Possibility to handle two MPedestalCams: one for the signal extractor and | 
|---|
| 49 | //     a second to be filled during the pedestal calculating process. | 
|---|
| 50 | // | 
|---|
| 51 | //  ad a): Every calculated value is referred to one FADC slice (e.g. Mean pedestal per slice), | 
|---|
| 52 | //         RMS per slice. | 
|---|
| 53 | //         MExtractPedestal applies the following formula (1): | 
|---|
| 54 | // | 
|---|
| 55 | //         Pedestal per slice = sum(x_i) / n / slices | 
|---|
| 56 | //         PedRMS per slice   = Sqrt(  ( sum(x_i^2) - sum(x_i)^2/n ) / n-1 / slices ) | 
|---|
| 57 | //         AB-Offset per slice = (sumAB0 - sumAB1) / n / slices | 
|---|
| 58 | // | 
|---|
| 59 | //         where x_i is the sum of "slices" FADC slices and sum means the sum over all | 
|---|
| 60 | //         events. "n" is the number of events, "slices" is the number of summed FADC samples. | 
|---|
| 61 | // | 
|---|
| 62 | //         Note that the slice-to-slice fluctuations are not Gaussian, but Poissonian, thus | 
|---|
| 63 | //         asymmetric and they are correlated. | 
|---|
| 64 | // | 
|---|
| 65 | //         It is important to know that the Pedestal per slice and PedRMS per slice depend | 
|---|
| 66 | //         on the number of used FADC slices, as seen in the following plots: | 
|---|
| 67 | // | 
|---|
| 68 | //Begin_Html | 
|---|
| 69 | /* | 
|---|
| 70 | <img src="images/PedestalStudyInner.gif"> | 
|---|
| 71 | */ | 
|---|
| 72 | //End_Html | 
|---|
| 73 | // | 
|---|
| 74 | //Begin_Html | 
|---|
| 75 | /* | 
|---|
| 76 | <img src="images/PedestalStudyOuter.gif"> | 
|---|
| 77 | */ | 
|---|
| 78 | //End_Html | 
|---|
| 79 | // | 
|---|
| 80 | //        The plots show the inner and outer pixels, respectivly and have the following meaning: | 
|---|
| 81 | // | 
|---|
| 82 | //        1) The calculated mean pedestal per slice (from MPedCalcPedRun) | 
|---|
| 83 | //        2) The fitted mean pedestal per slice     (from MHPedestalCam) | 
|---|
| 84 | //        3) The calculated pedestal RMS per slice  (from MPedCalcPedRun) | 
|---|
| 85 | //        4) The fitted sigma of the pedestal distribution per slice | 
|---|
| 86 | //                                                  (from MHPedestalCam) | 
|---|
| 87 | //        5) The relative difference between calculation and histogram fit | 
|---|
| 88 | //           for the mean | 
|---|
| 89 | //        6) The relative difference between calculation and histogram fit | 
|---|
| 90 | //           for the sigma or RMS, respectively. | 
|---|
| 91 | // | 
|---|
| 92 | //        The calculated means do not change significantly except for the case of 2 slices, | 
|---|
| 93 | //        however the RMS changes from 5.7 per slice in the case of 2 extracted slices | 
|---|
| 94 | //        to 8.3 per slice in the case of 26 extracted slices. This change is very significant. | 
|---|
| 95 | // | 
|---|
| 96 | // ad b)  Every calculated value is referred to one FADC slice and one (averaged) pixel, | 
|---|
| 97 | //        (e.g. Mean Pedestal per area index per slice per pixel, etc. ) | 
|---|
| 98 | // | 
|---|
| 99 | //         MExtractPedestal applies the following formula (2): | 
|---|
| 100 | // | 
|---|
| 101 | //         Averaged Pedestal per slice = sum(x_i) / n / slices / n_pix | 
|---|
| 102 | //         PedRMS per slice   = Sqrt(  ( sum(x_i^2) - sum(x_i)^2/n ) / n-1 / slices / n_pix ) | 
|---|
| 103 | //         AB-Offset per slice = (sumAB0 - sumAB1) / n / slices / n_pix | 
|---|
| 104 | // | 
|---|
| 105 | //         where x_i is the sum of "slices" FADC slices and sum means the sum over all | 
|---|
| 106 | //         events and all concerned pixels. | 
|---|
| 107 | //         "n" is the number of events, "slices" is the number of summed FADC samples and | 
|---|
| 108 | //         "n_pix" is the number of pixels belonging to the specific area index or camera sector. | 
|---|
| 109 | // | 
|---|
| 110 | //         Calculating these averaged event-by-event values is very important to trace coherent | 
|---|
| 111 | //         fluctuations. An example is given in the following plots: | 
|---|
| 112 | // | 
|---|
| 113 | //Begin_Html | 
|---|
| 114 | /* | 
|---|
| 115 | <img src="images/PedestalOscillations.gif"> | 
|---|
| 116 | */ | 
|---|
| 117 | //End_Html | 
|---|
| 118 | // | 
|---|
| 119 | //        The plots show the extracted pedestals of the inner pixels (obtained | 
|---|
| 120 | //        with MHPedestalCam), averaged on an event-by-event basis from | 
|---|
| 121 | //        run 13428 with switched off camera LV. | 
|---|
| 122 | //        The meaning of the four plots is: | 
|---|
| 123 | // | 
|---|
| 124 | //        1) The distribution of the averaged pedestals | 
|---|
| 125 | //        2) The averaged pedestals vs. time. | 
|---|
| 126 | //           One can see clearly the oscillation pattern | 
|---|
| 127 | //        3) The fourier transform of the averaged pedestals vs. time. | 
|---|
| 128 | //           One can see clearly a peak at a certain frequency | 
|---|
| 129 | //        4) The projection of the fourier components with the non-exponential | 
|---|
| 130 | //           (and therefore significant) outlier. | 
|---|
| 131 | // | 
|---|
| 132 | //    ad c) Many signal extractors, especially those using a sliding window | 
|---|
| 133 | //          have biases and their resolutions for zero-signals do not agree | 
|---|
| 134 | //          with the pedestal RMS. For the F-Factor method in the calibration | 
|---|
| 135 | //          and the image cleaning, however, both have to be known and measured. | 
|---|
| 136 | // | 
|---|
| 137 | //          For this reason, a signal extractor can be handed over to the | 
|---|
| 138 | //          pedestal extractor and applied on the pedestal events with the | 
|---|
| 139 | //          function SetExtractor(). | 
|---|
| 140 | //          The results will get stored in an MPedestalCam. | 
|---|
| 141 | // | 
|---|
| 142 | //          Note that only extractors deriving from MExtractTimeAndCharge | 
|---|
| 143 | //          can be used. | 
|---|
| 144 | // | 
|---|
| 145 | //   ad d)  The signal extractors themselves need a pedestal to be subtracted | 
|---|
| 146 | //          from the FADC slices. | 
|---|
| 147 | //          If the user wishes that the pededestals do not get overwritten by | 
|---|
| 148 | //          the results from the signal extractor, a different named MPedestalCam | 
|---|
| 149 | //          can be created with the function: SetNamePedestalOut(). | 
|---|
| 150 | // | 
|---|
| 151 | //  See also: MPedestalCam, MPedestalPix, MPedCalcPedRun, MPedCalcFromLoGain | 
|---|
| 152 | // | 
|---|
| 153 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 154 | #include "MExtractPedestal.h" | 
|---|
| 155 |  | 
|---|
| 156 | #include "MParList.h" | 
|---|
| 157 |  | 
|---|
| 158 | #include "MLog.h" | 
|---|
| 159 | #include "MLogManip.h" | 
|---|
| 160 |  | 
|---|
| 161 | #include "MRawRunHeader.h" | 
|---|
| 162 | #include "MRawEvtHeader.h" | 
|---|
| 163 | #include "MRawEvtPixelIter.h" | 
|---|
| 164 |  | 
|---|
| 165 | #include "MPedestalPix.h" | 
|---|
| 166 | #include "MPedestalCam.h" | 
|---|
| 167 |  | 
|---|
| 168 | #include "MGeomPix.h" | 
|---|
| 169 | #include "MGeomCam.h" | 
|---|
| 170 |  | 
|---|
| 171 | #include "MExtractTimeAndCharge.h" | 
|---|
| 172 | #include "MPedestalSubtractedEvt.h" | 
|---|
| 173 |  | 
|---|
| 174 | ClassImp(MExtractPedestal); | 
|---|
| 175 |  | 
|---|
| 176 | using namespace std; | 
|---|
| 177 |  | 
|---|
| 178 | const TString  MExtractPedestal::fgNamePedestalCam = "MPedestalCam"; | 
|---|
| 179 | const TString  MExtractPedestal::fgNameRawEvtData  = "MRawEvtData"; | 
|---|
| 180 |  | 
|---|
| 181 | const UShort_t MExtractPedestal::fgCheckWinFirst   =  0; | 
|---|
| 182 | const UShort_t MExtractPedestal::fgCheckWinLast    = 29; | 
|---|
| 183 | const UShort_t MExtractPedestal::fgMaxSignalVar    = 40; | 
|---|
| 184 |  | 
|---|
| 185 | // -------------------------------------------------------------------------- | 
|---|
| 186 | // | 
|---|
| 187 | // Default constructor: | 
|---|
| 188 | // | 
|---|
| 189 | // Sets: | 
|---|
| 190 | // - all pointers to NULL | 
|---|
| 191 | // | 
|---|
| 192 | // Calls: | 
|---|
| 193 | // - Clear() | 
|---|
| 194 | // | 
|---|
| 195 | MExtractPedestal::MExtractPedestal(const char *name, const char *title) | 
|---|
| 196 | : fGeom(NULL), fPedestalsIn(NULL), fPedestalsInter(NULL), | 
|---|
| 197 | fPedestalsOut(NULL), fExtractor(NULL), fSignal(0), | 
|---|
| 198 | fExtractWinFirst(0), fExtractWinSize(0), fUseSpecialPixels(kFALSE) | 
|---|
| 199 | { | 
|---|
| 200 | fName  = name  ? name  : "MExtractPedestal"; | 
|---|
| 201 | fTitle = title ? title : "Base class to calculate pedestals"; | 
|---|
| 202 |  | 
|---|
| 203 | SetIntermediateStorage( kFALSE ); | 
|---|
| 204 | SetRandomCalculation  ( kTRUE  ); | 
|---|
| 205 |  | 
|---|
| 206 | SetNamePedestalCamIn(); | 
|---|
| 207 | SetNamePedestalCamOut(); | 
|---|
| 208 | SetNamePedestalCamInter(); | 
|---|
| 209 | SetNameRawEvtData(); | 
|---|
| 210 |  | 
|---|
| 211 | SetCheckRange(fgCheckWinFirst, fgCheckWinLast); | 
|---|
| 212 | SetMaxSignalVar(fgMaxSignalVar); | 
|---|
| 213 |  | 
|---|
| 214 | Clear(); | 
|---|
| 215 | } | 
|---|
| 216 |  | 
|---|
| 217 | // -------------------------------------------------------------------------- | 
|---|
| 218 | // | 
|---|
| 219 | // Call reset() of all Arays | 
|---|
| 220 | // | 
|---|
| 221 | void MExtractPedestal::ResetArrays() | 
|---|
| 222 | { | 
|---|
| 223 | // Reset contents of arrays. | 
|---|
| 224 | fSumx.Reset(); | 
|---|
| 225 | fSumx2.Reset(); | 
|---|
| 226 | fSumAB0.Reset(); | 
|---|
| 227 | fSumAB1.Reset(); | 
|---|
| 228 | fAreaSumx.Reset(); | 
|---|
| 229 | fAreaSumx2.Reset(); | 
|---|
| 230 | fAreaSumAB0.Reset(); | 
|---|
| 231 | fAreaSumAB1.Reset(); | 
|---|
| 232 | fAreaFilled.Reset(); | 
|---|
| 233 | fAreaValid.Reset(); | 
|---|
| 234 | fSectorSumx.Reset(); | 
|---|
| 235 | fSectorSumx2.Reset(); | 
|---|
| 236 | fSectorSumAB0.Reset(); | 
|---|
| 237 | fSectorSumAB1.Reset(); | 
|---|
| 238 | fSectorFilled.Reset(); | 
|---|
| 239 | fSectorValid.Reset(); | 
|---|
| 240 |  | 
|---|
| 241 | } | 
|---|
| 242 |  | 
|---|
| 243 | // -------------------------------------------------------------------------- | 
|---|
| 244 | // | 
|---|
| 245 | // Resets Arrays: | 
|---|
| 246 | // | 
|---|
| 247 | // Sets: | 
|---|
| 248 | // - fRawEvt to NULL | 
|---|
| 249 | // - fRunHeader to NULL | 
|---|
| 250 | // | 
|---|
| 251 | void MExtractPedestal::Clear(const Option_t *o) | 
|---|
| 252 | { | 
|---|
| 253 |  | 
|---|
| 254 | fRawEvt       = NULL; | 
|---|
| 255 | fRunHeader    = NULL; | 
|---|
| 256 |  | 
|---|
| 257 | // If the size is yet set, set the size | 
|---|
| 258 | if (fSumx.GetSize()>0) | 
|---|
| 259 | ResetArrays(); | 
|---|
| 260 |  | 
|---|
| 261 | } | 
|---|
| 262 |  | 
|---|
| 263 | // -------------------------------------------------------------------------- | 
|---|
| 264 | // | 
|---|
| 265 | // Checks: | 
|---|
| 266 | // - if a window is odd | 
|---|
| 267 | // | 
|---|
| 268 | Bool_t MExtractPedestal::SetExtractWindow(UShort_t windowf, UShort_t windows) | 
|---|
| 269 | { | 
|---|
| 270 | Bool_t rc = kTRUE; | 
|---|
| 271 |  | 
|---|
| 272 | if (windows==0) | 
|---|
| 273 | { | 
|---|
| 274 | *fLog << warn << GetDescriptor(); | 
|---|
| 275 | *fLog << " - WARNING: Window size in SetExtractWindow has to be > 0... adjusting to 2!" << endl; | 
|---|
| 276 | windows = 2; | 
|---|
| 277 | rc = kFALSE; | 
|---|
| 278 | } | 
|---|
| 279 |  | 
|---|
| 280 | fExtractWinSize  = windows; | 
|---|
| 281 | fExtractWinFirst = windowf; | 
|---|
| 282 | fExtractWinLast  = fExtractWinFirst+fExtractWinSize-1; | 
|---|
| 283 |  | 
|---|
| 284 | return rc; | 
|---|
| 285 | } | 
|---|
| 286 |  | 
|---|
| 287 | // -------------------------------------------------------------------------- | 
|---|
| 288 | // | 
|---|
| 289 | // SetCheckRange: | 
|---|
| 290 | // | 
|---|
| 291 | // Exits, if the first argument is smaller than 0 | 
|---|
| 292 | // Exits, if the the last argument is smaller than the first | 
|---|
| 293 | // | 
|---|
| 294 | Bool_t MExtractPedestal::SetCheckRange(UShort_t chfirst, UShort_t chlast) | 
|---|
| 295 | { | 
|---|
| 296 |  | 
|---|
| 297 | Bool_t rc = kTRUE; | 
|---|
| 298 |  | 
|---|
| 299 | if (chlast<=chfirst) | 
|---|
| 300 | { | 
|---|
| 301 | *fLog << warn << GetDescriptor(); | 
|---|
| 302 | *fLog << " - WARNING: Last slice in SetCheckRange smaller than first slice... set to first+2" << endl; | 
|---|
| 303 | chlast = chfirst+1; | 
|---|
| 304 | rc = kFALSE; | 
|---|
| 305 | } | 
|---|
| 306 |  | 
|---|
| 307 | fCheckWinFirst = chfirst; | 
|---|
| 308 | fCheckWinLast  = chlast; | 
|---|
| 309 |  | 
|---|
| 310 | return rc; | 
|---|
| 311 | } | 
|---|
| 312 |  | 
|---|
| 313 | Bool_t MExtractPedestal::SetRangeFromExtractor(const MExtractor &ext, Bool_t logain) | 
|---|
| 314 | { | 
|---|
| 315 | const Bool_t haslogains = ext.GetLoGainFirst()!=0 && ext.GetLoGainLast()!=0; | 
|---|
| 316 |  | 
|---|
| 317 | Bool_t rc1 = kTRUE; | 
|---|
| 318 | if (!haslogains) | 
|---|
| 319 | { | 
|---|
| 320 | // We assume that in case without lo-gains we | 
|---|
| 321 | // deal with pedestal events only | 
|---|
| 322 | rc1 = SetCheckRange(ext.GetHiGainFirst(), ext.GetHiGainLast()); | 
|---|
| 323 | } | 
|---|
| 324 |  | 
|---|
| 325 | const Int_t f = logain && haslogains ? ext.GetLoGainFirst() : ext.GetHiGainFirst(); | 
|---|
| 326 | const Int_t l = logain && haslogains ? ext.GetLoGainLast()  : ext.GetHiGainLast(); | 
|---|
| 327 |  | 
|---|
| 328 | const Int_t w = (l-f+1); | 
|---|
| 329 |  | 
|---|
| 330 | // Setup to use the hi-gain extraction window in the lo-gain | 
|---|
| 331 | // range (the start of the lo-gain range is added automatically | 
|---|
| 332 | // by MPedCalcFromLoGain) | 
|---|
| 333 | const Bool_t rc2 = SetExtractWindow(f, w); | 
|---|
| 334 |  | 
|---|
| 335 | return rc1 && rc2; | 
|---|
| 336 | } | 
|---|
| 337 |  | 
|---|
| 338 | // -------------------------------------------------------------------------- | 
|---|
| 339 | // | 
|---|
| 340 | // Check (and if neccesary: correct) the extraction and check ranges. | 
|---|
| 341 | // | 
|---|
| 342 | void MExtractPedestal::CheckExtractionWindow(UInt_t offset) | 
|---|
| 343 | { | 
|---|
| 344 | *fLog << inf; | 
|---|
| 345 | *fLog << "Requested CheckWindow is [" << fCheckWinFirst << "," << fCheckWinLast << "]." <<endl; | 
|---|
| 346 | *fLog << "Requested ExtractWindow is [" << fExtractWinFirst+offset << "," << fExtractWinLast+offset << "]." <<endl; | 
|---|
| 347 |  | 
|---|
| 348 | // fSignal->GetNumSamples() not yet initialized!!! | 
|---|
| 349 | const UInt_t num = fRunHeader->GetNumSamplesHiGain()+fRunHeader->GetNumSamplesLoGain(); | 
|---|
| 350 |  | 
|---|
| 351 | if (fCheckWinLast >= num) | 
|---|
| 352 | { | 
|---|
| 353 | *fLog << "CheckWindow [" << fCheckWinFirst << "," << fCheckWinLast; | 
|---|
| 354 | *fLog << "] out of range [0," << num-1 << "]... "; | 
|---|
| 355 | *fLog << "reset upper edge." << endl; | 
|---|
| 356 |  | 
|---|
| 357 | fCheckWinLast = num-1; | 
|---|
| 358 | } | 
|---|
| 359 |  | 
|---|
| 360 | if (offset+fExtractWinLast >= num) | 
|---|
| 361 | { | 
|---|
| 362 | *fLog << "ExtractWindow [" << fExtractWinFirst+offset << "," << fExtractWinLast+offset; | 
|---|
| 363 | *fLog << "] out of range [0," << num-1 << "]... "; | 
|---|
| 364 | *fLog << "reset upper edge." << endl; | 
|---|
| 365 |  | 
|---|
| 366 | fExtractWinLast = num-offset-1; | 
|---|
| 367 | } | 
|---|
| 368 |  | 
|---|
| 369 | fExtractWinSize = fExtractWinLast-fExtractWinFirst+1; | 
|---|
| 370 |  | 
|---|
| 371 | if (fExtractor || TMath::Even(fExtractWinSize)) | 
|---|
| 372 | return; | 
|---|
| 373 |  | 
|---|
| 374 | fExtractWinLast += offset+fExtractWinLast==num-1 ? -1 : +1; | 
|---|
| 375 |  | 
|---|
| 376 | *fLog << "ExtractionWindow odd... set to ["; | 
|---|
| 377 | *fLog << fExtractWinFirst+offset << "," << fExtractWinLast+offset << "]" << endl; | 
|---|
| 378 |  | 
|---|
| 379 | fExtractWinSize = fExtractWinLast-fExtractWinFirst+1; | 
|---|
| 380 | } | 
|---|
| 381 |  | 
|---|
| 382 | // -------------------------------------------------------------------------- | 
|---|
| 383 | // | 
|---|
| 384 | // Look for the following input containers: | 
|---|
| 385 | // | 
|---|
| 386 | //  - MRawEvtData | 
|---|
| 387 | //  - MRawRunHeader | 
|---|
| 388 | //  - MRawEvtHeader | 
|---|
| 389 | //  - MGeomCam | 
|---|
| 390 | // | 
|---|
| 391 | // The following output containers are also searched and created if | 
|---|
| 392 | // they were not found: | 
|---|
| 393 | // | 
|---|
| 394 | //  - MPedestalCam with the name fPedContainerName | 
|---|
| 395 | // | 
|---|
| 396 | Int_t MExtractPedestal::PreProcess(MParList *pList) | 
|---|
| 397 | { | 
|---|
| 398 |  | 
|---|
| 399 | Clear(); | 
|---|
| 400 |  | 
|---|
| 401 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber(fNameRawEvtData)); | 
|---|
| 402 | if (!fRawEvt) | 
|---|
| 403 | { | 
|---|
| 404 | *fLog << err << AddSerialNumber(fNameRawEvtData) << " not found... aborting." << endl; | 
|---|
| 405 | return kFALSE; | 
|---|
| 406 | } | 
|---|
| 407 |  | 
|---|
| 408 | fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader")); | 
|---|
| 409 | if (!fRunHeader) | 
|---|
| 410 | { | 
|---|
| 411 | *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl; | 
|---|
| 412 | return kFALSE; | 
|---|
| 413 | } | 
|---|
| 414 |  | 
|---|
| 415 | fGeom = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam")); | 
|---|
| 416 | if (!fGeom) | 
|---|
| 417 | { | 
|---|
| 418 | *fLog << err << AddSerialNumber("MGeomCam") << " not found... aborting." << endl; | 
|---|
| 419 | return kFALSE; | 
|---|
| 420 | } | 
|---|
| 421 |  | 
|---|
| 422 | fSignal = (MPedestalSubtractedEvt*)pList->FindObject(AddSerialNumber("MPedestalSubtractedEvt")); | 
|---|
| 423 | if (!fSignal) | 
|---|
| 424 | { | 
|---|
| 425 | *fLog << err << AddSerialNumber("MPedestalSubtractedEvt") << " not found... aborting." << endl; | 
|---|
| 426 | return kFALSE; | 
|---|
| 427 | } | 
|---|
| 428 |  | 
|---|
| 429 | if (fExtractor && !fPedestalsIn) | 
|---|
| 430 | { | 
|---|
| 431 | fPedestalsIn = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedestalCamIn), "MPedestalCam"); | 
|---|
| 432 | if (!fPedestalsIn) | 
|---|
| 433 | { | 
|---|
| 434 | *fLog << err << AddSerialNumber(fNamePedestalCamIn) << " not found... aborting." << endl; | 
|---|
| 435 | return kFALSE; | 
|---|
| 436 | } | 
|---|
| 437 | } | 
|---|
| 438 |  | 
|---|
| 439 | if (!fPedestalsInter && fIntermediateStorage) | 
|---|
| 440 | { | 
|---|
| 441 | fPedestalsInter = (MPedestalCam*)pList->FindCreateObj("MPedestalCam", AddSerialNumber(fNamePedestalCamInter)); | 
|---|
| 442 | if (!fPedestalsInter) | 
|---|
| 443 | return kFALSE; | 
|---|
| 444 | } | 
|---|
| 445 |  | 
|---|
| 446 | if (!fPedestalsOut) | 
|---|
| 447 | { | 
|---|
| 448 | fPedestalsOut = (MPedestalCam*)pList->FindCreateObj("MPedestalCam", AddSerialNumber(fNamePedestalCamOut)); | 
|---|
| 449 | if (!fPedestalsOut) | 
|---|
| 450 | return kFALSE; | 
|---|
| 451 | } | 
|---|
| 452 |  | 
|---|
| 453 | return fExtractor ? fExtractor->CallPreProcess(pList) : kTRUE; | 
|---|
| 454 | } | 
|---|
| 455 |  | 
|---|
| 456 | //----------------------------------------------------------------------- | 
|---|
| 457 | // | 
|---|
| 458 | // Call Calc(). If fExtractor!=NULL enclose the call in setting the | 
|---|
| 459 | // NoiseCalculation to fRandomCalculation | 
|---|
| 460 | // | 
|---|
| 461 | Int_t MExtractPedestal::Process() | 
|---|
| 462 | { | 
|---|
| 463 | // | 
|---|
| 464 | // Necessary check for extraction of special pixels | 
|---|
| 465 | // together with data which does not yet have them | 
|---|
| 466 | // | 
|---|
| 467 | if (fSumx.GetSize()==0) | 
|---|
| 468 | return kTRUE; | 
|---|
| 469 |  | 
|---|
| 470 | if (fExtractor) | 
|---|
| 471 | fExtractor->SetNoiseCalculation(fRandomCalculation); | 
|---|
| 472 |  | 
|---|
| 473 | const Int_t rc = Calc(); | 
|---|
| 474 |  | 
|---|
| 475 | if (fExtractor) | 
|---|
| 476 | fExtractor->SetNoiseCalculation(kFALSE); | 
|---|
| 477 |  | 
|---|
| 478 | return rc; | 
|---|
| 479 | } | 
|---|
| 480 |  | 
|---|
| 481 | // --------------------------------------------------------------------------------- | 
|---|
| 482 | // | 
|---|
| 483 | // Sets the size (from MPedestalCam::GetSize() ) and resets the following arrays: | 
|---|
| 484 | //  - fSumx | 
|---|
| 485 | //  - fSumx2 | 
|---|
| 486 | //  - fSumAB0 | 
|---|
| 487 | //  - fSumAB1 | 
|---|
| 488 | //  - fAreaSumx | 
|---|
| 489 | //  - fAreaSumx2 | 
|---|
| 490 | //  - fAreaSumAB0 | 
|---|
| 491 | //  - fAreaSumAB1 | 
|---|
| 492 | //  - fAreaFilled | 
|---|
| 493 | //  - fAreaValid | 
|---|
| 494 | //  - fSectorSumx | 
|---|
| 495 | //  - fSectorSumx2 | 
|---|
| 496 | //  - fSectorSumAB0 | 
|---|
| 497 | //  - fSectorSumAB1 | 
|---|
| 498 | //  - fSectorFilled | 
|---|
| 499 | //  - fSectorValid | 
|---|
| 500 | // | 
|---|
| 501 | Bool_t MExtractPedestal::ReInit(MParList *pList) | 
|---|
| 502 | { | 
|---|
| 503 | // Necessary check for special pixels which might not yet have existed | 
|---|
| 504 | if (!fRawEvt) | 
|---|
| 505 | { | 
|---|
| 506 | if (fRunHeader->GetFormatVersion() > 3) | 
|---|
| 507 | return kTRUE; | 
|---|
| 508 |  | 
|---|
| 509 | *fLog << err << "ERROR - " << fNameRawEvtData << " [MRawEvtData] has not "; | 
|---|
| 510 | *fLog << "been found and format version > 3... abort." << endl; | 
|---|
| 511 | return kFALSE; | 
|---|
| 512 | } | 
|---|
| 513 |  | 
|---|
| 514 | // If the size is not yet set, set the size | 
|---|
| 515 | if (fSumx.GetSize()==0) | 
|---|
| 516 | { | 
|---|
| 517 | // Initialize the normal pixels (size of MPedestalCam already set by MGeomApply) | 
|---|
| 518 | const Int_t npixels  = fPedestalsOut->GetSize(); | 
|---|
| 519 |  | 
|---|
| 520 | fSumx.  Set(npixels); | 
|---|
| 521 | fSumx2. Set(npixels); | 
|---|
| 522 | fSumAB0.Set(npixels); | 
|---|
| 523 | fSumAB1.Set(npixels); | 
|---|
| 524 |  | 
|---|
| 525 | if (fUseSpecialPixels) | 
|---|
| 526 | { | 
|---|
| 527 | // Initialize size of MPedestalCam in case of special pixels (not done by MGeomApply) | 
|---|
| 528 | const UShort_t nspecial = fRunHeader->GetNumSpecialPixels(); | 
|---|
| 529 | if (nspecial == 0) | 
|---|
| 530 | { | 
|---|
| 531 | *fLog << warn << "WARNING - Number of special pixels is 0." << endl; | 
|---|
| 532 | return kTRUE; | 
|---|
| 533 | } | 
|---|
| 534 |  | 
|---|
| 535 | fPedestalsOut->InitSize((UInt_t)nspecial); | 
|---|
| 536 | } | 
|---|
| 537 | else | 
|---|
| 538 | { | 
|---|
| 539 | // Initialize the averaged areas and sectors (do not exist for special pixels) | 
|---|
| 540 | const Int_t areas    = fPedestalsOut->GetNumAverageArea(); | 
|---|
| 541 | const Int_t sectors  = fPedestalsOut->GetNumAverageSector(); | 
|---|
| 542 |  | 
|---|
| 543 | fAreaSumx.  Set(areas); | 
|---|
| 544 | fAreaSumx2. Set(areas); | 
|---|
| 545 | fAreaSumAB0.Set(areas); | 
|---|
| 546 | fAreaSumAB1.Set(areas); | 
|---|
| 547 | fAreaFilled.Set(areas); | 
|---|
| 548 | fAreaValid .Set(areas); | 
|---|
| 549 |  | 
|---|
| 550 | fSectorSumx.  Set(sectors); | 
|---|
| 551 | fSectorSumx2. Set(sectors); | 
|---|
| 552 | fSectorSumAB0.Set(sectors); | 
|---|
| 553 | fSectorSumAB1.Set(sectors); | 
|---|
| 554 | fSectorFilled.Set(sectors); | 
|---|
| 555 | fSectorValid .Set(sectors); | 
|---|
| 556 |  | 
|---|
| 557 | for (Int_t i=0; i<npixels; i++) | 
|---|
| 558 | { | 
|---|
| 559 | const UInt_t aidx   = (*fGeom)[i].GetAidx(); | 
|---|
| 560 | const UInt_t sector = (*fGeom)[i].GetSector(); | 
|---|
| 561 |  | 
|---|
| 562 | fAreaValid  [aidx]  ++; | 
|---|
| 563 | fSectorValid[sector]++; | 
|---|
| 564 | } | 
|---|
| 565 | } | 
|---|
| 566 | } | 
|---|
| 567 |  | 
|---|
| 568 | if (fExtractor) | 
|---|
| 569 | { | 
|---|
| 570 | if (!fExtractor->ReInit(pList)) | 
|---|
| 571 | return kFALSE; | 
|---|
| 572 |  | 
|---|
| 573 | SetRangeFromExtractor(*fExtractor); | 
|---|
| 574 |  | 
|---|
| 575 | // fSignal->GetNumSamples() not yet initialized!!! | 
|---|
| 576 | const UInt_t num = fRunHeader->GetNumSamples(); | 
|---|
| 577 | if (fExtractWinLast >= num) | 
|---|
| 578 | { | 
|---|
| 579 | *fLog << err; | 
|---|
| 580 | *fLog << "ERROR - Selected fExtractWinLast " << fExtractWinLast; | 
|---|
| 581 | *fLog << " out of range (>=" << num<< ")." << endl; | 
|---|
| 582 | return kFALSE; | 
|---|
| 583 | } | 
|---|
| 584 | } | 
|---|
| 585 | else | 
|---|
| 586 | if (fRunHeader->GetNumSamplesLoGain()==0 && (fCheckWinFirst!=0 || fCheckWinLast!=0)) | 
|---|
| 587 | { | 
|---|
| 588 | *fLog << inf << "Data has no lo-gains... resetting check window to extraction window." << endl; | 
|---|
| 589 | SetCheckRange(fExtractWinFirst, fExtractWinLast); | 
|---|
| 590 | } | 
|---|
| 591 |  | 
|---|
| 592 | //CheckExtractionWindow(); | 
|---|
| 593 |  | 
|---|
| 594 | return kTRUE; | 
|---|
| 595 | } | 
|---|
| 596 |  | 
|---|
| 597 | // --------------------------------------------------------------------------------- | 
|---|
| 598 | // | 
|---|
| 599 | // PostProcess the extractor if available | 
|---|
| 600 | // | 
|---|
| 601 | Int_t MExtractPedestal::PostProcess() | 
|---|
| 602 | { | 
|---|
| 603 | fPedestalsIn = NULL; | 
|---|
| 604 | return fExtractor ? fExtractor->CallPostProcess() : kTRUE; | 
|---|
| 605 | } | 
|---|
| 606 |  | 
|---|
| 607 | // --------------------------------------------------------------------------------- | 
|---|
| 608 | // | 
|---|
| 609 | // Check whether the signal variation between fCheckWinFirst and fCheckWinLast | 
|---|
| 610 | // exceeds fMaxSignalVar or the signal is greater than 250 | 
|---|
| 611 | // | 
|---|
| 612 | Bool_t MExtractPedestal::CheckVariation(UInt_t idx) const | 
|---|
| 613 | { | 
|---|
| 614 | // This is the fast workaround to put hi- and lo-gains together | 
|---|
| 615 | Byte_t *slices = fSignal->GetSamplesRaw(idx);//pixel.GetSamples(); | 
|---|
| 616 |  | 
|---|
| 617 | // Start 'real' work | 
|---|
| 618 | UShort_t max = 0; | 
|---|
| 619 | UShort_t min = (UShort_t)-1; | 
|---|
| 620 |  | 
|---|
| 621 | // Find the maximum and minimum signal per slice in the high gain window | 
|---|
| 622 | for (Byte_t *slice=slices+fCheckWinFirst; slice<=slices+fCheckWinLast; slice++) | 
|---|
| 623 | { | 
|---|
| 624 | if (*slice > max) | 
|---|
| 625 | max = *slice; | 
|---|
| 626 | if (*slice < min) | 
|---|
| 627 | min = *slice; | 
|---|
| 628 | } | 
|---|
| 629 |  | 
|---|
| 630 | // If the maximum in the high gain window is smaller than | 
|---|
| 631 | // FIXME: Precompiled value! | 
|---|
| 632 | return max-min<fMaxSignalVar && max<250; | 
|---|
| 633 | } | 
|---|
| 634 |  | 
|---|
| 635 | // --------------------------------------------------------------------------------- | 
|---|
| 636 | // | 
|---|
| 637 | // Invoke the hi-gain extraction starting at fExtractWinFirst+offset | 
|---|
| 638 | // for fExtractWinLast-fExtractWinFirst+1 slices. If Noise calculation | 
|---|
| 639 | // is set it is up to the signal extractor to do the right thing. | 
|---|
| 640 | // | 
|---|
| 641 | // Returns the extracted signal. | 
|---|
| 642 | // | 
|---|
| 643 | Float_t MExtractPedestal::CalcExtractor(const MRawEvtPixelIter &pixel, Int_t offset) const | 
|---|
| 644 | { | 
|---|
| 645 | // Use the same extraction window as for signal extraction | 
|---|
| 646 | const Int_t first = fExtractWinFirst; | 
|---|
| 647 | const Int_t last  = fExtractWinLast; | 
|---|
| 648 |  | 
|---|
| 649 | const Int_t start = first+offset; | 
|---|
| 650 |  | 
|---|
| 651 | const Int_t range = last-first+1; | 
|---|
| 652 |  | 
|---|
| 653 | // This check is already done in CheckExtractionWindow | 
|---|
| 654 | //    if (range>pixel.GetNumSamples()-start) | 
|---|
| 655 | //        range = pixel.GetNumSamples()-start; | 
|---|
| 656 |  | 
|---|
| 657 | const Int_t idx = pixel.GetPixelId(); | 
|---|
| 658 |  | 
|---|
| 659 | // Do some handling if maxpos is last slice? | 
|---|
| 660 | const Int_t maxposhi = fSignal->GetMax(idx, start, start+range-1); | 
|---|
| 661 |  | 
|---|
| 662 | const Float_t *sig = fSignal->GetSamples(idx); | 
|---|
| 663 |  | 
|---|
| 664 | // The pedestal is extracted with the hi-gain extractor (eg. digital | 
|---|
| 665 | // filter weights) but from the lo-gains | 
|---|
| 666 | Float_t dummy[3]; | 
|---|
| 667 | Float_t sum = 0; | 
|---|
| 668 | fExtractor->FindTimeAndChargeHiGain2(sig+start, range, sum, | 
|---|
| 669 | dummy[0], dummy[1], dummy[2], | 
|---|
| 670 | 0, maxposhi); | 
|---|
| 671 | return sum; | 
|---|
| 672 | } | 
|---|
| 673 |  | 
|---|
| 674 | // --------------------------------------------------------------------------------- | 
|---|
| 675 | // | 
|---|
| 676 | // Sum slices from fExtractWinFirst to fExtractWinLast. The total sum is | 
|---|
| 677 | // returned. ab0 and ab1 will contain the total sum splitted by the | 
|---|
| 678 | // AB-flag. If the AB-flag is invalid ab0=ab1=0 is returned. | 
|---|
| 679 | // | 
|---|
| 680 | UInt_t MExtractPedestal::CalcSums(const MRawEvtPixelIter &pixel, Int_t offset, UInt_t &ab0, UInt_t &ab1) const | 
|---|
| 681 | { | 
|---|
| 682 | const Int_t first = fExtractWinFirst+offset; | 
|---|
| 683 |  | 
|---|
| 684 | Byte_t *ptr = fSignal->GetSamplesRaw(pixel.GetPixelId())+first; | 
|---|
| 685 | Byte_t *end = ptr + fExtractWinSize; | 
|---|
| 686 |  | 
|---|
| 687 | Int_t abflag = pixel.HasABFlag() + first; | 
|---|
| 688 |  | 
|---|
| 689 | UInt_t ab[2] = { 0, 0 }; | 
|---|
| 690 | while (ptr<end) | 
|---|
| 691 | ab[abflag++ & 0x1] += *ptr++; | 
|---|
| 692 |  | 
|---|
| 693 | // This check if for old data without AB-Flag in the data | 
|---|
| 694 | const Bool_t valid = pixel.IsABFlagValid(); | 
|---|
| 695 |  | 
|---|
| 696 | ab0 = valid ? ab[0] : 0; | 
|---|
| 697 | ab1 = valid ? ab[1] : 0; | 
|---|
| 698 |  | 
|---|
| 699 | return ab[0]+ab[1]; | 
|---|
| 700 | } | 
|---|
| 701 |  | 
|---|
| 702 | // -------------------------------------------------------------------------- | 
|---|
| 703 | // | 
|---|
| 704 | //  The following resources are available: | 
|---|
| 705 | //    ExtractWindowFirst:    15 | 
|---|
| 706 | //    ExtractWindowSize:      6 | 
|---|
| 707 | //    PedestalUpdate:       yes | 
|---|
| 708 | //    RandomCalculation:    yes | 
|---|
| 709 | // | 
|---|
| 710 | Int_t MExtractPedestal::ReadEnv(const TEnv &env, TString prefix, Bool_t print) | 
|---|
| 711 | { | 
|---|
| 712 | Bool_t rc=kFALSE; | 
|---|
| 713 |  | 
|---|
| 714 | // find resource for fUseSpecialPixels | 
|---|
| 715 | if (IsEnvDefined(env, prefix, "UseSpecialPixels", print)) | 
|---|
| 716 | { | 
|---|
| 717 | SetUseSpecialPixels(GetEnvValue(env, prefix, "UseSpecialPixels", fUseSpecialPixels)); | 
|---|
| 718 | rc = kTRUE; | 
|---|
| 719 | } | 
|---|
| 720 |  | 
|---|
| 721 | if (IsEnvDefined(env, prefix, "IntermediateStorage", print)) | 
|---|
| 722 | { | 
|---|
| 723 | SetIntermediateStorage(GetEnvValue(env, prefix, "IntermediateStorage", fIntermediateStorage)); | 
|---|
| 724 | rc = kTRUE; | 
|---|
| 725 | } | 
|---|
| 726 |  | 
|---|
| 727 | // find resource for random calculation | 
|---|
| 728 | if (IsEnvDefined(env, prefix, "RandomCalculation", print)) | 
|---|
| 729 | { | 
|---|
| 730 | SetRandomCalculation(GetEnvValue(env, prefix, "RandomCalculation", fRandomCalculation)); | 
|---|
| 731 | rc = kTRUE; | 
|---|
| 732 | } | 
|---|
| 733 |  | 
|---|
| 734 | // Find resources for ExtractWindow | 
|---|
| 735 | Int_t ef = fExtractWinFirst; | 
|---|
| 736 | Int_t es = fExtractWinSize; | 
|---|
| 737 | if (IsEnvDefined(env, prefix, "ExtractWinFirst", print)) | 
|---|
| 738 | { | 
|---|
| 739 | ef = GetEnvValue(env, prefix, "ExtractWinFirst", ef); | 
|---|
| 740 | rc = kTRUE; | 
|---|
| 741 | } | 
|---|
| 742 | if (IsEnvDefined(env, prefix, "ExtractWinSize", print)) | 
|---|
| 743 | { | 
|---|
| 744 | es = GetEnvValue(env, prefix, "ExtractWinSize", es); | 
|---|
| 745 | rc = kTRUE; | 
|---|
| 746 | } | 
|---|
| 747 |  | 
|---|
| 748 | SetExtractWindow(ef,es); | 
|---|
| 749 |  | 
|---|
| 750 | // Find resources for CheckWindow | 
|---|
| 751 | Int_t cfs = fCheckWinFirst; | 
|---|
| 752 | Int_t cls = fCheckWinLast; | 
|---|
| 753 | if (IsEnvDefined(env, prefix, "CheckWinFirst", print)) | 
|---|
| 754 | { | 
|---|
| 755 | cfs = GetEnvValue(env, prefix, "CheckWinFirst", cfs); | 
|---|
| 756 | rc = kTRUE; | 
|---|
| 757 | } | 
|---|
| 758 | if (IsEnvDefined(env, prefix, "CheckWinLast", print)) | 
|---|
| 759 | { | 
|---|
| 760 | cls = GetEnvValue(env, prefix, "CheckWinLast", cls); | 
|---|
| 761 | rc = kTRUE; | 
|---|
| 762 | } | 
|---|
| 763 |  | 
|---|
| 764 | SetCheckRange(cfs,cls); | 
|---|
| 765 |  | 
|---|
| 766 | // find resource for maximum signal variation | 
|---|
| 767 | if (IsEnvDefined(env, prefix, "MaxSignalVar", print)) | 
|---|
| 768 | { | 
|---|
| 769 | SetMaxSignalVar(GetEnvValue(env, prefix, "MaxSignalVar", fMaxSignalVar)); | 
|---|
| 770 | rc = kTRUE; | 
|---|
| 771 | } | 
|---|
| 772 |  | 
|---|
| 773 | // find resource for MPedestalCam | 
|---|
| 774 | if (IsEnvDefined(env, prefix, "NamePedestalCamIn", print)) | 
|---|
| 775 | { | 
|---|
| 776 | SetNamePedestalCamIn(GetEnvValue(env, prefix, "NamePedestalCamIn", fNamePedestalCamIn)); | 
|---|
| 777 | rc = kTRUE; | 
|---|
| 778 | } | 
|---|
| 779 |  | 
|---|
| 780 | if (IsEnvDefined(env, prefix, "NamePedestalCamInter", print)) | 
|---|
| 781 | { | 
|---|
| 782 | SetNamePedestalCamInter(GetEnvValue(env, prefix, "NamePedestalCamInter", fNamePedestalCamInter)); | 
|---|
| 783 | rc = kTRUE; | 
|---|
| 784 | } | 
|---|
| 785 |  | 
|---|
| 786 | if (IsEnvDefined(env, prefix, "NamePedestalCamOut", print)) | 
|---|
| 787 | { | 
|---|
| 788 | SetNamePedestalCamOut(GetEnvValue(env, prefix, "NamePedestalCamOut", fNamePedestalCamOut)); | 
|---|
| 789 | rc = kTRUE; | 
|---|
| 790 | } | 
|---|
| 791 |  | 
|---|
| 792 | return rc; | 
|---|
| 793 | } | 
|---|
| 794 |  | 
|---|
| 795 | // --------------------------------------------------------------------------------- | 
|---|
| 796 | // | 
|---|
| 797 | // Calculates for pixel "idx": | 
|---|
| 798 | // | 
|---|
| 799 | // Ped per slice      = sum / n / fExtractWinSize; | 
|---|
| 800 | // RMS per slice      = sqrt { (sum2 -  sum*sum/n) / (n-1) / fExtractWinSize } | 
|---|
| 801 | // ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / n / fExtractWinSize; | 
|---|
| 802 | // | 
|---|
| 803 | // Stores the results in MPedestalCam[pixid] | 
|---|
| 804 | // | 
|---|
| 805 | void MExtractPedestal::CalcPixResults(const UInt_t nevts, const UInt_t pixid) | 
|---|
| 806 | { | 
|---|
| 807 | const Double_t sum  = fSumx[pixid]; | 
|---|
| 808 | const Double_t sum2 = fSumx2[pixid]; | 
|---|
| 809 |  | 
|---|
| 810 | // 1. Calculate the mean of the sums: | 
|---|
| 811 | Double_t ped = sum/nevts; | 
|---|
| 812 |  | 
|---|
| 813 | // 2. Calculate the Variance of the sums: | 
|---|
| 814 | Double_t var = (sum2-sum*sum/nevts)/(nevts-1.); | 
|---|
| 815 |  | 
|---|
| 816 | // 3. Calculate the amplitude of the 150MHz "AB" noise | 
|---|
| 817 | Double_t abOffs = (fSumAB0[pixid] - fSumAB1[pixid]) / nevts; | 
|---|
| 818 |  | 
|---|
| 819 | // 4. Scale the mean, variance and AB-noise to the number of slices: | 
|---|
| 820 | ped    /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize; | 
|---|
| 821 | var    /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize; | 
|---|
| 822 | abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize; | 
|---|
| 823 | // The pedestal extracted with the extractor is divided by | 
|---|
| 824 | // the number of hi-gain samples because the calibration | 
|---|
| 825 | // multiplies by this number | 
|---|
| 826 |  | 
|---|
| 827 | // 5. Calculate the RMS from the Variance: | 
|---|
| 828 | const Double_t rms = var<0 ? 0 : TMath::Sqrt(var); | 
|---|
| 829 |  | 
|---|
| 830 | // abOffs contains only half of the signal as ped. | 
|---|
| 831 | // Therefor abOffs is not the full, but the half amplitude | 
|---|
| 832 | (*fPedestalsOut)[pixid].Set(ped, rms, abOffs, nevts); | 
|---|
| 833 | } | 
|---|
| 834 |  | 
|---|
| 835 | // --------------------------------------------------------------------------------- | 
|---|
| 836 | // | 
|---|
| 837 | // Calculates for area idx "aidx" with "napix" valid pixels: | 
|---|
| 838 | // | 
|---|
| 839 | // Ped per slice      = sum / nevts / fExtractWinSize / napix; | 
|---|
| 840 | // RMS per slice      = sqrt { (sum2 -  sum*sum/nevts) / (nevts-1) / fExtractWinSize / napix } | 
|---|
| 841 | // ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / nevts / fExtractWinSize / napix; | 
|---|
| 842 | // | 
|---|
| 843 | // Stores the results in MPedestalCam::GetAverageArea(aidx) | 
|---|
| 844 | // | 
|---|
| 845 | void MExtractPedestal::CalcAreaResults(const UInt_t nevts, const UInt_t napix, const UInt_t aidx) | 
|---|
| 846 | { | 
|---|
| 847 | const Double_t sum  = fAreaSumx[aidx]; | 
|---|
| 848 | const Double_t sum2 = fAreaSumx2[aidx]; | 
|---|
| 849 |  | 
|---|
| 850 | // 1. Calculate the mean of the sums: | 
|---|
| 851 | Double_t ped = sum/nevts; | 
|---|
| 852 |  | 
|---|
| 853 | // 2. Calculate the Variance of the sums: | 
|---|
| 854 | Double_t var = (sum2/napix-sum*sum/nevts)/(nevts-1.); | 
|---|
| 855 |  | 
|---|
| 856 | // 3. Calculate the amplitude of the 150MHz "AB" noise | 
|---|
| 857 | Double_t abOffs = (fAreaSumAB0[aidx] - fAreaSumAB1[aidx]) / nevts; | 
|---|
| 858 |  | 
|---|
| 859 | // 4. Scale the mean, variance and AB-noise to the number of slices: | 
|---|
| 860 | ped    /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize; | 
|---|
| 861 | var    /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize; | 
|---|
| 862 | abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize; | 
|---|
| 863 | // The pedestal extracted with the extractor is divided by | 
|---|
| 864 | // the number of hi-gain samples because the calibration | 
|---|
| 865 | // multiplies by this number | 
|---|
| 866 |  | 
|---|
| 867 | // 5. Scale the mean, variance and AB-noise to the number of pixels: | 
|---|
| 868 | ped    /= napix; | 
|---|
| 869 | var    /= napix; | 
|---|
| 870 | abOffs /= napix; | 
|---|
| 871 |  | 
|---|
| 872 | // 6. Calculate the RMS from the Variance: | 
|---|
| 873 | const Double_t rms = var<0 ? 0 : TMath::Sqrt(var); | 
|---|
| 874 |  | 
|---|
| 875 | // abOffs contains only half of the signal as ped. | 
|---|
| 876 | // Therefor abOffs is not the full, but the half amplitude | 
|---|
| 877 | fPedestalsOut->GetAverageArea(aidx).Set(ped, rms, abOffs, nevts); | 
|---|
| 878 | } | 
|---|
| 879 |  | 
|---|
| 880 | // --------------------------------------------------------------------------------- | 
|---|
| 881 | // | 
|---|
| 882 | // Calculates for sector idx "sector" with "nspix" valid pixels: | 
|---|
| 883 | // | 
|---|
| 884 | // Ped per slice      = sum / nevts / fExtractWinSize / nspix; | 
|---|
| 885 | // RMS per slice      = sqrt { (sum2 -  sum*sum/nevts) / (nevts-1) / fExtractWinSize / nspix } | 
|---|
| 886 | // ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / nevts / fExtractWinSize / nspix; | 
|---|
| 887 | // | 
|---|
| 888 | // Stores the results in MPedestalCam::GetAverageSector(sector) | 
|---|
| 889 | // | 
|---|
| 890 | void MExtractPedestal::CalcSectorResults(const UInt_t nevts, const UInt_t nspix, const UInt_t sector) | 
|---|
| 891 | { | 
|---|
| 892 | const Double_t sum  = fSectorSumx[sector]; | 
|---|
| 893 | const Double_t sum2 = fSectorSumx2[sector]; | 
|---|
| 894 |  | 
|---|
| 895 | // 1. Calculate the mean of the sums: | 
|---|
| 896 | Double_t ped        = sum/nevts; | 
|---|
| 897 |  | 
|---|
| 898 | // 2. Calculate the Variance of the sums: | 
|---|
| 899 | Double_t var = (sum2/nspix-sum*sum/nevts)/(nevts-1.); | 
|---|
| 900 |  | 
|---|
| 901 | // 3. Calculate the amplitude of the 150MHz "AB" noise | 
|---|
| 902 | Double_t abOffs = (fSectorSumAB0[sector] - fSectorSumAB1[sector]) / nevts; | 
|---|
| 903 |  | 
|---|
| 904 | // 4. Scale the mean, variance and AB-noise to the number of slices: | 
|---|
| 905 | ped    /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize; | 
|---|
| 906 | var    /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize; | 
|---|
| 907 | abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize; | 
|---|
| 908 | // The pedestal extracted with the extractor is divided by | 
|---|
| 909 | // the number of hi-gain samples because the calibration | 
|---|
| 910 | // multiplies by this number | 
|---|
| 911 |  | 
|---|
| 912 | // 5. Scale the mean, variance and AB-noise to the number of pixels: | 
|---|
| 913 | ped    /= nspix; | 
|---|
| 914 | var    /= nspix; | 
|---|
| 915 | abOffs /= nspix; | 
|---|
| 916 |  | 
|---|
| 917 | // 6. Calculate the RMS from the Variance: | 
|---|
| 918 | const Double_t rms = var<0 ? 0 : TMath::Sqrt(var); | 
|---|
| 919 |  | 
|---|
| 920 | // abOffs contains only half of the signal as ped. | 
|---|
| 921 | // Therefor abOffs is not the full, but the half amplitude | 
|---|
| 922 | fPedestalsOut->GetAverageSector(sector).Set(ped, rms, abOffs, nevts); | 
|---|
| 923 | } | 
|---|
| 924 |  | 
|---|
| 925 | //----------------------------------------------------------------------- | 
|---|
| 926 | // | 
|---|
| 927 | void MExtractPedestal::Print(Option_t *o) const | 
|---|
| 928 | { | 
|---|
| 929 | *fLog << GetDescriptor() << ":" << endl; | 
|---|
| 930 | *fLog << "Name of input  MPedestalCam:  " << (fPedestalsIn?fPedestalsIn->GetName():fNamePedestalCamIn.Data()) << " (" << fPedestalsIn << ")" << endl; | 
|---|
| 931 | *fLog << "Name of interm. MPedestalCam: " << (fPedestalsInter?fPedestalsInter->GetName():fNamePedestalCamInter.Data()) << " (" << fPedestalsInter << ")" << endl; | 
|---|
| 932 | *fLog << "Name of output MPedestalCam:  " << (fPedestalsOut?fPedestalsOut->GetName():fNamePedestalCamOut.Data()) << " (" << fPedestalsOut << ")" << endl; | 
|---|
| 933 | *fLog << "Intermediate Storage is       " << (fIntermediateStorage?"on":"off") << endl; | 
|---|
| 934 | *fLog << "Special pixel mode            " << (fUseSpecialPixels?"on":"off") << endl; | 
|---|
| 935 | if (fExtractor) | 
|---|
| 936 | { | 
|---|
| 937 | *fLog << "Extractor used:               " << fExtractor->ClassName() << " ("; | 
|---|
| 938 | *fLog << (fRandomCalculation?"":"non-") << "random)" << endl; | 
|---|
| 939 | } | 
|---|
| 940 | *fLog << "ExtractWindow from slice " << fExtractWinFirst << " to " << fExtractWinLast << " incl." << endl; | 
|---|
| 941 | *fLog << "CheckWindow from slice " << fCheckWinFirst   << " to " << fCheckWinLast << " incl." << endl; | 
|---|
| 942 | *fLog << "Max.allowed signal variation: " << fMaxSignalVar << endl; | 
|---|
| 943 | } | 
|---|