source: trunk/MagicSoft/Mars/mpedestal/MPedCalcFromData.cc@ 5498

Last change on this file since 5498 was 4362, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 5.1 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 expressed
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Josep Flix 06/2004 <mailto:jflix@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26// //
27// MPedCalcFromData //
28// //
29// Input Containers: //
30// MRawEvtData //
31// //
32// Output Containers: //
33// MPedestalCam //
34// //
35/////////////////////////////////////////////////////////////////////////////
36
37#include "MPedCalcFromData.h"
38#include "MExtractor.h"
39
40#include "MParList.h"
41
42#include "MLog.h"
43#include "MLogManip.h"
44
45#include "MRawRunHeader.h"
46#include "MRawEvtPixelIter.h"
47#include "MRawEvtData.h"
48
49#include "MPedestalPix.h"
50#include "MPedestalCam.h"
51
52ClassImp(MPedCalcFromData);
53
54using namespace std;
55
56MPedCalcFromData::MPedCalcFromData(const char *name, const char *title)
57{
58 fName = name ? name : "MPedCalcFromData";
59 fTitle = title ? title : "Task to calculate pedestals from data runs";
60
61 AddToBranchList("fHiGainPixId");
62 AddToBranchList("fHiGainFadcSamples");
63
64 SetRange(fLoGainFirst, fLoGainLast);
65 Clear();
66}
67
68void MPedCalcFromData::Clear(const Option_t *o)
69{
70
71 fRawEvt = NULL;
72 fRunHeader = NULL;
73
74}
75
76void MPedCalcFromData::SetLoRange(Byte_t lofirst, Byte_t lolast)
77{
78 fLoGainFirst = lofirst;
79 fLoGainLast = lolast;
80
81 fWindowSizeLoGain = lolast - lofirst;
82
83}
84
85Int_t MPedCalcFromData::PreProcess( MParList *pList )
86{
87 Clear();
88
89 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
90 if (!fRawEvt)
91 {
92 *fLog << err << "MRawEvtData not found... aborting." << endl;
93 return kFALSE;
94 }
95
96 fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
97 if (!fRunHeader)
98 {
99 *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
100 return kFALSE;
101 }
102
103 fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
104 if (!fPedestals)
105 return kFALSE;
106
107 return kTRUE;
108}
109
110
111Bool_t MPedCalcFromData::ReInit(MParList *pList)
112{
113
114 Int_t npixels = fPedestals->GetSize();
115
116 if (fSumx.GetSize()==0)
117 {
118 fSumx. Set(npixels);
119 fSumx2.Set(npixels);
120 fEvtCounter.Set(npixels);
121 fTotalCounter.Set(npixels);
122
123 fEvtCounter.Reset();
124 fTotalCounter.Reset();
125 fSumx.Reset();
126 fSumx2.Reset();
127 }
128
129 return kTRUE;
130
131}
132
133Int_t MPedCalcFromData::Process()
134{
135
136 MRawEvtPixelIter pixel(fRawEvt);
137
138 while (pixel.Next())
139 {
140
141 const UInt_t idx = pixel.GetPixelId();
142
143 if ( (UInt_t)pixel.GetMaxHiGainSample() < fHiGainThreshold ) {
144
145 fEvtCounter[idx]++;
146
147 Byte_t *ptr = pixel.GetLoGainSamples() + fLoGainFirst;
148 Byte_t *end = ptr + fWindowSizeLoGain;
149
150 UInt_t sum = 0;
151 UInt_t sqr = 0;
152
153 if (fWindowSizeLoGain != 0)
154 {
155 do
156 {
157 sum += *ptr;
158 sqr += *ptr * *ptr;
159 }
160 while (++ptr != end);
161 }
162
163 const Float_t msum = (Float_t)sum;
164 fSumx[idx] += msum;
165
166 const Float_t sqrsum = msum*msum;
167 fSumx2[idx] += sqrsum;
168
169 if ((UInt_t)fEvtCounter[idx] == fDump){
170
171 // Compute pedestals and rms from the sample
172 const ULong_t n = fWindowSizeLoGain*fDump;
173
174 const Float_t sum = fSumx.At(idx);
175 const Float_t sum2 = fSumx2.At(idx);
176 const Float_t higainped = sum/n;
177
178 // 1. Calculate the Variance of the sums:
179 Float_t higainVar = (sum2-sum*sum/fDump)/(fDump-1.);
180 // 2. Scale the variance to the number of slices:
181 higainVar /= (Float_t)(fWindowSizeLoGain);
182 // 3. Calculate the RMS from the Variance:
183 (*fPedestals)[idx].Set(higainped, higainVar < 0 ? 0. : TMath::Sqrt(higainVar));
184
185 fTotalCounter[idx]++;
186 fEvtCounter[idx]=0;
187 fSumx[idx]=0;
188 fSumx2[idx]=0;
189 };
190 }
191
192 };
193
194 fPedestals->SetReadyToSave();
195 return kTRUE;
196}
197
Note: See TracBrowser for help on using the repository browser.