source: trunk/MagicSoft/Mars/manalysis/MExtractSignal.cc@ 2946

Last change on this file since 2946 was 2946, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 7.4 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, 09/2003 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MExtractSignal
28//
29//////////////////////////////////////////////////////////////////////////////
30#include "MExtractSignal.h"
31
32#include <fstream>
33
34#include "MLog.h"
35#include "MLogManip.h"
36
37#include "MParList.h"
38#include "MGeomCam.h"
39
40#include "MRawEvtData.h"
41#include "MRawEvtPixelIter.h"
42
43#include "MPedestalCam.h"
44#include "MPedestalPix.h"
45
46#include "MExtractedSignalCam.h"
47#include "MExtractedSignalPix.h"
48
49#include "MArrivalTime.h"
50
51ClassImp(MExtractSignal);
52
53using namespace std;
54
55const Byte_t MExtractSignal::fgSaturationLimit = 254;
56const Byte_t MExtractSignal::fgFirst = 3;
57const Byte_t MExtractSignal::fgLast = 10;
58
59// --------------------------------------------------------------------------
60//
61// Default constructor.
62//
63MExtractSignal::MExtractSignal(const char *name, const char *title)
64 : fSaturationLimit(fgSaturationLimit)
65{
66
67 fName = name ? name : "MExtractSignal";
68 fTitle = title ? title : "Task to extract the signal from the FADC slices";
69
70 AddToBranchList("MRawEvtData.*");
71
72 SetRange();
73}
74
75void MExtractSignal::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
76{
77
78 fNumHiGainSamples = hilast-hifirst+1;
79 fNumLoGainSamples = lolast-lofirst+1;
80
81 fHiGainFirst = hifirst;
82 fLoGainFirst = lofirst;
83
84 fSqrtHiGainSamples = TMath::Sqrt((Float_t)fNumHiGainSamples);
85 fSqrtLoGainSamples = TMath::Sqrt((Float_t)fNumLoGainSamples);
86}
87
88// --------------------------------------------------------------------------
89//
90// The PreProcess searches for the following input containers:
91// - MRawEvtData
92// - MPedestalCam
93//
94// The following output containers are also searched and created if
95// they were not found:
96//
97// - MExtractedSignalCam
98//
99Int_t MExtractSignal::PreProcess(MParList *pList)
100{
101 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
102 if (!fRawEvt)
103 {
104 *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
105 return kFALSE;
106 }
107
108
109 fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
110 if (!fSignals)
111 return kFALSE;
112
113 fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainFirst+fNumHiGainSamples-1,
114 fLoGainFirst, fLoGainFirst+fNumLoGainSamples-1);
115
116 fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
117 if (!fPedestals)
118 {
119 *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
120 return kFALSE;
121 }
122
123 fArrivalTime = (MArrivalTime*)pList->FindCreateObj(AddSerialNumber("MArrivalTime"));
124 if (!fArrivalTime)
125 return kFALSE;
126
127 return kTRUE;
128}
129
130
131// --------------------------------------------------------------------------
132//
133// The ReInit searches for the following input containers:
134// - MRawRunHeader
135//
136Bool_t MExtractSignal::ReInit(MParList *pList )
137{
138 MGeomCam *cam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
139 if (!cam)
140 {
141 *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
142 return kFALSE;
143 }
144
145 return kTRUE;
146}
147
148// --------------------------------------------------------------------------
149//
150// Calculate the integral of the FADC time slices and store them as a new
151// pixel in the MExtractedSignalCam container.
152//
153Int_t MExtractSignal::Process()
154{
155 MRawEvtPixelIter pixel(fRawEvt);
156 fSignals->Clear();
157
158 UInt_t satlo=0;
159
160 while (pixel.Next())
161 {
162 UShort_t satHi = 0;
163 UShort_t satLo = 0;
164
165 UInt_t sumHi = 0;
166 UInt_t sumLo = 0;
167
168 Byte_t maxhi = 0;
169 Byte_t midhi = 0;
170
171 Byte_t *ptr = pixel.GetHiGainSamples() + fHiGainFirst;
172 Byte_t *last = ptr + fNumHiGainSamples;
173
174 while (ptr<last)
175 {
176 sumHi += *ptr;
177
178 if (*ptr > maxhi)
179 {
180 maxhi = *ptr;
181 midhi = ptr-pixel.GetHiGainSamples();
182 }
183
184 if (*ptr >= fSaturationLimit)
185 satHi++;
186
187 ptr++;
188 }
189
190 ptr = pixel.GetLoGainSamples() + fLoGainFirst;
191 last = ptr + fNumLoGainSamples;
192
193 Byte_t maxlo = 0;
194 Byte_t midlo = 0;
195
196 while (ptr<last)
197 {
198 sumLo += *ptr;
199
200 if (*ptr > maxlo)
201 {
202 maxlo = *ptr;
203 midlo = ptr-pixel.GetLoGainSamples();
204 }
205
206 if (*ptr >= fSaturationLimit)
207 satLo++;
208
209 ptr++;
210 }
211
212 if (satLo)
213 satlo++;
214
215 const Int_t pixid = pixel.GetPixelId();
216
217 const MPedestalPix &ped = (*fPedestals)[pixid];
218 MExtractedSignalPix &pix = (*fSignals)[pixid];
219
220 const Float_t pedes = ped.GetPedestal();
221 const Float_t pedrms = ped.GetPedestalRms();
222
223 pix.SetExtractedSignal(sumHi - pedes*fNumHiGainSamples, pedrms*fSqrtHiGainSamples,
224 sumLo - pedes*fNumLoGainSamples, pedrms*fSqrtLoGainSamples);
225
226 pix.SetGainSaturation(satHi, satHi, satLo);
227
228 fArrivalTime->SetTime(pixid, satHi?midlo:midhi);
229
230 } /* while (pixel.Next()) */
231
232 if (satlo)
233 *fLog << warn << "WARNING - Lo Gain saturated in " << satlo << " pixels." << endl;
234
235
236 fSignals->SetReadyToSave();
237
238 return kTRUE;
239}
240
241// --------------------------------------------------------------------------
242//
243// Implementation of SavePrimitive. Used to write the call to a constructor
244// to a macro. In the original root implementation it is used to write
245// gui elements to a macro-file.
246//
247void MExtractSignal::StreamPrimitive(ofstream &out) const
248{
249 out << " " << ClassName() << " " << GetUniqueName() << "(\"";
250 out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
251
252 if (fSaturationLimit!=fgSaturationLimit)
253 {
254 out << " " << GetUniqueName() << ".SetSaturationLimit(";
255 out << (int)fSaturationLimit << ");" << endl;
256 }
257
258 const Bool_t arg4 = fNumLoGainSamples+fLoGainFirst-1 != fgLast;
259 const Bool_t arg3 = arg4 || fLoGainFirst != fgFirst;
260 const Bool_t arg2 = arg3 || fNumHiGainSamples+fHiGainFirst-1 != fgLast;
261 const Bool_t arg1 = arg2 || fHiGainFirst != fgFirst;
262
263 if (!arg1)
264 return;
265
266 out << " " << GetUniqueName() << ".SetRange(";
267 out << (int)fLoGainFirst;
268 if (arg2)
269 {
270 out << ", " << (int)(fNumHiGainSamples+fHiGainFirst-1);
271 if (arg3)
272 {
273 out << ", " << (int)fLoGainFirst;
274 if (arg4)
275 out << ", " << (int)(fNumLoGainSamples+fLoGainFirst-1);
276 }
277 }
278 out << ");" << endl;
279}
Note: See TracBrowser for help on using the repository browser.