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 | ! Thomas Bretz, 01/2004
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | //////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MExtractSignal
|
---|
29 | //
|
---|
30 | //////////////////////////////////////////////////////////////////////////////
|
---|
31 | #include "MExtractSignal.h"
|
---|
32 |
|
---|
33 | #include <fstream>
|
---|
34 |
|
---|
35 | #include "MLog.h"
|
---|
36 | #include "MLogManip.h"
|
---|
37 |
|
---|
38 | #include "MParList.h"
|
---|
39 |
|
---|
40 | #include "MRawEvtData.h"
|
---|
41 | #include "MRawEvtPixelIter.h"
|
---|
42 |
|
---|
43 | #include "MPedestalCam.h"
|
---|
44 | #include "MPedestalPix.h"
|
---|
45 |
|
---|
46 | #include "MExtractedSignalCam.h"
|
---|
47 | #include "MExtractedSignalPix.h"
|
---|
48 |
|
---|
49 | ClassImp(MExtractSignal);
|
---|
50 |
|
---|
51 | using namespace std;
|
---|
52 |
|
---|
53 | const Byte_t MExtractSignal::fgSaturationLimit = 254;
|
---|
54 | const Byte_t MExtractSignal::fgFirst = 3;
|
---|
55 | const Byte_t MExtractSignal::fgLast = 10;
|
---|
56 |
|
---|
57 | // --------------------------------------------------------------------------
|
---|
58 | //
|
---|
59 | // Default constructor.
|
---|
60 | //
|
---|
61 | MExtractSignal::MExtractSignal(const char *name, const char *title)
|
---|
62 | : fSaturationLimit(fgSaturationLimit)
|
---|
63 | {
|
---|
64 |
|
---|
65 | fName = name ? name : "MExtractSignal";
|
---|
66 | fTitle = title ? title : "Task to extract the signal from the FADC slices";
|
---|
67 |
|
---|
68 | AddToBranchList("MRawEvtData.*");
|
---|
69 |
|
---|
70 | SetRange();
|
---|
71 | }
|
---|
72 |
|
---|
73 | void MExtractSignal::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
|
---|
74 | {
|
---|
75 |
|
---|
76 | fNumHiGainSamples = hilast-hifirst+1;
|
---|
77 | fNumLoGainSamples = lolast-lofirst+1;
|
---|
78 |
|
---|
79 | fHiGainFirst = hifirst;
|
---|
80 | fLoGainFirst = lofirst;
|
---|
81 |
|
---|
82 | fSqrtHiGainSamples = TMath::Sqrt((Float_t)fNumHiGainSamples);
|
---|
83 | fSqrtLoGainSamples = TMath::Sqrt((Float_t)fNumLoGainSamples);
|
---|
84 | }
|
---|
85 |
|
---|
86 | // --------------------------------------------------------------------------
|
---|
87 | //
|
---|
88 | // The PreProcess searches for the following input containers:
|
---|
89 | // - MRawEvtData
|
---|
90 | // - MPedestalCam
|
---|
91 | //
|
---|
92 | // The following output containers are also searched and created if
|
---|
93 | // they were not found:
|
---|
94 | //
|
---|
95 | // - MExtractedSignalCam
|
---|
96 | //
|
---|
97 | Int_t MExtractSignal::PreProcess(MParList *pList)
|
---|
98 | {
|
---|
99 | fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
|
---|
100 | if (!fRawEvt)
|
---|
101 | {
|
---|
102 | *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
|
---|
103 | return kFALSE;
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
|
---|
108 | if (!fSignals)
|
---|
109 | return kFALSE;
|
---|
110 |
|
---|
111 | fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainFirst+fNumHiGainSamples-1,
|
---|
112 | fLoGainFirst, fLoGainFirst+fNumLoGainSamples-1);
|
---|
113 |
|
---|
114 | fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
|
---|
115 |
|
---|
116 | if (!fPedestals)
|
---|
117 | {
|
---|
118 | *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
|
---|
119 | return kFALSE;
|
---|
120 | }
|
---|
121 |
|
---|
122 | return kTRUE;
|
---|
123 | }
|
---|
124 |
|
---|
125 | void MExtractSignal::FindSignal(Byte_t *ptr, Int_t size, Int_t &sum, Byte_t &sat) const
|
---|
126 | {
|
---|
127 |
|
---|
128 | Byte_t *end = ptr + size;
|
---|
129 |
|
---|
130 | sum = 0;
|
---|
131 | sat = 0;
|
---|
132 |
|
---|
133 | while (ptr<end)
|
---|
134 | {
|
---|
135 | sum += *ptr;
|
---|
136 |
|
---|
137 | if (*ptr++ >= fSaturationLimit)
|
---|
138 | sat++;
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | // --------------------------------------------------------------------------
|
---|
143 | //
|
---|
144 | // Calculate the integral of the FADC time slices and store them as a new
|
---|
145 | // pixel in the MExtractedSignalCam container.
|
---|
146 | //
|
---|
147 | Int_t MExtractSignal::Process()
|
---|
148 | {
|
---|
149 |
|
---|
150 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
151 | fSignals->Clear();
|
---|
152 |
|
---|
153 | UInt_t sat=0;
|
---|
154 | TString satpixels;
|
---|
155 |
|
---|
156 | while (pixel.Next())
|
---|
157 | {
|
---|
158 | Int_t sumhi, sumlo;
|
---|
159 | Byte_t sathi, satlo;
|
---|
160 |
|
---|
161 | FindSignal(pixel.GetHiGainSamples()+fHiGainFirst-1, fNumHiGainSamples, sumhi, sathi);
|
---|
162 | FindSignal(pixel.GetLoGainSamples()+fLoGainFirst-1, fNumLoGainSamples, sumlo, satlo);
|
---|
163 |
|
---|
164 | if (satlo)
|
---|
165 | {
|
---|
166 | sat++;
|
---|
167 | satpixels += Form(" %d", pixel.GetPixelId());
|
---|
168 | }
|
---|
169 |
|
---|
170 |
|
---|
171 | const Int_t pixid = pixel.GetPixelId();
|
---|
172 |
|
---|
173 | const MPedestalPix &ped = (*fPedestals)[pixid];
|
---|
174 | MExtractedSignalPix &pix = (*fSignals)[pixid];
|
---|
175 |
|
---|
176 | const Float_t pedes = ped.GetPedestal();
|
---|
177 | const Float_t pedrms = ped.GetPedestalRms();
|
---|
178 |
|
---|
179 |
|
---|
180 | pix.SetExtractedSignal(sumhi - pedes*fNumHiGainSamples, pedrms*fSqrtHiGainSamples,
|
---|
181 | sumlo - pedes*fNumLoGainSamples, pedrms*fSqrtLoGainSamples);
|
---|
182 |
|
---|
183 | pix.SetGainSaturation(sathi, sathi, satlo);
|
---|
184 |
|
---|
185 | } /* while (pixel.Next()) */
|
---|
186 |
|
---|
187 | if (sat)
|
---|
188 | *fLog << warn << "WARNING - Lo Gain saturated in " << sat << " pixels with Index:" << satpixels << endl;
|
---|
189 |
|
---|
190 | fSignals->SetReadyToSave();
|
---|
191 |
|
---|
192 | return kTRUE;
|
---|
193 | }
|
---|
194 |
|
---|
195 | // --------------------------------------------------------------------------
|
---|
196 | //
|
---|
197 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
---|
198 | // to a macro. In the original root implementation it is used to write
|
---|
199 | // gui elements to a macro-file.
|
---|
200 | //
|
---|
201 | void MExtractSignal::StreamPrimitive(ofstream &out) const
|
---|
202 | {
|
---|
203 | out << " " << ClassName() << " " << GetUniqueName() << "(\"";
|
---|
204 | out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
|
---|
205 |
|
---|
206 | if (fSaturationLimit!=fgSaturationLimit)
|
---|
207 | {
|
---|
208 | out << " " << GetUniqueName() << ".SetSaturationLimit(";
|
---|
209 | out << (int)fSaturationLimit << ");" << endl;
|
---|
210 | }
|
---|
211 |
|
---|
212 | const Bool_t arg4 = fNumLoGainSamples+fLoGainFirst-1 != fgLast;
|
---|
213 | const Bool_t arg3 = arg4 || fLoGainFirst != fgFirst;
|
---|
214 | const Bool_t arg2 = arg3 || fNumHiGainSamples+fHiGainFirst-1 != fgLast;
|
---|
215 | const Bool_t arg1 = arg2 || fHiGainFirst != fgFirst;
|
---|
216 |
|
---|
217 | if (!arg1)
|
---|
218 | return;
|
---|
219 |
|
---|
220 | out << " " << GetUniqueName() << ".SetRange(";
|
---|
221 | out << (int)fLoGainFirst;
|
---|
222 | if (arg2)
|
---|
223 | {
|
---|
224 | out << ", " << (int)(fNumHiGainSamples+fHiGainFirst-1);
|
---|
225 | if (arg3)
|
---|
226 | {
|
---|
227 | out << ", " << (int)fLoGainFirst;
|
---|
228 | if (arg4)
|
---|
229 | out << ", " << (int)(fNumLoGainSamples+fLoGainFirst-1);
|
---|
230 | }
|
---|
231 | }
|
---|
232 | out << ");" << endl;
|
---|
233 | }
|
---|