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

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