source: branches/removing_cpp11_features/msignal/MExtractSignal.cc@ 18459

Last change on this file since 18459 was 7810, checked in by tbretz, 18 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 = 14;
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, (Float_t)fNumHiGainSamples,
111 fLoGainFirst, fLoGainFirst+fNumLoGainSamples-1, (Float_t)fNumLoGainSamples);
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) const
125{
126
127 Byte_t *end = ptr + size;
128
129 sum = 0;
130 sat = 0;
131
132 while (ptr<end)
133 {
134 sum += *ptr;
135
136 if (*ptr++ >= fSaturationLimit)
137 sat++;
138 }
139}
140
141// --------------------------------------------------------------------------
142//
143// Calculate the integral of the FADC time slices and store them as a new
144// pixel in the MExtractedSignalCam container.
145//
146Int_t MExtractSignal::Process()
147{
148 MRawEvtPixelIter pixel(fRawEvt);
149 fSignals->Clear();
150
151 UInt_t sat=0;
152
153 while (pixel.Next())
154 {
155 Int_t sumhi;
156 Byte_t sathi;
157
158 FindSignal(pixel.GetHiGainSamples()+fHiGainFirst, fNumHiGainSamples, sumhi, sathi);
159
160 Int_t sumlo = 0;
161 Byte_t satlo = 0;
162 if (pixel.HasLoGain())
163 {
164 FindSignal(pixel.GetLoGainSamples()+fLoGainFirst, fNumLoGainSamples, sumlo, satlo);
165
166 if (satlo)
167 sat++;
168 }
169
170 const Int_t pixid = pixel.GetPixelId();
171
172 const MPedestalPix &ped = (*fPedestals)[pixid];
173 MExtractedSignalPix &pix = (*fSignals)[pixid];
174
175 const Float_t pedes = ped.GetPedestal();
176 const Float_t pedrms = ped.GetPedestalRms();
177
178 pix.SetExtractedSignal(sumhi - pedes*fNumHiGainSamples, pedrms*fSqrtHiGainSamples,
179 sumlo - pedes*fNumLoGainSamples, pedrms*fSqrtLoGainSamples);
180
181 pix.SetGainSaturation(sathi, satlo);
182
183 } /* while (pixel.Next()) */
184
185 fSignals->SetReadyToSave();
186
187 return kTRUE;
188}
189
190// --------------------------------------------------------------------------
191//
192// Implementation of SavePrimitive. Used to write the call to a constructor
193// to a macro. In the original root implementation it is used to write
194// gui elements to a macro-file.
195//
196void MExtractSignal::StreamPrimitive(ostream &out) const
197{
198 out << " " << ClassName() << " " << GetUniqueName() << "(\"";
199 out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
200
201 if (fSaturationLimit!=fgSaturationLimit)
202 {
203 out << " " << GetUniqueName() << ".SetSaturationLimit(";
204 out << (int)fSaturationLimit << ");" << endl;
205 }
206
207 const Bool_t arg4 = fNumLoGainSamples+fLoGainFirst-1 != fgLast;
208 const Bool_t arg3 = arg4 || fLoGainFirst != fgFirst;
209 const Bool_t arg2 = arg3 || fNumHiGainSamples+fHiGainFirst-1 != fgLast;
210 const Bool_t arg1 = arg2 || fHiGainFirst != fgFirst;
211
212 if (!arg1)
213 return;
214
215 out << " " << GetUniqueName() << ".SetRange(";
216 out << (int)fLoGainFirst;
217 if (arg2)
218 {
219 out << ", " << (int)(fNumHiGainSamples+fHiGainFirst-1);
220 if (arg3)
221 {
222 out << ", " << (int)fLoGainFirst;
223 if (arg4)
224 out << ", " << (int)(fNumLoGainSamples+fLoGainFirst-1);
225 }
226 }
227 out << ");" << endl;
228}
Note: See TracBrowser for help on using the repository browser.