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