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

Last change on this file since 8364 was 8364, checked in by tbretz, 18 years ago
*** empty log message ***
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//
127#include <TSystem.h>
128Int_t MSignalCalc::Process()
129{
130 const Int_t npix = fRawEvt->GetNumPixels();
131 const Int_t nhi = fRunHeader->GetNumSamplesHiGain();
132 const Int_t nlo = fRunHeader->GetNumSamplesLoGain();
133
134 for (int i=0; i<npix; i++)
135 {
136 Byte_t *raw = fRawEvt->GetSamplesRaw(i);
137
138 Byte_t *ptr = raw;
139 Byte_t *max = ptr+fRawEvt->GetMax(i, 0, nhi);
140 Byte_t *end = ptr+nhi;
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 (nlo>0 && sat==0 && ishi)
178 {
179 // Area: x9
180 ptr = raw+nhi;
181 end = ptr+nlo;
182
183 sumb = 0; // sum background
184 sqb = 0; // sum sqares background
185 nb = 0;
186
187 while (ptr<end)
188 {
189 // Background already caced from hi-gains!
190 sumb += *ptr;
191 sqb += *ptr* *ptr;
192 nb++;
193 ptr++;
194 }
195 }
196
197 if (nlo>0 && sat>1 && !ishi)
198 {
199 // Area: x9
200 ptr = raw+nhi;
201 max = ptr+fRawEvt->GetMax(i, nhi, nhi+nlo);
202
203 if (*max>250)
204 {
205 fSkip++;
206 return kCONTINUE;
207 }
208
209 end = ptr+nlo;
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 = nb==0 ? 0 : (float)sumb/nb; // background
241 //Float_t sb = (float)sumsb/nsb; // signal+background
242
243 Float_t msb = nb==0 ? 0 : (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 //fCerPhotEvt->AddPixel(idx, s, sigs);
259
260 // Preliminary: Do not overwrite pedestals calculated by
261 // MMcPedestalCopy and MMcPedestalNSBAdd
262 if (fPedestals)
263 (*fPedestals)[i].Set(b, sigb);
264 }
265
266 //fCerPhotEvt->FixSize();
267 //fCerPhotEvt->SetReadyToSave();
268
269 if (fPedestals)
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.