source: trunk/MagicSoft/Mars/mcalib/MCalibrate.cc@ 3279

Last change on this file since 3279 was 3279, checked in by gaug, 21 years ago
*** empty log message ***
File size: 8.4 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): 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
61ClassImp(MCalibrate);
62
63using namespace std;
64// --------------------------------------------------------------------------
65//
66// Default constructor.
67//
68MCalibrate::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//
86Int_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//
121Bool_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//
170Int_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 = 0.;
187 Float_t hiloconverr = 0.;
188 Float_t calibrationConversionFactor = 0.;
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 switch(fCalibrationMode)
201 {
202 case kBlindPixel:
203 if (pix.IsBlindPixelMethodValid())
204 {
205 calibrationConversionFactor = pix.GetMeanConversionBlindPixelMethod();
206 calibrationConversionFactorErr = pix.GetConversionBlindPixelMethodErr();
207 }
208 else
209 continue;
210 break;
211 case kPinDiode:
212 if (pix.IsPINDiodeMethodValid())
213 {
214 calibrationConversionFactor = pix.GetMeanConversionPINDiodeMethod();
215 calibrationConversionFactorErr = pix.GetConversionPINDiodeMethodErr();
216 }
217 else
218 continue;
219 break;
220 case kFfactor:
221 if (pix.IsFFactorMethodValid())
222 {
223 calibrationConversionFactor = pix.GetMeanConversionFFactorMethod();
224 calibrationConversionFactorErr = pix.GetConversionFFactorMethodErr();
225 }
226 else
227 continue;
228 break;
229 case kCombined:
230 if (pix.IsCombinedMethodValid())
231 {
232 calibrationConversionFactor = pix.GetMeanConversionCombinedMethod();
233 calibrationConversionFactorErr = pix.GetConversionCombinedMethodErr();
234 }
235 else
236 continue;
237 break;
238 case kDummy:
239 hiloconv = 1.;
240 hiloconverr = 0.;
241 calibrationConversionFactor = 1.;
242 calibrationConversionFactorErr = 0.;
243 break;
244
245 } /* switch calibration mode */
246
247 hiloconv = pix.GetConversionHiLo();
248 hiloconverr= pix.GetConversionHiLoErr();
249
250 } /* if(fCalibrationMode!=kNone) */
251
252 MExtractedSignalPix &sig = (*fSignals)[pixidx];
253
254 Float_t signal;
255 Float_t signalErr = 0.;
256 Float_t nphot,nphotErr;
257
258 if (sig.IsLoGainUsed())
259 {
260 signal = sig.GetExtractedSignalLoGain()*hiloconv;
261 signalErr = signal*hiloconverr;
262 }
263 else
264 {
265 if (sig.GetExtractedSignalHiGain() > 9999.)
266 {
267 signal = 0.;
268 signalErr = 0.;
269 }
270 else
271 signal = sig.GetExtractedSignalHiGain();
272 }
273
274 nphot = signal*calibrationConversionFactor;
275 nphotErr = signal*calibrationConversionFactorErr
276 *signal*calibrationConversionFactorErr
277 + signalErr*calibrationConversionFactor
278 *signalErr*calibrationConversionFactor;
279
280 nphotErr = TMath::Sqrt(nphotErr);
281
282 MCerPhotPix *cpix = fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
283
284 if (sig.GetNumLoGainSaturated() > 0)
285 cpix->SetPixelSaturated();
286
287 } /* for (UInt_t pixidx=0; pixidx<npix; pixidx++) */
288
289 fCerPhotEvt->FixSize();
290 fCerPhotEvt->SetReadyToSave();
291
292 return kTRUE;
293}
Note: See TracBrowser for help on using the repository browser.