source: trunk/MagicSoft/Mars/manalysis/MExtractSignal.cc@ 3013

Last change on this file since 3013 was 3010, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 6.6 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!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MExtractSignal
28//
29//////////////////////////////////////////////////////////////////////////////
30#include "MExtractSignal.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 "MExtractedSignalCam.h"
46#include "MExtractedSignalPix.h"
47
48ClassImp(MExtractSignal);
49
50using namespace std;
51
52const Byte_t MExtractSignal::fgSaturationLimit = 254;
53const Byte_t MExtractSignal::fgFirst = 3;
54const Byte_t MExtractSignal::fgLast = 10;
55
56// --------------------------------------------------------------------------
57//
58// Default constructor.
59//
60MExtractSignal::MExtractSignal(const char *name, const char *title)
61 : fSaturationLimit(fgSaturationLimit)
62{
63
64 fName = name ? name : "MExtractSignal";
65 fTitle = title ? title : "Task to extract the signal from the FADC slices";
66
67 AddToBranchList("MRawEvtData.*");
68
69 SetRange();
70}
71
72void MExtractSignal::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
73{
74
75 fNumHiGainSamples = hilast-hifirst+1;
76 fNumLoGainSamples = lolast-lofirst+1;
77
78 fHiGainFirst = hifirst;
79 fLoGainFirst = lofirst;
80
81 fSqrtHiGainSamples = TMath::Sqrt((Float_t)fNumHiGainSamples);
82 fSqrtLoGainSamples = TMath::Sqrt((Float_t)fNumLoGainSamples);
83}
84
85// --------------------------------------------------------------------------
86//
87// The PreProcess searches for the following input containers:
88// - MRawEvtData
89// - MPedestalCam
90//
91// The following output containers are also searched and created if
92// they were not found:
93//
94// - MExtractedSignalCam
95//
96Int_t MExtractSignal::PreProcess(MParList *pList)
97{
98 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
99 if (!fRawEvt)
100 {
101 *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
102 return kFALSE;
103 }
104
105
106 fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
107 if (!fSignals)
108 return kFALSE;
109
110 fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainFirst+fNumHiGainSamples-1,
111 fLoGainFirst, fLoGainFirst+fNumLoGainSamples-1);
112
113 fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
114
115 if (!fPedestals)
116 {
117 *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
118 return kFALSE;
119 }
120
121 return kTRUE;
122}
123
124void MExtractSignal::FindSignal(Byte_t *ptr, Int_t size, Int_t &sum, Byte_t &sat/*, Byte_t* &max*/) const
125{
126 Byte_t *end = ptr + size;
127
128 sum = 0;
129 sat = 0;
130 //max = ptr;
131 while (ptr<end)
132 {
133 sum += *ptr;
134
135 //if (*ptr>*max)
136 // max = ptr;
137
138 if (*ptr++ >= fSaturationLimit)
139 sat++;
140 }
141}
142
143// --------------------------------------------------------------------------
144//
145// Calculate the integral of the FADC time slices and store them as a new
146// pixel in the MExtractedSignalCam container.
147//
148Int_t MExtractSignal::Process()
149{
150 MRawEvtPixelIter pixel(fRawEvt);
151 fSignals->Clear();
152
153 UInt_t sat=0;
154
155 while (pixel.Next())
156 {
157 Int_t sumhi, sumlo;
158 Byte_t sathi, satlo;
159 //Byte_t *maxhi, *maxlo;
160
161 FindSignal(pixel.GetHiGainSamples()+fHiGainFirst, fNumHiGainSamples, sumhi, sathi);//, maxhi);
162 FindSignal(pixel.GetLoGainSamples()+fLoGainFirst, fNumLoGainSamples, sumlo, satlo);//, maxlo);
163
164 if (satlo)
165 sat++;
166
167 const Int_t pixid = pixel.GetPixelId();
168
169 const MPedestalPix &ped = (*fPedestals)[pixid];
170 MExtractedSignalPix &pix = (*fSignals)[pixid];
171
172 const Float_t pedes = ped.GetPedestal();
173 const Float_t pedrms = ped.GetPedestalRms();
174
175 pix.SetExtractedSignal(sumhi - pedes*fNumHiGainSamples, pedrms*fSqrtHiGainSamples,
176 sumlo - pedes*fNumLoGainSamples, pedrms*fSqrtLoGainSamples);
177
178 pix.SetGainSaturation(sathi, sathi, satlo);
179
180 /*
181 const Byte_t midhi = maxhi-pixel.GetHiGainSamples();
182 const Byte_t midlo = maxlo-pixel.GetLoGainSamples();
183
184 fArrivalTime->SetTime(pixid, sathi?midlo:midhi);
185 */
186
187 } /* while (pixel.Next()) */
188
189 if (sat)
190 *fLog << warn << "WARNING - Lo Gain saturated in " << sat << " pixels." << endl;
191
192 fSignals->SetReadyToSave();
193
194 return kTRUE;
195}
196
197// --------------------------------------------------------------------------
198//
199// Implementation of SavePrimitive. Used to write the call to a constructor
200// to a macro. In the original root implementation it is used to write
201// gui elements to a macro-file.
202//
203void MExtractSignal::StreamPrimitive(ofstream &out) const
204{
205 out << " " << ClassName() << " " << GetUniqueName() << "(\"";
206 out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
207
208 if (fSaturationLimit!=fgSaturationLimit)
209 {
210 out << " " << GetUniqueName() << ".SetSaturationLimit(";
211 out << (int)fSaturationLimit << ");" << endl;
212 }
213
214 const Bool_t arg4 = fNumLoGainSamples+fLoGainFirst-1 != fgLast;
215 const Bool_t arg3 = arg4 || fLoGainFirst != fgFirst;
216 const Bool_t arg2 = arg3 || fNumHiGainSamples+fHiGainFirst-1 != fgLast;
217 const Bool_t arg1 = arg2 || fHiGainFirst != fgFirst;
218
219 if (!arg1)
220 return;
221
222 out << " " << GetUniqueName() << ".SetRange(";
223 out << (int)fLoGainFirst;
224 if (arg2)
225 {
226 out << ", " << (int)(fNumHiGainSamples+fHiGainFirst-1);
227 if (arg3)
228 {
229 out << ", " << (int)fLoGainFirst;
230 if (arg4)
231 out << ", " << (int)(fNumLoGainSamples+fLoGainFirst-1);
232 }
233 }
234 out << ");" << endl;
235}
Note: See TracBrowser for help on using the repository browser.