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 |
|
---|
245 | calpix.SetConversionHiLo(fConversionHiLo);
|
---|
246 | calpix.SetConversionHiLoErr(0.); // FIXME ?
|
---|
247 |
|
---|
248 | //
|
---|
249 | // Write conversion factor ADC to photons (different for inner
|
---|
250 | // and outer pixels).
|
---|
251 | //
|
---|
252 |
|
---|
253 | Float_t adc2phot = (fGeom->GetPixRatio(i) < fGeom->GetPixRatio(0))?
|
---|
254 | fADC2PhOuter : fADC2PhInner;
|
---|
255 |
|
---|
256 | calpix.SetConversionBlindPixelMethod(adc2phot, 0., 0.);
|
---|
257 | }
|
---|
258 |
|
---|
259 |
|
---|
260 | return kTRUE;
|
---|
261 | }
|
---|
262 |
|
---|
263 |
|
---|
264 | // --------------------------------------------------------------------------
|
---|
265 | //
|
---|
266 | // Fill the MCerPhotPed object
|
---|
267 | //
|
---|
268 | Int_t MMcCalibrationUpdate::Process()
|
---|
269 | {
|
---|
270 | const int num = fCalCam->GetSize();
|
---|
271 |
|
---|
272 | for (int i=0; i<num; i++)
|
---|
273 | {
|
---|
274 | MExtractedSignalPix &sigpix = (*fSignalCam)[i];
|
---|
275 |
|
---|
276 | //
|
---|
277 | // ped mean and rms per pixel, in ADC counts, according to signal
|
---|
278 | // calculation (hi or low gain and number of integrated slices):
|
---|
279 | //
|
---|
280 | const Float_t pedestmean = sigpix.IsLoGainUsed()?
|
---|
281 | fSignalCam->GetNumUsedLoGainFADCSlices()*fHeaderFadc->GetPedestal(i) :
|
---|
282 | fSignalCam->GetNumUsedHiGainFADCSlices()*fHeaderFadc->GetPedestal(i);
|
---|
283 |
|
---|
284 | //
|
---|
285 | // In some cases, depending on the camera simulation parameters, one can
|
---|
286 | // have very little or no noise in the FADC. In the case the rms of
|
---|
287 | // pedestal is zero, the pixel will be cleaned out later in the image
|
---|
288 | // cleaning. To avoid this problem,we set a default value of 0.01 ADC
|
---|
289 | // counts for the RMS per slice:
|
---|
290 | //
|
---|
291 | const Double_t used = (Double_t)(sigpix.IsLoGainUsed() ?
|
---|
292 | fSignalCam->GetNumUsedLoGainFADCSlices() :
|
---|
293 | fSignalCam->GetNumUsedHiGainFADCSlices());
|
---|
294 |
|
---|
295 | const Float_t rms0 = sigpix.IsLoGainUsed() ?
|
---|
296 | fHeaderFadc->GetPedestalRmsLow(i) :
|
---|
297 | fHeaderFadc->GetPedestalRmsHigh(i);
|
---|
298 |
|
---|
299 | const Float_t pedestrms = TMath::Sqrt(used) * (rms0>0 ? rms0 : 0.01);
|
---|
300 |
|
---|
301 | //
|
---|
302 | // Write mean pedestal and pedestal rms per pixel
|
---|
303 | // in number of photons:
|
---|
304 | //
|
---|
305 | MPedPhotPix &pedpix = (*fPedPhotCam)[i];
|
---|
306 |
|
---|
307 | MCalibrationChargePix &calpix = (*fCalCam)[i];
|
---|
308 | Float_t adc2phot = calpix.GetMeanConversionBlindPixelMethod();
|
---|
309 | Float_t hi2lo = calpix.GetConversionHiLo();
|
---|
310 |
|
---|
311 | if (sigpix.IsLoGainUsed())
|
---|
312 | pedpix.Set(adc2phot*hi2lo*pedestmean, adc2phot*hi2lo*pedestrms);
|
---|
313 | else
|
---|
314 | pedpix.Set(adc2phot*pedestmean, adc2phot*pedestrms);
|
---|
315 |
|
---|
316 | }
|
---|
317 |
|
---|
318 | return kTRUE;
|
---|
319 | }
|
---|