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

Last change on this file since 2692 was 2667, checked in by gaug, 21 years ago
*** empty log message ***
File size: 5.9 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 "MGeomCam.h"
40
41#include "MLog.h"
42#include "MLogManip.h"
43
44#include "MParList.h"
45
46#include "MRawEvtData.h"
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 Byte_t first, const Byte_t last, const char *name, const char *title)
59 : fNumHiGainSamples(last-first+1), fNumLoGainSamples(last-first+1),
60 fSaturationLimit(254), fConversionHiLo(10.)
61{
62
63 fName = name ? name : "MExtractSignal";
64 fTitle = title ? title : "Task to extract the signal from the FADC slices";
65
66 AddToBranchList("MRawEvtData.*");
67
68 fFirst = first;
69
70 fSqrtHiGainSamples = TMath::Sqrt((Float_t)fNumHiGainSamples);
71 fSqrtLoGainSamples = TMath::Sqrt((Float_t)fNumLoGainSamples);
72}
73
74// --------------------------------------------------------------------------
75//
76// The PreProcess searches for the following input containers:
77// - MRawEvtData
78// - MPedestalCam
79//
80// The following output containers are also searched and created if
81// they were not found:
82//
83// - MExtractedSignalCam
84//
85Int_t MExtractSignal::PreProcess(MParList *pList)
86{
87
88 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
89 if (!fRawEvt)
90 {
91 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
92 return kFALSE;
93 }
94
95
96 fSignals = (MExtractedSignalCam*)pList->FindCreateObj("MExtractedSignalCam");
97 if (!fSignals)
98 return kFALSE;
99
100 fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
101 if (!fPedestals)
102 {
103 *fLog << err << dbginf << "Cannot find MPedestalCam ... aborting" << endl;
104 return kFALSE;
105 }
106
107 return kTRUE;
108}
109
110
111// --------------------------------------------------------------------------
112//
113// The ReInit searches for the following input containers:
114// - MRawRunHeader
115//
116Bool_t MExtractSignal::ReInit(MParList *pList )
117{
118
119
120 MGeomCam *cam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
121 if (!cam)
122 {
123 *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
124 return kFALSE;
125 }
126
127 fSignals->InitSize(cam->GetNumPixels());
128
129 return kTRUE;
130}
131
132
133// --------------------------------------------------------------------------
134//
135// Calculate the integral of the FADC time slices and store them as a new
136// pixel in the MExtractedSignalCam container.
137//
138Int_t MExtractSignal::Process()
139{
140
141 MRawEvtPixelIter pixel(fRawEvt);
142 fSignals->Clear();
143
144 while (pixel.Next())
145 {
146
147 UShort_t satHi = 0;
148 UShort_t satLo = 0;
149
150 Byte_t *ptr = pixel.GetHiGainSamples();
151 Byte_t *first = ptr + fFirst;
152 Byte_t *last = ptr + fFirst + fNumHiGainSamples;
153
154 UInt_t sumHi = 0;
155 UInt_t sumLo = 0;
156
157 const Int_t pixid = pixel.GetPixelId();
158 const MPedestalPix &ped = (*fPedestals)[pixid];
159 MExtractedSignalPix &pix = (*fSignals)[pixid];
160
161 const Float_t pedes = ped.GetPedestal();
162 const Float_t pedrms = ped.GetPedestalRms();
163
164 Byte_t maxhi = 0;
165 Byte_t midhi = 0;
166
167 for (ptr=first;ptr<last;ptr++)
168 {
169
170 if (*ptr > maxhi)
171 {
172 maxhi = *ptr;
173 midhi = ptr-first;
174 }
175
176 sumHi += *ptr;
177
178 if (*ptr >= fSaturationLimit)
179 satHi++;
180
181 }
182
183 ptr = pixel.GetLoGainSamples();
184 first = ptr + fFirst;
185 last = ptr + fFirst + fNumLoGainSamples;
186 Byte_t maxlo = 0;
187 Byte_t midlo = 0;
188
189 for (ptr=first;ptr<last;ptr++)
190 {
191
192 if (*ptr > maxlo)
193 {
194 maxlo = *ptr;
195 midlo = ptr-first;
196 }
197
198 sumLo += *ptr;
199
200 if (*ptr >= fSaturationLimit)
201 {
202 *fLog << err << dbginf
203 << "Warning: Saturation of Lo Gain reached in pixel: "
204 << pixid << " " << " sum = " << sumLo << endl;
205 satLo++;
206 }
207 }
208
209 pix.SetExtractedSignal((Float_t)sumHi - pedes*(Float_t)fNumHiGainSamples,
210 pedrms*fSqrtHiGainSamples,
211 ((Float_t)sumLo - pedes*(Float_t)fNumLoGainSamples)*fConversionHiLo,
212 pedrms*fSqrtLoGainSamples
213 );
214
215 pix.SetGainSaturation((satHi),satHi,satLo);
216
217 if (satHi)
218 pix.SetArrivalTimes((Float_t)(midlo+fFirst),0.,0.);
219 else
220 pix.SetArrivalTimes((Float_t)(midhi+fFirst),0.,0.);
221
222 } /* while (pixel.Next()) */
223
224 fSignals->SetNumUsedFADCSlices(fNumHiGainSamples,fFirst,fFirst+fNumHiGainSamples-1,
225 fNumLoGainSamples,fFirst,fFirst+fNumLoGainSamples-1);
226 fSignals->SetReadyToSave();
227
228 return kTRUE;
229}
230
231Int_t MExtractSignal::PostProcess()
232{
233
234 return kTRUE;
235
236}
Note: See TracBrowser for help on using the repository browser.