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

Last change on this file since 2641 was 2640, checked in by gaug, 21 years ago
*** empty log message ***
File size: 6.7 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 : fBefore(2), fAfter(4), fSaturationLimit(254), fConversionHiLo(10.)
60{
61
62 fName = name ? name : "MExtractSignal";
63 fTitle = title ? title : "Task to extract the signal from the FADC slices";
64
65 AddToBranchList("MRawEvtData.*");
66}
67
68// --------------------------------------------------------------------------
69//
70// The PreProcess searches for the following input containers:
71// - MRawEvtData
72// - MPedestalCam
73//
74// The following output containers are also searched and created if
75// they were not found:
76//
77// - MExtractedSignalCam
78//
79Int_t MExtractSignal::PreProcess(MParList *pList)
80{
81
82 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
83 if (!fRawEvt)
84 {
85 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
86 return kFALSE;
87 }
88
89 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
90 if (!runheader)
91 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
92
93
94 fSignals = (MExtractedSignalCam*)pList->FindCreateObj("MExtractedSignalCam");
95 if (!fSignals)
96 return kFALSE;
97
98 fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
99 if (!fPedestals)
100 {
101 *fLog << err << dbginf << "Cannot find MPedestalCam ... aborting" << endl;
102 return kFALSE;
103 }
104
105 return kTRUE;
106}
107
108
109// --------------------------------------------------------------------------
110//
111// The ReInit searches for the following input containers:
112// - MRawRunHeader
113//
114Bool_t MExtractSignal::ReInit(MParList *pList )
115{
116
117 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
118 if (!fRunHeader)
119 {
120 *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
121 return kFALSE;
122 }
123
124 //fNumHiGainSamples = fRunHeader->GetNumSamplesHiGain();
125 //fNumLoGainSamples = fRunHeader->GetNumSamplesLoGain();
126 fNumHiGainSamples = fAfter+fBefore;
127 fNumLoGainSamples = fAfter+fBefore;
128
129 fSqrtHiGainSamples = TMath::Sqrt((float)fNumHiGainSamples);
130 fSqrtLoGainSamples = TMath::Sqrt((float)fNumLoGainSamples);
131
132 //
133 // FIXME: The next statement simply does not work:
134 // fRawEvt->GetNumPixels() returns always 0
135 //
136
137 fSignals->InitSize(577);
138 // fExtractedSignals->InitSize(fRawEvt->GetNumPixels());
139
140 return kTRUE;
141}
142
143
144// --------------------------------------------------------------------------
145//
146// Calculate the integral of the FADC time slices and store them as a new
147// pixel in the MExtractedSignalCam container.
148//
149Int_t MExtractSignal::Process()
150{
151
152 MRawEvtPixelIter pixel(fRawEvt);
153 fSignals->Clear();
154
155 while (pixel.Next())
156 {
157
158 UShort_t satHi = 0;
159 UShort_t satLo = 0;
160
161 Byte_t *ptr = pixel.GetHiGainSamples();
162 Byte_t *max = ptr + pixel.GetIdxMaxHiGainSample();
163 Byte_t *end = ptr + fRawEvt->GetNumHiGainSamples();
164 Byte_t *first;
165 Byte_t *last;
166
167 UInt_t sumHi = 0;
168 UInt_t sumLo = 0;
169
170 const Int_t pixid = pixel.GetPixelId();
171 const MPedestalPix &ped = (*fPedestals)[pixid];
172 MExtractedSignalPix &pix = (*fSignals)[pixid];
173
174 const Float_t pedes = ped.GetPedestal();
175 const Float_t pedrms = ped.GetPedestalRms();
176
177 if (max-3 < ptr)
178 {
179 first = ptr+3;
180 last = ptr+3+fAfter+fBefore;
181 }
182 else if (max+fAfter-1 > end)
183 {
184 first = end-fAfter-fBefore-1;
185 last = end-1;
186 }
187 else
188 {
189 first = max-fBefore;
190 last = max+fAfter;
191 }
192
193 for (ptr=first;ptr<last;ptr++)
194 {
195 sumHi += *ptr;
196 if (*ptr >= fSaturationLimit)
197 satHi++;
198 }
199
200 ptr = pixel.GetLoGainSamples();
201 max = ptr+pixel.GetIdxMaxLoGainSample();
202 end = ptr+fRawEvt->GetNumLoGainSamples();
203
204 if (max-4 < ptr)
205 {
206 first = ptr+4;
207 last = ptr+4+fAfter+fBefore;
208 }
209 else if (max+fAfter > end)
210 {
211 first = end-fAfter-fBefore;
212 last = end;
213 }
214 else
215 {
216 first = max-fBefore;
217 last = max+fAfter;
218 }
219
220 for (ptr=first;ptr<last;ptr++)
221 {
222 sumLo += *ptr;
223 if (*ptr >= fSaturationLimit)
224 {
225 *fLog << err << dbginf
226 << "Warning: Saturation of Lo Gain reached in pixel: "
227 << pixid << " " << " sum = " << sumLo << endl;
228 satLo++;
229 }
230 }
231
232 //
233 // FIXME: This is preliminary, we will change to pedestals per slice!!!
234 // Assume pedestals per time slice ==> multiply with number of slices
235 //
236
237 pix.SetExtractedSignal((float)sumHi - pedes*(float)fNumHiGainSamples,
238 pedrms*fSqrtHiGainSamples,
239 ((float)sumLo - pedes*(float)fNumLoGainSamples)*fConversionHiLo,
240 pedrms*fSqrtLoGainSamples
241 );
242
243 pix.SetGainSaturation((satHi),satHi,satLo);
244
245 } /* while (pixel.Next()) */
246
247
248 fSignals->SetNumUsedFADCSlices(fNumHiGainSamples);
249 fSignals->SetReadyToSave();
250
251 return kTRUE;
252}
253
254Int_t MExtractSignal::PostProcess()
255{
256
257 return kTRUE;
258
259}
Note: See TracBrowser for help on using the repository browser.