source: trunk/MagicSoft/Mars/msignal/MSignalCalc.cc@ 8357

Last change on this file since 8357 was 8357, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 8.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 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2007
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MSignalCalc
28//
29// This is a task which calculates the number of photons from the FADC
30// time slices. At the moment it integrates simply the FADC values.
31//
32// Input Containers:
33// MRawEvtData, MPedestalCam
34//
35// Output Containers:
36// MSignalCam
37//
38//////////////////////////////////////////////////////////////////////////////
39
40#include "MSignalCalc.h"
41
42#include "MParList.h"
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47#include "MRawRunHeader.h"
48#include "MRawEvtData.h" // MRawEvtData::GetNumPixels
49#include "MSignalCam.h"
50#include "MPedestalPix.h"
51#include "MPedestalCam.h"
52#include "MRawEvtPixelIter.h"
53
54ClassImp(MSignalCalc);
55
56using namespace std;
57
58// --------------------------------------------------------------------------
59//
60// Default constructor. b is the number of slices before the maximum slice,
61// a the number of slices behind the maximum slice which is taken as signal.
62//
63MSignalCalc::MSignalCalc(Byte_t b, Byte_t a, const char *name, const char *title)
64 : fBefore(b), fAfter(a)
65{
66 fName = name ? name : "MSignalCalc";
67 fTitle = title ? title : "Task to calculate Cerenkov photons from raw data";
68
69 AddToBranchList("MRawEvtData.fHiGainPixId");
70 AddToBranchList("MRawEvtData.fLoGainPixId");
71 AddToBranchList("MRawEvtData.fHiGainFadcSamples");
72 AddToBranchList("MRawEvtData.fLoGainFadcSamples");
73}
74
75// --------------------------------------------------------------------------
76//
77// The PreProcess searches for the following input containers:
78// - MRawRunHeader
79// - MRawEvtData
80// - MPestalCam
81//
82// The following output containers are also searched and created if
83// they were not found:
84// - MSignalCam
85//
86Int_t MSignalCalc::PreProcess(MParList *pList)
87{
88 fSkip = 0;
89
90 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
91 if (!fRunHeader)
92 {
93 *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
94 return kFALSE;
95 }
96
97 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
98 if (!fRawEvt)
99 {
100 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
101 return kFALSE;
102 }
103
104 fCerPhotEvt = (MSignalCam*)pList->FindCreateObj("MSignalCam");
105 if (!fCerPhotEvt)
106 return kFALSE;
107
108 return kTRUE;
109}
110
111Bool_t MSignalCalc::ReInit(MParList *pList)
112{
113 fPedestals=NULL;
114
115 // This must be done in ReInit because in PreProcess the
116 // headers are not available
117 if (fRunHeader->IsMonteCarloRun())
118 return kTRUE;
119
120 fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
121 if (!fPedestals)
122 return kFALSE;
123
124 return kTRUE;
125}
126
127// --------------------------------------------------------------------------
128//
129// Calculate the integral of the FADC time slices and store them as a new
130// pixel in the MSignalCam container.
131//
132Int_t MSignalCalc::Process()
133{
134 MRawEvtPixelIter pixel(fRawEvt);
135
136 while (pixel.Next())
137 {
138 Byte_t *ptr = pixel.GetHiGainSamples();
139 Byte_t *max = ptr+pixel.GetIdxMaxHiGainSample();
140 Byte_t *end = ptr+fRunHeader->GetNumSamplesHiGain();
141 Byte_t *first = max-fBefore;
142 Byte_t *last = max+fAfter;
143
144 ULong_t sumb = 0; // sum background
145 ULong_t sqb = 0; // sum sqares background
146 ULong_t sumsb = 0; // sum signal+background
147 ULong_t sqsb = 0; // sum sqares signal+background
148
149 Int_t sat = 0; // saturates?
150 Int_t ishi = 0; // has a high content?
151 Int_t nb = 0;
152 Int_t nsb = 0;
153
154 if (*max==255)
155 sat++;
156
157 if (*max>80)
158 ishi++;
159
160 while (ptr<end)
161 {
162 if (ptr<first || ptr>last)
163 {
164 sumb += *ptr;
165 sqb += *ptr* *ptr;
166 nb++;
167 }
168 else
169 {
170 sumsb += *ptr;
171 sqsb += *ptr* *ptr;
172 nsb++;
173 }
174 ptr++;
175 }
176
177 if (sat==0 && ishi)
178 {
179 // Area: x9
180 ptr = pixel.GetLoGainSamples();
181 end = ptr+fRunHeader->GetNumSamplesLoGain();
182
183 sumb = 0; // sum background
184 sqb = 0; // sum sqares background
185 nb = 0;
186
187 while (ptr<end)
188 {
189 // Background already calced from hi-gains!
190 sumb += *ptr;
191 sqb += *ptr* *ptr;
192 nb++;
193 ptr++;
194 }
195 }
196
197 if (sat>1 && !ishi)
198 {
199 // Area: x9
200 ptr = pixel.GetLoGainSamples();
201 max = ptr+pixel.GetIdxMaxLoGainSample();
202
203 if (*max>250)
204 {
205 fSkip++;
206 return kCONTINUE;
207 }
208
209 end = ptr+fRunHeader->GetNumSamplesLoGain();
210 first = max-fBefore;
211 last = max+fAfter;
212
213 sumsb = 0; // sum signal+background
214 sqsb = 0; // sum sqares signal+background
215 //sumb = 0; // sum background
216 //sqb = 0; // sum sqares background
217
218 //nb = 0;
219 nsb = 0;
220 while (ptr<end)
221 {
222 if (ptr<first || ptr>last)
223 {
224 /*
225 // Background already calced from hi-gains!
226 sumb += ptr[i];
227 sqb += ptr[i]*ptr[i];
228 nb++;*/
229 }
230 else
231 {
232 sumsb += *ptr;
233 sqsb += *ptr* *ptr;
234 nsb++;
235 }
236 ptr++;
237 }
238 }
239
240 Float_t b = (float)sumb/nb; // background
241 Float_t sb = (float)sumsb/nsb; // signal+background
242
243 Float_t msb = (float)sqb/nb; // mean square background
244 //Float_t mssb = (float)sqsb/nsb; // mean square signal+background
245
246 Float_t sigb = sqrt(msb-b*b); // sigma background
247 //Float_t sigsb = sqrt(mssb-sb*sb); // sigma signal+background
248
249 Float_t s = sb-b; // signal
250 //Float_t sqs = sqsb-nsb*b; // sum squares signal
251
252 //Float_t mss = (float)sqs/nsb; // mean quare signal
253 //Float_t sigs = sqrt(mss-s*s); // sigma signal
254
255 if (sat>1)
256 s *= 11.3;
257
258 Int_t idx = pixel.GetPixelId();
259 //fCerPhotEvt->AddPixel(idx, s, sigs);
260
261 // Preliminary: Do not overwrite pedestals calculated by
262 // MMcPedestalCopy and MMcPedestalNSBAdd
263 if (fPedestals)
264 (*fPedestals)[idx].Set(b, sigb);
265 }
266
267 //fCerPhotEvt->FixSize();
268 //fCerPhotEvt->SetReadyToSave();
269
270 if (fPedestals)
271 fPedestals->SetReadyToSave();
272
273 return kTRUE;
274}
275
276Int_t MSignalCalc::PostProcess()
277{
278 if (GetNumExecutions()==0 || fSkip==0)
279 return kTRUE;
280
281 *fLog << inf << endl;
282 *fLog << GetDescriptor() << " execution statistics:" << endl;
283 *fLog << dec << setfill(' ');
284 *fLog << " " << setw(7) << fSkip << " (" << setw(3) << (int)(fSkip*100/GetNumExecutions()) << "%) Evts skipped due to: lo gain saturated." << endl;
285
286 return kTRUE;
287}
Note: See TracBrowser for help on using the repository browser.