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