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

Last change on this file since 8179 was 8158, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 5.7 KB
Line 
1/* ======================================================================== *\
2! $Name: not supported by cvs2svn $:$Id: MPedestalSubtract.cc,v 1.3 2006-10-24 12:39:00 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 || fNamePedestalCam.IsNull())
108 return kTRUE;
109
110 fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedestalCam), "MPedestalCam");
111 if (!fPedestals)
112 {
113 *fLog << err << AddSerialNumber(fNamePedestalCam) << " [MPedestalCam] not found... aborting" << endl;
114 return kFALSE;
115 }
116
117 return kTRUE;
118}
119
120// --------------------------------------------------------------------------
121//
122//
123Int_t MPedestalSubtract::Process()
124{
125 // Total number of samples
126 const Int_t numh = fRawEvt->GetNumHiGainSamples();
127 const Int_t numl = fRawEvt->GetNumLoGainSamples();
128
129 // initialize fSignal
130 fSignal->InitSamples(fRawEvt->GetNumPixels(), numh+numl);
131
132 // iterate over all pixels
133 MRawEvtPixelIter pixel(fRawEvt);
134 while (pixel.Next())
135 {
136 // Get index ofthis pixel
137 const Int_t pixidx = pixel.GetPixelId();
138
139 // Get pointer were to store merged raw data
140 Byte_t *sample = fSignal->GetSamplesRaw(pixidx);
141
142 // copy hi- and lo-gains samples together
143 memcpy(sample, pixel.GetHiGainSamples(), numh);
144 memcpy(sample+numh, pixel.GetLoGainSamples(), numl);
145
146 // start of destination array, end of hi-gain destination array
147 // and start of hi-gain samples
148 Float_t *beg = fSignal->GetSamples(pixidx);
149 Float_t *end = beg + fSignal->GetNumSamples();
150
151 const Byte_t *src = sample;
152
153 // if no pedestals are given just convert the data into
154 // floats and we are finished
155 if (!fPedestals)
156 {
157 while (beg<end)
158 *beg++ = *src++;
159 continue;
160 }
161
162 // get pedestal information for this pixel
163 const MPedestalPix &pedpix = (*fPedestals)[pixidx];
164
165 // pedestal information
166 const Int_t ab = pixel.HasABFlag() ? 1 : 0;
167 const Float_t ped = pedpix.GetPedestal();
168
169 // determine with which pedestal (+/- AB offset) to start
170 const Bool_t swap = (ab&1)==1;
171 const Float_t offh = swap ? -pedpix.GetPedestalABoffset() : pedpix.GetPedestalABoffset();
172 const Float_t mean[2] = { ped + offh, ped - offh };
173
174 // Copy hi-gains into array and substract pedestal
175 // FIXME: Shell we really subtract the pedestal from saturating slices???
176 for (Float_t *ptr=beg; ptr<end; ptr++)
177 *ptr = (Float_t)*src++ - mean[(ptr-beg)&1];
178 }
179
180 return kTRUE;
181}
Note: See TracBrowser for help on using the repository browser.