| 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, 02/2004 <mailto:markus@ifae.es> | 
|---|
| 19 | ! | 
|---|
| 20 | !   Copyright: MAGIC Software Development, 2000-2004 | 
|---|
| 21 | ! | 
|---|
| 22 | ! | 
|---|
| 23 | \* ======================================================================== */ | 
|---|
| 24 |  | 
|---|
| 25 | ////////////////////////////////////////////////////////////////////////////// | 
|---|
| 26 | // | 
|---|
| 27 | //   MExtractBlindPixel | 
|---|
| 28 | // | 
|---|
| 29 | //  Extracts the signal from a fixed window in a given range. | 
|---|
| 30 | // | 
|---|
| 31 | //    Call: SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast) | 
|---|
| 32 | //    to modify the ranges. The "low-gain" ranges are used for the NSB rejection | 
|---|
| 33 | //    whereas the high-gain ranges for blind pixel signal extraction. "High-gain" | 
|---|
| 34 | //    ranges can extend to the slices stored as "low-gain" in MRawEvtPixelIter | 
|---|
| 35 | // | 
|---|
| 36 | //    Defaults are: | 
|---|
| 37 | // | 
|---|
| 38 | //     fHiGainFirst =  fgHiGainFirst =  10 | 
|---|
| 39 | //     fHiGainLast  =  fgHiGainLast  =  29 | 
|---|
| 40 | //     fLoGainFirst =  fgLoGainFirst =  0 | 
|---|
| 41 | //     fLoGainLast  =  fgLoGainLast  =  7 | 
|---|
| 42 | // | 
|---|
| 43 | //  The switches: | 
|---|
| 44 | //  - SetExtractionType ( kAmplitude ) and  SetExtractionType ( kIntegral ) | 
|---|
| 45 | //    can be used to choose between amplitude extraction (using a spline) and | 
|---|
| 46 | //    summed integral. | 
|---|
| 47 | //  - SetExtractionType ( kFilter    ) | 
|---|
| 48 | //    can be used to apply a filter discarding events passing over a threshold | 
|---|
| 49 | //    defined in fNSBFilterLimit | 
|---|
| 50 | // | 
|---|
| 51 | ////////////////////////////////////////////////////////////////////////////// | 
|---|
| 52 | #include "MExtractBlindPixel.h" | 
|---|
| 53 |  | 
|---|
| 54 | #include "MLog.h" | 
|---|
| 55 | #include "MLogManip.h" | 
|---|
| 56 |  | 
|---|
| 57 | #include "MParList.h" | 
|---|
| 58 |  | 
|---|
| 59 | #include "MRawEvtData.h" | 
|---|
| 60 | #include "MRawRunHeader.h" | 
|---|
| 61 | #include "MRawEvtPixelIter.h" | 
|---|
| 62 |  | 
|---|
| 63 | #include "MExtractedSignalBlindPixel.h" | 
|---|
| 64 |  | 
|---|
| 65 | #include "MPedestalCam.h" | 
|---|
| 66 | #include "MPedestalPix.h" | 
|---|
| 67 |  | 
|---|
| 68 | ClassImp(MExtractBlindPixel); | 
|---|
| 69 |  | 
|---|
| 70 | using namespace std; | 
|---|
| 71 |  | 
|---|
| 72 | const UInt_t  MExtractBlindPixel::fgBlindPixelIdx    = 559; | 
|---|
| 73 | const Byte_t  MExtractBlindPixel::fgHiGainFirst      =  10; | 
|---|
| 74 | const Byte_t  MExtractBlindPixel::fgHiGainLast       =  19; | 
|---|
| 75 | const Byte_t  MExtractBlindPixel::fgLoGainFirst      =   0; | 
|---|
| 76 | const Byte_t  MExtractBlindPixel::fgLoGainLast       =   7; | 
|---|
| 77 | const Int_t   MExtractBlindPixel::fgNSBFilterLimit   =  70; | 
|---|
| 78 | const Float_t MExtractBlindPixel::fgResolution       = 0.003; | 
|---|
| 79 | const Float_t MExtractBlindPixel::gkOverflow         = 300.; | 
|---|
| 80 | // -------------------------------------------------------------------------- | 
|---|
| 81 | // | 
|---|
| 82 | // Default constructor. | 
|---|
| 83 | // | 
|---|
| 84 | // Initializes: | 
|---|
| 85 | // - fBlindPixelIdx to fgBlindPixelIdx | 
|---|
| 86 | // - fNSBFilterLimit to fgNSBFilterLimit | 
|---|
| 87 | // - fResolution to fgResolution | 
|---|
| 88 | // - fExtractionType to 0. | 
|---|
| 89 | // | 
|---|
| 90 | // Calls: | 
|---|
| 91 | // - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast); | 
|---|
| 92 | // | 
|---|
| 93 | MExtractBlindPixel::MExtractBlindPixel(const char *name, const char *title) | 
|---|
| 94 | : fHiGainSignal(NULL), | 
|---|
| 95 | fHiGainFirstDeriv(NULL), | 
|---|
| 96 | fHiGainSecondDeriv(NULL), | 
|---|
| 97 | fDataType(0) | 
|---|
| 98 | { | 
|---|
| 99 |  | 
|---|
| 100 | fName  = name  ? name  : "MExtractBlindPixel"; | 
|---|
| 101 | fTitle = title ? title : "Task to extract the signal from the FADC slices"; | 
|---|
| 102 |  | 
|---|
| 103 | SetResolution(); | 
|---|
| 104 | SetNSBFilterLimit(); | 
|---|
| 105 | SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast); | 
|---|
| 106 |  | 
|---|
| 107 | SetNumBlindPixels(); | 
|---|
| 108 |  | 
|---|
| 109 | Clear(); | 
|---|
| 110 |  | 
|---|
| 111 | } | 
|---|
| 112 |  | 
|---|
| 113 | // -------------------------------------------------------------------------- | 
|---|
| 114 | // | 
|---|
| 115 | // Destructor: | 
|---|
| 116 | // | 
|---|
| 117 | // - Deletes, (if not NULL): | 
|---|
| 118 | //   fHiGainSignal; | 
|---|
| 119 | //   fHiGainFirstDeriv; | 
|---|
| 120 | //   fHiGainSecondDeriv; | 
|---|
| 121 | // | 
|---|
| 122 | MExtractBlindPixel::~MExtractBlindPixel() | 
|---|
| 123 | { | 
|---|
| 124 |  | 
|---|
| 125 | if (fHiGainSignal) | 
|---|
| 126 | delete [] fHiGainSignal; | 
|---|
| 127 | if (fHiGainFirstDeriv) | 
|---|
| 128 | delete [] fHiGainFirstDeriv; | 
|---|
| 129 | if (fHiGainSecondDeriv) | 
|---|
| 130 | delete [] fHiGainSecondDeriv; | 
|---|
| 131 |  | 
|---|
| 132 | } | 
|---|
| 133 |  | 
|---|
| 134 | // -------------------------------------------------------------------------- | 
|---|
| 135 | // | 
|---|
| 136 | // Clear | 
|---|
| 137 | // | 
|---|
| 138 | // Initializes: | 
|---|
| 139 | // - fBlindPixelIdx to 0 | 
|---|
| 140 | // - fExtractionType to 0 | 
|---|
| 141 | // | 
|---|
| 142 | // Calls: | 
|---|
| 143 | // - SetBlindPixelIdx() | 
|---|
| 144 | // | 
|---|
| 145 | // Deletes and sets to NULL (if exists): | 
|---|
| 146 | // - fHiGainSignal | 
|---|
| 147 | // - fHiGainFirstDeriv | 
|---|
| 148 | // - fHiGainSecondDeriv | 
|---|
| 149 | // | 
|---|
| 150 | void MExtractBlindPixel::Clear( const Option_t *o) | 
|---|
| 151 | { | 
|---|
| 152 |  | 
|---|
| 153 | fExtractionType = 0; | 
|---|
| 154 |  | 
|---|
| 155 | fBlindPixelIdx.Set(0); | 
|---|
| 156 | SetBlindPixelIdx(); | 
|---|
| 157 |  | 
|---|
| 158 | if (fHiGainSignal) | 
|---|
| 159 | { | 
|---|
| 160 | delete [] fHiGainSignal; | 
|---|
| 161 | fHiGainSignal = NULL; | 
|---|
| 162 | } | 
|---|
| 163 | if (fHiGainFirstDeriv) | 
|---|
| 164 | { | 
|---|
| 165 | delete [] fHiGainFirstDeriv; | 
|---|
| 166 | fHiGainFirstDeriv = NULL; | 
|---|
| 167 | } | 
|---|
| 168 | if (fHiGainSecondDeriv) | 
|---|
| 169 | { | 
|---|
| 170 | delete [] fHiGainSecondDeriv; | 
|---|
| 171 | fHiGainSecondDeriv = NULL; | 
|---|
| 172 | } | 
|---|
| 173 |  | 
|---|
| 174 | } | 
|---|
| 175 |  | 
|---|
| 176 | void MExtractBlindPixel::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast) | 
|---|
| 177 | { | 
|---|
| 178 |  | 
|---|
| 179 | MExtractor::SetRange(hifirst,hilast,lofirst,lolast); | 
|---|
| 180 |  | 
|---|
| 181 | fNumHiGainSamples = (Float_t)(fHiGainLast-fHiGainFirst+1); | 
|---|
| 182 | if (lolast) | 
|---|
| 183 | fNumLoGainSamples = (Float_t)(fLoGainLast-fLoGainFirst+1); | 
|---|
| 184 | else | 
|---|
| 185 | fNumLoGainSamples = 0.; | 
|---|
| 186 |  | 
|---|
| 187 | fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples); | 
|---|
| 188 | fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples); | 
|---|
| 189 |  | 
|---|
| 190 | fHiLoFirst = 0; | 
|---|
| 191 | fHiLoLast  = 0; | 
|---|
| 192 | } | 
|---|
| 193 |  | 
|---|
| 194 | // -------------------------------------------------------------------------- | 
|---|
| 195 | // | 
|---|
| 196 | // Calls: | 
|---|
| 197 | // - MExtractor::PreProcess(pList) | 
|---|
| 198 | // | 
|---|
| 199 | // The following output containers are also searched and created if | 
|---|
| 200 | // they were not found: | 
|---|
| 201 | // | 
|---|
| 202 | //  - MExtractedBlindPixel | 
|---|
| 203 | // | 
|---|
| 204 | Int_t MExtractBlindPixel::PreProcess(MParList *pList) | 
|---|
| 205 | { | 
|---|
| 206 |  | 
|---|
| 207 | if (!MExtractor::PreProcess(pList)) | 
|---|
| 208 | return kFALSE; | 
|---|
| 209 |  | 
|---|
| 210 | fBlindPixel = (MExtractedSignalBlindPixel*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalBlindPixel")); | 
|---|
| 211 | if (!fBlindPixel) | 
|---|
| 212 | return kFALSE; | 
|---|
| 213 |  | 
|---|
| 214 | if (IsDataType(kRawEvt2)) | 
|---|
| 215 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData2")); | 
|---|
| 216 | else | 
|---|
| 217 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData")); | 
|---|
| 218 |  | 
|---|
| 219 | if (!fRawEvt) | 
|---|
| 220 | { | 
|---|
| 221 | *fLog << err << GetDescriptor() | 
|---|
| 222 | << Form("%s%s",IsDataType(kRawEvt2) ? "MRawEvtData2" : "MRawEvtData", | 
|---|
| 223 | " not found... aborting.") << endl; | 
|---|
| 224 | return kFALSE; | 
|---|
| 225 | } | 
|---|
| 226 | return kTRUE; | 
|---|
| 227 | } | 
|---|
| 228 |  | 
|---|
| 229 | // -------------------------------------------------------------------------- // | 
|---|
| 230 | // | 
|---|
| 231 | // The ReInit searches for: | 
|---|
| 232 | // -  MRawRunHeader::GetNumSamplesHiGain() | 
|---|
| 233 | // -  MRawRunHeader::GetNumSamplesLoGain() | 
|---|
| 234 | // | 
|---|
| 235 | // In case that the variables fHiGainLast and fLoGainLast are smaller than | 
|---|
| 236 | // the even part of the number of samples obtained from the run header, a | 
|---|
| 237 | // warning is given an the range is set back accordingly. A call to: | 
|---|
| 238 | // - SetRange(fHiGainFirst, fHiGainLast-diff, fLoGainFirst, fLoGainLast) or | 
|---|
| 239 | // - SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff) | 
|---|
| 240 | // is performed in that case. The variable diff means here the difference | 
|---|
| 241 | // between the requested range (fHiGainLast) and the available one. Note that | 
|---|
| 242 | // the functions SetRange() are mostly overloaded and perform more checks, | 
|---|
| 243 | // modifying the ranges again, if necessary. | 
|---|
| 244 | // | 
|---|
| 245 | Bool_t MExtractBlindPixel::ReInit(MParList *pList) | 
|---|
| 246 | { | 
|---|
| 247 |  | 
|---|
| 248 | if (fHiGainSignal) | 
|---|
| 249 | delete [] fHiGainSignal; | 
|---|
| 250 | if (fHiGainFirstDeriv) | 
|---|
| 251 | delete [] fHiGainFirstDeriv; | 
|---|
| 252 | if (fHiGainSecondDeriv) | 
|---|
| 253 | delete [] fHiGainSecondDeriv; | 
|---|
| 254 |  | 
|---|
| 255 | for (Int_t i=0;i<fNumBlindPixels;i++) | 
|---|
| 256 | fBlindPixel->SetBlindPixelIdx(fBlindPixelIdx.At(i),i); | 
|---|
| 257 |  | 
|---|
| 258 | fBlindPixel->SetExtractionType(fExtractionType); | 
|---|
| 259 |  | 
|---|
| 260 | for (Int_t i=0;i<fBlindPixelIdx.GetSize();i++) | 
|---|
| 261 | { | 
|---|
| 262 |  | 
|---|
| 263 | MPedestalPix &pedpix  = (*fPedestals)[fBlindPixelIdx.At(i)]; | 
|---|
| 264 |  | 
|---|
| 265 | if (&pedpix) | 
|---|
| 266 | { | 
|---|
| 267 | fBlindPixel->SetPed      ( pedpix.GetPedestal()   * fNumLoGainSamples, i ); | 
|---|
| 268 | fBlindPixel->SetPedErr   ( pedpix.GetPedestalRms()* fNumLoGainSamples | 
|---|
| 269 | / TMath::Sqrt((Float_t)fPedestals->GetTotalEntries()), i ); | 
|---|
| 270 | fBlindPixel->SetPedRms   ( pedpix.GetPedestalRms()* TMath::Sqrt((Float_t)fNumLoGainSamples), i ); | 
|---|
| 271 | fBlindPixel->SetPedRmsErr( fBlindPixel->GetPedErr()/2., i ); | 
|---|
| 272 | } | 
|---|
| 273 | } | 
|---|
| 274 |  | 
|---|
| 275 | const Int_t higainsamples = fRunHeader->GetNumSamplesHiGain(); | 
|---|
| 276 | const Int_t logainsamples = fRunHeader->GetNumSamplesLoGain(); | 
|---|
| 277 | Int_t lastavailable       =  higainsamples-1; | 
|---|
| 278 |  | 
|---|
| 279 | if (logainsamples) | 
|---|
| 280 | { | 
|---|
| 281 | // | 
|---|
| 282 | // If the signal is searched entirely in the low-gain range, have | 
|---|
| 283 | // to skip the higain completely. This is steered by the variable fHiLoFirst | 
|---|
| 284 | // | 
|---|
| 285 | const Int_t firstdesired   = (Int_t)fHiGainFirst; | 
|---|
| 286 |  | 
|---|
| 287 | if (firstdesired > lastavailable) | 
|---|
| 288 | { | 
|---|
| 289 | const Int_t diff = firstdesired - lastavailable; | 
|---|
| 290 | *fLog << endl; | 
|---|
| 291 | *fLog << warn << "First Hi Gain slice " << (int)fHiGainFirst << " out of range [0,"; | 
|---|
| 292 | *fLog << lastavailable << "]... start at slice " << diff << " of the Lo Gain " << endl; | 
|---|
| 293 |  | 
|---|
| 294 | fHiLoFirst   = diff; | 
|---|
| 295 | } | 
|---|
| 296 | } | 
|---|
| 297 |  | 
|---|
| 298 | const Int_t lastdesired = (Int_t)fHiGainLast; | 
|---|
| 299 |  | 
|---|
| 300 | if (lastdesired > lastavailable) | 
|---|
| 301 | { | 
|---|
| 302 | Int_t diff     = lastdesired - lastavailable; | 
|---|
| 303 | lastavailable += logainsamples ? logainsamples-1 : 0; | 
|---|
| 304 |  | 
|---|
| 305 | if (lastdesired > lastavailable) | 
|---|
| 306 | { | 
|---|
| 307 | *fLog << endl; | 
|---|
| 308 | *fLog << "Last Hi Gain slice " << (int)fHiGainLast << " out of range [0,"; | 
|---|
| 309 | *fLog << lastavailable << "]... reduce upper limit by " << diff << endl; | 
|---|
| 310 | diff = logainsamples; | 
|---|
| 311 | } | 
|---|
| 312 |  | 
|---|
| 313 | fHiGainLast = higainsamples - 1; | 
|---|
| 314 | fHiLoLast   = logainsamples ? diff : 0; | 
|---|
| 315 | } | 
|---|
| 316 |  | 
|---|
| 317 | const Int_t range = fHiLoFirst ? fHiLoLast - fHiLoFirst + 1 : fHiGainLast - fHiGainFirst + fHiLoLast + 1; | 
|---|
| 318 |  | 
|---|
| 319 | fHiGainSignal      = new Float_t[range]; | 
|---|
| 320 | memset(fHiGainSignal,0,range*sizeof(Float_t)); | 
|---|
| 321 | fHiGainFirstDeriv  = new Float_t[range]; | 
|---|
| 322 | memset(fHiGainFirstDeriv,0,range*sizeof(Float_t)); | 
|---|
| 323 | fHiGainSecondDeriv = new Float_t[range]; | 
|---|
| 324 | memset(fHiGainSecondDeriv,0,range*sizeof(Float_t)); | 
|---|
| 325 |  | 
|---|
| 326 | *fLog << endl; | 
|---|
| 327 | *fLog << inf << "Extracting " | 
|---|
| 328 | << (IsExtractionType(kAmplitude) ? "Amplitude" : " Integral") | 
|---|
| 329 | << " using " << range << " FADC samples from " | 
|---|
| 330 | << (fHiLoFirst ? "Low Gain slice" : " High Gain slice") | 
|---|
| 331 | << (fHiLoFirst ? (Int_t)fHiLoFirst : (Int_t)fHiGainFirst) | 
|---|
| 332 | << " to (including) " | 
|---|
| 333 | << (fHiLoLast ? "Low Gain slice" : "High Gain slice") | 
|---|
| 334 | << (fHiLoLast ?  (Int_t)fHiLoLast-1 : (Int_t)fHiGainLast) | 
|---|
| 335 | << endl; | 
|---|
| 336 |  | 
|---|
| 337 | if (IsExtractionType(kFilter)) | 
|---|
| 338 | *fLog << inf << "Will use Filter using " | 
|---|
| 339 | << (Int_t)(fLoGainLast-fLoGainFirst+1) << " FADC slices" | 
|---|
| 340 | << " from High Gain slice " << (Int_t)fLoGainFirst | 
|---|
| 341 | << " to High Gain slice " << (Int_t)fLoGainLast << endl; | 
|---|
| 342 |  | 
|---|
| 343 | fBlindPixel->SetUsedFADCSlices(fHiGainFirst, range); | 
|---|
| 344 |  | 
|---|
| 345 | return kTRUE; | 
|---|
| 346 |  | 
|---|
| 347 | } | 
|---|
| 348 |  | 
|---|
| 349 | // -------------------------------------------------------------------------- | 
|---|
| 350 | // | 
|---|
| 351 | // FindSignalHiGain: | 
|---|
| 352 | // | 
|---|
| 353 | // - Loop from ptr to (ptr+fHiGainLast-fHiGainFirst) | 
|---|
| 354 | // - Sum up contents of *ptr | 
|---|
| 355 | // - If *ptr is greater than fSaturationLimit, raise sat by 1 | 
|---|
| 356 | // - If fHiLoLast is set, loop from logain to (logain+fHiLoLast) | 
|---|
| 357 | // - Add contents of *logain to sum | 
|---|
| 358 | // | 
|---|
| 359 | void MExtractBlindPixel::FindIntegral(Byte_t *ptr, Byte_t *logain, Float_t &sum, Byte_t &sat) | 
|---|
| 360 | { | 
|---|
| 361 |  | 
|---|
| 362 | Int_t summ = 0; | 
|---|
| 363 | Byte_t *p   = ptr; | 
|---|
| 364 | Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1; | 
|---|
| 365 |  | 
|---|
| 366 | if (fHiLoFirst == 0) | 
|---|
| 367 | { | 
|---|
| 368 |  | 
|---|
| 369 | while (p<end) | 
|---|
| 370 | { | 
|---|
| 371 | summ += *ptr; | 
|---|
| 372 |  | 
|---|
| 373 | if (*p++ >= fSaturationLimit) | 
|---|
| 374 | sat++; | 
|---|
| 375 | } | 
|---|
| 376 |  | 
|---|
| 377 | } | 
|---|
| 378 |  | 
|---|
| 379 | p   = logain + fHiLoFirst; | 
|---|
| 380 | end = logain + fHiLoLast; | 
|---|
| 381 | while (p<end) | 
|---|
| 382 | { | 
|---|
| 383 | summ += *p; | 
|---|
| 384 |  | 
|---|
| 385 | if (*p++ >= fSaturationLimit) | 
|---|
| 386 | sat++; | 
|---|
| 387 | } | 
|---|
| 388 |  | 
|---|
| 389 | sum = (Float_t)summ; | 
|---|
| 390 | } | 
|---|
| 391 |  | 
|---|
| 392 | // -------------------------------------------------------------------------- | 
|---|
| 393 | // | 
|---|
| 394 | // FindSignalPhe: | 
|---|
| 395 | // | 
|---|
| 396 | // - Loop from ptr to (ptr+fHiGainLast-fHiGainFirst) | 
|---|
| 397 | // - Sum up contents of *ptr | 
|---|
| 398 | // - If *ptr is greater than fSaturationLimit, raise sat by 1 | 
|---|
| 399 | // - If fHiLoLast is set, loop from logain to (logain+fHiLoLast) | 
|---|
| 400 | // - Add contents of *logain to sum | 
|---|
| 401 | // | 
|---|
| 402 | void MExtractBlindPixel::FindAmplitude(Byte_t *ptr, Byte_t *logain, Float_t &sum, Byte_t &sat) | 
|---|
| 403 | { | 
|---|
| 404 |  | 
|---|
| 405 | Int_t range   = 0; | 
|---|
| 406 | Int_t count   = 0; | 
|---|
| 407 | Float_t abmaxpos = 0.; | 
|---|
| 408 | Byte_t *p     = ptr; | 
|---|
| 409 | Byte_t *end; | 
|---|
| 410 | Byte_t max    = 0; | 
|---|
| 411 | Byte_t maxpos = 0; | 
|---|
| 412 | Int_t summ   = 0; | 
|---|
| 413 |  | 
|---|
| 414 | if (fHiLoFirst == 0) | 
|---|
| 415 | { | 
|---|
| 416 |  | 
|---|
| 417 | range = fHiGainLast - fHiGainFirst + 1; | 
|---|
| 418 |  | 
|---|
| 419 | end   = ptr + range; | 
|---|
| 420 | // | 
|---|
| 421 | // Check for saturation in all other slices | 
|---|
| 422 | // | 
|---|
| 423 | while (p++<end) | 
|---|
| 424 | { | 
|---|
| 425 |  | 
|---|
| 426 | fHiGainSignal[count] = (Float_t)*p; | 
|---|
| 427 | summ += *p; | 
|---|
| 428 |  | 
|---|
| 429 | if (*p > max) | 
|---|
| 430 | { | 
|---|
| 431 | max    = *p; | 
|---|
| 432 | maxpos =  count; | 
|---|
| 433 | } | 
|---|
| 434 |  | 
|---|
| 435 | count++; | 
|---|
| 436 |  | 
|---|
| 437 | if (*p >= fSaturationLimit) | 
|---|
| 438 | sat++; | 
|---|
| 439 | } | 
|---|
| 440 | } | 
|---|
| 441 |  | 
|---|
| 442 | if (fHiLoLast != 0) | 
|---|
| 443 | { | 
|---|
| 444 |  | 
|---|
| 445 | p    = logain + fHiLoFirst; | 
|---|
| 446 | end  = logain + fHiLoLast; | 
|---|
| 447 |  | 
|---|
| 448 | while (p<end) | 
|---|
| 449 | { | 
|---|
| 450 |  | 
|---|
| 451 | fHiGainSignal[count] = (Float_t)*p; | 
|---|
| 452 | summ += *p; | 
|---|
| 453 |  | 
|---|
| 454 | if (*p > max) | 
|---|
| 455 | { | 
|---|
| 456 | max    = *p; | 
|---|
| 457 | maxpos =  count; | 
|---|
| 458 | } | 
|---|
| 459 |  | 
|---|
| 460 | range++; | 
|---|
| 461 | count++; | 
|---|
| 462 |  | 
|---|
| 463 | if (*p++ >= fSaturationLimit) | 
|---|
| 464 | sat++; | 
|---|
| 465 | } | 
|---|
| 466 | } | 
|---|
| 467 |  | 
|---|
| 468 | // | 
|---|
| 469 | // allow one saturated slice | 
|---|
| 470 | // | 
|---|
| 471 | if (sat > 1) | 
|---|
| 472 | { | 
|---|
| 473 | sum = gkOverflow; | 
|---|
| 474 | return; | 
|---|
| 475 | } | 
|---|
| 476 |  | 
|---|
| 477 | // | 
|---|
| 478 | // Don't start if the maxpos is too close to the left limit. | 
|---|
| 479 | // | 
|---|
| 480 | if (maxpos < 2) | 
|---|
| 481 | { | 
|---|
| 482 | sum = (Float_t)max; | 
|---|
| 483 | return; | 
|---|
| 484 | } | 
|---|
| 485 |  | 
|---|
| 486 | Float_t pp; | 
|---|
| 487 |  | 
|---|
| 488 | for (Int_t i=1;i<range-1;i++) | 
|---|
| 489 | { | 
|---|
| 490 | pp = fHiGainSecondDeriv[i-1] + 4.; | 
|---|
| 491 | fHiGainSecondDeriv[i] = -1.0/pp; | 
|---|
| 492 | fHiGainFirstDeriv [i] = fHiGainSignal[i+1] - fHiGainSignal[i] - fHiGainSignal[i] + fHiGainSignal[i-1]; | 
|---|
| 493 | fHiGainFirstDeriv [i] = (6.0*fHiGainFirstDeriv[i]-fHiGainFirstDeriv[i-1])/pp; | 
|---|
| 494 | p++; | 
|---|
| 495 | } | 
|---|
| 496 |  | 
|---|
| 497 | fHiGainSecondDeriv[range-1] = 0.; | 
|---|
| 498 | for (Int_t k=range-2;k>=0;k--) | 
|---|
| 499 | fHiGainSecondDeriv[k] = (fHiGainSecondDeriv[k]*fHiGainSecondDeriv[k+1] + fHiGainFirstDeriv[k])/6.; | 
|---|
| 500 |  | 
|---|
| 501 | // | 
|---|
| 502 | // Now find the maximum | 
|---|
| 503 | // | 
|---|
| 504 | Float_t step  = 0.2; // start with step size of 1ns and loop again with the smaller one | 
|---|
| 505 | Float_t lower = (Float_t)maxpos-1.; | 
|---|
| 506 | Float_t upper = (Float_t)maxpos; | 
|---|
| 507 | Float_t x     = lower; | 
|---|
| 508 | Float_t y     = 0.; | 
|---|
| 509 | Float_t a     = 1.; | 
|---|
| 510 | Float_t b     = 0.; | 
|---|
| 511 | Int_t   klo = maxpos-1; | 
|---|
| 512 | Int_t   khi = maxpos; | 
|---|
| 513 | Float_t klocont = fHiGainSignal[klo]; | 
|---|
| 514 | Float_t khicont = fHiGainSignal[khi]; | 
|---|
| 515 | sum       = (Float_t)khicont; | 
|---|
| 516 | abmaxpos  = lower; | 
|---|
| 517 |  | 
|---|
| 518 | // | 
|---|
| 519 | // Search for the maximum, starting in interval maxpos-1. If no maximum is found, go to | 
|---|
| 520 | // interval maxpos+1. | 
|---|
| 521 | // | 
|---|
| 522 | while (x<upper-0.3) | 
|---|
| 523 | { | 
|---|
| 524 |  | 
|---|
| 525 | x += step; | 
|---|
| 526 | a -= step; | 
|---|
| 527 | b += step; | 
|---|
| 528 |  | 
|---|
| 529 | y = a*klocont | 
|---|
| 530 | + b*khicont | 
|---|
| 531 | + (a*a*a-a)*fHiGainSecondDeriv[klo] | 
|---|
| 532 | + (b*b*b-b)*fHiGainSecondDeriv[khi]; | 
|---|
| 533 |  | 
|---|
| 534 | if (y > sum) | 
|---|
| 535 | { | 
|---|
| 536 | sum      = y; | 
|---|
| 537 | abmaxpos = x; | 
|---|
| 538 | } | 
|---|
| 539 | } | 
|---|
| 540 |  | 
|---|
| 541 | if (abmaxpos > upper-0.1) | 
|---|
| 542 | { | 
|---|
| 543 |  | 
|---|
| 544 | upper = (Float_t)maxpos+1; | 
|---|
| 545 | lower = (Float_t)maxpos; | 
|---|
| 546 | x     = lower; | 
|---|
| 547 | a     = 1.; | 
|---|
| 548 | b     = 0.; | 
|---|
| 549 | khi   = maxpos+1; | 
|---|
| 550 | klo   = maxpos; | 
|---|
| 551 | klocont = fHiGainSignal[klo]; | 
|---|
| 552 | khicont = fHiGainSignal[khi]; | 
|---|
| 553 |  | 
|---|
| 554 | while (x<upper-0.3) | 
|---|
| 555 | { | 
|---|
| 556 |  | 
|---|
| 557 | x += step; | 
|---|
| 558 | a -= step; | 
|---|
| 559 | b += step; | 
|---|
| 560 |  | 
|---|
| 561 | y = a* klocont | 
|---|
| 562 | + b* khicont | 
|---|
| 563 | + (a*a*a-a)*fHiGainSecondDeriv[klo] | 
|---|
| 564 | + (b*b*b-b)*fHiGainSecondDeriv[khi]; | 
|---|
| 565 |  | 
|---|
| 566 | if (y > sum) | 
|---|
| 567 | { | 
|---|
| 568 | sum    = y; | 
|---|
| 569 | abmaxpos = x; | 
|---|
| 570 | } | 
|---|
| 571 | } | 
|---|
| 572 | } | 
|---|
| 573 |  | 
|---|
| 574 | const Float_t up = abmaxpos+step-0.055; | 
|---|
| 575 | const Float_t lo = abmaxpos-step+0.055; | 
|---|
| 576 | const Float_t maxpossave = abmaxpos; | 
|---|
| 577 |  | 
|---|
| 578 | x     = abmaxpos; | 
|---|
| 579 | a     = upper - x; | 
|---|
| 580 | b     = x - lower; | 
|---|
| 581 |  | 
|---|
| 582 | step  = 0.04; // step size of 83 ps | 
|---|
| 583 |  | 
|---|
| 584 | while (x<up) | 
|---|
| 585 | { | 
|---|
| 586 |  | 
|---|
| 587 | x += step; | 
|---|
| 588 | a -= step; | 
|---|
| 589 | b += step; | 
|---|
| 590 |  | 
|---|
| 591 | y = a* klocont | 
|---|
| 592 | + b* khicont | 
|---|
| 593 | + (a*a*a-a)*fHiGainSecondDeriv[klo] | 
|---|
| 594 | + (b*b*b-b)*fHiGainSecondDeriv[khi]; | 
|---|
| 595 |  | 
|---|
| 596 | if (y > sum) | 
|---|
| 597 | { | 
|---|
| 598 | sum    = y; | 
|---|
| 599 | abmaxpos = x; | 
|---|
| 600 | } | 
|---|
| 601 | } | 
|---|
| 602 |  | 
|---|
| 603 | if (abmaxpos < klo + 0.02) | 
|---|
| 604 | { | 
|---|
| 605 | klo--; | 
|---|
| 606 | khi--; | 
|---|
| 607 | klocont = fHiGainSignal[klo]; | 
|---|
| 608 | khicont = fHiGainSignal[khi]; | 
|---|
| 609 | upper--; | 
|---|
| 610 | lower--; | 
|---|
| 611 | } | 
|---|
| 612 |  | 
|---|
| 613 | x     = maxpossave; | 
|---|
| 614 | a     = upper - x; | 
|---|
| 615 | b     = x - lower; | 
|---|
| 616 |  | 
|---|
| 617 | while (x>lo) | 
|---|
| 618 | { | 
|---|
| 619 |  | 
|---|
| 620 | x -= step; | 
|---|
| 621 | a += step; | 
|---|
| 622 | b -= step; | 
|---|
| 623 |  | 
|---|
| 624 | y = a* klocont | 
|---|
| 625 | + b* khicont | 
|---|
| 626 | + (a*a*a-a)*fHiGainSecondDeriv[klo] | 
|---|
| 627 | + (b*b*b-b)*fHiGainSecondDeriv[khi]; | 
|---|
| 628 |  | 
|---|
| 629 | if (y > sum) | 
|---|
| 630 | { | 
|---|
| 631 | sum    = y; | 
|---|
| 632 | abmaxpos = x; | 
|---|
| 633 | } | 
|---|
| 634 | } | 
|---|
| 635 |  | 
|---|
| 636 | } | 
|---|
| 637 |  | 
|---|
| 638 | // -------------------------------------------------------------------------- | 
|---|
| 639 | // | 
|---|
| 640 | // FindSignalFilter: | 
|---|
| 641 | // | 
|---|
| 642 | // - Loop from ptr to (ptr+fLoGainLast-fLoGainFirst) | 
|---|
| 643 | // - Sum up contents of *ptr | 
|---|
| 644 | // - If *ptr is greater than fSaturationLimit, raise sat by 1 | 
|---|
| 645 | // | 
|---|
| 646 | void MExtractBlindPixel::FindSignalFilter(Byte_t *ptr, Int_t &sum, Byte_t &sat) const | 
|---|
| 647 | { | 
|---|
| 648 |  | 
|---|
| 649 | Byte_t *end = ptr + fLoGainLast - fLoGainFirst + 1; | 
|---|
| 650 |  | 
|---|
| 651 | while (ptr<end) | 
|---|
| 652 | { | 
|---|
| 653 | sum += *ptr; | 
|---|
| 654 |  | 
|---|
| 655 | if (*ptr++ >= fSaturationLimit) | 
|---|
| 656 | sat++; | 
|---|
| 657 | } | 
|---|
| 658 | } | 
|---|
| 659 |  | 
|---|
| 660 | // -------------------------------------------------------------------------- | 
|---|
| 661 | // | 
|---|
| 662 | // Calculate the integral of the FADC time slices and store them as a new | 
|---|
| 663 | // pixel in the MExtractedBlindPixel container. | 
|---|
| 664 | // | 
|---|
| 665 | Int_t MExtractBlindPixel::Process() | 
|---|
| 666 | { | 
|---|
| 667 |  | 
|---|
| 668 | MRawEvtPixelIter pixel(fRawEvt); | 
|---|
| 669 |  | 
|---|
| 670 | fBlindPixel->Clear(); | 
|---|
| 671 |  | 
|---|
| 672 | for (Int_t id=0;id<fBlindPixelIdx.GetSize();id++) | 
|---|
| 673 | { | 
|---|
| 674 |  | 
|---|
| 675 | pixel.Jump(fBlindPixelIdx[id]); | 
|---|
| 676 |  | 
|---|
| 677 | Int_t sum   = 0; | 
|---|
| 678 | Byte_t sat  = 0; | 
|---|
| 679 |  | 
|---|
| 680 | if (IsExtractionType(kFilter)) | 
|---|
| 681 | { | 
|---|
| 682 |  | 
|---|
| 683 | FindSignalFilter(pixel.GetHiGainSamples()+fLoGainFirst, sum, sat); | 
|---|
| 684 |  | 
|---|
| 685 | if (sum > fNSBFilterLimit) | 
|---|
| 686 | { | 
|---|
| 687 | fBlindPixel->SetExtractedSignal(-1.,id); | 
|---|
| 688 | fBlindPixel->SetNumSaturated(sat,id); | 
|---|
| 689 | fBlindPixel->SetReadyToSave(); | 
|---|
| 690 | continue; | 
|---|
| 691 | } | 
|---|
| 692 |  | 
|---|
| 693 | sum = 0; | 
|---|
| 694 | if (pixel.HasLoGain()) | 
|---|
| 695 | FindSignalFilter(pixel.GetLoGainSamples(), sum, sat); | 
|---|
| 696 |  | 
|---|
| 697 | /* | 
|---|
| 698 | if (fModified) | 
|---|
| 699 | { | 
|---|
| 700 | if (sum > fNSBFilterLimit) | 
|---|
| 701 | { | 
|---|
| 702 | fBlindPixel->SetExtractedSignal(-1.,id); | 
|---|
| 703 | fBlindPixel->SetNumSaturated(sat,id); | 
|---|
| 704 | fBlindPixel->SetReadyToSave(); | 
|---|
| 705 | continue; | 
|---|
| 706 | } | 
|---|
| 707 | } | 
|---|
| 708 | */ | 
|---|
| 709 | } | 
|---|
| 710 |  | 
|---|
| 711 | Float_t newsum = 0.; | 
|---|
| 712 | sat = 0; | 
|---|
| 713 |  | 
|---|
| 714 | if (IsExtractionType(kAmplitude)) | 
|---|
| 715 | FindAmplitude   (pixel.GetHiGainSamples()+fHiGainFirst, pixel.GetLoGainSamples(), newsum, sat); | 
|---|
| 716 | else | 
|---|
| 717 | FindIntegral    (pixel.GetHiGainSamples()+fHiGainFirst, pixel.GetLoGainSamples(), newsum, sat); | 
|---|
| 718 |  | 
|---|
| 719 |  | 
|---|
| 720 | fBlindPixel->SetExtractedSignal(newsum,id); | 
|---|
| 721 | fBlindPixel->SetNumSaturated(sat,id); | 
|---|
| 722 | } | 
|---|
| 723 |  | 
|---|
| 724 | fBlindPixel->SetReadyToSave(); | 
|---|
| 725 | return kTRUE; | 
|---|
| 726 | } | 
|---|
| 727 |  | 
|---|
| 728 | // ------------------------------------------------------------------------------------ | 
|---|
| 729 | // | 
|---|
| 730 | // Returns true if the Data type. Available are: kAmplitude, kIntegral and kFilter | 
|---|
| 731 | // The flags kIntegral and kFilter may be set both. | 
|---|
| 732 | // | 
|---|
| 733 | Bool_t MExtractBlindPixel::IsDataType( const DataType_t typ ) | 
|---|
| 734 | { | 
|---|
| 735 |  | 
|---|
| 736 | return TESTBIT( fDataType, typ ); | 
|---|
| 737 |  | 
|---|
| 738 | } | 
|---|
| 739 |  | 
|---|
| 740 | // ------------------------------------------------------------------------------------ | 
|---|
| 741 | // | 
|---|
| 742 | // Returns true if the extraction type. Available are: kAmplitude, kIntegral and kFilter | 
|---|
| 743 | // The flags kIntegral and kFilter may be set both. | 
|---|
| 744 | // | 
|---|
| 745 | Bool_t MExtractBlindPixel::IsExtractionType( const ExtractionType_t typ ) | 
|---|
| 746 | { | 
|---|
| 747 |  | 
|---|
| 748 | return TESTBIT( fExtractionType, typ ); | 
|---|
| 749 |  | 
|---|
| 750 | } | 
|---|
| 751 |  | 
|---|
| 752 | // -------------------------------------------------------------------------- | 
|---|
| 753 | // | 
|---|
| 754 | // Sets the Data type. Available are: kAmplitude and kIntegral | 
|---|
| 755 | // | 
|---|
| 756 | void MExtractBlindPixel::SetDataType( const DataType_t typ ) | 
|---|
| 757 | { | 
|---|
| 758 | SETBIT( fDataType, typ ); | 
|---|
| 759 | } | 
|---|
| 760 |  | 
|---|
| 761 | // -------------------------------------------------------------------------- | 
|---|
| 762 | // | 
|---|
| 763 | // Sets the extraction type. Available are: kAmplitude and kIntegral | 
|---|
| 764 | // | 
|---|
| 765 | void MExtractBlindPixel::SetExtractionType( const ExtractionType_t typ ) | 
|---|
| 766 | { | 
|---|
| 767 | SETBIT( fExtractionType, typ ); | 
|---|
| 768 | } | 
|---|