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

Last change on this file since 2665 was 2665, checked in by gaug, 21 years ago
*** empty log message ***
File size: 6.4 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-2001
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26// //
27// MExtractSignal //
28// //
29//////////////////////////////////////////////////////////////////////////////
30
31#include "MExtractSignal.h"
32
33#include "MExtractedSignalCam.h"
34#include "MExtractedSignalPix.h"
35
36#include "MPedestalCam.h"
37#include "MPedestalPix.h"
38
39#include "MLog.h"
40#include "MLogManip.h"
41
42#include "MParList.h"
43#include "MH.h"
44
45#include "MRawRunHeader.h"
46#include "MRawEvtData.h" // MRawEvtData::GetNumPixels
47#include "MRawEvtPixelIter.h"
48
49#include "TMath.h"
50
51ClassImp(MExtractSignal);
52
53using namespace std;
54// --------------------------------------------------------------------------
55//
56// Default constructor.
57//
58MExtractSignal::MExtractSignal(const char *name, const char *title)
59 : fNumHiGainSamples(0), fNumLoGainSamples(0),
60 fSqrtHiGainSamples(0), fSqrtLoGainSamples(0),
61 fBefore(2), fAfter(4),
62 fSaturationLimit(254), fConversionHiLo(10.)
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
71// --------------------------------------------------------------------------
72//
73// The PreProcess searches for the following input containers:
74// - MRawEvtData
75// - MPedestalCam
76//
77// The following output containers are also searched and created if
78// they were not found:
79//
80// - MExtractedSignalCam
81//
82Int_t MExtractSignal::PreProcess(MParList *pList)
83{
84
85 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
86 if (!fRawEvt)
87 {
88 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
89 return kFALSE;
90 }
91
92 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
93 if (!runheader)
94 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
95
96
97 fSignals = (MExtractedSignalCam*)pList->FindCreateObj("MExtractedSignalCam");
98 if (!fSignals)
99 return kFALSE;
100
101 fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
102 if (!fPedestals)
103 {
104 *fLog << err << dbginf << "Cannot find MPedestalCam ... aborting" << endl;
105 return kFALSE;
106 }
107
108 return kTRUE;
109}
110
111
112// --------------------------------------------------------------------------
113//
114// The ReInit searches for the following input containers:
115// - MRawRunHeader
116//
117Bool_t MExtractSignal::ReInit(MParList *pList )
118{
119
120 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
121 if (!fRunHeader)
122 {
123 *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
124 return kFALSE;
125 }
126
127 //fNumHiGainSamples = fRunHeader->GetNumSamplesHiGain();
128 //fNumLoGainSamples = fRunHeader->GetNumSamplesLoGain();
129 fNumHiGainSamples = 6;
130 fNumLoGainSamples = 6;
131
132 fSqrtHiGainSamples = TMath::Sqrt((float)fNumHiGainSamples);
133 fSqrtLoGainSamples = TMath::Sqrt((float)fNumLoGainSamples);
134
135 //
136 // FIXME: The next statement simply does not work:
137 // fRawEvt->GetNumPixels() returns always 0
138 //
139
140 fSignals->InitSize(577);
141 // fExtractedSignals->InitSize(fRawEvt->GetNumPixels());
142
143 return kTRUE;
144}
145
146
147// --------------------------------------------------------------------------
148//
149// Calculate the integral of the FADC time slices and store them as a new
150// pixel in the MExtractedSignalCam container.
151//
152Int_t MExtractSignal::Process()
153{
154
155 MRawEvtPixelIter pixel(fRawEvt);
156 fSignals->Clear();
157
158 while (pixel.Next())
159 {
160
161 UShort_t satHi = 0;
162 UShort_t satLo = 0;
163
164 Byte_t *ptr = pixel.GetHiGainSamples();
165 Byte_t *first = ptr + 3;
166 Byte_t *last = ptr + 9;
167
168 UInt_t sumHi = 0;
169 UInt_t sumLo = 0;
170
171 const Int_t pixid = pixel.GetPixelId();
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 Byte_t maxhi = 0;
179 Byte_t midhi = 0;
180
181 for (ptr=first;ptr<last;ptr++)
182 {
183
184 if (*ptr > maxhi)
185 {
186 maxhi = *ptr;
187 midhi = ptr-first;
188 }
189
190 sumHi += *ptr;
191
192 if (*ptr >= fSaturationLimit)
193 satHi++;
194
195 }
196
197 ptr = pixel.GetLoGainSamples();
198 first = ptr + 3;
199 last = ptr + 9;
200 Byte_t maxlo = 0;
201 Byte_t midlo = 0;
202
203 for (ptr=first;ptr<last;ptr++)
204 {
205
206 if (*ptr > maxlo)
207 {
208 maxlo = *ptr;
209 midlo = ptr-first;
210 }
211
212 sumLo += *ptr;
213
214 if (*ptr >= fSaturationLimit)
215 {
216 *fLog << err << dbginf
217 << "Warning: Saturation of Lo Gain reached in pixel: "
218 << pixid << " " << " sum = " << sumLo << endl;
219 satLo++;
220 }
221 }
222
223 pix.SetExtractedSignal((Float_t)sumHi - pedes*(Float_t)fNumHiGainSamples,
224 pedrms*fSqrtHiGainSamples,
225 ((Float_t)sumLo - pedes*(Float_t)fNumLoGainSamples)*fConversionHiLo,
226 pedrms*fSqrtLoGainSamples
227 );
228
229 pix.SetGainSaturation((satHi),satHi,satLo);
230
231 if (satHi)
232 pix.SetArrivalTimes((Float_t)(midlo+3),0.,0.);
233 else
234 pix.SetArrivalTimes((Float_t)(midhi+3),0.,0.);
235
236 } /* while (pixel.Next()) */
237
238 fSignals->SetNumUsedFADCSlices(fNumHiGainSamples,3,8,fNumLoGainSamples,3,8);
239 fSignals->SetReadyToSave();
240
241 return kTRUE;
242}
243
244Int_t MExtractSignal::PostProcess()
245{
246
247 return kTRUE;
248
249}
Note: See TracBrowser for help on using the repository browser.