source: trunk/MagicSoft/Mars/msignal/MExtractSignalABcorr.cc@ 6000

Last change on this file since 6000 was 4404, checked in by fgoebel, 20 years ago
*** empty log message ***
File size: 7.1 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, 09/2003 <mailto:markus@ifae.es>
19! Thomas Bretz, 01/2004
20! Florian Goebel, 06/2004
21!
22! Copyright: MAGIC Software Development, 2000-2004
23!
24\* ======================================================================== */
25
26//////////////////////////////////////////////////////////////////////////////
27//
28// MExtractSignalABcorr
29//
30// this class is basically a copy of MExtractSignal and is mainly ment as
31// an example of how to use the "AB pedestal offset" to correct for the
32// 150 MHz clock noise. It allows to extract a signal using an odd number
33// of slices
34//
35//////////////////////////////////////////////////////////////////////////////
36#include "MExtractSignalABcorr.h"
37
38#include <fstream>
39
40#include "MLog.h"
41#include "MLogManip.h"
42
43#include "MParList.h"
44
45#include "MRawEvtData.h"
46#include "MRawEvtPixelIter.h"
47
48#include "MPedestalCam.h"
49#include "MPedestalPix.h"
50
51#include "MExtractedSignalCam.h"
52#include "MExtractedSignalPix.h"
53
54ClassImp(MExtractSignalABcorr);
55
56using namespace std;
57
58const Byte_t MExtractSignalABcorr::fgSaturationLimit = 254;
59const Byte_t MExtractSignalABcorr::fgFirst = 3;
60const Byte_t MExtractSignalABcorr::fgLast = 14;
61// --------------------------------------------------------------------------
62//
63// Default constructor.
64//
65MExtractSignalABcorr::MExtractSignalABcorr(const char *name, const char *title)
66 : fSaturationLimit(fgSaturationLimit)
67{
68
69 fName = name ? name : "MExtractSignalABcorr";
70 fTitle = title ? title : "Task to extract the signal from the FADC slices";
71
72 AddToBranchList("MRawEvtData.*");
73
74 SetRange();
75}
76
77void MExtractSignalABcorr::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
78{
79
80 fNumHiGainSamples = hilast-hifirst+1;
81 fNumLoGainSamples = lolast-lofirst+1;
82
83 fHiGainFirst = hifirst;
84 fLoGainFirst = lofirst;
85
86 fSqrtHiGainSamples = TMath::Sqrt((Float_t)fNumHiGainSamples);
87 fSqrtLoGainSamples = TMath::Sqrt((Float_t)fNumLoGainSamples);
88}
89
90// --------------------------------------------------------------------------
91//
92// The PreProcess searches for the following input containers:
93// - MRawEvtData
94// - MPedestalCam
95//
96// The following output containers are also searched and created if
97// they were not found:
98//
99// - MExtractedSignalCam
100//
101Int_t MExtractSignalABcorr::PreProcess(MParList *pList)
102{
103 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
104 if (!fRawEvt)
105 {
106 *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
107 return kFALSE;
108 }
109
110
111 fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
112 if (!fSignals)
113 return kFALSE;
114
115 fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainFirst+fNumHiGainSamples-1, (Float_t)fNumHiGainSamples,
116 fLoGainFirst, fLoGainFirst+fNumLoGainSamples-1, (Float_t)fNumLoGainSamples);
117
118 fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
119
120 if (!fPedestals)
121 {
122 *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
123 return kFALSE;
124 }
125
126 return kTRUE;
127}
128
129void MExtractSignalABcorr::FindSignal(Byte_t *ptr, Int_t size, Int_t &sum, Byte_t &sat) const
130{
131
132 Byte_t *end = ptr + size;
133
134 sum = 0;
135 sat = 0;
136
137 while (ptr<end)
138 {
139 sum += *ptr;
140
141 if (*ptr++ >= fSaturationLimit)
142 sat++;
143 }
144}
145
146// --------------------------------------------------------------------------
147//
148// Calculate the integral of the FADC time slices and store them as a new
149// pixel in the MExtractedSignalCam container.
150//
151Int_t MExtractSignalABcorr::Process()
152{
153 MRawEvtPixelIter pixel(fRawEvt);
154 fSignals->Clear();
155
156 UInt_t sat=0;
157
158 const Bool_t ApplyABcorrHi = fNumHiGainSamples&0x1;
159 const Bool_t ApplyABcorrLo = fNumLoGainSamples&0x1;
160
161 while (pixel.Next())
162 {
163 Int_t sumhi;
164 Byte_t sathi;
165
166 FindSignal(pixel.GetHiGainSamples()+fHiGainFirst, fNumHiGainSamples, sumhi, sathi);
167
168 Int_t sumlo = 0;
169 Byte_t satlo = 0;
170 if (pixel.HasLoGain())
171 {
172 FindSignal(pixel.GetLoGainSamples()+fLoGainFirst, fNumLoGainSamples, sumlo, satlo);
173
174 if (satlo)
175 sat++;
176 }
177
178 const Int_t pixid = pixel.GetPixelId();
179 const Bool_t ABFlag = pixel.HasABFlag();
180
181 const MPedestalPix &ped = (*fPedestals)[pixid];
182 MExtractedSignalPix &pix = (*fSignals)[pixid];
183
184 const Float_t pedes = ped.GetPedestal();
185 const Float_t pedrms = ped.GetPedestalRms();
186 const Float_t ABoffs = ped.GetPedestalABoffset();
187
188 Float_t pedtothi = pedes*fNumHiGainSamples;
189 Float_t pedtotlo = pedes*fNumLoGainSamples;
190
191 if (ApplyABcorrHi) {
192 pedtothi += ABoffs*(1-2*((fHiGainFirst+ABFlag)&0x1));
193 }
194 if (ApplyABcorrLo) {
195 pedtotlo += ABoffs*(1-2*((fLoGainFirst+ABFlag)&0x1));
196 }
197
198 pix.SetExtractedSignal(sumhi - pedtothi, pedrms*fSqrtHiGainSamples,
199 sumlo - pedtotlo, pedrms*fSqrtLoGainSamples);
200
201 pix.SetGainSaturation(sathi, sathi, satlo);
202
203 } /* while (pixel.Next()) */
204
205 fSignals->SetReadyToSave();
206
207 return kTRUE;
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//
216void MExtractSignalABcorr::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 arg4 = fNumLoGainSamples+fLoGainFirst-1 != fgLast;
228 const Bool_t arg3 = arg4 || fLoGainFirst != fgFirst;
229 const Bool_t arg2 = arg3 || fNumHiGainSamples+fHiGainFirst-1 != fgLast;
230 const Bool_t arg1 = arg2 || fHiGainFirst != fgFirst;
231
232 if (!arg1)
233 return;
234
235 out << " " << GetUniqueName() << ".SetRange(";
236 out << (int)fLoGainFirst;
237 if (arg2)
238 {
239 out << ", " << (int)(fNumHiGainSamples+fHiGainFirst-1);
240 if (arg3)
241 {
242 out << ", " << (int)fLoGainFirst;
243 if (arg4)
244 out << ", " << (int)(fNumLoGainSamples+fLoGainFirst-1);
245 }
246 }
247 out << ");" << endl;
248}
Note: See TracBrowser for help on using the repository browser.