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