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

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