source: trunk/MagicSoft/Mars/manalysis/MExtractSignal2.cc@ 3003

Last change on this file since 3003 was 3003, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.0 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): Thomas Bretz, 02/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MExtractSignal2
28//
29// Calculate the signal as the fWindow time slices which have the highest
30// integral contents.
31//
32// Calculation of arrival time not yet implemented
33//
34//////////////////////////////////////////////////////////////////////////////
35#include "MExtractSignal2.h"
36
37#include "MLog.h"
38#include "MLogManip.h"
39
40#include "MParList.h"
41
42#include "MRawEvtData.h"
43#include "MRawEvtPixelIter.h"
44
45#include "MPedestalCam.h"
46#include "MPedestalPix.h"
47
48#include "MExtractedSignalCam.h"
49#include "MExtractedSignalPix.h"
50
51//#include "MArrivalTime.h"
52
53ClassImp(MExtractSignal2);
54
55using namespace std;
56
57const Byte_t MExtractSignal2::fgSaturationLimit = 254;
58const Byte_t MExtractSignal2::fgFirst = 2;
59const Byte_t MExtractSignal2::fgLast = 14;
60const Byte_t MExtractSignal2::fgWindow = 8;
61
62// --------------------------------------------------------------------------
63//
64// Default constructor.
65//
66MExtractSignal2::MExtractSignal2(const char *name, const char *title)
67 : fSaturationLimit(fgSaturationLimit)
68{
69
70 fName = name ? name : "MExtractSignal2";
71 fTitle = title ? title : "Task to extract the signal from the FADC slices";
72
73 AddToBranchList("MRawEvtData.*");
74
75 SetRange();
76}
77
78void MExtractSignal2::SetRange(Byte_t first, Byte_t last, Byte_t window)
79{
80
81 fNumHiGainSamples = last-first+1;
82 fNumLoGainSamples = last-first+1;
83
84 fHiGainFirst = first;
85 fLoGainFirst = first;
86
87 fWindow = window;
88
89 fWindowSqrt = TMath::Sqrt((Float_t)fWindow);
90}
91
92// --------------------------------------------------------------------------
93//
94// The PreProcess searches for the following input containers:
95// - MRawEvtData
96// - MPedestalCam
97//
98// The following output containers are also searched and created if
99// they were not found:
100//
101// - MExtractedSignalCam
102//
103Int_t MExtractSignal2::PreProcess(MParList *pList)
104{
105 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
106 if (!fRawEvt)
107 {
108 *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
109 return kFALSE;
110 }
111
112
113 fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
114 if (!fSignals)
115 return kFALSE;
116
117 fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainFirst+fNumHiGainSamples-1,
118 fLoGainFirst, fLoGainFirst+fNumLoGainSamples-1);
119
120 fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
121 if (!fPedestals)
122 {
123 *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
124 return kFALSE;
125 }
126/*
127 fArrivalTime = (MArrivalTime*)pList->FindCreateObj(AddSerialNumber("MArrivalTime"));
128 if (!fArrivalTime)
129 return kFALSE;
130 */
131 return kTRUE;
132}
133
134void MExtractSignal2::FindSignal(Byte_t *ptr, Byte_t size, Int_t &max, Int_t &sat) const
135{
136 const Byte_t *end = ptr + size;
137
138 Int_t sum=0;
139
140 //
141 // Calculate the sum of the first fWindow slices
142 //
143 sat = 0;
144 Byte_t *p = ptr;
145 while (p<ptr+fWindow)
146 {
147 sum += *p;
148 if (*p++ >= fSaturationLimit)
149 sat++;
150 }
151
152 //
153 // Check for saturation in all other slices
154 //
155 while (p<end)
156 if (*p++ >= fSaturationLimit)
157 sat++;
158
159 //
160 // Calculate the i-th sum as
161 // sum_i+1 = sum_i + slice[i+8] - slice[i]
162 // This is fast and accurate (because we are using int's)
163 //
164 max=0;
165 for (p=ptr; p+fWindow<end; p++)
166 {
167 sum += *(p+fWindow) - *p;
168 if (sum>max)
169 max = sum;
170 }
171}
172
173// --------------------------------------------------------------------------
174//
175// Calculate the integral of the FADC of fWindow time slices which have the
176// highest signal
177//
178Int_t MExtractSignal2::Process()
179{
180 MRawEvtPixelIter pixel(fRawEvt);
181 fSignals->Clear();
182
183 Int_t sat=0;
184 while (pixel.Next())
185 {
186 //
187 // Find signal in hi- and lo-gain
188 //
189 Int_t sumhi, sumlo, sathi, satlo;
190 FindSignal(pixel.GetHiGainSamples()+fHiGainFirst, fNumHiGainSamples, sumhi, sathi);
191 FindSignal(pixel.GetLoGainSamples()+fLoGainFirst, fNumLoGainSamples, sumlo, satlo);
192 if (satlo)
193 sat++;
194
195 //
196 // Take correspodning pedestal
197 //
198 const Int_t pixid = pixel.GetPixelId();
199
200 const MPedestalPix &ped = (*fPedestals)[pixid];
201 MExtractedSignalPix &pix = (*fSignals)[pixid];
202
203 const Float_t pedes = ped.GetPedestal();
204 const Float_t pedrms = ped.GetPedestalRms();
205
206 //
207 // Set extracted signal with pedestal substracted
208 //
209 pix.SetExtractedSignal(sumhi - pedes*fWindow, pedrms*fWindowSqrt,
210 sumlo - pedes*fWindow, pedrms*fWindowSqrt);
211
212 pix.SetGainSaturation(sathi, sathi, satlo);
213 } /* while (pixel.Next()) */
214
215 //
216 // Print a warning if evant has saturationg lo-gains
217 //
218 if (sat)
219 *fLog << warn << "WARNING - Lo Gain saturated in " << sat << " pixels." << endl;
220
221 fSignals->SetReadyToSave();
222
223 return kTRUE;
224}
Note: See TracBrowser for help on using the repository browser.