source: trunk/MagicSoft/Mars/msignal/MExtractPINDiode.cc@ 3615

Last change on this file since 3615 was 3322, 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// MExtractPINDiode
28//
29//////////////////////////////////////////////////////////////////////////////
30#include "MExtractPINDiode.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 "MExtractedSignalPINDiode.h"
46
47ClassImp(MExtractPINDiode);
48
49using namespace std;
50
51const UInt_t MExtractPINDiode::fgPINDiodeIdx = 1;
52const Byte_t MExtractPINDiode::fgSaturationLimit = 254;
53const Byte_t MExtractPINDiode::fgFirst = 1;
54const Byte_t MExtractPINDiode::fgLast = 30;
55
56// --------------------------------------------------------------------------
57//
58// Default constructor.
59//
60MExtractPINDiode::MExtractPINDiode(const char *name, const char *title)
61 : fSaturationLimit(fgSaturationLimit)
62{
63
64 fName = name ? name : "MExtractPINDiode";
65 fTitle = title ? title : "Task to extract the signal from the FADC slices";
66
67 AddToBranchList("MRawEvtData.*");
68
69 SetPINDiodeIdx();
70 SetSaturationLimit();
71 SetRange();
72}
73
74void MExtractPINDiode::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// - MPedestalCam
89//
90// The following output containers are also searched and created if
91// they were not found:
92//
93// - MExtractedPINDiode
94//
95Int_t MExtractPINDiode::PreProcess(MParList *pList)
96{
97 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
98 if (!fRawEvt)
99 {
100 *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
101 return kFALSE;
102 }
103
104
105 fPINDiode = (MExtractedSignalPINDiode*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalPINDiode"));
106 if (!fPINDiode)
107 return kFALSE;
108
109 fPINDiode->SetUsedFADCSlices(fFirst, fLast);
110
111 fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
112
113 if (!fPedestals)
114 {
115 *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
116 return kFALSE;
117 }
118
119 const MPedestalPix &ped = (*fPedestals)[fPINDiodeIdx];
120
121 if (&ped)
122 {
123 fPedestal = ped.GetPedestal();
124 fPedRms = ped.GetPedestalRms();
125 }
126 else
127 {
128 *fLog << err << " Cannot find MPedestalPix of the PIN Diode (idx="
129 << fPINDiodeIdx << ")" << endl;
130 return kFALSE;
131 }
132
133 return kTRUE;
134}
135
136void MExtractPINDiode::FindSignal(Byte_t *ptr, Int_t size, UInt_t &sum, UInt_t &sum2, UInt_t &sat, UInt_t &max) const
137{
138
139 Byte_t *end = ptr + size;
140
141 while (ptr<end)
142 {
143 sum += *ptr;
144 sum2 += *ptr * *ptr;
145 if (*ptr > max)
146 max = *ptr;
147
148 if (*ptr++ >= fSaturationLimit)
149 sat++;
150 }
151}
152
153// --------------------------------------------------------------------------
154//
155// Calculate the integral of the FADC time slices and store them as a new
156// pixel in the MExtractedPINDiode container.
157//
158Int_t MExtractPINDiode::Process()
159{
160
161 MRawEvtPixelIter pixel(fRawEvt);
162
163 fPINDiode->Clear();
164
165 pixel.Jump(fPINDiodeIdx);
166
167 UInt_t sum = 0;
168 UInt_t sum2 = 0;
169 UInt_t sat = 0;
170 UInt_t max = 0;
171
172 FindSignal(pixel.GetHiGainSamples()+fFirst-1,
173 fRawEvt->GetNumHiGainSamples(),
174 sum, sum2, sat, max);
175 FindSignal(pixel.GetLoGainSamples(),
176 fLast-fRawEvt->GetNumLoGainSamples(),
177 sum, sum2, sat, max);
178
179
180 const Float_t var = ((Float_t)sum2 - (Float_t)sum*sum/fNumSamples)/(fNumSamples-1);
181 const Float_t rms = TMath::Sqrt(var);
182
183 //
184 // FIXME: The following formulae have to be revised!!
185 //
186 fPINDiode->SetExtractedSignal(sum - fPedestal*fNumSamples, fPedRms*fSqrtSamples);
187 fPINDiode->SetExtractedRms (rms, rms/2./fSqrtSamples);
188 fPINDiode->SetExtractedTime (max, rms/fSqrtSamples);
189 fPINDiode->SetSaturation(sat);
190
191 if (sat)
192 *fLog << warn << "WARNING - saturation occurred in the PIN Diode " << endl;
193
194 fPINDiode->SetReadyToSave();
195
196 return kTRUE;
197}
198
199// --------------------------------------------------------------------------
200//
201// Implementation of SavePrimitive. Used to write the call to a constructor
202// to a macro. In the original root implementation it is used to write
203// gui elements to a macro-file.
204//
205void MExtractPINDiode::StreamPrimitive(ofstream &out) const
206{
207 out << " " << ClassName() << " " << GetUniqueName() << "(\"";
208 out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
209
210 if (fSaturationLimit!=fgSaturationLimit)
211 {
212 out << " " << GetUniqueName() << ".SetSaturationLimit(";
213 out << (int)fSaturationLimit << ");" << endl;
214 }
215
216 const Bool_t arg2 = fNumSamples+fFirst-1 != fgLast;
217 const Bool_t arg1 = arg2 || fFirst != fgFirst;
218
219 if (!arg1)
220 return;
221
222 out << " " << GetUniqueName() << ".SetRange(";
223 out << (int)fFirst;
224 if (arg2)
225 out << ", " << (int)(fNumSamples+fFirst-1);
226 out << ");" << endl;
227}
Note: See TracBrowser for help on using the repository browser.