source: trunk/MagicSoft/Mars/manalysis/MCerPhotAnal2.cc@ 3779

Last change on this file since 3779 was 3538, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 8.3 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@uni-sw.gwdg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MCerPhotAnal2
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, MPedPhotCam
34//
35// Output Containers:
36// MCerPhotEvt
37//
38//////////////////////////////////////////////////////////////////////////////
39
40#include "MCerPhotAnal2.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 "MCerPhotEvt.h"
50#include "MPedPhotPix.h"
51#include "MPedPhotCam.h"
52#include "MRawEvtPixelIter.h"
53
54ClassImp(MCerPhotAnal2);
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//
63MCerPhotAnal2::MCerPhotAnal2(Byte_t b, Byte_t a, const char *name, const char *title)
64 : fBefore(b), fAfter(a)
65{
66 fName = name ? name : "MCerPhotAnal2";
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// - MPedPhotCam
81//
82// The following output containers are also searched and created if
83// they were not found:
84// - MCerPhotEvt
85//
86Int_t MCerPhotAnal2::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 = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
105 if (!fCerPhotEvt)
106 return kFALSE;
107
108 return kTRUE;
109}
110
111Bool_t MCerPhotAnal2::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 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
118 if (!runheader)
119 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
120 else
121 {
122 if (runheader->IsMonteCarloRun())
123 return kTRUE;
124 }
125
126 fPedestals = (MPedPhotCam*)pList->FindCreateObj("MPedPhotCam");
127 if (runheader && !fPedestals)
128 return kFALSE;
129
130 return kTRUE;
131}
132
133// --------------------------------------------------------------------------
134//
135// Calculate the integral of the FADC time slices and store them as a new
136// pixel in the MCerPhotEvt container.
137//
138Int_t MCerPhotAnal2::Process()
139{
140 MRawEvtPixelIter pixel(fRawEvt);
141
142 while (pixel.Next())
143 {
144 Byte_t *ptr = pixel.GetHiGainSamples();
145 Byte_t *max = ptr+pixel.GetIdxMaxHiGainSample();
146 Byte_t *end = ptr+fRawEvt->GetNumHiGainSamples();
147 Byte_t *first = max-fBefore;
148 Byte_t *last = max+fAfter;
149
150 ULong_t sumb = 0; // sum background
151 ULong_t sqb = 0; // sum sqares background
152 ULong_t sumsb = 0; // sum signal+background
153 ULong_t sqsb = 0; // sum sqares signal+background
154
155 Int_t sat = 0; // saturates?
156 Int_t ishi = 0; // has a high content?
157 Int_t nb = 0;
158 Int_t nsb = 0;
159
160 if (*max==255)
161 sat++;
162
163 if (*max>80)
164 ishi++;
165
166 while (ptr<end)
167 {
168 if (ptr<first || ptr>last)
169 {
170 sumb += *ptr;
171 sqb += *ptr* *ptr;
172 nb++;
173 }
174 else
175 {
176 sumsb += *ptr;
177 sqsb += *ptr* *ptr;
178 nsb++;
179 }
180 ptr++;
181 }
182
183 if (sat==0 && ishi)
184 {
185 // Area: x9
186 ptr = pixel.GetLoGainSamples();
187 end = ptr+fRawEvt->GetNumLoGainSamples();
188
189 sumb = 0; // sum background
190 sqb = 0; // sum sqares background
191 nb = 0;
192
193 while (ptr<end)
194 {
195 // Background already calced from hi-gains!
196 sumb += *ptr;
197 sqb += *ptr* *ptr;
198 nb++;
199 ptr++;
200 }
201 }
202
203 if (sat>1 && !ishi)
204 {
205 // Area: x9
206 ptr = pixel.GetLoGainSamples();
207 max = ptr+pixel.GetIdxMaxLoGainSample();
208
209 if (*max>250)
210 {
211 fSkip++;
212 return kCONTINUE;
213 }
214
215 end = ptr+fRawEvt->GetNumLoGainSamples();
216 first = max-fBefore;
217 last = max+fAfter;
218
219 sumsb = 0; // sum signal+background
220 sqsb = 0; // sum sqares signal+background
221 //sumb = 0; // sum background
222 //sqb = 0; // sum sqares background
223
224 //nb = 0;
225 nsb = 0;
226 while (ptr<end)
227 {
228 if (ptr<first || ptr>last)
229 {
230 /*
231 // Background already calced from hi-gains!
232 sumb += ptr[i];
233 sqb += ptr[i]*ptr[i];
234 nb++;*/
235 }
236 else
237 {
238 sumsb += *ptr;
239 sqsb += *ptr* *ptr;
240 nsb++;
241 }
242 ptr++;
243 }
244 }
245
246 Float_t b = (float)sumb/nb; // background
247 Float_t sb = (float)sumsb/nsb; // signal+background
248
249 Float_t msb = (float)sqb/nb; // mean square background
250 //Float_t mssb = (float)sqsb/nsb; // mean square signal+background
251
252 Float_t sigb = sqrt(msb-b*b); // sigma background
253 //Float_t sigsb = sqrt(mssb-sb*sb); // sigma signal+background
254
255 Float_t s = sb-b; // signal
256 Float_t sqs = sqsb-nsb*b; // sum sqaures signal
257
258 Float_t mss = (float)sqs/nsb; // mean quare signal
259 Float_t sigs = sqrt(mss-s*s); // sigma signal
260
261 if (sat>1)
262 s*=10; // tgb has measured 9, but Florian said it's 10.
263
264 Int_t idx = pixel.GetPixelId();
265 fCerPhotEvt->AddPixel(idx, s, sigs);
266
267 // Preliminary: Do not overwrite pedestals calculated by
268 // MMcPedestalCopy and MMcPedestalNSBAdd
269 if (fPedestals)
270 (*fPedestals)[idx].Set(b, sigb);
271 }
272
273 fCerPhotEvt->FixSize();
274 fCerPhotEvt->SetReadyToSave();
275
276 if (fPedestals)
277 fPedestals->SetReadyToSave();
278
279 return kTRUE;
280}
281
282Int_t MCerPhotAnal2::PostProcess()
283{
284 if (GetNumExecutions()==0 || fSkip==0)
285 return kTRUE;
286
287 *fLog << inf << endl;
288 *fLog << GetDescriptor() << " execution statistics:" << endl;
289 *fLog << dec << setfill(' ');
290 *fLog << " " << setw(7) << fSkip << " (" << setw(3) << (int)(fSkip*100/GetNumExecutions()) << "%) Evts skipped due to: lo gain saturated." << endl;
291
292 return kTRUE;
293}
Note: See TracBrowser for help on using the repository browser.