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