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

Last change on this file since 2666 was 2666, 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 "MGeomCam.h"
40
41#include "MLog.h"
42#include "MLogManip.h"
43
44#include "MParList.h"
45#include "MH.h"
46
47#include "MRawRunHeader.h"
48#include "MRawEvtData.h" // MRawEvtData::GetNumPixels
49#include "MRawEvtPixelIter.h"
50
51#include "TMath.h"
52
53ClassImp(MExtractSignal);
54
55using namespace std;
56// --------------------------------------------------------------------------
57//
58// Default constructor.
59//
60MExtractSignal::MExtractSignal(const Byte_t first, const Byte_t last, const char *name, const char *title)
61 : fNumHiGainSamples(last-first+1), fNumLoGainSamples(last-first+1),
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 fFirst = first;
71
72 fSqrtHiGainSamples = TMath::Sqrt((Float_t)fNumHiGainSamples);
73 fSqrtLoGainSamples = TMath::Sqrt((Float_t)fNumLoGainSamples);
74}
75
76// --------------------------------------------------------------------------
77//
78// The PreProcess searches for the following input containers:
79// - MRawEvtData
80// - MPedestalCam
81//
82// The following output containers are also searched and created if
83// they were not found:
84//
85// - MExtractedSignalCam
86//
87Int_t MExtractSignal::PreProcess(MParList *pList)
88{
89
90 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
91 if (!fRawEvt)
92 {
93 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
94 return kFALSE;
95 }
96
97 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
98 if (!runheader)
99 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
100
101
102 fSignals = (MExtractedSignalCam*)pList->FindCreateObj("MExtractedSignalCam");
103 if (!fSignals)
104 return kFALSE;
105
106 fPedestals = (MPedestalCam*)pList->FindObject("MPedestalCam");
107 if (!fPedestals)
108 {
109 *fLog << err << dbginf << "Cannot find MPedestalCam ... aborting" << endl;
110 return kFALSE;
111 }
112
113 return kTRUE;
114}
115
116
117// --------------------------------------------------------------------------
118//
119// The ReInit searches for the following input containers:
120// - MRawRunHeader
121//
122Bool_t MExtractSignal::ReInit(MParList *pList )
123{
124
125 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
126 if (!fRunHeader)
127 {
128 *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
129 return kFALSE;
130 }
131
132
133 MGeomCam *cam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
134 if (!cam)
135 {
136 *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
137 return kFALSE;
138 }
139
140 fSignals->InitSize(cam->GetNumPixels());
141
142 return kTRUE;
143}
144
145
146// --------------------------------------------------------------------------
147//
148// Calculate the integral of the FADC time slices and store them as a new
149// pixel in the MExtractedSignalCam container.
150//
151Int_t MExtractSignal::Process()
152{
153
154 MRawEvtPixelIter pixel(fRawEvt);
155 fSignals->Clear();
156
157 while (pixel.Next())
158 {
159
160 UShort_t satHi = 0;
161 UShort_t satLo = 0;
162
163 Byte_t *ptr = pixel.GetHiGainSamples();
164 Byte_t *first = ptr + fFirst;
165 Byte_t *last = ptr + fFirst + fNumHiGainSamples;
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 Byte_t maxhi = 0;
178 Byte_t midhi = 0;
179
180 for (ptr=first;ptr<last;ptr++)
181 {
182
183 if (*ptr > maxhi)
184 {
185 maxhi = *ptr;
186 midhi = ptr-first;
187 }
188
189 sumHi += *ptr;
190
191 if (*ptr >= fSaturationLimit)
192 satHi++;
193
194 }
195
196 ptr = pixel.GetLoGainSamples();
197 first = ptr + fFirst;
198 last = ptr + fFirst + fNumLoGainSamples;
199 Byte_t maxlo = 0;
200 Byte_t midlo = 0;
201
202 for (ptr=first;ptr<last;ptr++)
203 {
204
205 if (*ptr > maxlo)
206 {
207 maxlo = *ptr;
208 midlo = ptr-first;
209 }
210
211 sumLo += *ptr;
212
213 if (*ptr >= fSaturationLimit)
214 {
215 *fLog << err << dbginf
216 << "Warning: Saturation of Lo Gain reached in pixel: "
217 << pixid << " " << " sum = " << sumLo << endl;
218 satLo++;
219 }
220 }
221
222 pix.SetExtractedSignal((Float_t)sumHi - pedes*(Float_t)fNumHiGainSamples,
223 pedrms*fSqrtHiGainSamples,
224 ((Float_t)sumLo - pedes*(Float_t)fNumLoGainSamples)*fConversionHiLo,
225 pedrms*fSqrtLoGainSamples
226 );
227
228 pix.SetGainSaturation((satHi),satHi,satLo);
229
230 if (satHi)
231 pix.SetArrivalTimes((Float_t)(midlo+fFirst),0.,0.);
232 else
233 pix.SetArrivalTimes((Float_t)(midhi+fFirst),0.,0.);
234
235 } /* while (pixel.Next()) */
236
237 fSignals->SetNumUsedFADCSlices(fNumHiGainSamples,fFirst,fFirst+fNumHiGainSamples-1,
238 fNumLoGainSamples,fFirst,fFirst+fNumLoGainSamples-1);
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.