source: trunk/MagicSoft/Mars/manalysis/MExtractSignal.cc@ 3017

Last change on this file since 3017 was 3016, checked in by gaug, 22 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): Markus Gaug, 09/2003 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MExtractSignal
28//
29//////////////////////////////////////////////////////////////////////////////
30#include "MExtractSignal.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 "MExtractedSignalCam.h"
46#include "MExtractedSignalPix.h"
47
48ClassImp(MExtractSignal);
49
50using namespace std;
51
52const Byte_t MExtractSignal::fgSaturationLimit = 254;
53const Byte_t MExtractSignal::fgFirst = 3;
54const Byte_t MExtractSignal::fgLast = 10;
55
56// --------------------------------------------------------------------------
57//
58// Default constructor.
59//
60MExtractSignal::MExtractSignal(const char *name, const char *title)
61 : fSaturationLimit(fgSaturationLimit)
62{
63
64 fName = name ? name : "MExtractSignal";
65 fTitle = title ? title : "Task to extract the signal from the FADC slices";
66
67 AddToBranchList("MRawEvtData.*");
68
69 SetRange();
70}
71
72void MExtractSignal::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
73{
74
75 fNumHiGainSamples = hilast-hifirst+1;
76 fNumLoGainSamples = lolast-lofirst+1;
77
78 fHiGainFirst = hifirst;
79 fLoGainFirst = lofirst;
80
81 fSqrtHiGainSamples = TMath::Sqrt((Float_t)fNumHiGainSamples);
82 fSqrtLoGainSamples = TMath::Sqrt((Float_t)fNumLoGainSamples);
83}
84
85// --------------------------------------------------------------------------
86//
87// The PreProcess searches for the following input containers:
88// - MRawEvtData
89// - MPedestalCam
90//
91// The following output containers are also searched and created if
92// they were not found:
93//
94// - MExtractedSignalCam
95//
96Int_t MExtractSignal::PreProcess(MParList *pList)
97{
98 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
99 if (!fRawEvt)
100 {
101 *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
102 return kFALSE;
103 }
104
105
106 fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
107 if (!fSignals)
108 return kFALSE;
109
110 fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainFirst+fNumHiGainSamples-1,
111 fLoGainFirst, fLoGainFirst+fNumLoGainSamples-1);
112
113 fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
114
115 if (!fPedestals)
116 {
117 *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
118 return kFALSE;
119 }
120
121 return kTRUE;
122}
123
124void MExtractSignal::FindSignal(Byte_t *ptr, Int_t size, Int_t &sum, Byte_t &sat) const
125{
126 Byte_t *end = ptr + size;
127
128 sum = 0;
129 sat = 0;
130
131 while (ptr<end)
132 {
133 sum += *ptr;
134
135 if (*ptr++ >= fSaturationLimit)
136 sat++;
137 }
138}
139
140// --------------------------------------------------------------------------
141//
142// Calculate the integral of the FADC time slices and store them as a new
143// pixel in the MExtractedSignalCam container.
144//
145Int_t MExtractSignal::Process()
146{
147
148 MRawEvtPixelIter pixel(fRawEvt);
149 fSignals->Clear();
150
151 UInt_t sat=0;
152
153 while (pixel.Next())
154 {
155 Int_t sumhi, sumlo;
156 Byte_t sathi, satlo;
157
158 FindSignal(pixel.GetHiGainSamples()+fHiGainFirst, fNumHiGainSamples, sumhi, sathi);
159 FindSignal(pixel.GetLoGainSamples()+fLoGainFirst, fNumLoGainSamples, sumlo, satlo);
160
161 if (satlo)
162 sat++;
163
164 const Int_t pixid = pixel.GetPixelId();
165
166 const MPedestalPix &ped = (*fPedestals)[pixid];
167 MExtractedSignalPix &pix = (*fSignals)[pixid];
168
169 const Float_t pedes = ped.GetPedestal();
170 const Float_t pedrms = ped.GetPedestalRms();
171
172 pix.SetExtractedSignal(sumhi - pedes*fNumHiGainSamples, pedrms*fSqrtHiGainSamples,
173 sumlo - pedes*fNumLoGainSamples, pedrms*fSqrtLoGainSamples);
174
175 pix.SetGainSaturation(sathi, sathi, satlo);
176
177 } /* while (pixel.Next()) */
178
179 if (sat)
180 *fLog << warn << "WARNING - Lo Gain saturated in " << sat << " pixels." << endl;
181
182 fSignals->SetReadyToSave();
183
184 return kTRUE;
185}
186
187// --------------------------------------------------------------------------
188//
189// Implementation of SavePrimitive. Used to write the call to a constructor
190// to a macro. In the original root implementation it is used to write
191// gui elements to a macro-file.
192//
193void MExtractSignal::StreamPrimitive(ofstream &out) const
194{
195 out << " " << ClassName() << " " << GetUniqueName() << "(\"";
196 out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
197
198 if (fSaturationLimit!=fgSaturationLimit)
199 {
200 out << " " << GetUniqueName() << ".SetSaturationLimit(";
201 out << (int)fSaturationLimit << ");" << endl;
202 }
203
204 const Bool_t arg4 = fNumLoGainSamples+fLoGainFirst-1 != fgLast;
205 const Bool_t arg3 = arg4 || fLoGainFirst != fgFirst;
206 const Bool_t arg2 = arg3 || fNumHiGainSamples+fHiGainFirst-1 != fgLast;
207 const Bool_t arg1 = arg2 || fHiGainFirst != fgFirst;
208
209 if (!arg1)
210 return;
211
212 out << " " << GetUniqueName() << ".SetRange(";
213 out << (int)fLoGainFirst;
214 if (arg2)
215 {
216 out << ", " << (int)(fNumHiGainSamples+fHiGainFirst-1);
217 if (arg3)
218 {
219 out << ", " << (int)fLoGainFirst;
220 if (arg4)
221 out << ", " << (int)(fNumLoGainSamples+fLoGainFirst-1);
222 }
223 }
224 out << ");" << endl;
225}
Note: See TracBrowser for help on using the repository browser.