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

Last change on this file since 2945 was 2945, checked in by rico, 21 years ago
*** empty log message ***
File size: 6.8 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! Modified by: 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// MCalibrationCam
38//
39// Output Containers:
40// MCerPhotEvt
41//
42//////////////////////////////////////////////////////////////////////////////
43#include "MCalibrate.h"
44#include "MCalibrationConfig.h"
45
46#include "MLog.h"
47#include "MLogManip.h"
48
49#include "MParList.h"
50#include "MH.h"
51
52#include "MGeomCam.h"
53
54#include "MCalibrationCam.h"
55#include "MCalibrationPix.h"
56
57#include "MExtractedSignalCam.h"
58#include "MExtractedSignalPix.h"
59
60#include "MCerPhotEvt.h"
61
62ClassImp(MCalibrate);
63
64using namespace std;
65// --------------------------------------------------------------------------
66//
67// Default constructor.
68//
69MCalibrate::MCalibrate(CalibrationMode_t calmode,const char *name, const char *title) : fCalibrationMode(calmode)
70{
71 fName = name ? name : "MCalibrate";
72 fTitle = title ? title : "Task to calculate the number of photons in one event";
73}
74
75// --------------------------------------------------------------------------
76//
77// The PreProcess searches for the following input containers:
78// - MGeomCam
79// - MCalibrationCam
80// - MExtractedSignalCam
81//
82// The following output containers are also searched and created if
83// they were not found:
84//
85// - MCerPhotEvt
86//
87Int_t MCalibrate::PreProcess(MParList *pList)
88{
89
90 fSignals = (MExtractedSignalCam*)pList->FindObject(AddSerialNumber("MExtractedSignalCam"));
91
92 if (!fSignals)
93 {
94 *fLog << err << AddSerialNumber("MExtractedSignalCam") << " not found ... aborting" << endl;
95 return kFALSE;
96 }
97
98 if(fCalibrationMode>kNone)
99 {
100
101 fCalibrations = (MCalibrationCam*)pList->FindObject(AddSerialNumber("MCalibrationCam"));
102 if (!fCalibrations)
103 {
104 *fLog << err << AddSerialNumber("MCalibrationCam") << " not found ... aborting." << endl;
105 return kFALSE;
106 }
107
108 }
109
110 fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj(AddSerialNumber("MCerPhotEvt"));
111 if (!fCerPhotEvt)
112 return kFALSE;
113
114 return kTRUE;
115}
116
117// --------------------------------------------------------------------------
118//
119// Check for validity of the selected calibration method, switch to a
120// different one in case of need
121//
122Int_t MCalibrate::ReInit()
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 return kTRUE;
136}
137// --------------------------------------------------------------------------
138//
139// Apply the calibration factors to the extracted signal according to the
140// selected calibration method
141//
142Int_t MCalibrate::Process()
143{
144 /*
145 if (fCalibrations->GetNumPixels() != (UInt_t)fSignals->GetSize())
146 {
147 // FIXME: MExtractedSignal must be of variable size -
148 // like MCerPhotEvt - because we must be able
149 // to reduce size by zero supression
150 // For the moment this check could be done in ReInit...
151 *fLog << err << "MExtractedSignal and MCalibrationCam have different sizes... abort." << endl;
152 return kFALSE;
153 }
154 */
155
156 UInt_t npix = fSignals->GetSize();
157
158 Float_t hiloconv = 1.;
159 Float_t hiloconverr= 0.;
160 Float_t calibrationConversionFactor = 1.;
161 Float_t calibrationConversionFactorError = 0.;
162
163 for (UInt_t pixidx=0; pixidx<npix; pixidx++)
164 {
165 if(fCalibrationMode!=kNone)
166 {
167 const MCalibrationPix &pix = (*fCalibrations)[pixidx];
168
169 if (!pix.IsFitValid())
170 continue;
171
172 hiloconv = pix.GetConversionHiLo();
173 hiloconverr= pix.GetConversionHiLoError();
174
175 switch(fCalibrationMode)
176 {
177 case kBlindPixel:
178 calibrationConversionFactor = pix.GetMeanConversionBlindPixelMethod();
179 calibrationConversionFactorError = pix.GetErrorConversionBlindPixelMethod();
180 break;
181 case kFfactor:
182 calibrationConversionFactor = pix.GetMeanConversionFFactorMethod();
183 calibrationConversionFactorError = pix.GetErrorConversionFFactorMethod();
184 break;
185 default:
186 *fLog << warn << "MCalibrate::Process Warning: Calibration mode value ("<<fCalibrationMode<<") not known" << endl;
187 break;
188 }
189 }
190
191 MExtractedSignalPix &sig = (*fSignals)[pixidx];
192
193 Float_t signal;
194 Float_t signalErr = 0.;
195 Float_t nphot,nphotErr;
196
197 if (sig.IsLoGainUsed())
198 {
199 signal = sig.GetExtractedSignalLoGain()*hiloconv;
200 signalErr = signal*hiloconverr;
201 }
202 else
203 {
204 if (sig.GetExtractedSignalHiGain() > 9999.)
205 {
206 signal = 0.;
207 signalErr = 0.;
208 }
209 else
210 signal = sig.GetExtractedSignalHiGain();
211 }
212
213 nphot = signal*calibrationConversionFactor;
214 nphotErr = signal*calibrationConversionFactorError
215 *signal*calibrationConversionFactorError
216 +signalErr*calibrationConversionFactor
217 *signalErr*calibrationConversionFactor;
218
219 nphotErr = TMath::Sqrt(nphotErr);
220
221 MCerPhotPix *cpix = fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
222
223 if (sig.GetNumLoGainSaturated() > 0)
224 cpix->SetPixelSaturated();
225 }
226
227 fCerPhotEvt->FixSize();
228 fCerPhotEvt->SetReadyToSave();
229
230 return kTRUE;
231}
Note: See TracBrowser for help on using the repository browser.