| 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, 04/2004 <mailto:markus@ifae.es>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MExtractor
|
|---|
| 28 | //
|
|---|
| 29 | // Base class for the signal extractors, used the functions
|
|---|
| 30 | // FindSignalHiGain() and FindSignalLoGain() to extract the signal and
|
|---|
| 31 | // substract the pedestal value
|
|---|
| 32 | //
|
|---|
| 33 | // The following variables have to be set by the derived class and
|
|---|
| 34 | // do not have defaults:
|
|---|
| 35 | // - fNumHiGainSamples
|
|---|
| 36 | // - fNumLoGainSamples
|
|---|
| 37 | // - fSqrtHiGainSamples
|
|---|
| 38 | // - fSqrtLoGainSamples
|
|---|
| 39 | //
|
|---|
| 40 | // Input Containers:
|
|---|
| 41 | // MRawEvtData
|
|---|
| 42 | // MRawRunHeader
|
|---|
| 43 | // MPedestalCam
|
|---|
| 44 | //
|
|---|
| 45 | // Output Containers:
|
|---|
| 46 | // MExtractedSignalCam
|
|---|
| 47 | //
|
|---|
| 48 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 49 | #include "MExtractor.h"
|
|---|
| 50 |
|
|---|
| 51 | #include <fstream>
|
|---|
| 52 |
|
|---|
| 53 | #include "MLog.h"
|
|---|
| 54 | #include "MLogManip.h"
|
|---|
| 55 |
|
|---|
| 56 | #include "MParList.h"
|
|---|
| 57 |
|
|---|
| 58 | #include "MRawEvtData.h"
|
|---|
| 59 | #include "MRawEvtPixelIter.h"
|
|---|
| 60 | #include "MRawRunHeader.h"
|
|---|
| 61 |
|
|---|
| 62 | #include "MPedestalCam.h"
|
|---|
| 63 | #include "MPedestalPix.h"
|
|---|
| 64 |
|
|---|
| 65 | #include "MExtractedSignalCam.h"
|
|---|
| 66 | #include "MExtractedSignalPix.h"
|
|---|
| 67 |
|
|---|
| 68 | ClassImp(MExtractor);
|
|---|
| 69 |
|
|---|
| 70 | using namespace std;
|
|---|
| 71 |
|
|---|
| 72 | const Byte_t MExtractor::fgSaturationLimit = 254;
|
|---|
| 73 | // --------------------------------------------------------------------------
|
|---|
| 74 | //
|
|---|
| 75 | // Default constructor.
|
|---|
| 76 | //
|
|---|
| 77 | // Set:
|
|---|
| 78 | // - all pointers to NULL
|
|---|
| 79 | // - all variables to 0
|
|---|
| 80 | // - fSaturationLimit to fgSaturationLimit
|
|---|
| 81 | //
|
|---|
| 82 | // Call:
|
|---|
| 83 | // - AddToBranchList("MRawEvtData.*")
|
|---|
| 84 | //
|
|---|
| 85 | MExtractor::MExtractor(const char *name, const char *title)
|
|---|
| 86 | : fPedestals(NULL), fSignals(NULL), fRawEvt(NULL), fRunHeader(NULL),
|
|---|
| 87 | fHiLoLast(0), fNumHiGainSamples(0.), fNumLoGainSamples(0.),
|
|---|
| 88 | fSaturationLimit(fgSaturationLimit)
|
|---|
| 89 | {
|
|---|
| 90 |
|
|---|
| 91 | fName = name ? name : "MExtractor";
|
|---|
| 92 | fTitle = title ? title : "Base class for signal extractors";
|
|---|
| 93 |
|
|---|
| 94 | AddToBranchList("MRawEvtData.*");
|
|---|
| 95 |
|
|---|
| 96 | SetRange();
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | void MExtractor::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
|
|---|
| 100 | {
|
|---|
| 101 |
|
|---|
| 102 | fHiGainFirst = hifirst;
|
|---|
| 103 | fHiGainLast = hilast;
|
|---|
| 104 |
|
|---|
| 105 | fLoGainFirst = lofirst;
|
|---|
| 106 | fLoGainLast = lolast;
|
|---|
| 107 |
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 | // --------------------------------------------------------------------------
|
|---|
| 112 | //
|
|---|
| 113 | // The PreProcess searches for the following input containers:
|
|---|
| 114 | // - MRawEvtData
|
|---|
| 115 | // - MRawRunHeader
|
|---|
| 116 | // - MPedestalCam
|
|---|
| 117 | //
|
|---|
| 118 | // The following output containers are also searched and created if
|
|---|
| 119 | // they were not found:
|
|---|
| 120 | //
|
|---|
| 121 | // - MExtractedSignalCam
|
|---|
| 122 | //
|
|---|
| 123 | Int_t MExtractor::PreProcess(MParList *pList)
|
|---|
| 124 | {
|
|---|
| 125 |
|
|---|
| 126 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
|
|---|
| 127 | if (!fRawEvt)
|
|---|
| 128 | {
|
|---|
| 129 | *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
|
|---|
| 130 | return kFALSE;
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
|
|---|
| 134 | if (!fRunHeader)
|
|---|
| 135 | {
|
|---|
| 136 | *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
|
|---|
| 137 | return kFALSE;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 | fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
|
|---|
| 142 | if (!fSignals)
|
|---|
| 143 | return kFALSE;
|
|---|
| 144 |
|
|---|
| 145 | fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
|
|---|
| 146 | if (!fPedestals)
|
|---|
| 147 | {
|
|---|
| 148 | *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
|
|---|
| 149 | return kFALSE;
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | return kTRUE;
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | // --------------------------------------------------------------------------
|
|---|
| 156 | //
|
|---|
| 157 | // The ReInit searches for:
|
|---|
| 158 | // - MRawRunHeader::GetNumSamplesHiGain()
|
|---|
| 159 | // - MRawRunHeader::GetNumSamplesLoGain()
|
|---|
| 160 | //
|
|---|
| 161 | // In case that the variable fLoGainLast is smaller than
|
|---|
| 162 | // the even part of the number of samples obtained from the run header, a
|
|---|
| 163 | // warning is given an the range is set back accordingly. A call to:
|
|---|
| 164 | // - SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff)
|
|---|
| 165 | // is performed in that case. The variable diff means here the difference
|
|---|
| 166 | // between the requested range (fLoGainLast) and the available one. Note that
|
|---|
| 167 | // the functions SetRange() are mostly overloaded and perform more checks,
|
|---|
| 168 | // modifying the ranges again, if necessary.
|
|---|
| 169 | //
|
|---|
| 170 | // In case that the variable fHiGainLast is smaller than the available range
|
|---|
| 171 | // obtained from the run header, a warning is given that a part of the low-gain
|
|---|
| 172 | // samples are used for the extraction of the high-gain signal.
|
|---|
| 173 | //
|
|---|
| 174 | // Call:
|
|---|
| 175 | // - MExtractedSignalCam::SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
|
|---|
| 176 | // fLoGainFirst, fLoGainLast, fNumLoGainSamples);
|
|---|
| 177 | //
|
|---|
| 178 | Bool_t MExtractor::ReInit(MParList *pList)
|
|---|
| 179 | {
|
|---|
| 180 |
|
|---|
| 181 | Int_t lastdesired = (Int_t)(fLoGainLast);
|
|---|
| 182 | Int_t lastavailable = (Int_t)fRunHeader->GetNumSamplesLoGain()-1;
|
|---|
| 183 |
|
|---|
| 184 | if (lastavailable < 0)
|
|---|
| 185 | *fLog << warn << GetDescriptor()
|
|---|
| 186 | << ": WARNING: Number of available Low-Gain Slices is smaller than or equal zero!" << endl;
|
|---|
| 187 |
|
|---|
| 188 | if (lastdesired > lastavailable)
|
|---|
| 189 | {
|
|---|
| 190 | const Int_t diff = lastdesired - lastavailable;
|
|---|
| 191 | *fLog << endl;
|
|---|
| 192 | *fLog << warn << GetDescriptor()
|
|---|
| 193 | << Form("%s%2i%s%2i%s%2i%s",": Selected Lo Gain FADC Window [",
|
|---|
| 194 | (int)fLoGainFirst,",",lastdesired,
|
|---|
| 195 | "] ranges out of the available limits: [0,",lastavailable,"].") << endl;
|
|---|
| 196 | *fLog << GetDescriptor() << ": Will reduce the upper edge to " << (int)(fLoGainLast - diff) << endl;
|
|---|
| 197 | SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff);
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | lastdesired = (Int_t)fHiGainLast;
|
|---|
| 201 | lastavailable = (Int_t)fRunHeader->GetNumSamplesHiGain()-1;
|
|---|
| 202 |
|
|---|
| 203 | if (lastavailable < 0)
|
|---|
| 204 | {
|
|---|
| 205 | *fLog << err << GetDescriptor()
|
|---|
| 206 | << ": ERROR: Number of available High-Gain Slices is smaller than or equal zero!" << endl;
|
|---|
| 207 | return kFALSE;
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | if (lastdesired > lastavailable)
|
|---|
| 211 | {
|
|---|
| 212 | const Int_t diff = lastdesired - lastavailable;
|
|---|
| 213 | *fLog << endl;
|
|---|
| 214 | *fLog << warn << GetDescriptor()
|
|---|
| 215 | << Form("%s%2i%s%2i%s%2i%s",": Selected Hi Gain FADC Window [",
|
|---|
| 216 | (int)fHiGainFirst,",",lastdesired,
|
|---|
| 217 | "] ranges out of the available limits: [0,",lastavailable,"].") << endl;
|
|---|
| 218 | *fLog << warn << GetDescriptor()
|
|---|
| 219 | << Form("%s%2i%s",": Will use ",diff," samples from the Low-Gain for the High-Gain extraction")
|
|---|
| 220 | << endl;
|
|---|
| 221 | fHiGainLast -= diff;
|
|---|
| 222 | fHiLoLast = diff;
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | return kTRUE;
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 | void MExtractor::FindSignalHiGain(Byte_t *firstused, Byte_t *logain, Int_t &sum, Byte_t &sat) const
|
|---|
| 231 | {
|
|---|
| 232 | return;
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | void MExtractor::FindSignalLoGain(Byte_t *firstused, Int_t &sum, Byte_t &sat) const
|
|---|
| 236 | {
|
|---|
| 237 | return;
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | // --------------------------------------------------------------------------
|
|---|
| 241 | //
|
|---|
| 242 | // Calculate the integral of the FADC time slices and store them as a new
|
|---|
| 243 | // pixel in the MExtractedSignalCam container.
|
|---|
| 244 | //
|
|---|
| 245 | Int_t MExtractor::Process()
|
|---|
| 246 | {
|
|---|
| 247 |
|
|---|
| 248 | MRawEvtPixelIter pixel(fRawEvt);
|
|---|
| 249 | fSignals->Clear();
|
|---|
| 250 |
|
|---|
| 251 | while (pixel.Next())
|
|---|
| 252 | {
|
|---|
| 253 | Int_t sumhi = 0;
|
|---|
| 254 | Byte_t sathi = 0;
|
|---|
| 255 |
|
|---|
| 256 | FindSignalHiGain(pixel.GetHiGainSamples()+fHiGainFirst, pixel.GetLoGainSamples(), sumhi, sathi);
|
|---|
| 257 |
|
|---|
| 258 | Int_t sumlo = 0;
|
|---|
| 259 | Byte_t satlo = 0;
|
|---|
| 260 |
|
|---|
| 261 | if (pixel.HasLoGain())
|
|---|
| 262 | FindSignalLoGain(pixel.GetLoGainSamples()+fLoGainFirst, sumlo, satlo);
|
|---|
| 263 |
|
|---|
| 264 | const Int_t pixid = pixel.GetPixelId();
|
|---|
| 265 |
|
|---|
| 266 | const MPedestalPix &ped = (*fPedestals)[pixid];
|
|---|
| 267 | MExtractedSignalPix &pix = (*fSignals)[pixid];
|
|---|
| 268 |
|
|---|
| 269 | const Float_t pedes = ped.GetPedestal();
|
|---|
| 270 | const Float_t pedrms = ped.GetPedestalRms();
|
|---|
| 271 |
|
|---|
| 272 | pix.SetExtractedSignal(sumhi - pedes*fNumHiGainSamples, pedrms*fSqrtHiGainSamples,
|
|---|
| 273 | sumlo - pedes*fNumLoGainSamples, pedrms*fSqrtLoGainSamples);
|
|---|
| 274 |
|
|---|
| 275 | pix.SetGainSaturation(sathi, sathi, satlo);
|
|---|
| 276 |
|
|---|
| 277 | } /* while (pixel.Next()) */
|
|---|
| 278 |
|
|---|
| 279 | fSignals->SetReadyToSave();
|
|---|
| 280 |
|
|---|
| 281 | return kTRUE;
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | // --------------------------------------------------------------------------
|
|---|
| 285 | //
|
|---|
| 286 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
|---|
| 287 | // to a macro. In the original root implementation it is used to write
|
|---|
| 288 | // gui elements to a macro-file.
|
|---|
| 289 | //
|
|---|
| 290 | void MExtractor::StreamPrimitive(ofstream &out) const
|
|---|
| 291 | {
|
|---|
| 292 |
|
|---|
| 293 | out << " " << ClassName() << " " << GetUniqueName() << "(\"";
|
|---|
| 294 | out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
|
|---|
| 295 |
|
|---|
| 296 | if (fSaturationLimit!=fgSaturationLimit)
|
|---|
| 297 | {
|
|---|
| 298 | out << " " << GetUniqueName() << ".SetSaturationLimit(";
|
|---|
| 299 | out << (int)fSaturationLimit << ");" << endl;
|
|---|
| 300 | }
|
|---|
| 301 |
|
|---|
| 302 | out << " " << GetUniqueName() << ".SetRange(";
|
|---|
| 303 | out << (int)fHiGainFirst;
|
|---|
| 304 | out << ", " << (int)fHiGainLast;
|
|---|
| 305 | out << ", " << (int)fLoGainFirst;
|
|---|
| 306 | out << ", " << (int)fLoGainLast;
|
|---|
| 307 | out << ");" << endl;
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|