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

Last change on this file since 3018 was 3018, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.1 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 & ~1;
88 fWindowSqrt = TMath::Sqrt((Float_t)fWindow);
89
90 if (fWindow==window)
91 return;
92
93 *fLog << warn << "MExtractSignal2::SetRange - Window size set to even " << fWindow << endl;
94}
95
96// --------------------------------------------------------------------------
97//
98// The PreProcess searches for the following input containers:
99// - MRawEvtData
100// - MPedestalCam
101//
102// The following output containers are also searched and created if
103// they were not found:
104//
105// - MExtractedSignalCam
106//
107Int_t MExtractSignal2::PreProcess(MParList *pList)
108{
109 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
110 if (!fRawEvt)
111 {
112 *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
113 return kFALSE;
114 }
115
116
117 fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
118 if (!fSignals)
119 return kFALSE;
120
121 fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainFirst+fNumHiGainSamples-1,
122 fLoGainFirst, fLoGainFirst+fNumLoGainSamples-1);
123
124 fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
125 if (!fPedestals)
126 {
127 *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
128 return kFALSE;
129 }
130/*
131 fArrivalTime = (MArrivalTime*)pList->FindCreateObj(AddSerialNumber("MArrivalTime"));
132 if (!fArrivalTime)
133 return kFALSE;
134 */
135 return kTRUE;
136}
137
138void MExtractSignal2::FindSignal(Byte_t *ptr, Byte_t size, Int_t &max, Int_t &sat) const
139{
140 const Byte_t *end = ptr + size;
141
142 Int_t sum=0;
143
144 //
145 // Calculate the sum of the first fWindow slices
146 //
147 sat = 0;
148 Byte_t *p = ptr;
149 while (p<ptr+fWindow)
150 {
151 sum += *p;
152 if (*p++ >= fSaturationLimit)
153 sat++;
154 }
155
156 //
157 // Check for saturation in all other slices
158 //
159 while (p<end)
160 if (*p++ >= fSaturationLimit)
161 sat++;
162
163 //
164 // Calculate the i-th sum as
165 // sum_i+1 = sum_i + slice[i+8] - slice[i]
166 // This is fast and accurate (because we are using int's)
167 //
168 max=0;
169 for (p=ptr; p+fWindow<end; p++)
170 {
171 sum += *(p+fWindow) - *p;
172 if (sum>max)
173 max = sum;
174 }
175}
176
177// --------------------------------------------------------------------------
178//
179// Calculate the integral of the FADC of fWindow time slices which have the
180// highest signal
181//
182Int_t MExtractSignal2::Process()
183{
184 MRawEvtPixelIter pixel(fRawEvt);
185 fSignals->Clear();
186
187 Int_t sat=0;
188 while (pixel.Next())
189 {
190 //
191 // Find signal in hi- and lo-gain
192 //
193 Int_t sumhi, sumlo, sathi, satlo;
194 FindSignal(pixel.GetHiGainSamples()+fHiGainFirst, fNumHiGainSamples, sumhi, sathi);
195 FindSignal(pixel.GetLoGainSamples()+fLoGainFirst, fNumLoGainSamples, sumlo, satlo);
196 if (satlo)
197 sat++;
198
199 //
200 // Take correspodning pedestal
201 //
202 const Int_t pixid = pixel.GetPixelId();
203
204 const MPedestalPix &ped = (*fPedestals)[pixid];
205 MExtractedSignalPix &pix = (*fSignals)[pixid];
206
207 const Float_t pedes = ped.GetPedestal();
208 const Float_t pedrms = ped.GetPedestalRms();
209
210 //
211 // Set extracted signal with pedestal substracted
212 //
213 pix.SetExtractedSignal(sumhi - pedes*fWindow, pedrms*fWindowSqrt,
214 sumlo - pedes*fWindow, pedrms*fWindowSqrt);
215
216 pix.SetGainSaturation(sathi, sathi, satlo);
217 } /* while (pixel.Next()) */
218
219 //
220 // Print a warning if evant has saturationg lo-gains
221 //
222 if (sat)
223 *fLog << warn << "WARNING - Lo Gain saturated in " << sat << " pixels." << endl;
224
225 fSignals->SetReadyToSave();
226
227 return kTRUE;
228}
Note: See TracBrowser for help on using the repository browser.