| 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 | // MExtractPINDiode
|
|---|
| 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. Ranges have to be an even number. In case of odd
|
|---|
| 33 | // ranges, the last slice will be reduced by one.
|
|---|
| 34 | // Defaults are:
|
|---|
| 35 | //
|
|---|
| 36 | // fHiGainFirst = fgHiGainFirst = 3
|
|---|
| 37 | // fHiGainLast = fgHiGainLast = 14
|
|---|
| 38 | // fLoGainFirst = fgLoGainFirst = 3
|
|---|
| 39 | // fLoGainLast = fgLoGainLast = 14
|
|---|
| 40 | //
|
|---|
| 41 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 42 | #include "MExtractPINDiode.h"
|
|---|
| 43 |
|
|---|
| 44 | #include <fstream>
|
|---|
| 45 |
|
|---|
| 46 | #include "MLog.h"
|
|---|
| 47 | #include "MLogManip.h"
|
|---|
| 48 |
|
|---|
| 49 | #include "MParList.h"
|
|---|
| 50 |
|
|---|
| 51 | #include "MRawEvtData.h"
|
|---|
| 52 | #include "MRawEvtPixelIter.h"
|
|---|
| 53 |
|
|---|
| 54 | #include "MPedestalCam.h"
|
|---|
| 55 | #include "MPedestalPix.h"
|
|---|
| 56 |
|
|---|
| 57 | #include "MExtractedSignalPINDiode.h"
|
|---|
| 58 |
|
|---|
| 59 | ClassImp(MExtractPINDiode);
|
|---|
| 60 |
|
|---|
| 61 | using namespace std;
|
|---|
| 62 |
|
|---|
| 63 | const UInt_t MExtractPINDiode::fgPINDiodeIdx = 100;
|
|---|
| 64 | const Byte_t MExtractPINDiode::fgHiGainFirst = 0;
|
|---|
| 65 | const Byte_t MExtractPINDiode::fgHiGainLast = 14;
|
|---|
| 66 | const Byte_t MExtractPINDiode::fgLoGainFirst = 0;
|
|---|
| 67 | const Byte_t MExtractPINDiode::fgLoGainLast = 14;
|
|---|
| 68 | // --------------------------------------------------------------------------
|
|---|
| 69 | //
|
|---|
| 70 | // Default constructor.
|
|---|
| 71 | //
|
|---|
| 72 | // Calls:
|
|---|
| 73 | // - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
|
|---|
| 74 | // - SetPINDiodeIdx()
|
|---|
| 75 | //
|
|---|
| 76 | MExtractPINDiode::MExtractPINDiode(const char *name, const char *title)
|
|---|
| 77 | {
|
|---|
| 78 |
|
|---|
| 79 | fName = name ? name : "MExtractPINDiode";
|
|---|
| 80 | fTitle = title ? title : "Task to extract the signal from the FADC slices";
|
|---|
| 81 |
|
|---|
| 82 | SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
|
|---|
| 83 | SetPINDiodeIdx();
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | // --------------------------------------------------------------------------
|
|---|
| 87 | //
|
|---|
| 88 | // SetRange:
|
|---|
| 89 | //
|
|---|
| 90 | // Checks:
|
|---|
| 91 | // - if the window defined by (fHiGainLast-fHiGainFirst-1) are odd, subtract one
|
|---|
| 92 | // - if the window defined by (fLoGainLast-fLoGainFirst-1) are odd, subtract one
|
|---|
| 93 | // - if the Hi Gain window is smaller than 2, set fHiGainLast to fHiGainFirst+1
|
|---|
| 94 | // - if the Lo Gain window is smaller than 2, set fLoGainLast to fLoGainFirst+1
|
|---|
| 95 | //
|
|---|
| 96 | // Calls:
|
|---|
| 97 | // - MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
|
|---|
| 98 | //
|
|---|
| 99 | // Sets:
|
|---|
| 100 | // - fNumHiGainSamples to: (Float_t)(fHiGainLast-fHiGainFirst+1)
|
|---|
| 101 | // - fNumLoGainSamples to: (Float_t)(fLoGainLast-fLoGainFirst+1)
|
|---|
| 102 | // - fSqrtHiGainSamples to: TMath::Sqrt(fNumHiGainSamples)
|
|---|
| 103 | // - fSqrtLoGainSamples to: TMath::Sqrt(fNumLoGainSamples)
|
|---|
| 104 | //
|
|---|
| 105 | void MExtractPINDiode::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
|
|---|
| 106 | {
|
|---|
| 107 |
|
|---|
| 108 | const Byte_t window = hilast-hifirst+1+lolast-lofirst+1;
|
|---|
| 109 | const Byte_t weven = window & ~1;
|
|---|
| 110 |
|
|---|
| 111 | if (weven != window)
|
|---|
| 112 | {
|
|---|
| 113 | *fLog << warn << GetDescriptor()
|
|---|
| 114 | << Form("%s%2i%s%2i",": Total window size has to be even, set last slice from "
|
|---|
| 115 | ,(int)lolast," to ",(int)(lolast-1)) << endl;
|
|---|
| 116 | lolast -= 1;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | if (window<2)
|
|---|
| 120 | {
|
|---|
| 121 | *fLog << warn << GetDescriptor()
|
|---|
| 122 | << Form("%s%2i%s%2i",": Total window is smaller than 2 FADC sampes, set last slice from"
|
|---|
| 123 | ,(int)lolast," to ",(int)(lofirst+1)) << endl;
|
|---|
| 124 | hilast = hifirst+1;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 | MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
|
|---|
| 129 |
|
|---|
| 130 | fNumHiGainSamples = (Float_t)(fHiGainLast-fHiGainFirst+1);
|
|---|
| 131 | fNumLoGainSamples = (fLoGainLast == 0) ? 0. : (Float_t)(fLoGainLast-fLoGainFirst+1);
|
|---|
| 132 |
|
|---|
| 133 | fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
|
|---|
| 134 | fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
|
|---|
| 135 |
|
|---|
| 136 | fNumSamples = (fLoGainLast == 0)
|
|---|
| 137 | ? fHiGainLast-fHiGainFirst+1
|
|---|
| 138 | : fHiGainLast-fHiGainFirst+1+fLoGainLast-fLoGainFirst+1;
|
|---|
| 139 | fSqrtSamples = TMath::Sqrt((Float_t)fNumSamples);
|
|---|
| 140 |
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | // --------------------------------------------------------------------------
|
|---|
| 144 | //
|
|---|
| 145 | // Calls:
|
|---|
| 146 | // - MExtractor::PreProcess
|
|---|
| 147 | //
|
|---|
| 148 | // The following output containers are also searched and created if
|
|---|
| 149 | // they were not found:
|
|---|
| 150 | //
|
|---|
| 151 | // - MExtractedPINDiode
|
|---|
| 152 | //
|
|---|
| 153 | Int_t MExtractPINDiode::PreProcess(MParList *pList)
|
|---|
| 154 | {
|
|---|
| 155 |
|
|---|
| 156 | if (!MExtractor::PreProcess(pList))
|
|---|
| 157 | return kFALSE;
|
|---|
| 158 |
|
|---|
| 159 | fPINDiode = (MExtractedSignalPINDiode*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalPINDiode"));
|
|---|
| 160 | if (!fPINDiode)
|
|---|
| 161 | return kFALSE;
|
|---|
| 162 |
|
|---|
| 163 | const MPedestalPix &ped = (*fPedestals)[fPINDiodeIdx];
|
|---|
| 164 |
|
|---|
| 165 | if (&ped)
|
|---|
| 166 | {
|
|---|
| 167 | fPedestal = ped.GetPedestal();
|
|---|
| 168 | fPedRms = ped.GetPedestalRms();
|
|---|
| 169 | }
|
|---|
| 170 | else
|
|---|
| 171 | {
|
|---|
| 172 | *fLog << err << " Cannot find MPedestalPix of the PIN Diode (idx="
|
|---|
| 173 | << fPINDiodeIdx << ")" << endl;
|
|---|
| 174 | return kFALSE;
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | return kTRUE;
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | // --------------------------------------------------------------------------
|
|---|
| 181 | //
|
|---|
| 182 | // The ReInit calls:
|
|---|
| 183 | // - MExtractor::ReInit()
|
|---|
| 184 | // - fPINDiode->SetUsedFADCSlices(fHiGainFirst, fLoGainLast);
|
|---|
| 185 | //
|
|---|
| 186 | Bool_t MExtractPINDiode::ReInit(MParList *pList)
|
|---|
| 187 | {
|
|---|
| 188 |
|
|---|
| 189 | MExtractor::ReInit(pList);
|
|---|
| 190 |
|
|---|
| 191 | fPINDiode->SetUsedFADCSlices(fHiGainFirst, fLoGainLast);
|
|---|
| 192 |
|
|---|
| 193 | return kTRUE;
|
|---|
| 194 |
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 | void MExtractPINDiode::FindSignalandVarianceHiGain(Byte_t *ptr, Int_t &sum, Int_t &sum2, Byte_t &sat) const
|
|---|
| 200 | {
|
|---|
| 201 |
|
|---|
| 202 | Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1;
|
|---|
| 203 |
|
|---|
| 204 | while (ptr<end)
|
|---|
| 205 | {
|
|---|
| 206 | sum += *ptr;
|
|---|
| 207 | sum2 += *ptr * *ptr;
|
|---|
| 208 |
|
|---|
| 209 | if (*ptr++ >= fSaturationLimit)
|
|---|
| 210 | sat++;
|
|---|
| 211 | }
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | void MExtractPINDiode::FindSignalandVarianceLoGain(Byte_t *ptr, Int_t &sum, Int_t &sum2, Byte_t &sat) const
|
|---|
| 215 | {
|
|---|
| 216 |
|
|---|
| 217 | Byte_t *end = ptr + fLoGainLast - fLoGainFirst + 1;
|
|---|
| 218 |
|
|---|
| 219 | while (ptr<end)
|
|---|
| 220 | {
|
|---|
| 221 | sum += *ptr;
|
|---|
| 222 | sum2 += *ptr * *ptr;
|
|---|
| 223 |
|
|---|
| 224 | if (*ptr++ >= fSaturationLimit)
|
|---|
| 225 | sat++;
|
|---|
| 226 | }
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 | // --------------------------------------------------------------------------
|
|---|
| 232 | //
|
|---|
| 233 | // Calculate the integral of the FADC time slices and store them as a new
|
|---|
| 234 | // pixel in the MExtractedPINDiode container.
|
|---|
| 235 | //
|
|---|
| 236 | Int_t MExtractPINDiode::Process()
|
|---|
| 237 | {
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 | MRawEvtPixelIter pixel(fRawEvt);
|
|---|
| 241 |
|
|---|
| 242 | fPINDiode->Clear();
|
|---|
| 243 |
|
|---|
| 244 | pixel.Jump(fPINDiodeIdx);
|
|---|
| 245 |
|
|---|
| 246 | Int_t sum = 0;
|
|---|
| 247 | Int_t sum2 = 0;
|
|---|
| 248 | Byte_t sat = 0;
|
|---|
| 249 | Int_t max = 0;
|
|---|
| 250 |
|
|---|
| 251 | //
|
|---|
| 252 | // Calculate first the time:
|
|---|
| 253 | //
|
|---|
| 254 | const Int_t maxhi = pixel.GetIdxMaxHiGainSample();
|
|---|
| 255 | const Int_t maxlo = pixel.GetIdxMaxLoGainSample();
|
|---|
| 256 |
|
|---|
| 257 | if (maxhi > maxlo)
|
|---|
| 258 | max = maxhi;
|
|---|
| 259 | else
|
|---|
| 260 | max = maxlo + pixel.GetNumHiGainSamples();
|
|---|
| 261 |
|
|---|
| 262 | FindSignalandVarianceHiGain(pixel.GetHiGainSamples()+fHiGainFirst,sum,sum2,sat);
|
|---|
| 263 | if (pixel.HasLoGain())
|
|---|
| 264 | FindSignalandVarianceLoGain(pixel.GetLoGainSamples()+fLoGainFirst,sum,sum2,sat);
|
|---|
| 265 |
|
|---|
| 266 | const Float_t var = ((Float_t)sum2 - (Float_t)sum*sum/fNumSamples)/(fNumSamples-1);
|
|---|
| 267 | const Float_t rms = TMath::Sqrt(var);
|
|---|
| 268 |
|
|---|
| 269 | //
|
|---|
| 270 | // FIXME: The following formulae have to be revised!!
|
|---|
| 271 | //
|
|---|
| 272 | fPINDiode->SetExtractedSignal(sum - fPedestal*fNumSamples, fPedRms*fSqrtSamples);
|
|---|
| 273 | fPINDiode->SetExtractedRms (rms, rms/2./fSqrtSamples);
|
|---|
| 274 | fPINDiode->SetExtractedTime (max, rms/fSqrtSamples);
|
|---|
| 275 | fPINDiode->SetSaturation(sat);
|
|---|
| 276 | fPINDiode->SetReadyToSave();
|
|---|
| 277 |
|
|---|
| 278 | return kTRUE;
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|