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

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