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