source: trunk/MagicSoft/Mars/mpedestal/MPedestalSubtract.cc@ 8887

Last change on this file since 8887 was 8795, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 6.6 KB
Line 
1/* ======================================================================== *\
2! $Name: not supported by cvs2svn $:$Id: MPedestalSubtract.cc,v 1.9 2007-12-19 18:53:03 tbretz Exp $
3! --------------------------------------------------------------------------
4!
5! *
6! * This file is part of MARS, the MAGIC Analysis and Reconstruction
7! * Software. It is distributed to you in the hope that it can be a useful
8! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
9! * It is distributed WITHOUT ANY WARRANTY.
10! *
11! * Permission to use, copy, modify and distribute this software and its
12! * documentation for any purpose is hereby granted without fee,
13! * provided that the above copyright notice appear in all copies and
14! * that both that copyright notice and this permission notice appear
15! * in supporting documentation. It is provided "as is" without express
16! * or implied warranty.
17! *
18!
19!
20! Author(s): Thomas Bretz, 10/2006 <mailto:tbretz@astro.uni-wuerzburg.de>
21!
22! Copyright: MAGIC Software Development, 2000-2006
23!
24!
25\* ======================================================================== */
26
27//////////////////////////////////////////////////////////////////////////////
28//
29// MPedestalSubtract
30//
31// This class merges hi- and lo-gain samples into one array and
32// subtracts the pedestal (including the AB-offset) from the
33// data and stores the result in MPedestalSubtractedEvt.
34//
35// Input Containers:
36// MRawEvtData
37// MRawRunHeader
38// MPedestalCam
39//
40// Output Containers:
41// MPedestalSubtractedEvt
42//
43//////////////////////////////////////////////////////////////////////////////
44#include "MPedestalSubtract.h"
45
46#include "MLog.h"
47#include "MLogManip.h"
48
49#include "MParList.h"
50
51#include "MArrayB.h"
52
53#include "MRawEvtData.h"
54#include "MRawEvtPixelIter.h"
55
56#include "MPedestalCam.h"
57#include "MPedestalPix.h"
58
59#include "MPedestalSubtractedEvt.h"
60
61#include "MExtractedSignalCam.h"
62#include "MExtractedSignalPix.h"
63
64ClassImp(MPedestalSubtract);
65
66using namespace std;
67
68const TString MPedestalSubtract::fgNamePedestalCam = "MPedestalCam";
69const TString MPedestalSubtract::fgNamePedestalSubtractedEvt = "MPedestalSubtractedEvt";
70
71// --------------------------------------------------------------------------
72//
73// Default constructor.
74//
75MPedestalSubtract::MPedestalSubtract(const char *name, const char *title)
76 : fRawEvt(NULL), fPedestals(NULL), fSignal(NULL)
77{
78 fName = name ? name : "MPedestalSubtract";
79 fTitle = title ? title : "Class to subtract pedestal";
80}
81
82// --------------------------------------------------------------------------
83//
84// The PreProcess searches for the following input containers:
85// - MRawEvtData
86// - MRawRunHeader
87// - MPedestalCam
88//
89// The following output containers are also searched and created if
90// they were not found:
91//
92// - MPedestalSubtractedEvt
93//
94Int_t MPedestalSubtract::PreProcess(MParList *pList)
95{
96 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
97 if (!fRawEvt)
98 {
99 *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
100 return kFALSE;
101 }
102
103 fSignal = (MPedestalSubtractedEvt*)pList->FindCreateObj("MPedestalSubtractedEvt");//, AddSerialNumber(fNamePedestalSubtractedEvt));
104 if (!fSignal)
105 return kFALSE;
106
107 if (fPedestals)
108 {
109 *fLog << inf << "Pedestals given by pointer will be subtracted." << endl;
110 return kTRUE;
111 }
112
113 if (fNamePedestalCam.IsNull())
114 {
115 *fLog << inf << "No name for MPedestalCam given, pedestal subtraction will be skipped." << endl;
116 return kTRUE;
117 }
118
119 fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedestalCam), "MPedestalCam");
120 if (!fPedestals)
121 {
122 *fLog << err << AddSerialNumber(fNamePedestalCam) << " [MPedestalCam] not found... aborting" << endl;
123 return kFALSE;
124 }
125
126 *fLog << inf << "Pedestals " << fNamePedestalCam << " will be subtracted." << endl;
127
128 return kTRUE;
129}
130
131void MPedestalSubtract::Memcpy(void *dest, void *src, Int_t cnt) const
132{
133 if (fRawEvt->GetNumBytesPerSample()==2)
134 memcpy(dest, src, cnt*2);
135 else
136 {
137 const Byte_t *b = (Byte_t*)src;
138 for (USample_t *ptr=(USample_t*)dest; ptr<(USample_t*)dest+cnt; ptr++)
139 *ptr = *b++;
140 }
141}
142
143// --------------------------------------------------------------------------
144//
145//
146Int_t MPedestalSubtract::Process()
147{
148 // Total number of samples
149 const Int_t numh = fRawEvt->GetNumHiGainSamples();
150 const Int_t numl = fRawEvt->GetNumLoGainSamples();
151
152 const UInt_t scale = fRawEvt->GetScale();
153
154 // initialize fSignal
155 fSignal->InitSamples(numh+numl);//, fRawEvt->GetNumPixels(), numh+numl);
156
157 // iterate over all pixels
158 MRawEvtPixelIter pixel(fRawEvt);
159 while (pixel.Next())
160 {
161 // Get index ofthis pixel
162 const Int_t pixidx = pixel.GetPixelId();
163
164 if (pixidx>=fSignal->GetNumPixels())
165 {
166 *fLog << err << "ERROR - Pixel index " << pixidx << " out of bounds... abort." << endl;
167 return kERROR;
168 }
169 // Get pointer were to store merged raw data
170 USample_t *sample = fSignal->GetSamplesRaw(pixidx);
171
172 // copy hi- and lo-gains samples together
173 Memcpy(sample, pixel.GetHiGainSamples(), numh);
174 Memcpy(sample+numh, pixel.GetLoGainSamples(), numl);
175
176 // start of destination array, end of hi-gain destination array
177 // and start of hi-gain samples
178 Float_t *beg = fSignal->GetSamples(pixidx);
179 Float_t *end = beg + fSignal->GetNumSamples();
180
181 const USample_t *src = sample;
182
183 // if no pedestals are given just convert the data into
184 // floats and we are finished
185 if (!fPedestals)
186 {
187 while (beg<end)
188 *beg++ = *src++;//Float_t(*src++)/scale;
189 continue;
190 }
191
192 // get pedestal information for this pixel
193 const MPedestalPix &pedpix = (*fPedestals)[pixidx];
194
195 // pedestal information
196 const Int_t ab = pixel.HasABFlag() ? 1 : 0;
197 const Float_t ped = pedpix.GetPedestal();
198
199 // determine with which pedestal (+/- AB offset) to start
200 const Bool_t swap = (ab&1)==1;
201 const Float_t offh = swap ? -pedpix.GetPedestalABoffset() : pedpix.GetPedestalABoffset();
202 const Float_t mean[2] = { ped + offh, ped - offh };
203
204 // Copy hi-gains into array and substract pedestal
205 // FIXME: Shell we really subtract the pedestal from saturating slices???
206 for (Float_t *ptr=beg; ptr<end; ptr++)
207 *ptr = Float_t(*src++)/scale - mean[(ptr-beg)&1];
208 }
209
210 return kTRUE;
211}
Note: See TracBrowser for help on using the repository browser.