source: trunk/Mars/mpedestal/MPedestalCalc.cc@ 19945

Last change on this file since 19945 was 3803, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.2 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): Josep Flix 11/2002 <mailto:jflix@ifae.es>
19! Author(s): Thomas Bretz 11/2002 <mailto:tbretz@astro.uni-wuerburg.de>
20!
21! Copyright: MAGIC Software Development, 2002
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MPedestalCalc
29//
30// Task to calculate the pedestals from the event stream.
31//
32// From the events two streams of pedestals are created like in the
33// following table
34// MRawEvtData: 1 2 3 4 5 6 7 8 9 10 11 12
35// MPedestalCam;1: ------1------ ------2------ ------3------...
36// MPedestalCam;2: ------1------ ------2------ ------...
37//
38// Input Containers:
39// MRawEvtData
40//
41// Output Containers:
42// MPedestalCam;1
43// MPedestalCam;2
44//
45/////////////////////////////////////////////////////////////////////////////
46#include "MPedestalCalc.h"
47
48#include "MParList.h"
49
50#include "MLog.h"
51#include "MLogManip.h"
52
53#include "MTime.h"
54#include "MHFadcCam.h"
55#include "MRawEvtPixelIter.h"
56
57#include "MPedestalCam.h"
58#include "MPedestalPix.h"
59
60ClassImp(MPedestalCalc);
61
62MPedestalCalc::MPedestalCalc(const char *name, const char *title)
63 : fNumBranches(2), fTimeSlot(6), fHists(NULL)
64{
65 fName = name ? name : "MPedestalCalc";
66 fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data";
67
68 AddToBranchList("fHiGainPixId");
69 AddToBranchList("fLoGainPixId");
70 AddToBranchList("fHiGainFadcSamples");
71 AddToBranchList("fLoGainFadcSamples");
72}
73
74Int_t MPedestalCalc::PreProcess(MParList *pList)
75{
76 if (fHists)
77 {
78 *fLog << err << "ERROR - Previous PostProcess not called." << endl;
79 return kFALSE;
80 }
81
82 fHists = new MHFadcCam[fNumBranches];
83 fStart = new MTime [fNumBranches];
84
85 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
86 if (!fRawEvt)
87 {
88 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
89 return kFALSE;
90 }
91
92 fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
93 if (!fPedestals)
94 return kFALSE;
95
96 fPedTime = (MTime*)pList->FindCreateObj("MTime", "MPedestalTime");
97 if (!fPedTime)
98 return kFALSE;
99
100 //
101 // Fixme: FindCreateObj --> FindObject
102 //
103 fEvtTime = (MTime*)pList->FindCreateObj("MTime", "MRawEvtTime");
104 if (!fEvtTime)
105 return kFALSE;
106
107 for (int i=0; i<fNumBranches; i++)
108 fStart[i].SetTime(fTimeSlot*10/fNumBranches*i, 0);
109
110 fPedTime->SetDuration(fTimeSlot);
111 fEvtTime->SetTime(0, 0);
112
113 return kTRUE;
114}
115
116// --------------------------------------------------------------------------
117//
118// Checks whether the current event exceed the validity range of a pedestal
119// in one of the streams. If this is the case the data from the histogram
120// is dumped as pedestals into the corresponding containers and the
121// histograms are reset.
122//
123// Then the current event is filled into the histograms.
124//
125Int_t MPedestalCalc::Process()
126{
127 //
128 // Time when filling of stream a/b must be restarted
129 //
130 for (int i=0; i<fNumBranches; i++)
131 {
132 Check(i);
133 Fill(i);
134 }
135
136 fEvtTime->SetTime(fEvtTime->GetTimeLo()+10, 0);
137
138 return kTRUE;
139}
140
141// --------------------------------------------------------------------------
142//
143// Fill the event in the histogram if the current time of the
144// event is _after_ the start time for filling
145//
146void MPedestalCalc::Fill(Int_t i)
147{
148 if (*fEvtTime < fStart[i])
149 return;
150
151 fHists[i].Fill(fRawEvt);
152}
153
154// --------------------------------------------------------------------------
155//
156// If the current time of the event is equal or after the time
157// which is given by the start time plus the validity range
158// calculate the corresponding set of pedestals and reset the
159// histograms
160//
161void MPedestalCalc::Check(Int_t i)
162{
163 if (*fEvtTime-fStart[i] < fTimeSlot*10)
164 return;
165
166 Calc(i);
167
168 fStart[i] = *fEvtTime;
169 fHists[i].ResetHistograms();
170}
171
172// --------------------------------------------------------------------------
173//
174// Deletes all dynamicly allocated arrays
175//
176Bool_t MPedestalCalc::PostProcess()
177{
178 delete fHists;
179 delete fStart;
180
181 fHists=NULL;
182
183 return kTRUE;
184}
185
186/*
187 #include "MRawEvtData.h"
188 */
189// --------------------------------------------------------------------------
190//
191// Dumps the mean, rms and their errors from the filled histograms into
192// the Pedestal container. Sets the ReadyToSaveFlag of the MPedestalCam
193// container.
194//
195void MPedestalCalc::Calc(Int_t i) const
196{
197 // FIXME! Fit +- 3 sigma to avoid outliers...
198
199 MRawEvtPixelIter pixel(fRawEvt);
200 while (pixel.Next())
201 {
202 const UInt_t pixid = pixel.GetPixelId();
203
204 const TH1 &h = *fHists[i].GetHistHi(pixid);
205
206 const Int_t entries = (Int_t)h.GetEntries();
207 const Float_t meanhi = h.GetMean();
208 const Float_t rmshi = h.GetRMS();
209
210 const Float_t meanhierr = rmshi/sqrt(entries);
211 const Float_t rmshierr = rmshi/sqrt(entries*2);
212
213 MPedestalPix &pix = (*fPedestals)[pixid];
214 pix.SetPedestal(meanhi, rmshi);
215 pix.SetPedestalRms(meanhierr, rmshierr);
216 }
217
218 *fPedTime = fStart[i];
219
220 fPedTime->SetReadyToSave();
221 fPedestals->SetReadyToSave();
222
223 /*
224 *fLog << i << "[" << fHists[i].GetHistHi(0)->GetEntries()/fRawEvt->GetNumHiGainSamples() << "]: ";
225 *fLog << fEvtTime->GetTimeLo() << ": Calc [";
226 *fLog << fStart[i].GetTimeLo() << " < ";
227 *fLog << fStart[i].GetTimeLo()+fTimeSlot*10 << "]" << endl;
228 */
229}
Note: See TracBrowser for help on using the repository browser.