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): Abelardo Moralejo, 12/2003 <mailto:moralejo@pd.infn.it>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2003
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MMcCalibrationUpdate
|
---|
28 | //
|
---|
29 | // This task looks for the ìnformation about FADC pedestals in
|
---|
30 | // MMcFadcHeader and translates it to the pedestal mean and rms (in adc counts).
|
---|
31 | // If not already existing in the parameter list, an MCalibrationCam object
|
---|
32 | // is created, with the conversion factor between photons and ADC counts is
|
---|
33 | // set to 1 to allow the analysis to proceed.
|
---|
34 | //
|
---|
35 | // Then it creates and fills also the MPedPhotCam object containing the pedestal
|
---|
36 | // mean and rms in units of photons.
|
---|
37 | //
|
---|
38 | // Input Containers:
|
---|
39 | // MMcFadcHeader
|
---|
40 | // MRawRunHeader
|
---|
41 | // [MCalibrationCam] (if it existed previously)
|
---|
42 | //
|
---|
43 | // Output Containers:
|
---|
44 | // MPedPhotCam
|
---|
45 | // [MCalibrationCam] (if it did not exist previously)
|
---|
46 | //
|
---|
47 | /////////////////////////////////////////////////////////////////////////////
|
---|
48 | #include "MMcCalibrationUpdate.h"
|
---|
49 |
|
---|
50 | #include "MParList.h"
|
---|
51 |
|
---|
52 | #include "MLog.h"
|
---|
53 | #include "MLogManip.h"
|
---|
54 |
|
---|
55 | #include "MCalibrationChargePix.h"
|
---|
56 | #include "MCalibrationChargeCam.h"
|
---|
57 | #include "MExtractedSignalCam.h"
|
---|
58 | #include "MExtractedSignalPix.h"
|
---|
59 | #include "MGeomCam.h"
|
---|
60 | #include "MPedPhotCam.h"
|
---|
61 | #include "MPedPhotPix.h"
|
---|
62 |
|
---|
63 | #include "MRawRunHeader.h"
|
---|
64 | #include "MMcRunHeader.hxx"
|
---|
65 | #include "MMcFadcHeader.hxx"
|
---|
66 |
|
---|
67 | ClassImp(MMcCalibrationUpdate);
|
---|
68 |
|
---|
69 | using namespace std;
|
---|
70 |
|
---|
71 | MMcCalibrationUpdate::MMcCalibrationUpdate(const char *name, const char *title)
|
---|
72 | {
|
---|
73 | fName = name ? name : "MMcCalibrationUpdate";
|
---|
74 | fTitle = title ? title : "Write MC pedestals and conversion factors into MCalibration Container";
|
---|
75 |
|
---|
76 | fADC2PhInner = 1.;
|
---|
77 | fADC2PhOuter = 1.;
|
---|
78 |
|
---|
79 | fAmplitude = -1.;
|
---|
80 | fAmplitudeOuter = -1.;
|
---|
81 | fConversionHiLo = -1.;
|
---|
82 |
|
---|
83 | fFillCalibrationCam = kTRUE;
|
---|
84 | fOuterPixelsGainScaling = kTRUE;
|
---|
85 | }
|
---|
86 |
|
---|
87 | // --------------------------------------------------------------------------
|
---|
88 | //
|
---|
89 | // Check for the run type. Return kTRUE if it is a MC run or if there
|
---|
90 | // is no MC run header (old camera files) kFALSE in case of a different
|
---|
91 | // run type
|
---|
92 | //
|
---|
93 | Bool_t MMcCalibrationUpdate::CheckRunType(MParList *pList) const
|
---|
94 | {
|
---|
95 | const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
96 | if (!run)
|
---|
97 | {
|
---|
98 | *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
|
---|
99 | return kTRUE;
|
---|
100 | }
|
---|
101 |
|
---|
102 | return run->IsMonteCarloRun();
|
---|
103 | }
|
---|
104 |
|
---|
105 | // --------------------------------------------------------------------------
|
---|
106 | //
|
---|
107 | // Make sure, that there is an MCalibrationCam Object in the Parameter List.
|
---|
108 | //
|
---|
109 | Int_t MMcCalibrationUpdate::PreProcess(MParList *pList)
|
---|
110 | {
|
---|
111 | fCalCam = (MCalibrationChargeCam*) pList->FindObject(AddSerialNumber("MCalibrationChargeCam"));
|
---|
112 | if (!fCalCam)
|
---|
113 | {
|
---|
114 | fCalCam = (MCalibrationChargeCam*) pList->FindCreateObj(AddSerialNumber("MCalibrationChargeCam"));
|
---|
115 | if (!fCalCam)
|
---|
116 | return kFALSE;
|
---|
117 | }
|
---|
118 | else
|
---|
119 | {
|
---|
120 | fFillCalibrationCam = kFALSE;
|
---|
121 | *fLog << inf << AddSerialNumber("MCalibrationChargeCam") << " already exists... " << endl;
|
---|
122 | }
|
---|
123 |
|
---|
124 | fPedPhotCam = (MPedPhotCam*) pList->FindCreateObj(AddSerialNumber("MPedPhotCam"));
|
---|
125 | if (!fPedPhotCam)
|
---|
126 | return kFALSE;
|
---|
127 |
|
---|
128 | fSignalCam = (MExtractedSignalCam*) pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
|
---|
129 | if (!fSignalCam)
|
---|
130 | {
|
---|
131 | *fLog << err << AddSerialNumber("MExtractedSignalCam") << " not found... aborting." << endl;
|
---|
132 | return kFALSE;
|
---|
133 | }
|
---|
134 |
|
---|
135 | return kTRUE;
|
---|
136 | }
|
---|
137 |
|
---|
138 | // --------------------------------------------------------------------------
|
---|
139 | //
|
---|
140 | // Check for the runtype.
|
---|
141 | // Search for MGeomCam and MMcFadcHeader.
|
---|
142 | // Fill the MCalibrationCam object.
|
---|
143 | //
|
---|
144 | Bool_t MMcCalibrationUpdate::ReInit(MParList *pList)
|
---|
145 | {
|
---|
146 | //
|
---|
147 | // If it is no MC file skip this function...
|
---|
148 | //
|
---|
149 | if (!CheckRunType(pList))
|
---|
150 | {
|
---|
151 | *fLog << inf << "This is no MC file... skipping." << endl;
|
---|
152 | return kTRUE;
|
---|
153 | }
|
---|
154 |
|
---|
155 | //
|
---|
156 | // Now check the existence of all necessary containers.
|
---|
157 | //
|
---|
158 | fGeom = (MGeomCam*) pList->FindObject(AddSerialNumber("MGeomCam"));
|
---|
159 | if (!fGeom)
|
---|
160 | {
|
---|
161 | *fLog << err << AddSerialNumber("MGeomCam") << " not found... aborting." << endl;
|
---|
162 | return kFALSE;
|
---|
163 | }
|
---|
164 |
|
---|
165 | fHeaderFadc = (MMcFadcHeader*)pList->FindObject(AddSerialNumber("MMcFadcHeader"));
|
---|
166 | if (!fHeaderFadc)
|
---|
167 | {
|
---|
168 | *fLog << err << AddSerialNumber("MMcFadcHeader") << " not found... aborting." << endl;
|
---|
169 | return kFALSE;
|
---|
170 | }
|
---|
171 |
|
---|
172 | MMcRunHeader* mcrunh = (MMcRunHeader*) pList->FindObject("MMcRunHeader");
|
---|
173 |
|
---|
174 | //
|
---|
175 | // Initialize Fadc simulation parameters:
|
---|
176 | //
|
---|
177 | if (fAmplitude < 0)
|
---|
178 | {
|
---|
179 | fAmplitude = fHeaderFadc->GetAmplitud();
|
---|
180 | if (mcrunh->GetCamVersion() > 60)
|
---|
181 | {
|
---|
182 | fAmplitudeOuter = fHeaderFadc->GetAmplitudOuter();
|
---|
183 | fConversionHiLo = fHeaderFadc->GetLow2HighGain();
|
---|
184 | }
|
---|
185 | else // old MC files, camera < v0.7
|
---|
186 | {
|
---|
187 | fAmplitudeOuter = fAmplitude;
|
---|
188 | fConversionHiLo = 1; // dummy value
|
---|
189 | }
|
---|
190 |
|
---|
191 | }
|
---|
192 | else // Check that following files have all the same FADC parameters
|
---|
193 | {
|
---|
194 | if ( fabs(fHeaderFadc->GetAmplitud()-fAmplitude) > 1.e-6 )
|
---|
195 | {
|
---|
196 | *fLog << err << "Parameters of MMcFadcHeader are not the same for all files... aborting." << endl;
|
---|
197 | return kFALSE;
|
---|
198 | }
|
---|
199 |
|
---|
200 | if (mcrunh->GetCamVersion() > 60) // old MC files, camera < v0.7
|
---|
201 | {
|
---|
202 | if( fabs(fHeaderFadc->GetAmplitudOuter()-fAmplitudeOuter) > 1.e-6 ||
|
---|
203 | fabs(fConversionHiLo-fHeaderFadc->GetLow2HighGain()) > 1.e-6 )
|
---|
204 | {
|
---|
205 | *fLog << err << "Parameters of MMcFadcHeader are not the same for all files... aborting." << endl;
|
---|
206 | return kFALSE;
|
---|
207 | }
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 |
|
---|
212 |
|
---|
213 | //
|
---|
214 | // If MCalibrationCam already existed in the parameter list before
|
---|
215 | // MMcCalibrationUpdate::PreProcess was executed (from a
|
---|
216 | // previous calibration loop) we must not fill it, hence nothing
|
---|
217 | // else has to be done in ReInit:
|
---|
218 | //
|
---|
219 | if (!fFillCalibrationCam)
|
---|
220 | return kTRUE;
|
---|
221 |
|
---|
222 | //
|
---|
223 | // Set the ADC to photons conversion factor for outer pixels.
|
---|
224 | // One can choose not to apply the known (in MC) gain factor between
|
---|
225 | // inner and outer pixels, (fOuterPixelsGainScaling = kFALSE),
|
---|
226 | // which may be useful for display purposes.
|
---|
227 | //
|
---|
228 |
|
---|
229 | if (fOuterPixelsGainScaling)
|
---|
230 | fADC2PhOuter = fADC2PhInner * (fAmplitude / fAmplitudeOuter);
|
---|
231 | else
|
---|
232 | fADC2PhOuter = fADC2PhInner;
|
---|
233 |
|
---|
234 |
|
---|
235 | const int num = fCalCam->GetSize();
|
---|
236 |
|
---|
237 | fCalCam->SetBlindPixelMethodValid(kTRUE);
|
---|
238 |
|
---|
239 | for (int i=0; i<num; i++)
|
---|
240 | {
|
---|
241 | MCalibrationChargePix &calpix = (*fCalCam)[i];
|
---|
242 |
|
---|
243 | calpix.SetBlindPixelMethodValid();
|
---|
244 | calpix.SetChargeValid();
|
---|
245 |
|
---|
246 | calpix.SetConversionHiLo(fConversionHiLo);
|
---|
247 | calpix.SetConversionHiLoErr(0.); // FIXME ?
|
---|
248 |
|
---|
249 | //
|
---|
250 | // Write conversion factor ADC to photons (different for inner
|
---|
251 | // and outer pixels).
|
---|
252 | //
|
---|
253 |
|
---|
254 | Float_t adc2phot = (fGeom->GetPixRatio(i) < fGeom->GetPixRatio(0))?
|
---|
255 | fADC2PhOuter : fADC2PhInner;
|
---|
256 |
|
---|
257 | calpix.SetConversionBlindPixelMethod(adc2phot, 0., 0.);
|
---|
258 | }
|
---|
259 |
|
---|
260 |
|
---|
261 | return kTRUE;
|
---|
262 | }
|
---|
263 |
|
---|
264 |
|
---|
265 | // --------------------------------------------------------------------------
|
---|
266 | //
|
---|
267 | // Fill the MCerPhotPed object
|
---|
268 | //
|
---|
269 | Int_t MMcCalibrationUpdate::Process()
|
---|
270 | {
|
---|
271 | const int num = fCalCam->GetSize();
|
---|
272 |
|
---|
273 | for (int i=0; i<num; i++)
|
---|
274 | {
|
---|
275 | MExtractedSignalPix &sigpix = (*fSignalCam)[i];
|
---|
276 |
|
---|
277 | //
|
---|
278 | // ped mean and rms per pixel, in ADC counts, according to signal
|
---|
279 | // calculation (hi or low gain and number of integrated slices):
|
---|
280 | //
|
---|
281 | const Float_t pedestmean = sigpix.IsLoGainUsed()?
|
---|
282 | fSignalCam->GetNumUsedLoGainFADCSlices()*fHeaderFadc->GetPedestal(i) :
|
---|
283 | fSignalCam->GetNumUsedHiGainFADCSlices()*fHeaderFadc->GetPedestal(i);
|
---|
284 |
|
---|
285 | //
|
---|
286 | // In some cases, depending on the camera simulation parameters, one can
|
---|
287 | // have very little or no noise in the FADC. In the case the rms of
|
---|
288 | // pedestal is zero, the pixel will be cleaned out later in the image
|
---|
289 | // cleaning. To avoid this problem,we set a default value of 0.01 ADC
|
---|
290 | // counts for the RMS per slice:
|
---|
291 | //
|
---|
292 | const Double_t used = (Double_t)(sigpix.IsLoGainUsed() ?
|
---|
293 | fSignalCam->GetNumUsedLoGainFADCSlices() :
|
---|
294 | fSignalCam->GetNumUsedHiGainFADCSlices());
|
---|
295 |
|
---|
296 | const Float_t rms0 = sigpix.IsLoGainUsed() ?
|
---|
297 | fHeaderFadc->GetPedestalRmsLow(i) :
|
---|
298 | fHeaderFadc->GetPedestalRmsHigh(i);
|
---|
299 |
|
---|
300 | const Float_t pedestrms = TMath::Sqrt(used) * (rms0>0 ? rms0 : 0.01);
|
---|
301 |
|
---|
302 | //
|
---|
303 | // Write mean pedestal and pedestal rms per pixel
|
---|
304 | // in number of photons:
|
---|
305 | //
|
---|
306 | MPedPhotPix &pedpix = (*fPedPhotCam)[i];
|
---|
307 |
|
---|
308 | MCalibrationChargePix &calpix = (*fCalCam)[i];
|
---|
309 | Float_t adc2phot = calpix.GetMeanConversionBlindPixelMethod();
|
---|
310 | Float_t hi2lo = calpix.GetConversionHiLo();
|
---|
311 |
|
---|
312 | if (sigpix.IsLoGainUsed())
|
---|
313 | pedpix.Set(adc2phot*hi2lo*pedestmean, adc2phot*hi2lo*pedestrms);
|
---|
314 | else
|
---|
315 | pedpix.Set(adc2phot*pedestmean, adc2phot*pedestrms);
|
---|
316 |
|
---|
317 | }
|
---|
318 |
|
---|
319 | return kTRUE;
|
---|
320 | }
|
---|