source: releases/Mars.2014.05.26/msignal/MSignalCalc.cc@ 18029

Last change on this file since 18029 was 11427, checked in by tbretz, 13 years ago
the upper bound of searching the maximum was wrong
File size: 7.9 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 "MSignalCam.h"
49#include "MPedestalPix.h"
50#include "MPedestalCam.h"
51#include "MRawEvtPixelIter.h"
52#include "MPedestalSubtractedEvt.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
70// --------------------------------------------------------------------------
71//
72// The PreProcess searches for the following input containers:
73// - MRawRunHeader
74// - MRawEvtData
75// - MPestalCam
76//
77// The following output containers are also searched and created if
78// they were not found:
79// - MSignalCam
80//
81Int_t MSignalCalc::PreProcess(MParList *pList)
82{
83 fSkip = 0;
84
85 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
86 if (!fRunHeader)
87 {
88 *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
89 return kFALSE;
90 }
91
92 fRawEvt = (MPedestalSubtractedEvt*)pList->FindObject("MPedestalSubtractedEvt");
93 if (!fRawEvt)
94 {
95 *fLog << dbginf << "MPedestalSubtractedEvt not found... aborting." << endl;
96 return kFALSE;
97 }
98
99 fCerPhotEvt = (MSignalCam*)pList->FindCreateObj("MSignalCam");
100 if (!fCerPhotEvt)
101 return kFALSE;
102
103 return kTRUE;
104}
105
106Bool_t MSignalCalc::ReInit(MParList *pList)
107{
108 fPedestals=NULL;
109
110 // This must be done in ReInit because in PreProcess the
111 // headers are not available
112 if (fRunHeader->IsMonteCarloRun())
113 return kTRUE;
114
115 fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
116 if (!fPedestals)
117 return kFALSE;
118
119 return kTRUE;
120}
121
122// --------------------------------------------------------------------------
123//
124// Calculate the integral of the FADC time slices and store them as a new
125// pixel in the MSignalCam container.
126//
127Int_t MSignalCalc::Process()
128{
129 if (!fPedestals)
130 return kTRUE;
131
132 const Int_t npix = fRawEvt->GetNumPixels();
133 const Int_t nhi = fRunHeader->GetNumSamplesHiGain();
134 const Int_t nlo = fRunHeader->GetNumSamplesLoGain();
135
136 for (int i=0; i<npix; i++)
137 {
138 USample_t *raw = fRawEvt->GetSamplesRaw(i);
139
140 USample_t *ptr = raw;
141 USample_t *max = ptr+fRawEvt->GetMaxPos(i, 0, nhi-1);
142 USample_t *end = ptr+nhi;
143 USample_t *first = max-fBefore;
144 USample_t *last = max+fAfter;
145
146 ULong_t sumb = 0; // sum background
147 ULong_t sqb = 0; // sum sqares background
148 //ULong_t sumsb = 0; // sum signal+background
149 ULong_t sqsb = 0; // sum sqares signal+background
150
151 Int_t sat = 0; // saturates?
152 Int_t ishi = 0; // has a high content?
153 Int_t nb = 0;
154 Int_t nsb = 0;
155
156 if (*max==255) // FIXME!!!!
157 sat++;
158
159 if (*max>80)
160 ishi++;
161
162 while (ptr<end)
163 {
164 if (ptr<first || ptr>last)
165 {
166 sumb += *ptr;
167 sqb += *ptr* *ptr;
168 nb++;
169 }
170 else
171 {
172 //sumsb += *ptr;
173 sqsb += *ptr* *ptr;
174 nsb++;
175 }
176 ptr++;
177 }
178
179 if (nlo>0 && sat==0 && ishi)
180 {
181 // Area: x9
182 ptr = raw+nhi;
183 end = ptr+nlo;
184
185 sumb = 0; // sum background
186 sqb = 0; // sum sqares background
187 nb = 0;
188
189 while (ptr<end)
190 {
191 // Background already caced from hi-gains!
192 sumb += *ptr;
193 sqb += *ptr* *ptr;
194 nb++;
195 ptr++;
196 }
197 }
198
199 if (nlo>0 && sat>1 && !ishi)
200 {
201 // Area: x9
202 ptr = raw+nhi;
203 max = ptr+fRawEvt->GetMaxPos(i, nhi, nhi+nlo-1);
204
205 if (*max>250) // FIXME!!!!
206 {
207 fSkip++;
208 return kCONTINUE;
209 }
210
211 end = ptr+nlo;
212 first = max-fBefore;
213 last = max+fAfter;
214
215 //sumsb = 0; // sum signal+background
216 //sqsb = 0; // sum sqares signal+background
217 sumb = 0; // sum background
218 //sqb = 0; // sum sqares background
219
220 //nb = 0;
221 nsb = 0;
222 while (ptr<end)
223 {
224 if (ptr<first || ptr>last)
225 {
226 /*
227 // Background already calced from hi-gains!
228 sumb += ptr[i];
229 sqb += ptr[i]*ptr[i];
230 nb++;*/
231 }
232 else
233 {
234 //sumsb += *ptr;
235 sqsb += *ptr* *ptr;
236 nsb++;
237 }
238 ptr++;
239 }
240 }
241
242 Float_t b = nb==0 ? 0 : (float)sumb/nb; // background
243 //Float_t sb = (float)sumsb/nsb; // signal+background
244
245 Float_t msb = nb==0 ? 0 : (float)sqb/nb; // mean square background
246 //Float_t mssb = (float)sqsb/nsb; // mean square signal+background
247
248 Float_t sigb = sqrt(msb-b*b); // sigma background
249 //Float_t sigsb = sqrt(mssb-sb*sb); // sigma signal+background
250
251 //Float_t s = sb-b; // signal
252 //Float_t sqs = sqsb-nsb*b; // sum squares signal
253
254 //Float_t mss = (float)sqs/nsb; // mean quare signal
255 //Float_t sigs = sqrt(mss-s*s); // sigma signal
256
257 //if (sat>1)
258 // s *= 11.3;
259
260 //fCerPhotEvt->AddPixel(idx, s, sigs);
261
262 // Preliminary: Do not overwrite pedestals calculated by
263 // MMcPedestalCopy and MMcPedestalNSBAdd
264 (*fPedestals)[i].Set(b/fRunHeader->GetScale(), sigb/fRunHeader->GetScale());
265 }
266
267 //fCerPhotEvt->FixSize();
268 //fCerPhotEvt->SetReadyToSave();
269
270 fPedestals->SetReadyToSave();
271
272 return kTRUE;
273}
274
275Int_t MSignalCalc::PostProcess()
276{
277 if (GetNumExecutions()==0 || fSkip==0)
278 return kTRUE;
279
280 *fLog << inf << endl;
281 *fLog << GetDescriptor() << " execution statistics:" << endl;
282 *fLog << dec << setfill(' ');
283 *fLog << " " << setw(7) << fSkip << " (" << setw(3) << (int)(fSkip*100/GetNumExecutions()) << "%) Evts skipped due to: lo gain saturated." << endl;
284
285 return kTRUE;
286}
Note: See TracBrowser for help on using the repository browser.