source: trunk/MagicSoft/Mars/mcalib/MExtractBlindPixel.cc@ 3268

Last change on this file since 3268 was 3268, 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 UInt_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
116 return kTRUE;
117}
118
119// --------------------------------------------------------------------------
120//
121// Calculate the integral of the FADC time slices and store them as a new
122// pixel in the MExtractedBlindPixel container.
123//
124Int_t MExtractBlindPixel::Process()
125{
126
127 MRawEvtPixelIter pixel(fRawEvt);
128
129 fBlindPixel->Clear();
130
131 pixel.Jump(fBlindPixelIdx);
132
133 UInt_t sat = 0;
134
135 Byte_t *ptr = pixel.GetHiGainSamples();
136
137 //
138 // We need a dedicated signal extractor for the blind pixel
139 //
140 Int_t diff = 0;
141 UInt_t first = fFirst;
142 UInt_t last = fLast;
143
144 if (last > 15)
145 {
146 diff = last - 15;
147 last = 15;
148 }
149
150
151 Byte_t *start = ptr + first - 1;
152 Byte_t *end = ptr + last - 1;
153
154 ptr = start;
155
156 Int_t sum = 0;
157
158 while (ptr<=end)
159 {
160 sum += *ptr;
161
162 if (*ptr++ >= fSaturationLimit)
163 sat++;
164 }
165
166 if (diff > 0)
167 {
168 ptr = pixel.GetLoGainSamples();
169 end = ptr + diff - 1;
170
171 while (ptr<=end)
172 {
173
174 sum += *ptr;
175
176 if (*ptr++ >= fSaturationLimit)
177 sat++;
178
179 }
180 }
181
182 fBlindPixel->SetExtractedSignal(sum);
183 fBlindPixel->SetNumSaturated(sat);
184
185 if (sat)
186 *fLog << warn << "WARNING - saturation occurred in the Blind Pixel " << endl;
187
188 //
189 // catch the pointer to the event, because MHCalibrationChargeBlindPix will need it later
190 //
191 fPixelIter = &pixel;
192
193 fBlindPixel->SetReadyToSave();
194
195 return kTRUE;
196}
197
198Int_t MExtractBlindPixel::PostProcess()
199{
200
201 MPedestalPix &pedpix = (*fPedestals)[fBlindPixelIdx];
202
203 if (&pedpix)
204 {
205 fPed = pedpix.GetPedestal() * fNumSamples;
206 fPedErr = pedpix.GetPedestalRms()* fNumSamples / TMath::Sqrt((Float_t)fPedestals->GetTotalEntries());
207 fPedRms = pedpix.GetPedestalRms()* TMath::Sqrt((Float_t)fNumSamples);
208 fPedRmsErr = fPedErr/2.;
209 }
210
211 return kTRUE;
212
213}
214
215// --------------------------------------------------------------------------
216//
217// Implementation of SavePrimitive. Used to write the call to a constructor
218// to a macro. In the original root implementation it is used to write
219// gui elements to a macro-file.
220//
221void MExtractBlindPixel::StreamPrimitive(ofstream &out) const
222{
223 out << " " << ClassName() << " " << GetUniqueName() << "(\"";
224 out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
225
226 if (fSaturationLimit!=fgSaturationLimit)
227 {
228 out << " " << GetUniqueName() << ".SetSaturationLimit(";
229 out << (int)fSaturationLimit << ");" << endl;
230 }
231
232 const Bool_t arg2 = fNumSamples+fFirst-1 != fgLast;
233 const Bool_t arg1 = arg2 || fFirst != fgFirst;
234
235 if (!arg1)
236 return;
237
238 out << " " << GetUniqueName() << ".SetRange(";
239 out << (int)fFirst;
240 if (arg2)
241 out << ", " << (int)(fNumSamples+fFirst-1);
242 out << ");" << endl;
243}
Note: See TracBrowser for help on using the repository browser.