source: tags/Mars-V0.8.4/msignal/MExtractBlindPixel.cc

Last change on this file was 3681, checked in by gaug, 21 years ago
*** empty log message ***
File size: 6.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 express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Markus Gaug, 02/2004 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MExtractBlindPixel
28//
29//////////////////////////////////////////////////////////////////////////////
30#include "MExtractBlindPixel.h"
31
32#include <fstream>
33
34#include "MLog.h"
35#include "MLogManip.h"
36
37#include "MParList.h"
38
39#include "MRawEvtData.h"
40#include "MRawEvtPixelIter.h"
41
42#include "MPedestalCam.h"
43#include "MPedestalPix.h"
44
45#include "MExtractedSignalBlindPixel.h"
46
47ClassImp(MExtractBlindPixel);
48
49using namespace std;
50
51const Int_t MExtractBlindPixel::fgBlindPixelIdx = 559;
52const Byte_t MExtractBlindPixel::fgSaturationLimit = 254;
53const Byte_t MExtractBlindPixel::fgFirst = 3;
54const Byte_t MExtractBlindPixel::fgLast = 16;
55
56// --------------------------------------------------------------------------
57//
58// Default constructor.
59//
60MExtractBlindPixel::MExtractBlindPixel(const char *name, const char *title)
61 : fSaturationLimit(fgSaturationLimit)
62{
63
64 fName = name ? name : "MExtractBlindPixel";
65 fTitle = title ? title : "Task to extract the signal from the FADC slices";
66
67 AddToBranchList("MRawEvtData.*");
68
69 SetBlindPixelIdx();
70 SetSaturationLimit();
71 SetRange();
72}
73
74void MExtractBlindPixel::SetRange(Byte_t first, Byte_t last)
75{
76
77 fNumSamples = last-first+1;
78 fFirst = first;
79 fLast = last;
80
81 fSqrtSamples = TMath::Sqrt((Float_t)fNumSamples);
82}
83
84// --------------------------------------------------------------------------
85//
86// The PreProcess searches for the following input containers:
87// - MRawEvtData
88//
89// The following output containers are also searched and created if
90// they were not found:
91//
92// - MExtractedBlindPixel
93//
94Int_t MExtractBlindPixel::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 fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
104 if (!fPedestals)
105 {
106 *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting." << endl;
107 return kFALSE;
108 }
109
110 fBlindPixel = (MExtractedSignalBlindPixel*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalBlindPixel"));
111 if (!fBlindPixel)
112 return kFALSE;
113
114 fBlindPixel->SetUsedFADCSlices(fFirst, fLast);
115 fBlindPixel->SetBlindPixelIdx(fBlindPixelIdx);
116
117 return kTRUE;
118}
119
120// --------------------------------------------------------------------------
121//
122// Calculate the integral of the FADC time slices and store them as a new
123// pixel in the MExtractedBlindPixel container.
124//
125Int_t MExtractBlindPixel::Process()
126{
127
128 MRawEvtPixelIter pixel(fRawEvt);
129
130 fBlindPixel->Clear();
131
132 pixel.Jump(fBlindPixelIdx);
133
134 const UInt_t nhigain = pixel.GetNumHiGainSamples();
135
136 Byte_t *ptr = pixel.GetHiGainSamples();
137
138 //
139 // We need a dedicated signal extractor for the blind pixel
140 //
141 Int_t diff = 0;
142 UInt_t first = fFirst;
143 UInt_t last = fLast;
144 UInt_t sat = 0;
145
146 if (last > nhigain)
147 {
148 diff = last - nhigain;
149 last = nhigain;
150 }
151
152
153 Byte_t *start = ptr + first - 1;
154 Byte_t *end = ptr + last - 1;
155
156 ptr = start;
157
158 Int_t sum = 0;
159
160 while (ptr<=end)
161 {
162 sum += *ptr;
163
164 if (*ptr++ >= fSaturationLimit)
165 sat++;
166 }
167
168 if (diff > 0)
169 {
170 ptr = pixel.GetLoGainSamples();
171 end = ptr + diff - 1;
172
173 while (ptr<=end)
174 {
175
176 sum += *ptr;
177
178 if (*ptr++ >= fSaturationLimit)
179 sat++;
180
181 }
182 }
183
184 fBlindPixel->SetExtractedSignal(sum);
185 fBlindPixel->SetNumSaturated(sat);
186 fBlindPixel->SetReadyToSave();
187
188 return kTRUE;
189}
190
191Int_t MExtractBlindPixel::PostProcess()
192{
193
194 MPedestalPix &pedpix = (*fPedestals)[fBlindPixelIdx];
195
196 if (&pedpix)
197 {
198 fBlindPixel->SetPed ( pedpix.GetPedestal() * fNumSamples );
199 fBlindPixel->SetPedErr ( pedpix.GetPedestalRms()* fNumSamples / TMath::Sqrt((Float_t)fPedestals->GetTotalEntries()) );
200 fBlindPixel->SetPedRms ( pedpix.GetPedestalRms()* TMath::Sqrt((Float_t)fNumSamples) );
201 fBlindPixel->SetPedRmsErr( fBlindPixel->GetPedErr()/2. );
202 }
203
204 return kTRUE;
205
206}
207
208// --------------------------------------------------------------------------
209//
210// Implementation of SavePrimitive. Used to write the call to a constructor
211// to a macro. In the original root implementation it is used to write
212// gui elements to a macro-file.
213//
214void MExtractBlindPixel::StreamPrimitive(ofstream &out) const
215{
216 out << " " << ClassName() << " " << GetUniqueName() << "(\"";
217 out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
218
219 if (fSaturationLimit!=fgSaturationLimit)
220 {
221 out << " " << GetUniqueName() << ".SetSaturationLimit(";
222 out << (int)fSaturationLimit << ");" << endl;
223 }
224
225 const Bool_t arg2 = fNumSamples+fFirst-1 != fgLast;
226 const Bool_t arg1 = arg2 || fFirst != fgFirst;
227
228 if (!arg1)
229 return;
230
231 out << " " << GetUniqueName() << ".SetRange(";
232 out << (int)fFirst;
233 if (arg2)
234 out << ", " << (int)(fNumSamples+fFirst-1);
235 out << ");" << endl;
236}
Note: See TracBrowser for help on using the repository browser.