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

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