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

Last change on this file since 2706 was 2699, checked in by gaug, 22 years ago
*** empty log message ***
File size: 6.0 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-2001
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26// //
27// MExtractSignal //
28// //
29//////////////////////////////////////////////////////////////////////////////
30
31#include "MExtractSignal.h"
32
33#include "MExtractedSignalCam.h"
34#include "MExtractedSignalPix.h"
35
36#include "MPedestalCam.h"
37#include "MPedestalPix.h"
38
39#include "MGeomCam.h"
40
41#include "MLog.h"
42#include "MLogManip.h"
43
44#include "MParList.h"
45
46#include "MRawEvtData.h"
47#include "MRawEvtPixelIter.h"
48
49#include "TMath.h"
50
51ClassImp(MExtractSignal);
52
53using namespace std;
54// --------------------------------------------------------------------------
55//
56// Default constructor.
57//
58MExtractSignal::MExtractSignal(const Byte_t first, const Byte_t last, const char *name, const char *title)
59 : fNumHiGainSamples(last-first+1), fNumLoGainSamples(last-first+1),
60 fSaturationLimit(254), fConversionHiLo(10.)
61{
62
63 fName = name ? name : "MExtractSignal";
64 fTitle = title ? title : "Task to extract the signal from the FADC slices";
65
66 AddToBranchList("MRawEvtData.*");
67
68 fFirst = first;
69
70 fSqrtHiGainSamples = TMath::Sqrt((Float_t)fNumHiGainSamples);
71 fSqrtLoGainSamples = TMath::Sqrt((Float_t)fNumLoGainSamples);
72}
73
74// --------------------------------------------------------------------------
75//
76// The PreProcess searches for the following input containers:
77// - MRawEvtData
78// - MPedestalCam
79//
80// The following output containers are also searched and created if
81// they were not found:
82//
83// - MExtractedSignalCam
84//
85Int_t MExtractSignal::PreProcess(MParList *pList)
86{
87
88 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
89 if (!fRawEvt)
90 {
91 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
92 return kFALSE;
93 }
94
95
96 fSignals = (MExtractedSignalCam*)pList->FindCreateObj("MExtractedSignalCam");
97 if (!fSignals)
98 return kFALSE;
99
100 fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
101 if (!fPedestals)
102 {
103 *fLog << err << dbginf << "Cannot find MPedestalCam ... aborting" << endl;
104 return kFALSE;
105 }
106
107 return kTRUE;
108}
109
110
111// --------------------------------------------------------------------------
112//
113// The ReInit searches for the following input containers:
114// - MRawRunHeader
115//
116Bool_t MExtractSignal::ReInit(MParList *pList )
117{
118
119
120 MGeomCam *cam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
121 if (!cam)
122 {
123 *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
124 return kFALSE;
125 }
126
127 fSignals->InitSize(cam->GetNumPixels());
128
129
130 fSignals->SetNumUsedFADCSlices(fNumHiGainSamples,fFirst,fFirst+fNumHiGainSamples-1,
131 fNumLoGainSamples,fFirst,fFirst+fNumLoGainSamples-1);
132
133 return kTRUE;
134}
135
136
137// --------------------------------------------------------------------------
138//
139// Calculate the integral of the FADC time slices and store them as a new
140// pixel in the MExtractedSignalCam container.
141//
142Int_t MExtractSignal::Process()
143{
144
145 MRawEvtPixelIter pixel(fRawEvt);
146 fSignals->Clear();
147
148 while (pixel.Next())
149 {
150
151 UShort_t satHi = 0;
152 UShort_t satLo = 0;
153
154 Byte_t *ptr = pixel.GetHiGainSamples();
155 Byte_t *first = ptr + fFirst;
156 Byte_t *last = ptr + fFirst + fNumHiGainSamples;
157
158 UInt_t sumHi = 0;
159 UInt_t sumLo = 0;
160
161 const Int_t pixid = pixel.GetPixelId();
162 const MPedestalPix &ped = (*fPedestals)[pixid];
163 MExtractedSignalPix &pix = (*fSignals)[pixid];
164
165 const Float_t pedes = ped.GetPedestal();
166 const Float_t pedrms = ped.GetPedestalRms();
167
168 Byte_t maxhi = 0;
169 Byte_t midhi = 0;
170
171 for (ptr=first;ptr<last;ptr++)
172 {
173
174 if (*ptr > maxhi)
175 {
176 maxhi = *ptr;
177 midhi = ptr-first;
178 }
179
180 sumHi += *ptr;
181
182 if (*ptr >= fSaturationLimit)
183 satHi++;
184
185 }
186
187 ptr = pixel.GetLoGainSamples();
188 first = ptr + fFirst + 1;
189 last = ptr + fFirst + fNumLoGainSamples +1;
190 Byte_t maxlo = 0;
191 Byte_t midlo = 0;
192
193 for (ptr=first;ptr<last;ptr++)
194 {
195
196 if (*ptr > maxlo)
197 {
198 maxlo = *ptr;
199 midlo = ptr-first;
200 }
201
202 sumLo += *ptr;
203
204 if (*ptr >= fSaturationLimit)
205 {
206 *fLog << err << dbginf
207 << "Warning: Saturation of Lo Gain reached in pixel: "
208 << pixid << " " << " sum = " << sumLo << endl;
209 satLo++;
210 }
211 }
212
213 pix.SetExtractedSignal((Float_t)sumHi - pedes*(Float_t)fNumHiGainSamples,
214 pedrms*fSqrtHiGainSamples,
215 ((Float_t)sumLo - pedes*(Float_t)fNumLoGainSamples)*fConversionHiLo,
216 pedrms*fSqrtLoGainSamples
217 );
218
219 pix.SetGainSaturation((satHi),satHi,satLo);
220
221 if (satHi)
222 pix.SetArrivalTimes((Float_t)(midlo+fFirst),0.,0.);
223 else
224 pix.SetArrivalTimes((Float_t)(midhi+fFirst),0.,0.);
225
226 } /* while (pixel.Next()) */
227
228
229 fSignals->SetReadyToSave();
230
231 return kTRUE;
232}
233
234Int_t MExtractSignal::PostProcess()
235{
236
237 return kTRUE;
238
239}
Note: See TracBrowser for help on using the repository browser.