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): Javier Lopez 12/2003 <mailto:jlopez@ifae.es>
|
---|
19 | ! Author(s): Javier Rico 01/2004 <mailto:jrico@ifae.es>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | //////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MCalibrate
|
---|
29 | //
|
---|
30 | // This task takes the integrated charge from MExtractedSignal and apply
|
---|
31 | // the calibration constants from MCalibraitionCam to the charge. Then
|
---|
32 | // stores number of photons obtained in MCerPhotEvt. Selection of different
|
---|
33 | // calibration methods is allowed through SetCalibrationMode member function
|
---|
34 | //
|
---|
35 | // Input Containers:
|
---|
36 | // MExtractedSingal
|
---|
37 | // MCalibrationChargeCam
|
---|
38 | //
|
---|
39 | // Output Containers:
|
---|
40 | // MCerPhotEvt
|
---|
41 | //
|
---|
42 | //////////////////////////////////////////////////////////////////////////////
|
---|
43 | #include "MCalibrate.h"
|
---|
44 |
|
---|
45 | #include "MLog.h"
|
---|
46 | #include "MLogManip.h"
|
---|
47 |
|
---|
48 | #include "MParList.h"
|
---|
49 | #include "MH.h"
|
---|
50 |
|
---|
51 | #include "MGeomCam.h"
|
---|
52 |
|
---|
53 | #include "MCalibrationChargeCam.h"
|
---|
54 | #include "MCalibrationChargePix.h"
|
---|
55 |
|
---|
56 | #include "MExtractedSignalCam.h"
|
---|
57 | #include "MExtractedSignalPix.h"
|
---|
58 |
|
---|
59 | #include "MCerPhotEvt.h"
|
---|
60 |
|
---|
61 | ClassImp(MCalibrate);
|
---|
62 |
|
---|
63 | using namespace std;
|
---|
64 | // --------------------------------------------------------------------------
|
---|
65 | //
|
---|
66 | // Default constructor.
|
---|
67 | //
|
---|
68 | MCalibrate::MCalibrate(CalibrationMode_t calmode,const char *name, const char *title) : fCalibrationMode(calmode)
|
---|
69 | {
|
---|
70 | fName = name ? name : "MCalibrate";
|
---|
71 | fTitle = title ? title : "Task to calculate the number of photons in one event";
|
---|
72 | }
|
---|
73 |
|
---|
74 | // --------------------------------------------------------------------------
|
---|
75 | //
|
---|
76 | // The PreProcess searches for the following input containers:
|
---|
77 | // - MGeomCam
|
---|
78 | // - MCalibrationChargeCam
|
---|
79 | // - MExtractedSignalCam
|
---|
80 | //
|
---|
81 | // The following output containers are also searched and created if
|
---|
82 | // they were not found:
|
---|
83 | //
|
---|
84 | // - MCerPhotEvt
|
---|
85 | //
|
---|
86 | Int_t MCalibrate::PreProcess(MParList *pList)
|
---|
87 | {
|
---|
88 |
|
---|
89 | fSignals = (MExtractedSignalCam*)pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
|
---|
90 |
|
---|
91 | if (!fSignals)
|
---|
92 | {
|
---|
93 | *fLog << err << AddSerialNumber("MExtractedSignalCam") << " not found ... aborting" << endl;
|
---|
94 | return kFALSE;
|
---|
95 | }
|
---|
96 |
|
---|
97 | if(fCalibrationMode>kNone)
|
---|
98 | {
|
---|
99 |
|
---|
100 | fCalibrations = (MCalibrationChargeCam*)pList->FindObject(AddSerialNumber("MCalibrationChargeCam"));
|
---|
101 | if (!fCalibrations)
|
---|
102 | {
|
---|
103 | *fLog << err << AddSerialNumber("MCalibrationChargeCam") << " not found ... aborting." << endl;
|
---|
104 | return kFALSE;
|
---|
105 | }
|
---|
106 |
|
---|
107 | }
|
---|
108 |
|
---|
109 | fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj(AddSerialNumber("MCerPhotEvt"));
|
---|
110 | if (!fCerPhotEvt)
|
---|
111 | return kFALSE;
|
---|
112 |
|
---|
113 | return kTRUE;
|
---|
114 | }
|
---|
115 |
|
---|
116 | // --------------------------------------------------------------------------
|
---|
117 | //
|
---|
118 | // Check for validity of the selected calibration method, switch to a
|
---|
119 | // different one in case of need
|
---|
120 | //
|
---|
121 | Bool_t MCalibrate::ReInit(MParList *pList)
|
---|
122 | {
|
---|
123 |
|
---|
124 | if(fCalibrationMode == kBlindPixel && !fCalibrations->IsBlindPixelMethodValid())
|
---|
125 | {
|
---|
126 | *fLog << warn << GetDescriptor() << "Warning: Blind pixel calibration method not valid, switching to F-factor method" << endl;
|
---|
127 | fCalibrationMode = kFfactor;
|
---|
128 | }
|
---|
129 |
|
---|
130 | if(fCalibrationMode == kPinDiode && !fCalibrations->IsPINDiodeMethodValid())
|
---|
131 | {
|
---|
132 | *fLog << warn << GetDescriptor() << "Warning: PIN diode calibration method not valid, switching to F-factor method" << endl;
|
---|
133 | fCalibrationMode = kFfactor;
|
---|
134 | }
|
---|
135 |
|
---|
136 | switch(fCalibrationMode)
|
---|
137 | {
|
---|
138 | case kBlindPixel:
|
---|
139 | break;
|
---|
140 | case kFfactor:
|
---|
141 | break;
|
---|
142 | case kPinDiode:
|
---|
143 | *fLog << err << GetDescriptor()
|
---|
144 | << ": PIN Diode Calibration mode not yet available " << endl;
|
---|
145 | return kFALSE;
|
---|
146 | break;
|
---|
147 | case kCombined:
|
---|
148 | *fLog << err << GetDescriptor()
|
---|
149 | << ": Combined Calibration mode not yet available " << endl;
|
---|
150 | return kFALSE;
|
---|
151 | break;
|
---|
152 | case kDummy:
|
---|
153 | *fLog << warn << GetDescriptor()
|
---|
154 | << ": WARNING: Dummy calibration, no calibration applied!!" << endl;
|
---|
155 | break;
|
---|
156 | default:
|
---|
157 | *fLog << warn << GetDescriptor()
|
---|
158 | << ": WARNING: Calibration mode value ("
|
---|
159 | <<fCalibrationMode<<") not known" << endl;
|
---|
160 | return kFALSE;
|
---|
161 | }
|
---|
162 |
|
---|
163 | return kTRUE;
|
---|
164 | }
|
---|
165 | // --------------------------------------------------------------------------
|
---|
166 | //
|
---|
167 | // Apply the calibration factors to the extracted signal according to the
|
---|
168 | // selected calibration method
|
---|
169 | //
|
---|
170 | Int_t MCalibrate::Process()
|
---|
171 | {
|
---|
172 | /*
|
---|
173 | if (fCalibrations->GetNumPixels() != (UInt_t)fSignals->GetSize())
|
---|
174 | {
|
---|
175 | // FIXME: MExtractedSignal must be of variable size -
|
---|
176 | // like MCerPhotEvt - because we must be able
|
---|
177 | // to reduce size by zero supression
|
---|
178 | // For the moment this check could be done in ReInit...
|
---|
179 | *fLog << err << "MExtractedSignal and MCalibrationCam have different sizes... abort." << endl;
|
---|
180 | return kFALSE;
|
---|
181 | }
|
---|
182 | */
|
---|
183 |
|
---|
184 | UInt_t npix = fSignals->GetSize();
|
---|
185 |
|
---|
186 | Float_t hiloconv = 1.;
|
---|
187 | Float_t hiloconverr = 0.;
|
---|
188 | Float_t calibrationConversionFactor = 1.;
|
---|
189 | Float_t calibrationConversionFactorErr = 0.;
|
---|
190 |
|
---|
191 | for (UInt_t pixidx=0; pixidx<npix; pixidx++)
|
---|
192 | {
|
---|
193 | if(fCalibrationMode!=kNone)
|
---|
194 | {
|
---|
195 | MCalibrationChargePix &pix = (*fCalibrations)[pixidx];
|
---|
196 |
|
---|
197 | if (!pix.IsChargeValid())
|
---|
198 | continue;
|
---|
199 |
|
---|
200 | hiloconv = pix.GetConversionHiLo();
|
---|
201 | hiloconverr= pix.GetConversionHiLoErr();
|
---|
202 |
|
---|
203 | switch(fCalibrationMode)
|
---|
204 | {
|
---|
205 | case kBlindPixel:
|
---|
206 | if (pix.IsBlindPixelMethodValid())
|
---|
207 | {
|
---|
208 | calibrationConversionFactor = pix.GetMeanConversionBlindPixelMethod();
|
---|
209 | calibrationConversionFactorErr = pix.GetConversionBlindPixelMethodErr();
|
---|
210 | }
|
---|
211 | break;
|
---|
212 | case kPinDiode:
|
---|
213 | if (pix.IsPINDiodeMethodValid())
|
---|
214 | {
|
---|
215 | calibrationConversionFactor = pix.GetMeanConversionPINDiodeMethod();
|
---|
216 | calibrationConversionFactorErr = pix.GetConversionPINDiodeMethodErr();
|
---|
217 | }
|
---|
218 | break;
|
---|
219 | case kFfactor:
|
---|
220 | if (pix.IsFFactorMethodValid())
|
---|
221 | {
|
---|
222 | calibrationConversionFactor = pix.GetMeanConversionFFactorMethod();
|
---|
223 | calibrationConversionFactorErr = pix.GetConversionFFactorMethodErr();
|
---|
224 | }
|
---|
225 | break;
|
---|
226 | case kCombined:
|
---|
227 | if (pix.IsCombinedMethodValid())
|
---|
228 | {
|
---|
229 | calibrationConversionFactor = pix.GetMeanConversionCombinedMethod();
|
---|
230 | calibrationConversionFactorErr = pix.GetConversionCombinedMethodErr();
|
---|
231 | }
|
---|
232 | break;
|
---|
233 | case kDummy:
|
---|
234 | calibrationConversionFactor = 1.;
|
---|
235 | calibrationConversionFactorErr = 0.;
|
---|
236 | break;
|
---|
237 | }
|
---|
238 | }
|
---|
239 |
|
---|
240 | MExtractedSignalPix &sig = (*fSignals)[pixidx];
|
---|
241 |
|
---|
242 | Float_t signal;
|
---|
243 | Float_t signalErr = 0.;
|
---|
244 | Float_t nphot,nphotErr;
|
---|
245 |
|
---|
246 | if (sig.IsLoGainUsed())
|
---|
247 | {
|
---|
248 | signal = sig.GetExtractedSignalLoGain()*hiloconv;
|
---|
249 | signalErr = signal*hiloconverr;
|
---|
250 | }
|
---|
251 | else
|
---|
252 | {
|
---|
253 | if (sig.GetExtractedSignalHiGain() > 9999.)
|
---|
254 | {
|
---|
255 | signal = 0.;
|
---|
256 | signalErr = 0.;
|
---|
257 | }
|
---|
258 | else
|
---|
259 | signal = sig.GetExtractedSignalHiGain();
|
---|
260 | }
|
---|
261 |
|
---|
262 | nphot = signal*calibrationConversionFactor;
|
---|
263 | nphotErr = signal*calibrationConversionFactorErr
|
---|
264 | *signal*calibrationConversionFactorErr
|
---|
265 | + signalErr*calibrationConversionFactor
|
---|
266 | *signalErr*calibrationConversionFactor;
|
---|
267 |
|
---|
268 | nphotErr = TMath::Sqrt(nphotErr);
|
---|
269 |
|
---|
270 | MCerPhotPix *cpix = fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
|
---|
271 |
|
---|
272 | if (sig.GetNumLoGainSaturated() > 0)
|
---|
273 | cpix->SetPixelSaturated();
|
---|
274 | }
|
---|
275 |
|
---|
276 | fCerPhotEvt->FixSize();
|
---|
277 | fCerPhotEvt->SetReadyToSave();
|
---|
278 |
|
---|
279 | return kTRUE;
|
---|
280 | }
|
---|