| 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 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 30 | #include "MExtractBlindPixel.h"
|
|---|
| 31 |
|
|---|
| 32 | #include <fstream>
|
|---|
| 33 |
|
|---|
| 34 | #include "MLog.h"
|
|---|
| 35 | #include "MLogManip.h"
|
|---|
| 36 |
|
|---|
| 37 | #include "MParList.h"
|
|---|
| 38 |
|
|---|
| 39 | #include "MRawEvtData.h"
|
|---|
| 40 | #include "MRawEvtPixelIter.h"
|
|---|
| 41 |
|
|---|
| 42 | #include "MPedestalCam.h"
|
|---|
| 43 | #include "MPedestalPix.h"
|
|---|
| 44 |
|
|---|
| 45 | #include "MExtractedSignalBlindPixel.h"
|
|---|
| 46 |
|
|---|
| 47 | ClassImp(MExtractBlindPixel);
|
|---|
| 48 |
|
|---|
| 49 | using namespace std;
|
|---|
| 50 |
|
|---|
| 51 | const Int_t MExtractBlindPixel::fgBlindPixelIdx = 559;
|
|---|
| 52 | const Byte_t MExtractBlindPixel::fgSaturationLimit = 254;
|
|---|
| 53 | const Byte_t MExtractBlindPixel::fgFirst = 3;
|
|---|
| 54 | const Byte_t MExtractBlindPixel::fgLast = 16;
|
|---|
| 55 |
|
|---|
| 56 | // --------------------------------------------------------------------------
|
|---|
| 57 | //
|
|---|
| 58 | // Default constructor.
|
|---|
| 59 | //
|
|---|
| 60 | MExtractBlindPixel::MExtractBlindPixel(const char *name, const char *title)
|
|---|
| 61 | : fSaturationLimit(fgSaturationLimit)
|
|---|
| 62 | {
|
|---|
| 63 |
|
|---|
| 64 | fName = name ? name : "MExtractBlindPixel";
|
|---|
| 65 | fTitle = title ? title : "Task to extract the signal from the FADC slices";
|
|---|
| 66 |
|
|---|
| 67 | AddToBranchList("MRawEvtData.*");
|
|---|
| 68 |
|
|---|
| 69 | SetBlindPixelIdx();
|
|---|
| 70 | SetSaturationLimit();
|
|---|
| 71 | SetRange();
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | void MExtractBlindPixel::SetRange(Byte_t first, Byte_t last)
|
|---|
| 75 | {
|
|---|
| 76 |
|
|---|
| 77 | fNumSamples = last-first+1;
|
|---|
| 78 | fFirst = first;
|
|---|
| 79 | fLast = last;
|
|---|
| 80 |
|
|---|
| 81 | fSqrtSamples = TMath::Sqrt((Float_t)fNumSamples);
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | // --------------------------------------------------------------------------
|
|---|
| 85 | //
|
|---|
| 86 | // The PreProcess searches for the following input containers:
|
|---|
| 87 | // - MRawEvtData
|
|---|
| 88 | //
|
|---|
| 89 | // The following output containers are also searched and created if
|
|---|
| 90 | // they were not found:
|
|---|
| 91 | //
|
|---|
| 92 | // - MExtractedBlindPixel
|
|---|
| 93 | //
|
|---|
| 94 | Int_t MExtractBlindPixel::PreProcess(MParList *pList)
|
|---|
| 95 | {
|
|---|
| 96 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
|
|---|
| 97 | if (!fRawEvt)
|
|---|
| 98 | {
|
|---|
| 99 | *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
|
|---|
| 100 | return kFALSE;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
|
|---|
| 104 | if (!fPedestals)
|
|---|
| 105 | {
|
|---|
| 106 | *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting." << endl;
|
|---|
| 107 | return kFALSE;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | fBlindPixel = (MExtractedSignalBlindPixel*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalBlindPixel"));
|
|---|
| 111 | if (!fBlindPixel)
|
|---|
| 112 | return kFALSE;
|
|---|
| 113 |
|
|---|
| 114 | fBlindPixel->SetUsedFADCSlices(fFirst, fLast);
|
|---|
| 115 | fBlindPixel->SetBlindPixelIdx(fBlindPixelIdx);
|
|---|
| 116 |
|
|---|
| 117 | return kTRUE;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | // --------------------------------------------------------------------------
|
|---|
| 121 | //
|
|---|
| 122 | // Calculate the integral of the FADC time slices and store them as a new
|
|---|
| 123 | // pixel in the MExtractedBlindPixel container.
|
|---|
| 124 | //
|
|---|
| 125 | Int_t MExtractBlindPixel::Process()
|
|---|
| 126 | {
|
|---|
| 127 |
|
|---|
| 128 | MRawEvtPixelIter pixel(fRawEvt);
|
|---|
| 129 |
|
|---|
| 130 | fBlindPixel->Clear();
|
|---|
| 131 |
|
|---|
| 132 | pixel.Jump(fBlindPixelIdx);
|
|---|
| 133 |
|
|---|
| 134 | const UInt_t nhigain = pixel.GetNumHiGainSamples();
|
|---|
| 135 |
|
|---|
| 136 | Byte_t *ptr = pixel.GetHiGainSamples();
|
|---|
| 137 |
|
|---|
| 138 | //
|
|---|
| 139 | // We need a dedicated signal extractor for the blind pixel
|
|---|
| 140 | //
|
|---|
| 141 | Int_t diff = 0;
|
|---|
| 142 | UInt_t first = fFirst;
|
|---|
| 143 | UInt_t last = fLast;
|
|---|
| 144 | UInt_t sat = 0;
|
|---|
| 145 |
|
|---|
| 146 | if (last > nhigain)
|
|---|
| 147 | {
|
|---|
| 148 | diff = last - nhigain;
|
|---|
| 149 | last = nhigain;
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 | Byte_t *start = ptr + first - 1;
|
|---|
| 154 | Byte_t *end = ptr + last - 1;
|
|---|
| 155 |
|
|---|
| 156 | ptr = start;
|
|---|
| 157 |
|
|---|
| 158 | Int_t sum = 0;
|
|---|
| 159 |
|
|---|
| 160 | while (ptr<=end)
|
|---|
| 161 | {
|
|---|
| 162 | sum += *ptr;
|
|---|
| 163 |
|
|---|
| 164 | if (*ptr++ >= fSaturationLimit)
|
|---|
| 165 | sat++;
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | if (diff > 0)
|
|---|
| 169 | {
|
|---|
| 170 | ptr = pixel.GetLoGainSamples();
|
|---|
| 171 | end = ptr + diff - 1;
|
|---|
| 172 |
|
|---|
| 173 | while (ptr<=end)
|
|---|
| 174 | {
|
|---|
| 175 |
|
|---|
| 176 | sum += *ptr;
|
|---|
| 177 |
|
|---|
| 178 | if (*ptr++ >= fSaturationLimit)
|
|---|
| 179 | sat++;
|
|---|
| 180 |
|
|---|
| 181 | }
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | fBlindPixel->SetExtractedSignal(sum);
|
|---|
| 185 | fBlindPixel->SetNumSaturated(sat);
|
|---|
| 186 |
|
|---|
| 187 | if (sat)
|
|---|
| 188 | *fLog << warn << "WARNING - saturation occurred in the Blind Pixel " << endl;
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 | fBlindPixel->SetReadyToSave();
|
|---|
| 192 |
|
|---|
| 193 | return kTRUE;
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | Int_t MExtractBlindPixel::PostProcess()
|
|---|
| 197 | {
|
|---|
| 198 |
|
|---|
| 199 | MPedestalPix &pedpix = (*fPedestals)[fBlindPixelIdx];
|
|---|
| 200 |
|
|---|
| 201 | if (&pedpix)
|
|---|
| 202 | {
|
|---|
| 203 | fBlindPixel->SetPed ( pedpix.GetPedestal() * fNumSamples );
|
|---|
| 204 | fBlindPixel->SetPedErr ( pedpix.GetPedestalRms()* fNumSamples / TMath::Sqrt((Float_t)fPedestals->GetTotalEntries()) );
|
|---|
| 205 | fBlindPixel->SetPedRms ( pedpix.GetPedestalRms()* TMath::Sqrt((Float_t)fNumSamples) );
|
|---|
| 206 | fBlindPixel->SetPedRmsErr( fBlindPixel->GetPedErr()/2. );
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | return kTRUE;
|
|---|
| 210 |
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | // --------------------------------------------------------------------------
|
|---|
| 214 | //
|
|---|
| 215 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
|---|
| 216 | // to a macro. In the original root implementation it is used to write
|
|---|
| 217 | // gui elements to a macro-file.
|
|---|
| 218 | //
|
|---|
| 219 | void MExtractBlindPixel::StreamPrimitive(ofstream &out) const
|
|---|
| 220 | {
|
|---|
| 221 | out << " " << ClassName() << " " << GetUniqueName() << "(\"";
|
|---|
| 222 | out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
|
|---|
| 223 |
|
|---|
| 224 | if (fSaturationLimit!=fgSaturationLimit)
|
|---|
| 225 | {
|
|---|
| 226 | out << " " << GetUniqueName() << ".SetSaturationLimit(";
|
|---|
| 227 | out << (int)fSaturationLimit << ");" << endl;
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | const Bool_t arg2 = fNumSamples+fFirst-1 != fgLast;
|
|---|
| 231 | const Bool_t arg1 = arg2 || fFirst != fgFirst;
|
|---|
| 232 |
|
|---|
| 233 | if (!arg1)
|
|---|
| 234 | return;
|
|---|
| 235 |
|
|---|
| 236 | out << " " << GetUniqueName() << ".SetRange(";
|
|---|
| 237 | out << (int)fFirst;
|
|---|
| 238 | if (arg2)
|
|---|
| 239 | out << ", " << (int)(fNumSamples+fFirst-1);
|
|---|
| 240 | out << ");" << endl;
|
|---|
| 241 | }
|
|---|