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 "MMcFadcHeader.hxx"
|
---|
65 |
|
---|
66 | ClassImp(MMcCalibrationUpdate);
|
---|
67 |
|
---|
68 | using namespace std;
|
---|
69 |
|
---|
70 | MMcCalibrationUpdate::MMcCalibrationUpdate(const char *name, const char *title)
|
---|
71 | {
|
---|
72 | fName = name ? name : "MMcCalibrationUpdate";
|
---|
73 | fTitle = title ? title : "Write MC pedestals and conversion factors into MCalibration Container";
|
---|
74 |
|
---|
75 | fADC2PhInner = 1.;
|
---|
76 | fADC2PhOuter = 1.;
|
---|
77 |
|
---|
78 | fAmplitude = -1.;
|
---|
79 | fAmplitudeOuter = -1.;
|
---|
80 | fConversionHiLo = -1.;
|
---|
81 |
|
---|
82 | fFillCalibrationCam = kTRUE;
|
---|
83 |
|
---|
84 | }
|
---|
85 |
|
---|
86 | // --------------------------------------------------------------------------
|
---|
87 | //
|
---|
88 | // Check for the run type. Return kTRUE if it is a MC run or if there
|
---|
89 | // is no MC run header (old camera files) kFALSE in case of a different
|
---|
90 | // run type
|
---|
91 | //
|
---|
92 | Bool_t MMcCalibrationUpdate::CheckRunType(MParList *pList) const
|
---|
93 | {
|
---|
94 | const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
95 | if (!run)
|
---|
96 | {
|
---|
97 | *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
|
---|
98 | return kTRUE;
|
---|
99 | }
|
---|
100 |
|
---|
101 | return run->GetRunType() == kRTMonteCarlo;
|
---|
102 | }
|
---|
103 |
|
---|
104 | // --------------------------------------------------------------------------
|
---|
105 | //
|
---|
106 | // Make sure, that there is an MCalibrationCam Object in the Parameter List.
|
---|
107 | //
|
---|
108 | Int_t MMcCalibrationUpdate::PreProcess(MParList *pList)
|
---|
109 | {
|
---|
110 | fCalCam = (MCalibrationChargeCam*) pList->FindObject(AddSerialNumber("MCalibrationChargeCam"));
|
---|
111 | if ( !fCalCam )
|
---|
112 | {
|
---|
113 | *fLog << inf << dbginf << AddSerialNumber("MCalibrationChargeCam") << " does not exist... Creating." << endl;
|
---|
114 |
|
---|
115 | fCalCam = (MCalibrationChargeCam*) pList->FindCreateObj(AddSerialNumber("MCalibrationChargeCam"));
|
---|
116 | if ( !fCalCam )
|
---|
117 | {
|
---|
118 | *fLog << err << dbginf << "Cannot create " << AddSerialNumber("MCalibrationChargeCam") << "... aborting." << endl;
|
---|
119 | return kFALSE;
|
---|
120 | }
|
---|
121 | }
|
---|
122 | else
|
---|
123 | {
|
---|
124 | fFillCalibrationCam = kFALSE;
|
---|
125 | *fLog << inf << AddSerialNumber("MCalibrationChargeCam") << " already exists... " << endl;
|
---|
126 | }
|
---|
127 |
|
---|
128 | fPedPhotCam = (MPedPhotCam*) pList->FindCreateObj(AddSerialNumber("MPedPhotCam"));
|
---|
129 | if ( ! fPedPhotCam)
|
---|
130 | {
|
---|
131 | *fLog << err << dbginf << "Cannot create " << AddSerialNumber("MPedPhotCam") << "... aborting." << endl;
|
---|
132 | return kFALSE;
|
---|
133 | }
|
---|
134 |
|
---|
135 | fSignalCam = (MExtractedSignalCam*) pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
|
---|
136 | if ( ! fSignalCam)
|
---|
137 | {
|
---|
138 | *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MExtractedSignalCam") << "... aborting." << endl;
|
---|
139 | return kFALSE;
|
---|
140 | }
|
---|
141 |
|
---|
142 | return kTRUE;
|
---|
143 |
|
---|
144 | }
|
---|
145 |
|
---|
146 | // --------------------------------------------------------------------------
|
---|
147 | //
|
---|
148 | // Check for the runtype.
|
---|
149 | // Search for MGeomCam and MMcFadcHeader.
|
---|
150 | // Fill the MCalibrationCam object.
|
---|
151 | //
|
---|
152 | Bool_t MMcCalibrationUpdate::ReInit(MParList *pList)
|
---|
153 | {
|
---|
154 | //
|
---|
155 | // If it is no MC file skip this function...
|
---|
156 | //
|
---|
157 | if (!CheckRunType(pList))
|
---|
158 | {
|
---|
159 | *fLog << inf << "This is no MC file... skipping." << endl;
|
---|
160 | return kTRUE;
|
---|
161 | }
|
---|
162 |
|
---|
163 | //
|
---|
164 | // Now check the existence of all necessary containers.
|
---|
165 | //
|
---|
166 |
|
---|
167 | fGeom = (MGeomCam*) pList->FindObject(AddSerialNumber("MGeomCam"));
|
---|
168 | if ( ! fGeom )
|
---|
169 | {
|
---|
170 | *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MGeomCam") << "... aborting." << endl;
|
---|
171 | return kFALSE;
|
---|
172 | }
|
---|
173 |
|
---|
174 | fHeaderFadc = (MMcFadcHeader*)pList->FindObject(AddSerialNumber("MMcFadcHeader"));
|
---|
175 | if (!fHeaderFadc)
|
---|
176 | {
|
---|
177 | *fLog << err << dbginf << AddSerialNumber("MMcFadcHeader") << " not found... aborting." << endl;
|
---|
178 | return kFALSE;
|
---|
179 | }
|
---|
180 |
|
---|
181 | //
|
---|
182 | // Initialize Fadc simulation parameters:
|
---|
183 | //
|
---|
184 | if ( fAmplitude < 0. )
|
---|
185 | {
|
---|
186 | fAmplitude = fHeaderFadc->GetAmplitud();
|
---|
187 | fAmplitudeOuter = fHeaderFadc->GetAmplitudOuter();
|
---|
188 | fConversionHiLo = fHeaderFadc->GetLow2HighGain();
|
---|
189 | }
|
---|
190 | else // Check that following files have all the same FADC parameters
|
---|
191 | {
|
---|
192 | if ( fabs(fHeaderFadc->GetAmplitud()-fAmplitude) > 1.e-6 ||
|
---|
193 | fabs(fHeaderFadc->GetAmplitudOuter()-fAmplitudeOuter) > 1.e-6 ||
|
---|
194 | fabs(fConversionHiLo-fHeaderFadc->GetLow2HighGain()) > 1.e-6 )
|
---|
195 | {
|
---|
196 | *fLog << err << endl << endl << dbginf << "Parameters of MMcFadcHeader are not the same for all the read files. Aborting..." << endl << endl;
|
---|
197 | return kFALSE;
|
---|
198 | }
|
---|
199 | }
|
---|
200 |
|
---|
201 | //
|
---|
202 | // If MCalibrationCam already existed in the parameter list before
|
---|
203 | // MMcCalibrationUpdate::PreProcess was executed (from a
|
---|
204 | // previous calibration loop) we must not fill it, hence nothing
|
---|
205 | // else has to be done in ReInit:
|
---|
206 | //
|
---|
207 | if ( !fFillCalibrationCam )
|
---|
208 | return kTRUE;
|
---|
209 |
|
---|
210 | //
|
---|
211 | // Set the ADC to photons conversion factor for outer pixels:
|
---|
212 | //
|
---|
213 | fADC2PhOuter = fADC2PhInner * (fAmplitude / fAmplitudeOuter);
|
---|
214 |
|
---|
215 | const int num = fCalCam->GetSize();
|
---|
216 |
|
---|
217 | fCalCam->SetBlindPixelMethodValid(kTRUE);
|
---|
218 |
|
---|
219 | for (int i=0; i<num; i++)
|
---|
220 | {
|
---|
221 | MCalibrationChargePix &calpix = (*fCalCam)[i];
|
---|
222 |
|
---|
223 | calpix.SetBlindPixelMethodValid();
|
---|
224 | calpix.SetChargeValid();
|
---|
225 |
|
---|
226 | calpix.SetConversionHiLo(fConversionHiLo);
|
---|
227 | calpix.SetConversionHiLoErr(0.); // FIXME ?
|
---|
228 |
|
---|
229 | //
|
---|
230 | // Write conversion factor ADC to photons (different for inner
|
---|
231 | // and outer pixels).
|
---|
232 | //
|
---|
233 |
|
---|
234 | Float_t adc2phot = (fGeom->GetPixRatio(i) < fGeom->GetPixRatio(0))?
|
---|
235 | fADC2PhOuter : fADC2PhInner;
|
---|
236 |
|
---|
237 | calpix.SetConversionBlindPixelMethod(adc2phot, 0., 0.);
|
---|
238 | }
|
---|
239 |
|
---|
240 |
|
---|
241 | return kTRUE;
|
---|
242 | }
|
---|
243 |
|
---|
244 |
|
---|
245 | // --------------------------------------------------------------------------
|
---|
246 | //
|
---|
247 | // Fill the MCerPhotPed object
|
---|
248 | //
|
---|
249 | Int_t MMcCalibrationUpdate::Process()
|
---|
250 | {
|
---|
251 | const int num = fCalCam->GetSize();
|
---|
252 |
|
---|
253 | for (int i=0; i<num; i++)
|
---|
254 | {
|
---|
255 | MExtractedSignalPix &sigpix = (*fSignalCam)[i];
|
---|
256 |
|
---|
257 | //
|
---|
258 | // ped mean and rms per pixel, in ADC counts, according to signal
|
---|
259 | // calculation (hi or low gain and number of integrated slices):
|
---|
260 | //
|
---|
261 | const Float_t pedestmean = sigpix.IsLoGainUsed()?
|
---|
262 | fSignalCam->GetNumUsedLoGainFADCSlices()*fHeaderFadc->GetPedestal(i) :
|
---|
263 | fSignalCam->GetNumUsedHiGainFADCSlices()*fHeaderFadc->GetPedestal(i);
|
---|
264 |
|
---|
265 | //
|
---|
266 | // In some cases, depending on the camera simulation parameters, one can
|
---|
267 | // have very little or no noise in the FADC. In the case the rms of
|
---|
268 | // pedestal is zero, the pixel will be cleaned out later in the image
|
---|
269 | // cleaning. To avoid this problem,we set a default value of 0.01 ADC
|
---|
270 | // counts for the RMS per slice:
|
---|
271 | //
|
---|
272 |
|
---|
273 | const Float_t pedestrms = sigpix.IsLoGainUsed()?
|
---|
274 | sqrt((Double_t)(fSignalCam->GetNumUsedLoGainFADCSlices())) *
|
---|
275 | (fHeaderFadc->GetPedestalRmsLow(i)>0.? fHeaderFadc->GetPedestalRmsLow(i): 0.01)
|
---|
276 | :
|
---|
277 | sqrt((Double_t)(fSignalCam->GetNumUsedHiGainFADCSlices())) *
|
---|
278 | (fHeaderFadc->GetPedestalRmsHigh(i)>0.? fHeaderFadc->GetPedestalRmsHigh(i) : 0.01);
|
---|
279 |
|
---|
280 | //
|
---|
281 | // Write mean pedestal and pedestal rms per pixel
|
---|
282 | // in number of photons:
|
---|
283 | //
|
---|
284 | MPedPhotPix &pedpix = (*fPedPhotCam)[i];
|
---|
285 |
|
---|
286 | MCalibrationChargePix &calpix = (*fCalCam)[i];
|
---|
287 | Float_t adc2phot = calpix.GetMeanConversionBlindPixelMethod();
|
---|
288 | Float_t hi2lo = calpix.GetConversionHiLo();
|
---|
289 |
|
---|
290 | if (sigpix.IsLoGainUsed())
|
---|
291 | pedpix.Set(adc2phot*hi2lo*pedestmean,
|
---|
292 | adc2phot*hi2lo*pedestrms);
|
---|
293 | else
|
---|
294 | pedpix.Set(adc2phot*pedestmean, adc2phot*pedestrms);
|
---|
295 |
|
---|
296 | }
|
---|
297 |
|
---|
298 | return kTRUE;
|
---|
299 | }
|
---|