source: trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.cc@ 2692

Last change on this file since 2692 was 2647, checked in by gaug, 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 04/2001 <mailto:jflix@ifae.es>
19! Author(s): Thomas Bretz 05/2001 <mailto:tbretz@uni-sw.gwdg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2001
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27// //
28// MPedCalcPedRun //
29// //
30// Input Containers: //
31// MRawEvtData //
32// //
33// Output Containers: //
34// MPedestalCam //
35// //
36/////////////////////////////////////////////////////////////////////////////
37
38#include "MPedCalcPedRun.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
52#include "MGeomCamMagic.h"
53
54ClassImp(MPedCalcPedRun);
55
56using namespace std;
57
58MPedCalcPedRun::MPedCalcPedRun(const char *name, const char *title)
59{
60 fName = name ? name : "MPedCalcPedRun";
61 fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data";
62
63 AddToBranchList("fHiGainPixId");
64 AddToBranchList("fHiGainFadcSamples");
65
66 fCounter=0;
67}
68
69Int_t MPedCalcPedRun::PreProcess( MParList *pList )
70{
71 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
72 if (!fRawEvt)
73 {
74 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
75 return kFALSE;
76 }
77
78 fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
79 if (!fPedestals)
80 return kFALSE;
81
82 MGeomCamMagic magiccam;
83
84 fSumx.Set(magiccam.GetNumPixels());
85 fSumx2.Set(magiccam.GetNumPixels());
86
87 for(UInt_t i=0;i<magiccam.GetNumPixels();i++)
88 {
89 fSumx.AddAt(0,i);
90 fSumx2.AddAt(0,i);
91 }
92
93 return kTRUE;
94}
95
96Bool_t MPedCalcPedRun::ReInit(MParList *pList )
97{
98
99 fRunheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
100 if (!fRunheader)
101 {
102 *fLog << warn << dbginf <<
103 "Warning - cannot check file type, MRawRunHeader not found." << endl;
104 }
105 else
106 if (fRunheader->GetRunType() == kRTMonteCarlo)
107 {
108 return kTRUE;
109 }
110
111 fNumHiGainSamples = fRunheader->GetNumSamplesHiGain();
112
113 fPedestals->InitSize(fRunheader->GetNumPixel());
114
115 return kTRUE;
116
117}
118
119
120Int_t MPedCalcPedRun::Process()
121{
122
123 MRawEvtPixelIter pixel(fRawEvt);
124
125 while (pixel.Next())
126 {
127 Byte_t shift=(fNumHiGainSamples/2*2==fNumHiGainSamples) ? 0:1;
128 Byte_t *ptr = pixel.GetHiGainSamples();
129 const Byte_t *end = ptr + fRawEvt->GetNumHiGainSamples()-shift;
130
131 const Float_t higainped = CalcHiGainMean(ptr, end);
132 const Float_t higainrms = CalcHiGainRms(ptr, end, higainped);
133
134 const UInt_t pixid = pixel.GetPixelId();
135 MPedestalPix &pix = (*fPedestals)[pixid];
136
137 // cumulate the sum of pedestals and of pedestal squares
138 fSumx.AddAt(higainped+fSumx.At(pixid),pixid);
139 fSumx2.AddAt(GetSumx2(ptr, end)+fSumx2.At(pixid),pixid);
140
141 // set the value of the pedestal and rms computed from the processed event
142 pix.Set(higainped, higainrms);
143 }
144
145
146 fCounter++;
147
148 fPedestals->SetReadyToSave();
149
150 return kTRUE;
151}
152
153Int_t MPedCalcPedRun::PostProcess()
154{
155// Compute pedestals and rms from the whole run
156
157 MRawEvtPixelIter pixel(fRawEvt);
158
159 while (pixel.Next())
160 {
161 const UInt_t pixid = pixel.GetPixelId();
162 MPedestalPix &pix = (*fPedestals)[pixid];
163
164 const Int_t N = fCounter;
165 const Float_t sum = fSumx.At(pixid);
166 const Float_t sum2 = fSumx2.At(pixid);
167 const Float_t higainped = sum/N;
168 const Float_t higainrms = sqrt(1./(N-1.)*(sum2-sum*sum/N));
169 pix.Set(higainped,higainrms);
170
171 }
172 return kTRUE;
173
174}
175
176
177Float_t MPedCalcPedRun::CalcHiGainMean(Byte_t *ptr, const Byte_t *end) const
178{
179 Int_t sum=0;
180 Byte_t EvenNumSamples=(fNumHiGainSamples/2*2==fNumHiGainSamples) ? fNumHiGainSamples:fNumHiGainSamples-1;
181
182 do sum += *ptr;
183 while (++ptr != end);
184
185 return (Float_t)sum/EvenNumSamples;
186}
187
188
189
190Float_t MPedCalcPedRun::GetSumx2(Byte_t *ptr, const Byte_t *end) const
191{
192 Float_t square = 0;
193
194 // Take an even number of time slices to avoid biases due to A/B effect
195 Byte_t EvenNumSamples=(fNumHiGainSamples/2*2==fNumHiGainSamples) ? fNumHiGainSamples:fNumHiGainSamples-1;
196
197 do
198 {
199 const Float_t val = (Float_t)(*ptr);
200
201 square += val*val;
202 } while (++ptr != end);
203
204 return square/EvenNumSamples;
205}
206
207
208Float_t MPedCalcPedRun::CalcHiGainRms(Byte_t *ptr, const Byte_t *end, Float_t higainped) const
209{
210 Float_t rms = 0;
211 Byte_t EvenNumSamples=(fNumHiGainSamples/2*2==fNumHiGainSamples) ? fNumHiGainSamples:fNumHiGainSamples-1;
212
213 do
214 {
215 const Float_t diff = (Float_t)(*ptr)-higainped;
216
217 rms += diff*diff;
218 } while (++ptr != end);
219
220 return sqrt(rms/(EvenNumSamples-1));
221}
222
223
224
225/*
226Float_t MPedCalcPedRun::CalcHiGainMeanErr(Float_t higainrms) const
227{
228 return higainrms/sqrt((float)fNumHiGainSamples);
229}
230
231Float_t MPedCalcPedRun::CalcHiGainRmsErr(Float_t higainrms) const
232{
233 return higainrms/sqrt(2.*fNumHiGainSamples);
234}
235*/
Note: See TracBrowser for help on using the repository browser.