source: trunk/MagicSoft/Mars/msignal/MExtractor.cc@ 3886

Last change on this file since 3886 was 3881, checked in by gaug, 21 years ago
*** empty log message ***
File size: 7.9 KB
Line 
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// MPedestalCam
43//
44// Output Containers:
45// MExtractedSignalCam
46//
47//////////////////////////////////////////////////////////////////////////////
48#include "MExtractor.h"
49
50#include <fstream>
51
52#include "MLog.h"
53#include "MLogManip.h"
54
55#include "MParList.h"
56
57#include "MRawEvtData.h"
58#include "MRawEvtPixelIter.h"
59#include "MRawRunHeader.h"
60
61#include "MPedestalCam.h"
62#include "MPedestalPix.h"
63
64#include "MExtractedSignalCam.h"
65#include "MExtractedSignalPix.h"
66
67ClassImp(MExtractor);
68
69using namespace std;
70
71const Byte_t MExtractor::fgSaturationLimit = 254;
72// --------------------------------------------------------------------------
73//
74// Default constructor.
75//
76MExtractor::MExtractor(const char *name, const char *title)
77 : fNumHiGainSamples(0.), fNumLoGainSamples(0.), fSaturationLimit(fgSaturationLimit)
78{
79
80 fName = name ? name : "MExtractor";
81 fTitle = title ? title : "Base class for signal extractors";
82
83 AddToBranchList("MRawEvtData.*");
84
85 SetRange();
86}
87
88void MExtractor::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
89{
90
91 fHiGainFirst = hifirst;
92 fLoGainFirst = lofirst;
93
94 fHiGainLast = hilast;
95 fLoGainLast = lolast;
96
97}
98
99
100// --------------------------------------------------------------------------
101//
102// The PreProcess searches for the following input containers:
103// - MRawEvtData
104// - MRawRunHeader
105// - MPedestalCam
106//
107// The following output containers are also searched and created if
108// they were not found:
109//
110// - MExtractedSignalCam
111//
112Int_t MExtractor::PreProcess(MParList *pList)
113{
114
115 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
116 if (!fRawEvt)
117 {
118 *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
119 return kFALSE;
120 }
121
122 fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
123 if (!fRunHeader)
124 {
125 *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
126 return kFALSE;
127 }
128
129
130 fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
131 if (!fSignals)
132 return kFALSE;
133
134 fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
135 fLoGainFirst, fLoGainLast, fNumLoGainSamples);
136
137 fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
138
139 if (!fPedestals)
140 {
141 *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
142 return kFALSE;
143 }
144
145 return kTRUE;
146}
147
148// --------------------------------------------------------------------------
149//
150// The ReInit searches for:
151// - MRawRunHeader::GetNumSamplesHiGain()
152// - MRawRunHeader::GetNumSamplesLoGain()
153//
154// In case that the variables fHiGainLast and fLoGainLast are smaller than
155// the even part of the number of samples obtained from the run header, a
156// warning is given an the range is set back accordingly. A call to:
157// - SetRange(fHiGainFirst, fHiGainLast-diff, fLoGainFirst, fLoGainLast) or
158// - SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff)
159// is performed in that case. The variable diff means here the difference
160// between the requested range (fHiGainLast) and the available one. Note that
161// the functions SetRange() are mostly overloaded and perform more checks,
162// modifying the ranges again, if necessary.
163//
164Bool_t MExtractor::ReInit(MParList *pList)
165{
166
167 Int_t lastdesired = (Int_t)fHiGainLast;
168 Int_t lastavailable = (Int_t)fRunHeader->GetNumSamplesHiGain()-1;
169
170 if (lastdesired > lastavailable)
171 {
172 const Int_t diff = lastdesired - lastavailable;
173 *fLog << endl;
174 *fLog << warn << GetDescriptor()
175 << Form("%s%2i%s%2i%s%2i%s",": Selected Hi Gain FADC Window [",
176 (int)fHiGainFirst,",",lastdesired,
177 "] ranges out of the available limits: [0,",lastavailable,"].") << endl;
178 *fLog << GetDescriptor() << ": Will reduce the upper edge to " << (int)(fHiGainLast - diff) << endl;
179 SetRange(fHiGainFirst, fHiGainLast-diff, fLoGainFirst, fLoGainLast);
180 }
181
182 lastdesired = (Int_t)(fLoGainLast);
183 lastavailable = (Int_t)fRunHeader->GetNumSamplesLoGain()-1;
184
185 if (lastdesired > lastavailable)
186 {
187 const Int_t diff = lastdesired - lastavailable;
188 *fLog << endl;
189 *fLog << warn << GetDescriptor()
190 << Form("%s%2i%s%2i%s%2i%s",": Selected Lo Gain FADC Window [",
191 (int)fLoGainFirst,",",lastdesired,
192 "] ranges out of the available limits: [0,",lastavailable,"].") << endl;
193 *fLog << GetDescriptor() << ": Will reduce the upper edge to " << (int)(fLoGainLast - diff) << endl;
194 SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff);
195 }
196
197 return kTRUE;
198}
199
200
201
202void MExtractor::FindSignalHiGain(Byte_t *firstused, Int_t &sum, Byte_t &sat) const
203{
204 return;
205}
206
207void MExtractor::FindSignalLoGain(Byte_t *firstused, Int_t &sum, Byte_t &sat) const
208{
209 return;
210}
211
212// --------------------------------------------------------------------------
213//
214// Calculate the integral of the FADC time slices and store them as a new
215// pixel in the MExtractedSignalCam container.
216//
217Int_t MExtractor::Process()
218{
219
220 MRawEvtPixelIter pixel(fRawEvt);
221 fSignals->Clear();
222
223 while (pixel.Next())
224 {
225 Int_t sumhi;
226 Byte_t sathi;
227
228 FindSignalHiGain(pixel.GetHiGainSamples()+fHiGainFirst, sumhi, sathi);
229
230 Int_t sumlo = 0;
231 Byte_t satlo = 0;
232
233 if (pixel.HasLoGain())
234 FindSignalLoGain(pixel.GetLoGainSamples()+fLoGainFirst, sumlo, satlo);
235
236 const Int_t pixid = pixel.GetPixelId();
237
238 const MPedestalPix &ped = (*fPedestals)[pixid];
239 MExtractedSignalPix &pix = (*fSignals)[pixid];
240
241 const Float_t pedes = ped.GetPedestal();
242 const Float_t pedrms = ped.GetPedestalRms();
243
244 pix.SetExtractedSignal(sumhi - pedes*fNumHiGainSamples, pedrms*fSqrtHiGainSamples,
245 sumlo - pedes*fNumLoGainSamples, pedrms*fSqrtLoGainSamples);
246
247 pix.SetGainSaturation(sathi, sathi, satlo);
248
249 } /* while (pixel.Next()) */
250
251 fSignals->SetReadyToSave();
252
253 return kTRUE;
254}
255
256// --------------------------------------------------------------------------
257//
258// Implementation of SavePrimitive. Used to write the call to a constructor
259// to a macro. In the original root implementation it is used to write
260// gui elements to a macro-file.
261//
262void MExtractor::StreamPrimitive(ofstream &out) const
263{
264}
265
Note: See TracBrowser for help on using the repository browser.