source: trunk/MagicSoft/Mars/msignal/MExtractPINDiode.cc@ 3959

Last change on this file since 3959 was 3951, checked in by gaug, 21 years ago
*** empty log message ***
File size: 8.5 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, 02/2004 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MExtractPINDiode
28//
29// Extracts the signal from a fixed window in a given range.
30//
31// Call: SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast)
32// to modify the ranges. Ranges have to be an even number. In case of odd
33// ranges, the last slice will be reduced by one.
34// Defaults are:
35//
36// fHiGainFirst = fgHiGainFirst = 3
37// fHiGainLast = fgHiGainLast = 14
38// fLoGainFirst = fgLoGainFirst = 3
39// fLoGainLast = fgLoGainLast = 14
40//
41//////////////////////////////////////////////////////////////////////////////
42#include "MExtractPINDiode.h"
43#include "MExtractor.h"
44
45#include <fstream>
46
47#include "MLog.h"
48#include "MLogManip.h"
49
50#include "MParList.h"
51
52#include "MRawEvtData.h"
53#include "MRawEvtPixelIter.h"
54
55#include "MPedestalCam.h"
56#include "MPedestalPix.h"
57
58#include "MExtractedSignalPINDiode.h"
59
60ClassImp(MExtractPINDiode);
61
62using namespace std;
63
64const UInt_t MExtractPINDiode::fgPINDiodeIdx = 100;
65const Byte_t MExtractPINDiode::fgHiGainFirst = 0;
66const Byte_t MExtractPINDiode::fgHiGainLast = 14;
67const Byte_t MExtractPINDiode::fgLoGainFirst = 0;
68const Byte_t MExtractPINDiode::fgLoGainLast = 14;
69// --------------------------------------------------------------------------
70//
71// Default constructor.
72//
73// Calls:
74// - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
75// - SetPINDiodeIdx()
76//
77MExtractPINDiode::MExtractPINDiode(const char *name, const char *title)
78{
79
80 fName = name ? name : "MExtractPINDiode";
81 fTitle = title ? title : "Task to extract the signal from the FADC slices";
82
83 SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
84 SetPINDiodeIdx();
85}
86
87// --------------------------------------------------------------------------
88//
89// SetRange:
90//
91// Checks:
92// - if the window defined by (fHiGainLast-fHiGainFirst-1) are odd, subtract one
93// - if the window defined by (fLoGainLast-fLoGainFirst-1) are odd, subtract one
94// - if the Hi Gain window is smaller than 2, set fHiGainLast to fHiGainFirst+1
95// - if the Lo Gain window is smaller than 2, set fLoGainLast to fLoGainFirst+1
96//
97// Calls:
98// - MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
99//
100// Sets:
101// - fNumHiGainSamples to: (Float_t)(fHiGainLast-fHiGainFirst+1)
102// - fNumLoGainSamples to: (Float_t)(fLoGainLast-fLoGainFirst+1)
103// - fSqrtHiGainSamples to: TMath::Sqrt(fNumHiGainSamples)
104// - fSqrtLoGainSamples to: TMath::Sqrt(fNumLoGainSamples)
105//
106void MExtractPINDiode::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
107{
108
109 const Byte_t window = hilast-hifirst+1+lolast-lofirst+1;
110 const Byte_t weven = window & ~1;
111
112 if (weven != window)
113 {
114 *fLog << warn << GetDescriptor()
115 << Form("%s%2i%s%2i",": Total window size has to be even, set last slice from "
116 ,(int)lolast," to ",(int)(lolast-1)) << endl;
117 lolast -= 1;
118 }
119
120 if (window<2)
121 {
122 *fLog << warn << GetDescriptor()
123 << Form("%s%2i%s%2i",": Total window is smaller than 2 FADC sampes, set last slice from"
124 ,(int)lolast," to ",(int)(lofirst+1)) << endl;
125 hilast = hifirst+1;
126 }
127
128
129 MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
130
131
132 fNumHiGainSamples = (Float_t)(fHiGainLast-fHiGainFirst+1);
133 fNumLoGainSamples = (Float_t)(fLoGainLast-fLoGainFirst+1);
134
135 fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
136 fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
137
138 fNumSamples = fHiGainLast-fHiGainFirst+1+fLoGainLast-fLoGainFirst+1;
139 fSqrtSamples = TMath::Sqrt((Float_t)fNumSamples);
140
141}
142
143// --------------------------------------------------------------------------
144//
145// Calls:
146// - MExtractor::PreProcess
147//
148// The following output containers are also searched and created if
149// they were not found:
150//
151// - MExtractedPINDiode
152//
153Int_t MExtractPINDiode::PreProcess(MParList *pList)
154{
155
156 if (!MExtractor::PreProcess(pList))
157 return kFALSE;
158
159 fPINDiode = (MExtractedSignalPINDiode*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalPINDiode"));
160 if (!fPINDiode)
161 return kFALSE;
162
163 const MPedestalPix &ped = (*fPedestals)[fPINDiodeIdx];
164
165 if (&ped)
166 {
167 fPedestal = ped.GetPedestal();
168 fPedRms = ped.GetPedestalRms();
169 }
170 else
171 {
172 *fLog << err << " Cannot find MPedestalPix of the PIN Diode (idx="
173 << fPINDiodeIdx << ")" << endl;
174 return kFALSE;
175 }
176
177 return kTRUE;
178}
179
180// --------------------------------------------------------------------------
181//
182// The ReInit calls:
183// - MExtractor::ReInit()
184// - fPINDiode->SetUsedFADCSlices(fHiGainFirst, fLoGainLast);
185//
186Bool_t MExtractPINDiode::ReInit(MParList *pList)
187{
188
189 MExtractor::ReInit(pList);
190
191 fPINDiode->SetUsedFADCSlices(fHiGainFirst, fLoGainLast);
192
193 return kTRUE;
194
195}
196
197
198
199void MExtractPINDiode::FindSignalandVarianceHiGain(Byte_t *ptr, Int_t &sum, Int_t &sum2, Byte_t &sat) const
200{
201
202 Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1;
203
204 while (ptr<end)
205 {
206 sum += *ptr;
207 sum2 += *ptr * *ptr;
208
209 if (*ptr++ >= fSaturationLimit)
210 sat++;
211 }
212}
213
214void MExtractPINDiode::FindSignalandVarianceLoGain(Byte_t *ptr, Int_t &sum, Int_t &sum2, Byte_t &sat) const
215{
216
217 Byte_t *end = ptr + fLoGainLast - fLoGainFirst + 1;
218
219 while (ptr<end)
220 {
221 sum += *ptr;
222 sum2 += *ptr * *ptr;
223
224 if (*ptr++ >= fSaturationLimit)
225 sat++;
226 }
227}
228
229
230
231// --------------------------------------------------------------------------
232//
233// Calculate the integral of the FADC time slices and store them as a new
234// pixel in the MExtractedPINDiode container.
235//
236Int_t MExtractPINDiode::Process()
237{
238
239
240 MRawEvtPixelIter pixel(fRawEvt);
241
242 fPINDiode->Clear();
243
244 pixel.Jump(fPINDiodeIdx);
245
246 Int_t sum = 0;
247 Int_t sum2 = 0;
248 Byte_t sat = 0;
249 Int_t max = 0;
250
251 //
252 // Calculate first the time:
253 //
254 const Int_t maxhi = pixel.GetIdxMaxHiGainSample();
255 const Int_t maxlo = pixel.GetIdxMaxLoGainSample();
256
257 if (maxhi > maxlo)
258 max = maxhi;
259 else
260 max = maxlo + pixel.GetNumHiGainSamples();
261
262 FindSignalandVarianceHiGain(pixel.GetHiGainSamples()+fHiGainFirst,sum,sum2,sat);
263 FindSignalandVarianceLoGain(pixel.GetLoGainSamples()+fLoGainFirst,sum,sum2,sat);
264
265 const Float_t var = ((Float_t)sum2 - (Float_t)sum*sum/fNumSamples)/(fNumSamples-1);
266 const Float_t rms = TMath::Sqrt(var);
267
268 //
269 // FIXME: The following formulae have to be revised!!
270 //
271 fPINDiode->SetExtractedSignal(sum - fPedestal*fNumSamples, fPedRms*fSqrtSamples);
272 fPINDiode->SetExtractedRms (rms, rms/2./fSqrtSamples);
273 fPINDiode->SetExtractedTime (max, rms/fSqrtSamples);
274 fPINDiode->SetSaturation(sat);
275 fPINDiode->SetReadyToSave();
276
277 return kTRUE;
278}
279
280// --------------------------------------------------------------------------
281//
282// Implementation of SavePrimitive. Used to write the call to a constructor
283// to a macro. In the original root implementation it is used to write
284// gui elements to a macro-file.
285//
286void MExtractPINDiode::StreamPrimitive(ofstream &out) const
287{
288 out << " " << ClassName() << " " << GetUniqueName() << "(\"";
289 out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
290
291 if (fSaturationLimit!=fgSaturationLimit)
292 {
293 out << " " << GetUniqueName() << ".SetSaturationLimit(";
294 out << (int)fSaturationLimit << ");" << endl;
295 }
296
297 const Bool_t arg2 = fNumSamples+fHiGainFirst-1 != fgLoGainLast;
298 const Bool_t arg1 = arg2 || fHiGainFirst != fgHiGainFirst;
299
300 if (!arg1)
301 return;
302
303 out << " " << GetUniqueName() << ".SetRange(";
304 out << (int)fHiGainFirst;
305 if (arg2)
306 out << ", " << (int)(fNumSamples+fHiGainFirst-1);
307 out << ");" << endl;
308}
Note: See TracBrowser for help on using the repository browser.