source: trunk/MagicSoft/Mars/msignal/MExtractSignal.cc@ 3629

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