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 |
|
---|
51 | ClassImp(MExtractSignal);
|
---|
52 |
|
---|
53 | using namespace std;
|
---|
54 | // --------------------------------------------------------------------------
|
---|
55 | //
|
---|
56 | // Default constructor.
|
---|
57 | //
|
---|
58 | MExtractSignal::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 |
|
---|
70 | void 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 | //
|
---|
94 | Int_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 | fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
|
---|
109 | if (!fPedestals)
|
---|
110 | {
|
---|
111 | *fLog << err << "MPedestalCam not found... aborting" << endl;
|
---|
112 | return kFALSE;
|
---|
113 | }
|
---|
114 |
|
---|
115 | return kTRUE;
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | // --------------------------------------------------------------------------
|
---|
120 | //
|
---|
121 | // The ReInit searches for the following input containers:
|
---|
122 | // - MRawRunHeader
|
---|
123 | //
|
---|
124 | Bool_t MExtractSignal::ReInit(MParList *pList )
|
---|
125 | {
|
---|
126 | MGeomCam *cam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
|
---|
127 | if (!cam)
|
---|
128 | {
|
---|
129 | *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
|
---|
130 | return kFALSE;
|
---|
131 | }
|
---|
132 |
|
---|
133 | // FIXME: This solution may change in the future, MExtractedSignal
|
---|
134 | // must be similar to MCerPhotEvt not to MPedestalCam
|
---|
135 | // (Have to think about the mean size of both solutions)
|
---|
136 | fSignals->InitSize(cam->GetNumPixels());
|
---|
137 |
|
---|
138 | fSignals->SetNumUsedFADCSlices(fNumHiGainSamples, fHiGainFirst, fHiGainFirst+fNumHiGainSamples-1,
|
---|
139 | fNumLoGainSamples, fLoGainFirst, fLoGainFirst+fNumLoGainSamples-1);
|
---|
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 | //
|
---|
150 | Int_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 | {
|
---|
212 | *fLog << err << dbginf
|
---|
213 | << "Warning: Saturation of Lo Gain reached in pixel: "
|
---|
214 | << pixid << " " << " sum = " << sumLo << endl;
|
---|
215 | satLo++;
|
---|
216 | }
|
---|
217 | }
|
---|
218 |
|
---|
219 | pix.SetExtractedSignal((Float_t)sumHi - pedes*(Float_t)fNumHiGainSamples,
|
---|
220 | pedrms*fSqrtHiGainSamples,
|
---|
221 | ((Float_t)sumLo - pedes*(Float_t)fNumLoGainSamples),
|
---|
222 | pedrms*fSqrtLoGainSamples);
|
---|
223 |
|
---|
224 | pix.SetGainSaturation(satHi, satHi, satLo);
|
---|
225 |
|
---|
226 | // FIXME: Arrival time has to be stored in MArrivalTime!
|
---|
227 | if (satHi)
|
---|
228 | pix.SetArrivalTimes((Float_t)(midlo+fLoGainFirst),0.,0.);
|
---|
229 | else
|
---|
230 | pix.SetArrivalTimes((Float_t)(midhi+fHiGainFirst),0.,0.);
|
---|
231 |
|
---|
232 | } /* while (pixel.Next()) */
|
---|
233 |
|
---|
234 |
|
---|
235 | fSignals->SetReadyToSave();
|
---|
236 |
|
---|
237 | return kTRUE;
|
---|
238 | }
|
---|