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