| 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, 09/2003 <mailto:markus@ifae.es>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MExtractSignal
|
|---|
| 28 | //
|
|---|
| 29 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 30 | #include "MExtractSignal.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 "MExtractedSignalCam.h"
|
|---|
| 46 | #include "MExtractedSignalPix.h"
|
|---|
| 47 |
|
|---|
| 48 | ClassImp(MExtractSignal);
|
|---|
| 49 |
|
|---|
| 50 | using namespace std;
|
|---|
| 51 |
|
|---|
| 52 | const Byte_t MExtractSignal::fgSaturationLimit = 254;
|
|---|
| 53 | const Byte_t MExtractSignal::fgFirst = 3;
|
|---|
| 54 | const Byte_t MExtractSignal::fgLast = 10;
|
|---|
| 55 |
|
|---|
| 56 | // --------------------------------------------------------------------------
|
|---|
| 57 | //
|
|---|
| 58 | // Default constructor.
|
|---|
| 59 | //
|
|---|
| 60 | MExtractSignal::MExtractSignal(const char *name, const char *title)
|
|---|
| 61 | : fSaturationLimit(fgSaturationLimit)
|
|---|
| 62 | {
|
|---|
| 63 |
|
|---|
| 64 | fName = name ? name : "MExtractSignal";
|
|---|
| 65 | fTitle = title ? title : "Task to extract the signal from the FADC slices";
|
|---|
| 66 |
|
|---|
| 67 | AddToBranchList("MRawEvtData.*");
|
|---|
| 68 |
|
|---|
| 69 | SetRange();
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | void MExtractSignal::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
|
|---|
| 73 | {
|
|---|
| 74 |
|
|---|
| 75 | fNumHiGainSamples = hilast-hifirst+1;
|
|---|
| 76 | fNumLoGainSamples = lolast-lofirst+1;
|
|---|
| 77 |
|
|---|
| 78 | fHiGainFirst = hifirst;
|
|---|
| 79 | fLoGainFirst = lofirst;
|
|---|
| 80 |
|
|---|
| 81 | fSqrtHiGainSamples = TMath::Sqrt((Float_t)fNumHiGainSamples);
|
|---|
| 82 | fSqrtLoGainSamples = TMath::Sqrt((Float_t)fNumLoGainSamples);
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | // --------------------------------------------------------------------------
|
|---|
| 86 | //
|
|---|
| 87 | // The PreProcess searches for the following input containers:
|
|---|
| 88 | // - MRawEvtData
|
|---|
| 89 | // - MPedestalCam
|
|---|
| 90 | //
|
|---|
| 91 | // The following output containers are also searched and created if
|
|---|
| 92 | // they were not found:
|
|---|
| 93 | //
|
|---|
| 94 | // - MExtractedSignalCam
|
|---|
| 95 | //
|
|---|
| 96 | Int_t MExtractSignal::PreProcess(MParList *pList)
|
|---|
| 97 | {
|
|---|
| 98 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
|
|---|
| 99 | if (!fRawEvt)
|
|---|
| 100 | {
|
|---|
| 101 | *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
|
|---|
| 102 | return kFALSE;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 | fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
|
|---|
| 107 | if (!fSignals)
|
|---|
| 108 | return kFALSE;
|
|---|
| 109 |
|
|---|
| 110 | fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainFirst+fNumHiGainSamples-1,
|
|---|
| 111 | fLoGainFirst, fLoGainFirst+fNumLoGainSamples-1);
|
|---|
| 112 |
|
|---|
| 113 | fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
|
|---|
| 114 |
|
|---|
| 115 | if (!fPedestals)
|
|---|
| 116 | {
|
|---|
| 117 | *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
|
|---|
| 118 | return kFALSE;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | return kTRUE;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | // --------------------------------------------------------------------------
|
|---|
| 125 | //
|
|---|
| 126 | // Calculate the integral of the FADC time slices and store them as a new
|
|---|
| 127 | // pixel in the MExtractedSignalCam container.
|
|---|
| 128 | //
|
|---|
| 129 | Int_t MExtractSignal::Process()
|
|---|
| 130 | {
|
|---|
| 131 | MRawEvtPixelIter pixel(fRawEvt);
|
|---|
| 132 | fSignals->Clear();
|
|---|
| 133 |
|
|---|
| 134 | UInt_t satlo=0;
|
|---|
| 135 |
|
|---|
| 136 | while (pixel.Next())
|
|---|
| 137 | {
|
|---|
| 138 | UShort_t satHi = 0;
|
|---|
| 139 | UShort_t satLo = 0;
|
|---|
| 140 |
|
|---|
| 141 | UInt_t sumHi = 0;
|
|---|
| 142 | UInt_t sumLo = 0;
|
|---|
| 143 |
|
|---|
| 144 | Byte_t maxhi = 0;
|
|---|
| 145 | Byte_t midhi = 0;
|
|---|
| 146 |
|
|---|
| 147 | Byte_t *ptr = pixel.GetHiGainSamples() + fHiGainFirst;
|
|---|
| 148 | Byte_t *last = ptr + fNumHiGainSamples;
|
|---|
| 149 |
|
|---|
| 150 | while (ptr<last)
|
|---|
| 151 | {
|
|---|
| 152 | sumHi += *ptr;
|
|---|
| 153 |
|
|---|
| 154 | if (*ptr > maxhi)
|
|---|
| 155 | {
|
|---|
| 156 | maxhi = *ptr;
|
|---|
| 157 | midhi = ptr-pixel.GetHiGainSamples();
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | if (*ptr >= fSaturationLimit)
|
|---|
| 161 | satHi++;
|
|---|
| 162 |
|
|---|
| 163 | ptr++;
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | ptr = pixel.GetLoGainSamples() + fLoGainFirst;
|
|---|
| 167 | last = ptr + fNumLoGainSamples;
|
|---|
| 168 |
|
|---|
| 169 | Byte_t maxlo = 0;
|
|---|
| 170 | Byte_t midlo = 0;
|
|---|
| 171 |
|
|---|
| 172 | while (ptr<last)
|
|---|
| 173 | {
|
|---|
| 174 | sumLo += *ptr;
|
|---|
| 175 |
|
|---|
| 176 | if (*ptr > maxlo)
|
|---|
| 177 | {
|
|---|
| 178 | maxlo = *ptr;
|
|---|
| 179 | midlo = ptr-pixel.GetLoGainSamples();
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | if (*ptr >= fSaturationLimit)
|
|---|
| 183 | satLo++;
|
|---|
| 184 |
|
|---|
| 185 | ptr++;
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | if (satLo)
|
|---|
| 189 | satlo++;
|
|---|
| 190 |
|
|---|
| 191 | const Int_t pixid = pixel.GetPixelId();
|
|---|
| 192 |
|
|---|
| 193 | const MPedestalPix &ped = (*fPedestals)[pixid];
|
|---|
| 194 | MExtractedSignalPix &pix = (*fSignals)[pixid];
|
|---|
| 195 |
|
|---|
| 196 | const Float_t pedes = ped.GetPedestal();
|
|---|
| 197 | const Float_t pedrms = ped.GetPedestalRms();
|
|---|
| 198 |
|
|---|
| 199 | pix.SetExtractedSignal(sumHi - pedes*fNumHiGainSamples, pedrms*fSqrtHiGainSamples,
|
|---|
| 200 | sumLo - pedes*fNumLoGainSamples, pedrms*fSqrtLoGainSamples);
|
|---|
| 201 |
|
|---|
| 202 | pix.SetGainSaturation(satHi, satHi, satLo);
|
|---|
| 203 |
|
|---|
| 204 | } /* while (pixel.Next()) */
|
|---|
| 205 |
|
|---|
| 206 | if (satlo)
|
|---|
| 207 | *fLog << warn << "WARNING - Lo Gain saturated in " << satlo << " pixels." << endl;
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 | fSignals->SetReadyToSave();
|
|---|
| 211 |
|
|---|
| 212 | return kTRUE;
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | // --------------------------------------------------------------------------
|
|---|
| 216 | //
|
|---|
| 217 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
|---|
| 218 | // to a macro. In the original root implementation it is used to write
|
|---|
| 219 | // gui elements to a macro-file.
|
|---|
| 220 | //
|
|---|
| 221 | void MExtractSignal::StreamPrimitive(ofstream &out) const
|
|---|
| 222 | {
|
|---|
| 223 | out << " " << ClassName() << " " << GetUniqueName() << "(\"";
|
|---|
| 224 | out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
|
|---|
| 225 |
|
|---|
| 226 | if (fSaturationLimit!=fgSaturationLimit)
|
|---|
| 227 | {
|
|---|
| 228 | out << " " << GetUniqueName() << ".SetSaturationLimit(";
|
|---|
| 229 | out << (int)fSaturationLimit << ");" << endl;
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | const Bool_t arg4 = fNumLoGainSamples+fLoGainFirst-1 != fgLast;
|
|---|
| 233 | const Bool_t arg3 = arg4 || fLoGainFirst != fgFirst;
|
|---|
| 234 | const Bool_t arg2 = arg3 || fNumHiGainSamples+fHiGainFirst-1 != fgLast;
|
|---|
| 235 | const Bool_t arg1 = arg2 || fHiGainFirst != fgFirst;
|
|---|
| 236 |
|
|---|
| 237 | if (!arg1)
|
|---|
| 238 | return;
|
|---|
| 239 |
|
|---|
| 240 | out << " " << GetUniqueName() << ".SetRange(";
|
|---|
| 241 | out << (int)fLoGainFirst;
|
|---|
| 242 | if (arg2)
|
|---|
| 243 | {
|
|---|
| 244 | out << ", " << (int)(fNumHiGainSamples+fHiGainFirst-1);
|
|---|
| 245 | if (arg3)
|
|---|
| 246 | {
|
|---|
| 247 | out << ", " << (int)fLoGainFirst;
|
|---|
| 248 | if (arg4)
|
|---|
| 249 | out << ", " << (int)(fNumLoGainSamples+fLoGainFirst-1);
|
|---|
| 250 | }
|
|---|
| 251 | }
|
|---|
| 252 | out << ");" << endl;
|
|---|
| 253 | }
|
|---|