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

Last change on this file since 3921 was 3911, checked in by gaug, 21 years ago
*** empty log message ***
File size: 8.0 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 fNumSamples = fHiGainLast-fHiGainFirst+1+fLoGainLast-fLoGainFirst+1;
132 fSqrtSamples = TMath::Sqrt((Float_t)fNumSamples);
133
134}
135
136// --------------------------------------------------------------------------
137//
138// Calls:
139// - MExtractor::PreProcess
140//
141// The following output containers are also searched and created if
142// they were not found:
143//
144// - MExtractedPINDiode
145//
146Int_t MExtractPINDiode::PreProcess(MParList *pList)
147{
148
149 if (!MExtractor::PreProcess(pList))
150 return kFALSE;
151
152 fPINDiode = (MExtractedSignalPINDiode*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalPINDiode"));
153 if (!fPINDiode)
154 return kFALSE;
155
156 fPINDiode->SetUsedFADCSlices(fHiGainFirst, fLoGainLast);
157
158 const MPedestalPix &ped = (*fPedestals)[fPINDiodeIdx];
159
160 if (&ped)
161 {
162 fPedestal = ped.GetPedestal();
163 fPedRms = ped.GetPedestalRms();
164 }
165 else
166 {
167 *fLog << err << " Cannot find MPedestalPix of the PIN Diode (idx="
168 << fPINDiodeIdx << ")" << endl;
169 return kFALSE;
170 }
171
172 return kTRUE;
173}
174
175void MExtractPINDiode::FindSignalandVarianceHiGain(Byte_t *ptr, Int_t &sum, Int_t &sum2, Byte_t &sat) const
176{
177
178 Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1;
179
180 while (ptr<end)
181 {
182 sum += *ptr;
183 sum2 += *ptr * *ptr;
184
185 if (*ptr++ >= fSaturationLimit)
186 sat++;
187 }
188}
189
190void MExtractPINDiode::FindSignalandVarianceLoGain(Byte_t *ptr, Int_t &sum, Int_t &sum2, Byte_t &sat) const
191{
192
193 Byte_t *end = ptr + fLoGainLast - fLoGainFirst + 1;
194
195 while (ptr<end)
196 {
197 sum += *ptr;
198 sum2 += *ptr * *ptr;
199
200 if (*ptr++ >= fSaturationLimit)
201 sat++;
202 }
203}
204
205
206
207// --------------------------------------------------------------------------
208//
209// Calculate the integral of the FADC time slices and store them as a new
210// pixel in the MExtractedPINDiode container.
211//
212Int_t MExtractPINDiode::Process()
213{
214
215
216 MRawEvtPixelIter pixel(fRawEvt);
217
218 fPINDiode->Clear();
219
220 pixel.Jump(fPINDiodeIdx);
221
222 Int_t sum = 0;
223 Int_t sum2 = 0;
224 Byte_t sat = 0;
225 Int_t max = 0;
226
227 //
228 // Calculate first the time:
229 //
230 const Int_t maxhi = pixel.GetIdxMaxHiGainSample();
231 const Int_t maxlo = pixel.GetIdxMaxLoGainSample();
232
233 if (maxhi > maxlo)
234 max = maxhi;
235 else
236 max = maxlo + pixel.GetNumHiGainSamples();
237
238 FindSignalandVarianceHiGain(pixel.GetHiGainSamples()+fHiGainFirst,sum,sum2,sat);
239 FindSignalandVarianceLoGain(pixel.GetLoGainSamples()+fLoGainFirst,sum,sum2,sat);
240
241 const Float_t var = ((Float_t)sum2 - (Float_t)sum*sum/fNumSamples)/(fNumSamples-1);
242 const Float_t rms = TMath::Sqrt(var);
243
244 //
245 // FIXME: The following formulae have to be revised!!
246 //
247 fPINDiode->SetExtractedSignal(sum - fPedestal*fNumSamples, fPedRms*fSqrtSamples);
248 fPINDiode->SetExtractedRms (rms, rms/2./fSqrtSamples);
249 fPINDiode->SetExtractedTime (max, rms/fSqrtSamples);
250 fPINDiode->SetSaturation(sat);
251 fPINDiode->SetReadyToSave();
252
253 return kTRUE;
254}
255
256// --------------------------------------------------------------------------
257//
258// Implementation of SavePrimitive. Used to write the call to a constructor
259// to a macro. In the original root implementation it is used to write
260// gui elements to a macro-file.
261//
262void MExtractPINDiode::StreamPrimitive(ofstream &out) const
263{
264 out << " " << ClassName() << " " << GetUniqueName() << "(\"";
265 out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
266
267 if (fSaturationLimit!=fgSaturationLimit)
268 {
269 out << " " << GetUniqueName() << ".SetSaturationLimit(";
270 out << (int)fSaturationLimit << ");" << endl;
271 }
272
273 const Bool_t arg2 = fNumSamples+fHiGainFirst-1 != fgLoGainLast;
274 const Bool_t arg1 = arg2 || fHiGainFirst != fgHiGainFirst;
275
276 if (!arg1)
277 return;
278
279 out << " " << GetUniqueName() << ".SetRange(";
280 out << (int)fHiGainFirst;
281 if (arg2)
282 out << ", " << (int)(fNumSamples+fHiGainFirst-1);
283 out << ");" << endl;
284}
Note: See TracBrowser for help on using the repository browser.