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

Last change on this file since 9061 was 8939, checked in by tbretz, 17 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 "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 const Int_t npix = fRawEvt->GetNumPixels();
130 const Int_t nhi = fRunHeader->GetNumSamplesHiGain();
131 const Int_t nlo = fRunHeader->GetNumSamplesLoGain();
132
133 for (int i=0; i<npix; i++)
134 {
135 USample_t *raw = fRawEvt->GetSamplesRaw(i);
136
137 USample_t *ptr = raw;
138 USample_t *max = ptr+fRawEvt->GetMaxPos(i, 0, nhi);
139 USample_t *end = ptr+nhi;
140 USample_t *first = max-fBefore;
141 USample_t *last = max+fAfter;
142
143 ULong_t sumb = 0; // sum background
144 ULong_t sqb = 0; // sum sqares background
145 //ULong_t sumsb = 0; // sum signal+background
146 ULong_t sqsb = 0; // sum sqares signal+background
147
148 Int_t sat = 0; // saturates?
149 Int_t ishi = 0; // has a high content?
150 Int_t nb = 0;
151 Int_t nsb = 0;
152
153 if (*max==255) // FIXME!!!!
154 sat++;
155
156 if (*max>80)
157 ishi++;
158
159 while (ptr<end)
160 {
161 if (ptr<first || ptr>last)
162 {
163 sumb += *ptr;
164 sqb += *ptr* *ptr;
165 nb++;
166 }
167 else
168 {
169 //sumsb += *ptr;
170 sqsb += *ptr* *ptr;
171 nsb++;
172 }
173 ptr++;
174 }
175
176 if (nlo>0 && sat==0 && ishi)
177 {
178 // Area: x9
179 ptr = raw+nhi;
180 end = ptr+nlo;
181
182 sumb = 0; // sum background
183 sqb = 0; // sum sqares background
184 nb = 0;
185
186 while (ptr<end)
187 {
188 // Background already caced from hi-gains!
189 sumb += *ptr;
190 sqb += *ptr* *ptr;
191 nb++;
192 ptr++;
193 }
194 }
195
196 if (nlo>0 && sat>1 && !ishi)
197 {
198 // Area: x9
199 ptr = raw+nhi;
200 max = ptr+fRawEvt->GetMaxPos(i, nhi, nhi+nlo);
201
202 if (*max>250) // FIXME!!!!
203 {
204 fSkip++;
205 return kCONTINUE;
206 }
207
208 end = ptr+nlo;
209 first = max-fBefore;
210 last = max+fAfter;
211
212 //sumsb = 0; // sum signal+background
213 //sqsb = 0; // sum sqares signal+background
214 sumb = 0; // sum background
215 //sqb = 0; // sum sqares background
216
217 //nb = 0;
218 nsb = 0;
219 while (ptr<end)
220 {
221 if (ptr<first || ptr>last)
222 {
223 /*
224 // Background already calced from hi-gains!
225 sumb += ptr[i];
226 sqb += ptr[i]*ptr[i];
227 nb++;*/
228 }
229 else
230 {
231 //sumsb += *ptr;
232 sqsb += *ptr* *ptr;
233 nsb++;
234 }
235 ptr++;
236 }
237 }
238
239 Float_t b = nb==0 ? 0 : (float)sumb/nb; // background
240 //Float_t sb = (float)sumsb/nsb; // signal+background
241
242 Float_t msb = nb==0 ? 0 : (float)sqb/nb; // mean square background
243 //Float_t mssb = (float)sqsb/nsb; // mean square signal+background
244
245 Float_t sigb = sqrt(msb-b*b); // sigma background
246 //Float_t sigsb = sqrt(mssb-sb*sb); // sigma signal+background
247
248 //Float_t s = sb-b; // signal
249 //Float_t sqs = sqsb-nsb*b; // sum squares signal
250
251 //Float_t mss = (float)sqs/nsb; // mean quare signal
252 //Float_t sigs = sqrt(mss-s*s); // sigma signal
253
254 //if (sat>1)
255 // s *= 11.3;
256
257 //fCerPhotEvt->AddPixel(idx, s, sigs);
258
259 // Preliminary: Do not overwrite pedestals calculated by
260 // MMcPedestalCopy and MMcPedestalNSBAdd
261 if (fPedestals)
262 (*fPedestals)[i].Set(b/fRunHeader->GetScale(), sigb/fRunHeader->GetScale());
263 }
264
265 //fCerPhotEvt->FixSize();
266 //fCerPhotEvt->SetReadyToSave();
267
268 if (fPedestals)
269 fPedestals->SetReadyToSave();
270
271 return kTRUE;
272}
273
274Int_t MSignalCalc::PostProcess()
275{
276 if (GetNumExecutions()==0 || fSkip==0)
277 return kTRUE;
278
279 *fLog << inf << endl;
280 *fLog << GetDescriptor() << " execution statistics:" << endl;
281 *fLog << dec << setfill(' ');
282 *fLog << " " << setw(7) << fSkip << " (" << setw(3) << (int)(fSkip*100/GetNumExecutions()) << "%) Evts skipped due to: lo gain saturated." << endl;
283
284 return kTRUE;
285}
Note: See TracBrowser for help on using the repository browser.