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