source: trunk/MagicSoft/Mars/manalysis/MMcCalibrationUpdate.cc@ 3394

Last change on this file since 3394 was 3374, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 9.0 KB
Line 
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
66ClassImp(MMcCalibrationUpdate);
67
68using namespace std;
69
70MMcCalibrationUpdate::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 fOuterPixelsGainScaling = kTRUE;
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//
92Bool_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->IsMonteCarloRun();
102}
103
104// --------------------------------------------------------------------------
105//
106// Make sure, that there is an MCalibrationCam Object in the Parameter List.
107//
108Int_t MMcCalibrationUpdate::PreProcess(MParList *pList)
109{
110 fCalCam = (MCalibrationChargeCam*) pList->FindObject(AddSerialNumber("MCalibrationChargeCam"));
111 if (!fCalCam)
112 {
113 fCalCam = (MCalibrationChargeCam*) pList->FindCreateObj(AddSerialNumber("MCalibrationChargeCam"));
114 if (!fCalCam)
115 return kFALSE;
116 }
117 else
118 {
119 fFillCalibrationCam = kFALSE;
120 *fLog << inf << AddSerialNumber("MCalibrationChargeCam") << " already exists... " << endl;
121 }
122
123 fPedPhotCam = (MPedPhotCam*) pList->FindCreateObj(AddSerialNumber("MPedPhotCam"));
124 if (!fPedPhotCam)
125 return kFALSE;
126
127 fSignalCam = (MExtractedSignalCam*) pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
128 if (!fSignalCam)
129 {
130 *fLog << err << AddSerialNumber("MExtractedSignalCam") << " not found... aborting." << endl;
131 return kFALSE;
132 }
133
134 return kTRUE;
135}
136
137// --------------------------------------------------------------------------
138//
139// Check for the runtype.
140// Search for MGeomCam and MMcFadcHeader.
141// Fill the MCalibrationCam object.
142//
143Bool_t MMcCalibrationUpdate::ReInit(MParList *pList)
144{
145 //
146 // If it is no MC file skip this function...
147 //
148 if (!CheckRunType(pList))
149 {
150 *fLog << inf << "This is no MC file... skipping." << endl;
151 return kTRUE;
152 }
153
154 //
155 // Now check the existence of all necessary containers.
156 //
157 fGeom = (MGeomCam*) pList->FindObject(AddSerialNumber("MGeomCam"));
158 if (!fGeom)
159 {
160 *fLog << err << AddSerialNumber("MGeomCam") << " not found... aborting." << endl;
161 return kFALSE;
162 }
163
164 fHeaderFadc = (MMcFadcHeader*)pList->FindObject(AddSerialNumber("MMcFadcHeader"));
165 if (!fHeaderFadc)
166 {
167 *fLog << err << AddSerialNumber("MMcFadcHeader") << " not found... aborting." << endl;
168 return kFALSE;
169 }
170
171 //
172 // Initialize Fadc simulation parameters:
173 //
174 if (fAmplitude < 0)
175 {
176 fAmplitude = fHeaderFadc->GetAmplitud();
177 fAmplitudeOuter = fHeaderFadc->GetAmplitudOuter();
178 fConversionHiLo = fHeaderFadc->GetLow2HighGain();
179 }
180 else // Check that following files have all the same FADC parameters
181 {
182 if ( fabs(fHeaderFadc->GetAmplitud()-fAmplitude) > 1.e-6 ||
183 fabs(fHeaderFadc->GetAmplitudOuter()-fAmplitudeOuter) > 1.e-6 ||
184 fabs(fConversionHiLo-fHeaderFadc->GetLow2HighGain()) > 1.e-6 )
185 {
186 *fLog << err << "Parameters of MMcFadcHeader are not the same for all files... aborting." << endl;
187 return kFALSE;
188 }
189 }
190
191 //
192 // If MCalibrationCam already existed in the parameter list before
193 // MMcCalibrationUpdate::PreProcess was executed (from a
194 // previous calibration loop) we must not fill it, hence nothing
195 // else has to be done in ReInit:
196 //
197 if (!fFillCalibrationCam)
198 return kTRUE;
199
200 //
201 // Set the ADC to photons conversion factor for outer pixels.
202 // One can choose not to apply the known (in MC) gain factor between
203 // inner and outer pixels, (fOuterPixelsGainScaling = kFALSE),
204 // which may be useful for display purposes.
205 //
206
207 if (fOuterPixelsGainScaling)
208 fADC2PhOuter = fADC2PhInner * (fAmplitude / fAmplitudeOuter);
209 else
210 fADC2PhOuter = fADC2PhInner;
211
212
213 const int num = fCalCam->GetSize();
214
215 fCalCam->SetBlindPixelMethodValid(kTRUE);
216
217 for (int i=0; i<num; i++)
218 {
219 MCalibrationChargePix &calpix = (*fCalCam)[i];
220
221 calpix.SetBlindPixelMethodValid();
222 calpix.SetChargeValid();
223
224 calpix.SetConversionHiLo(fConversionHiLo);
225 calpix.SetConversionHiLoErr(0.); // FIXME ?
226
227 //
228 // Write conversion factor ADC to photons (different for inner
229 // and outer pixels).
230 //
231
232 Float_t adc2phot = (fGeom->GetPixRatio(i) < fGeom->GetPixRatio(0))?
233 fADC2PhOuter : fADC2PhInner;
234
235 calpix.SetConversionBlindPixelMethod(adc2phot, 0., 0.);
236 }
237
238
239 return kTRUE;
240}
241
242
243// --------------------------------------------------------------------------
244//
245// Fill the MCerPhotPed object
246//
247Int_t MMcCalibrationUpdate::Process()
248{
249 const int num = fCalCam->GetSize();
250
251 for (int i=0; i<num; i++)
252 {
253 MExtractedSignalPix &sigpix = (*fSignalCam)[i];
254
255 //
256 // ped mean and rms per pixel, in ADC counts, according to signal
257 // calculation (hi or low gain and number of integrated slices):
258 //
259 const Float_t pedestmean = sigpix.IsLoGainUsed()?
260 fSignalCam->GetNumUsedLoGainFADCSlices()*fHeaderFadc->GetPedestal(i) :
261 fSignalCam->GetNumUsedHiGainFADCSlices()*fHeaderFadc->GetPedestal(i);
262
263 //
264 // In some cases, depending on the camera simulation parameters, one can
265 // have very little or no noise in the FADC. In the case the rms of
266 // pedestal is zero, the pixel will be cleaned out later in the image
267 // cleaning. To avoid this problem,we set a default value of 0.01 ADC
268 // counts for the RMS per slice:
269 //
270 const Double_t used = (Double_t)(sigpix.IsLoGainUsed() ?
271 fSignalCam->GetNumUsedLoGainFADCSlices() :
272 fSignalCam->GetNumUsedHiGainFADCSlices());
273
274 const Float_t rms0 = sigpix.IsLoGainUsed() ?
275 fHeaderFadc->GetPedestalRmsLow(i) :
276 fHeaderFadc->GetPedestalRmsHigh(i);
277
278 const Float_t pedestrms = TMath::Sqrt(used) * (rms0>0 ? rms0 : 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, adc2phot*hi2lo*pedestrms);
292 else
293 pedpix.Set(adc2phot*pedestmean, adc2phot*pedestrms);
294
295 }
296
297 return kTRUE;
298}
Note: See TracBrowser for help on using the repository browser.