| 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 | fNumHiGainSamples(0.), fNumLoGainSamples(0.), fSaturationLimit(fgSaturationLimit)
|
|---|
| 88 | {
|
|---|
| 89 |
|
|---|
| 90 | fName = name ? name : "MExtractor";
|
|---|
| 91 | fTitle = title ? title : "Base class for signal extractors";
|
|---|
| 92 |
|
|---|
| 93 | AddToBranchList("MRawEvtData.*");
|
|---|
| 94 |
|
|---|
| 95 | SetRange();
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | void MExtractor::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
|
|---|
| 99 | {
|
|---|
| 100 |
|
|---|
| 101 | fHiGainFirst = hifirst;
|
|---|
| 102 | fLoGainFirst = lofirst;
|
|---|
| 103 |
|
|---|
| 104 | fHiGainLast = hilast;
|
|---|
| 105 | fLoGainLast = lolast;
|
|---|
| 106 |
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 | // --------------------------------------------------------------------------
|
|---|
| 111 | //
|
|---|
| 112 | // The PreProcess searches for the following input containers:
|
|---|
| 113 | // - MRawEvtData
|
|---|
| 114 | // - MRawRunHeader
|
|---|
| 115 | // - MPedestalCam
|
|---|
| 116 | //
|
|---|
| 117 | // The following output containers are also searched and created if
|
|---|
| 118 | // they were not found:
|
|---|
| 119 | //
|
|---|
| 120 | // - MExtractedSignalCam
|
|---|
| 121 | //
|
|---|
| 122 | Int_t MExtractor::PreProcess(MParList *pList)
|
|---|
| 123 | {
|
|---|
| 124 |
|
|---|
| 125 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
|
|---|
| 126 | if (!fRawEvt)
|
|---|
| 127 | {
|
|---|
| 128 | *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
|
|---|
| 129 | return kFALSE;
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
|
|---|
| 133 | if (!fRunHeader)
|
|---|
| 134 | {
|
|---|
| 135 | *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
|
|---|
| 136 | return kFALSE;
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 | fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
|
|---|
| 141 | if (!fSignals)
|
|---|
| 142 | return kFALSE;
|
|---|
| 143 |
|
|---|
| 144 | fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
|
|---|
| 145 | if (!fPedestals)
|
|---|
| 146 | {
|
|---|
| 147 | *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
|
|---|
| 148 | return kFALSE;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | return kTRUE;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | // --------------------------------------------------------------------------
|
|---|
| 155 | //
|
|---|
| 156 | // The ReInit searches for:
|
|---|
| 157 | // - MRawRunHeader::GetNumSamplesHiGain()
|
|---|
| 158 | // - MRawRunHeader::GetNumSamplesLoGain()
|
|---|
| 159 | //
|
|---|
| 160 | // In case that the variables fHiGainLast and fLoGainLast are smaller than
|
|---|
| 161 | // the even part of the number of samples obtained from the run header, a
|
|---|
| 162 | // warning is given an the range is set back accordingly. A call to:
|
|---|
| 163 | // - SetRange(fHiGainFirst, fHiGainLast-diff, fLoGainFirst, fLoGainLast) or
|
|---|
| 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 (fHiGainLast) 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 | // Call:
|
|---|
| 171 | // - MExtractedSignalCam::SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
|
|---|
| 172 | // fLoGainFirst, fLoGainLast, fNumLoGainSamples);
|
|---|
| 173 | //
|
|---|
| 174 | Bool_t MExtractor::ReInit(MParList *pList)
|
|---|
| 175 | {
|
|---|
| 176 |
|
|---|
| 177 | Int_t lastdesired = (Int_t)fHiGainLast;
|
|---|
| 178 | Int_t lastavailable = (Int_t)fRunHeader->GetNumSamplesHiGain()-1;
|
|---|
| 179 |
|
|---|
| 180 | if (lastdesired > lastavailable)
|
|---|
| 181 | {
|
|---|
| 182 | const Int_t diff = lastdesired - lastavailable;
|
|---|
| 183 | *fLog << endl;
|
|---|
| 184 | *fLog << warn << GetDescriptor()
|
|---|
| 185 | << Form("%s%2i%s%2i%s%2i%s",": Selected Hi Gain FADC Window [",
|
|---|
| 186 | (int)fHiGainFirst,",",lastdesired,
|
|---|
| 187 | "] ranges out of the available limits: [0,",lastavailable,"].") << endl;
|
|---|
| 188 | *fLog << GetDescriptor() << ": Will reduce the upper edge to " << (int)(fHiGainLast - diff) << endl;
|
|---|
| 189 | SetRange(fHiGainFirst, fHiGainLast-diff, fLoGainFirst, fLoGainLast);
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | lastdesired = (Int_t)(fLoGainLast);
|
|---|
| 193 | lastavailable = (Int_t)fRunHeader->GetNumSamplesLoGain()-1;
|
|---|
| 194 |
|
|---|
| 195 | if (lastdesired > lastavailable)
|
|---|
| 196 | {
|
|---|
| 197 | const Int_t diff = lastdesired - lastavailable;
|
|---|
| 198 | *fLog << endl;
|
|---|
| 199 | *fLog << warn << GetDescriptor()
|
|---|
| 200 | << Form("%s%2i%s%2i%s%2i%s",": Selected Lo Gain FADC Window [",
|
|---|
| 201 | (int)fLoGainFirst,",",lastdesired,
|
|---|
| 202 | "] ranges out of the available limits: [0,",lastavailable,"].") << endl;
|
|---|
| 203 | *fLog << GetDescriptor() << ": Will reduce the upper edge to " << (int)(fLoGainLast - diff) << endl;
|
|---|
| 204 | SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff);
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
|
|---|
| 208 | fLoGainFirst, fLoGainLast, fNumLoGainSamples);
|
|---|
| 209 |
|
|---|
| 210 | return kTRUE;
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 | void MExtractor::FindSignalHiGain(Byte_t *firstused, Int_t &sum, Byte_t &sat) const
|
|---|
| 216 | {
|
|---|
| 217 | return;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | void MExtractor::FindSignalLoGain(Byte_t *firstused, Int_t &sum, Byte_t &sat) const
|
|---|
| 221 | {
|
|---|
| 222 | return;
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | // --------------------------------------------------------------------------
|
|---|
| 226 | //
|
|---|
| 227 | // Calculate the integral of the FADC time slices and store them as a new
|
|---|
| 228 | // pixel in the MExtractedSignalCam container.
|
|---|
| 229 | //
|
|---|
| 230 | Int_t MExtractor::Process()
|
|---|
| 231 | {
|
|---|
| 232 |
|
|---|
| 233 | MRawEvtPixelIter pixel(fRawEvt);
|
|---|
| 234 | fSignals->Clear();
|
|---|
| 235 |
|
|---|
| 236 | while (pixel.Next())
|
|---|
| 237 | {
|
|---|
| 238 | Int_t sumhi;
|
|---|
| 239 | Byte_t sathi;
|
|---|
| 240 |
|
|---|
| 241 | FindSignalHiGain(pixel.GetHiGainSamples()+fHiGainFirst, sumhi, sathi);
|
|---|
| 242 |
|
|---|
| 243 | Int_t sumlo = 0;
|
|---|
| 244 | Byte_t satlo = 0;
|
|---|
| 245 |
|
|---|
| 246 | if (pixel.HasLoGain())
|
|---|
| 247 | FindSignalLoGain(pixel.GetLoGainSamples()+fLoGainFirst, sumlo, satlo);
|
|---|
| 248 |
|
|---|
| 249 | const Int_t pixid = pixel.GetPixelId();
|
|---|
| 250 |
|
|---|
| 251 | const MPedestalPix &ped = (*fPedestals)[pixid];
|
|---|
| 252 | MExtractedSignalPix &pix = (*fSignals)[pixid];
|
|---|
| 253 |
|
|---|
| 254 | const Float_t pedes = ped.GetPedestal();
|
|---|
| 255 | const Float_t pedrms = ped.GetPedestalRms();
|
|---|
| 256 |
|
|---|
| 257 | pix.SetExtractedSignal(sumhi - pedes*fNumHiGainSamples, pedrms*fSqrtHiGainSamples,
|
|---|
| 258 | sumlo - pedes*fNumLoGainSamples, pedrms*fSqrtLoGainSamples);
|
|---|
| 259 |
|
|---|
| 260 | pix.SetGainSaturation(sathi, sathi, satlo);
|
|---|
| 261 |
|
|---|
| 262 | } /* while (pixel.Next()) */
|
|---|
| 263 |
|
|---|
| 264 | fSignals->SetReadyToSave();
|
|---|
| 265 |
|
|---|
| 266 | return kTRUE;
|
|---|
| 267 | }
|
|---|
| 268 |
|
|---|
| 269 | // --------------------------------------------------------------------------
|
|---|
| 270 | //
|
|---|
| 271 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
|---|
| 272 | // to a macro. In the original root implementation it is used to write
|
|---|
| 273 | // gui elements to a macro-file.
|
|---|
| 274 | //
|
|---|
| 275 | void MExtractor::StreamPrimitive(ofstream &out) const
|
|---|
| 276 | {
|
|---|
| 277 | }
|
|---|
| 278 |
|
|---|