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 |
|
---|
47 | ClassImp(MExtractPINDiode);
|
---|
48 |
|
---|
49 | using namespace std;
|
---|
50 |
|
---|
51 | const UInt_t MExtractPINDiode::fgPINDiodeIdx = 999;
|
---|
52 | const Byte_t MExtractPINDiode::fgSaturationLimit = 254;
|
---|
53 | const Byte_t MExtractPINDiode::fgFirst = 1;
|
---|
54 | const Byte_t MExtractPINDiode::fgLast = 30;
|
---|
55 |
|
---|
56 | // --------------------------------------------------------------------------
|
---|
57 | //
|
---|
58 | // Default constructor.
|
---|
59 | //
|
---|
60 | MExtractPINDiode::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 |
|
---|
74 | void 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 | //
|
---|
95 | Int_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, fFirst+fNumSamples-1);
|
---|
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 | return kTRUE;
|
---|
120 | }
|
---|
121 |
|
---|
122 | void MExtractPINDiode::FindSignal(Byte_t *ptr, Int_t size, UInt_t &sum, UInt_t &sum2, UInt_t &sat, UInt_t &max) const
|
---|
123 | {
|
---|
124 |
|
---|
125 | Byte_t *end = ptr + size;
|
---|
126 |
|
---|
127 | while (ptr<end)
|
---|
128 | {
|
---|
129 | sum += *ptr;
|
---|
130 | sum2 += *ptr * *ptr;
|
---|
131 | if (*ptr > max)
|
---|
132 | max = *ptr;
|
---|
133 |
|
---|
134 | if (*ptr++ >= fSaturationLimit)
|
---|
135 | sat++;
|
---|
136 | }
|
---|
137 | }
|
---|
138 |
|
---|
139 | // --------------------------------------------------------------------------
|
---|
140 | //
|
---|
141 | // Calculate the integral of the FADC time slices and store them as a new
|
---|
142 | // pixel in the MExtractedPINDiode container.
|
---|
143 | //
|
---|
144 | Int_t MExtractPINDiode::Process()
|
---|
145 | {
|
---|
146 |
|
---|
147 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
148 |
|
---|
149 | fPINDiode->Clear();
|
---|
150 |
|
---|
151 | pixel.Jump(fPINDiodeIdx);
|
---|
152 |
|
---|
153 | UInt_t sum = 0;
|
---|
154 | UInt_t sum2 = 0;
|
---|
155 | UInt_t sat = 0;
|
---|
156 | UInt_t max = 0;
|
---|
157 |
|
---|
158 | FindSignal(pixel.GetHiGainSamples()+fFirst-1,
|
---|
159 | fRawEvt->GetNumHiGainSamples(),
|
---|
160 | sum, sum2, sat, max);
|
---|
161 | FindSignal(pixel.GetLoGainSamples(),
|
---|
162 | fLast-fRawEvt->GetNumLoGainSamples(),
|
---|
163 | sum, sum2, sat, max);
|
---|
164 |
|
---|
165 | const MPedestalPix &ped = (*fPedestals)[fPINDiodeIdx];
|
---|
166 |
|
---|
167 | Float_t pedes = -999.;
|
---|
168 | Float_t pedrms = -999.;
|
---|
169 |
|
---|
170 | if (&ped)
|
---|
171 | {
|
---|
172 | pedes = ped.GetPedestal();
|
---|
173 | pedrms = ped.GetPedestalRms();
|
---|
174 | }
|
---|
175 | else
|
---|
176 | {
|
---|
177 | *fLog << warn << " Cannot find MPedestalPix of the PIN Diode (idx="
|
---|
178 | << fPINDiodeIdx << ")" << endl;
|
---|
179 |
|
---|
180 | }
|
---|
181 |
|
---|
182 | const Float_t var = ((Float_t)sum2 - (Float_t)sum*sum/fNumSamples)/(fNumSamples-1);
|
---|
183 | const Float_t rms = TMath::Sqrt(var);
|
---|
184 |
|
---|
185 | //
|
---|
186 | // FIXME: The following formulae have to be revised!!
|
---|
187 | //
|
---|
188 | fPINDiode->SetExtractedSignal(sum - pedes*fNumSamples, pedrms*fSqrtSamples);
|
---|
189 | fPINDiode->SetExtractedRms (rms, rms/2./fSqrtSamples);
|
---|
190 | fPINDiode->SetExtractedTime (max, rms/fSqrtSamples);
|
---|
191 | fPINDiode->SetSaturation(sat);
|
---|
192 |
|
---|
193 | if (sat)
|
---|
194 | *fLog << warn << "WARNING - saturation occurred in the PIN Diode " << endl;
|
---|
195 |
|
---|
196 | fPINDiode->SetReadyToSave();
|
---|
197 |
|
---|
198 | return kTRUE;
|
---|
199 | }
|
---|
200 |
|
---|
201 | // --------------------------------------------------------------------------
|
---|
202 | //
|
---|
203 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
---|
204 | // to a macro. In the original root implementation it is used to write
|
---|
205 | // gui elements to a macro-file.
|
---|
206 | //
|
---|
207 | void MExtractPINDiode::StreamPrimitive(ofstream &out) const
|
---|
208 | {
|
---|
209 | out << " " << ClassName() << " " << GetUniqueName() << "(\"";
|
---|
210 | out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
|
---|
211 |
|
---|
212 | if (fSaturationLimit!=fgSaturationLimit)
|
---|
213 | {
|
---|
214 | out << " " << GetUniqueName() << ".SetSaturationLimit(";
|
---|
215 | out << (int)fSaturationLimit << ");" << endl;
|
---|
216 | }
|
---|
217 |
|
---|
218 | const Bool_t arg2 = fNumSamples+fFirst-1 != fgLast;
|
---|
219 | const Bool_t arg1 = arg2 || fFirst != fgFirst;
|
---|
220 |
|
---|
221 | if (!arg1)
|
---|
222 | return;
|
---|
223 |
|
---|
224 | out << " " << GetUniqueName() << ".SetRange(";
|
---|
225 | out << (int)fFirst;
|
---|
226 | if (arg2)
|
---|
227 | out << ", " << (int)(fNumSamples+fFirst-1);
|
---|
228 | out << ");" << endl;
|
---|
229 | }
|
---|