| 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 | //
|
|---|
| 30 | // Base class for the signal extractors, used the functions
|
|---|
| 31 | // FindSignalHiGain() and FindSignalLoGain() to extract the signal and
|
|---|
| 32 | // substract the pedestal value
|
|---|
| 33 | //
|
|---|
| 34 | // The following variables have to be set by the derived class and
|
|---|
| 35 | // do not have defaults:
|
|---|
| 36 | // - fNumHiGainSamples
|
|---|
| 37 | // - fNumLoGainSamples
|
|---|
| 38 | // - fSqrtHiGainSamples
|
|---|
| 39 | // - fSqrtLoGainSamples
|
|---|
| 40 | //
|
|---|
| 41 | // The signal extractor classes can be setup from an environmental
|
|---|
| 42 | // setup file. For more information see ReadEnv and MEvtLoop::ReadEnv
|
|---|
| 43 | //
|
|---|
| 44 | // Input Containers:
|
|---|
| 45 | // MRawEvtData
|
|---|
| 46 | // MRawRunHeader
|
|---|
| 47 | // MPedestalCam
|
|---|
| 48 | //
|
|---|
| 49 | // Output Containers:
|
|---|
| 50 | // MExtractedSignalCam
|
|---|
| 51 | //
|
|---|
| 52 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 53 | #include "MExtractor.h"
|
|---|
| 54 |
|
|---|
| 55 | #include <fstream>
|
|---|
| 56 |
|
|---|
| 57 | #include "MLog.h"
|
|---|
| 58 | #include "MLogManip.h"
|
|---|
| 59 |
|
|---|
| 60 | #include "MParList.h"
|
|---|
| 61 |
|
|---|
| 62 | #include "MRawEvtData.h"
|
|---|
| 63 | #include "MRawEvtPixelIter.h"
|
|---|
| 64 | #include "MRawRunHeader.h"
|
|---|
| 65 |
|
|---|
| 66 | #include "MPedestalCam.h"
|
|---|
| 67 | #include "MPedestalPix.h"
|
|---|
| 68 |
|
|---|
| 69 | #include "MExtractedSignalCam.h"
|
|---|
| 70 | #include "MExtractedSignalPix.h"
|
|---|
| 71 |
|
|---|
| 72 | ClassImp(MExtractor);
|
|---|
| 73 |
|
|---|
| 74 | using namespace std;
|
|---|
| 75 |
|
|---|
| 76 | const Byte_t MExtractor::fgSaturationLimit = 254;
|
|---|
| 77 | const TString MExtractor::fgNamePedContainer = "MPedestalCam";
|
|---|
| 78 | // --------------------------------------------------------------------------
|
|---|
| 79 | //
|
|---|
| 80 | // Default constructor.
|
|---|
| 81 | //
|
|---|
| 82 | // Set:
|
|---|
| 83 | // - all pointers to NULL
|
|---|
| 84 | // - all variables to 0
|
|---|
| 85 | // - fSaturationLimit to fgSaturationLimit
|
|---|
| 86 | // - fNamePedContainer to fgNamePedContainer
|
|---|
| 87 | //
|
|---|
| 88 | // Call:
|
|---|
| 89 | // - AddToBranchList("MRawEvtData.*")
|
|---|
| 90 | //
|
|---|
| 91 | MExtractor::MExtractor(const char *name, const char *title)
|
|---|
| 92 | : fPedestals(NULL), fSignals(NULL), fRawEvt(NULL), fRunHeader(NULL),
|
|---|
| 93 | fHiLoLast(0), fNumHiGainSamples(0.), fNumLoGainSamples(0.)
|
|---|
| 94 | {
|
|---|
| 95 | fName = name ? name : "MExtractor";
|
|---|
| 96 | fTitle = title ? title : "Base class for signal extractors";
|
|---|
| 97 |
|
|---|
| 98 | AddToBranchList("MRawEvtData.*");
|
|---|
| 99 |
|
|---|
| 100 | SetNamePedContainer();
|
|---|
| 101 | SetRange();
|
|---|
| 102 | SetSaturationLimit();
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | void MExtractor::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
|
|---|
| 106 | {
|
|---|
| 107 | fHiGainFirst = hifirst;
|
|---|
| 108 | fHiGainLast = hilast;
|
|---|
| 109 |
|
|---|
| 110 | fLoGainFirst = lofirst;
|
|---|
| 111 | fLoGainLast = lolast;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | // --------------------------------------------------------------------------
|
|---|
| 115 | //
|
|---|
| 116 | // The PreProcess searches for the following input containers:
|
|---|
| 117 | // - MRawEvtData
|
|---|
| 118 | // - MRawRunHeader
|
|---|
| 119 | // - MPedestalCam
|
|---|
| 120 | //
|
|---|
| 121 | // The following output containers are also searched and created if
|
|---|
| 122 | // they were not found:
|
|---|
| 123 | //
|
|---|
| 124 | // - MExtractedSignalCam
|
|---|
| 125 | //
|
|---|
| 126 | Int_t MExtractor::PreProcess(MParList *pList)
|
|---|
| 127 | {
|
|---|
| 128 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
|
|---|
| 129 | if (!fRawEvt)
|
|---|
| 130 | {
|
|---|
| 131 | *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
|
|---|
| 132 | return kFALSE;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
|
|---|
| 136 | if (!fRunHeader)
|
|---|
| 137 | {
|
|---|
| 138 | *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
|
|---|
| 139 | return kFALSE;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 | fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
|
|---|
| 144 | if (!fSignals)
|
|---|
| 145 | return kFALSE;
|
|---|
| 146 |
|
|---|
| 147 | fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedContainer), "MPedestalCam");
|
|---|
| 148 | if (!fPedestals)
|
|---|
| 149 | {
|
|---|
| 150 | *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
|
|---|
| 151 | return kFALSE;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | return kTRUE;
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | // --------------------------------------------------------------------------
|
|---|
| 158 | //
|
|---|
| 159 | // The ReInit searches for:
|
|---|
| 160 | // - MRawRunHeader::GetNumSamplesHiGain()
|
|---|
| 161 | // - MRawRunHeader::GetNumSamplesLoGain()
|
|---|
| 162 | //
|
|---|
| 163 | // In case that the variable fLoGainLast is smaller than
|
|---|
| 164 | // the even part of the number of samples obtained from the run header, a
|
|---|
| 165 | // warning is given an the range is set back accordingly. A call to:
|
|---|
| 166 | // - SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff)
|
|---|
| 167 | // is performed in that case. The variable diff means here the difference
|
|---|
| 168 | // between the requested range (fLoGainLast) and the available one. Note that
|
|---|
| 169 | // the functions SetRange() are mostly overloaded and perform more checks,
|
|---|
| 170 | // modifying the ranges again, if necessary.
|
|---|
| 171 | //
|
|---|
| 172 | // In case that the variable fHiGainLast is smaller than the available range
|
|---|
| 173 | // obtained from the run header, a warning is given that a part of the low-gain
|
|---|
| 174 | // samples are used for the extraction of the high-gain signal.
|
|---|
| 175 | //
|
|---|
| 176 | // Call:
|
|---|
| 177 | // - MExtractedSignalCam::SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
|
|---|
| 178 | // fLoGainFirst, fLoGainLast, fNumLoGainSamples);
|
|---|
| 179 | //
|
|---|
| 180 | Bool_t MExtractor::ReInit(MParList *pList)
|
|---|
| 181 | {
|
|---|
| 182 | Int_t lastdesired = (Int_t)(fLoGainLast);
|
|---|
| 183 | Int_t lastavailable = (Int_t)fRunHeader->GetNumSamplesLoGain()-1;
|
|---|
| 184 |
|
|---|
| 185 | if (lastavailable < 0)
|
|---|
| 186 | *fLog << warn << GetDescriptor() << " - 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 |
|
|---|
| 192 | *fLog << endl;
|
|---|
| 193 | *fLog << warn << GetDescriptor() << ": Selected Lo Gain FADC Window [";
|
|---|
| 194 | *fLog << Form("%2i,%2i", (int)fLoGainFirst, lastdesired);
|
|---|
| 195 | *fLog << "] ranges out of the available limits: [0," << Form("%2i", 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 | *fLog << " - 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 |
|
|---|
| 214 | *fLog << endl;
|
|---|
| 215 | *fLog << warn << GetDescriptor() << ": Selected Hi Gain FADC Window [";
|
|---|
| 216 | *fLog << Form("%2i,%2i", (int)fHiGainFirst,lastdesired);
|
|---|
| 217 | *fLog << "] ranges out of the available limits: [0," << Form("%2i", lastavailable) << "]" << endl;
|
|---|
| 218 | *fLog << warn << GetDescriptor() << ": Will use ";
|
|---|
| 219 | *fLog << Form("%2i", diff) << " samples from the Low-Gain for the High-Gain extraction";
|
|---|
| 220 | *fLog << endl;
|
|---|
| 221 |
|
|---|
| 222 | fHiGainLast -= diff;
|
|---|
| 223 | fHiLoLast = diff;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | return kTRUE;
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 | /*
|
|---|
| 231 | void MExtractor::FindPedestalLoGain(Byte_t *maxpos, Float_t &sum) const
|
|---|
| 232 | {
|
|---|
| 233 |
|
|---|
| 234 | Byte_t *p = maxpos-4;
|
|---|
| 235 | Byte_t *end = maxpos-2;
|
|---|
| 236 |
|
|---|
| 237 | Int_t summ = 0;
|
|---|
| 238 |
|
|---|
| 239 | while (p<end)
|
|---|
| 240 | summ += *p++;
|
|---|
| 241 |
|
|---|
| 242 | sum = summ/2.;
|
|---|
| 243 |
|
|---|
| 244 | return;
|
|---|
| 245 | }
|
|---|
| 246 | */
|
|---|
| 247 | // --------------------------------------------------------------------------
|
|---|
| 248 | //
|
|---|
| 249 | // Calculate the integral of the FADC time slices and store them as a new
|
|---|
| 250 | // pixel in the MExtractedSignalCam container.
|
|---|
| 251 | //
|
|---|
| 252 | Int_t MExtractor::Process()
|
|---|
| 253 | {
|
|---|
| 254 | MRawEvtPixelIter pixel(fRawEvt);
|
|---|
| 255 | fSignals->Clear();
|
|---|
| 256 |
|
|---|
| 257 | while (pixel.Next())
|
|---|
| 258 | {
|
|---|
| 259 | Float_t sumhi = 0.;
|
|---|
| 260 | Byte_t sathi = 0;
|
|---|
| 261 |
|
|---|
| 262 | FindSignalHiGain(pixel.GetHiGainSamples()+fHiGainFirst, pixel.GetLoGainSamples(), sumhi, sathi);
|
|---|
| 263 |
|
|---|
| 264 | Float_t sumlo = 0.;
|
|---|
| 265 | Byte_t satlo = 0;
|
|---|
| 266 |
|
|---|
| 267 | if (pixel.HasLoGain())
|
|---|
| 268 | FindSignalLoGain(pixel.GetLoGainSamples()+fLoGainFirst, sumlo, satlo);
|
|---|
| 269 |
|
|---|
| 270 | const Int_t pixid = pixel.GetPixelId();
|
|---|
| 271 |
|
|---|
| 272 | const MPedestalPix &ped = (*fPedestals)[pixid];
|
|---|
| 273 | MExtractedSignalPix &pix = (*fSignals)[pixid];
|
|---|
| 274 |
|
|---|
| 275 | const Float_t pedes = ped.GetPedestal();
|
|---|
| 276 | const Float_t pedrms = ped.GetPedestalRms();
|
|---|
| 277 |
|
|---|
| 278 | pix.SetExtractedSignal(sumhi - pedes*fNumHiGainSamples, pedrms*fSqrtHiGainSamples,
|
|---|
| 279 | sumlo - pedes*fNumLoGainSamples, pedrms*fSqrtLoGainSamples);
|
|---|
| 280 |
|
|---|
| 281 | pix.SetGainSaturation(sathi, sathi, satlo);
|
|---|
| 282 |
|
|---|
| 283 | } /* while (pixel.Next()) */
|
|---|
| 284 |
|
|---|
| 285 | fSignals->SetReadyToSave();
|
|---|
| 286 |
|
|---|
| 287 | return kTRUE;
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | // --------------------------------------------------------------------------
|
|---|
| 291 | //
|
|---|
| 292 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
|---|
| 293 | // to a macro. In the original root implementation it is used to write
|
|---|
| 294 | // gui elements to a macro-file.
|
|---|
| 295 | //
|
|---|
| 296 | void MExtractor::StreamPrimitive(ofstream &out) const
|
|---|
| 297 | {
|
|---|
| 298 | out << " " << ClassName() << " " << GetUniqueName() << "(\"";
|
|---|
| 299 | out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
|
|---|
| 300 |
|
|---|
| 301 | if (fSaturationLimit!=fgSaturationLimit)
|
|---|
| 302 | {
|
|---|
| 303 | out << " " << GetUniqueName() << ".SetSaturationLimit(";
|
|---|
| 304 | out << (int)fSaturationLimit << ");" << endl;
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 | out << " " << GetUniqueName() << ".SetRange(";
|
|---|
| 308 | out << (int)fHiGainFirst;
|
|---|
| 309 | out << ", " << (int)fHiGainLast;
|
|---|
| 310 | out << ", " << (int)fLoGainFirst;
|
|---|
| 311 | out << ", " << (int)fLoGainLast;
|
|---|
| 312 | out << ");" << endl;
|
|---|
| 313 | }
|
|---|
| 314 |
|
|---|
| 315 | // --------------------------------------------------------------------------
|
|---|
| 316 | //
|
|---|
| 317 | // Read the setup from a TEnv, eg:
|
|---|
| 318 | // MJPedestal.MExtractor.HiGainFirst: 5
|
|---|
| 319 | // MJPedestal.MExtractor.LoGainFirst: 5
|
|---|
| 320 | // MJPedestal.MExtractor.HiGainLast: 10
|
|---|
| 321 | // MJPedestal.MExtractor.LoGainLast: 10
|
|---|
| 322 | // MJPedestal.MExtractor.SaturationLimit: 88
|
|---|
| 323 | //
|
|---|
| 324 | Int_t MExtractor::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
|---|
| 325 | {
|
|---|
| 326 | Byte_t hf = fHiGainFirst;
|
|---|
| 327 | Byte_t lf = fLoGainFirst;
|
|---|
| 328 | Byte_t hl = fHiGainLast;
|
|---|
| 329 | Byte_t ll = fLoGainLast;
|
|---|
| 330 |
|
|---|
| 331 | Bool_t rc = kFALSE;
|
|---|
| 332 |
|
|---|
| 333 | if (IsEnvDefined(env, prefix, "HiGainFirst", print))
|
|---|
| 334 | {
|
|---|
| 335 | hf = GetEnvValue(env, prefix, "HiGainFirst", hf);
|
|---|
| 336 | rc = kTRUE;
|
|---|
| 337 | }
|
|---|
| 338 | if (IsEnvDefined(env, prefix, "LoGainFirst", print))
|
|---|
| 339 | {
|
|---|
| 340 | lf = GetEnvValue(env, prefix, "LoGainFirst", lf);
|
|---|
| 341 | rc = kTRUE;
|
|---|
| 342 | }
|
|---|
| 343 |
|
|---|
| 344 | if (IsEnvDefined(env, prefix, "HiGainLast", print))
|
|---|
| 345 | {
|
|---|
| 346 | hl = GetEnvValue(env, prefix, "HiGainLast", hl);
|
|---|
| 347 | rc = kTRUE;
|
|---|
| 348 | }
|
|---|
| 349 | if (IsEnvDefined(env, prefix, "LoGainLast", print))
|
|---|
| 350 | {
|
|---|
| 351 | ll = GetEnvValue(env, prefix, "LoGainLast", ll);
|
|---|
| 352 | rc = kTRUE;
|
|---|
| 353 | }
|
|---|
| 354 |
|
|---|
| 355 | SetRange(hf, hl, lf, ll);
|
|---|
| 356 |
|
|---|
| 357 | if (IsEnvDefined(env, prefix, "SaturationLimit", print))
|
|---|
| 358 | {
|
|---|
| 359 | SetSaturationLimit(GetEnvValue(env, prefix, "SaturationLimit", fSaturationLimit));
|
|---|
| 360 | rc = kTRUE;
|
|---|
| 361 | }
|
|---|
| 362 |
|
|---|
| 363 | return rc;
|
|---|
| 364 | }
|
|---|