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

Last change on this file since 3027 was 3007, checked in by gaug, 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//
122Bool_t MCalibrate::ReInit(MParList *pList)
123{
124
125 if(fCalibrationMode == kBlindPixel && !fCalibrations->IsBlindPixelMethodValid())
126 {
127 *fLog << warn << GetDescriptor() << "Warning: Blind pixel calibration method not valid, switching to F-factor method" << endl;
128 fCalibrationMode = kFfactor;
129 }
130
131 if(fCalibrationMode == kPinDiode && !fCalibrations->IsPINDiodeMethodValid())
132 {
133 *fLog << warn << GetDescriptor() << "Warning: PIN diode calibration method not valid, switching to F-factor method" << endl;
134 fCalibrationMode = kFfactor;
135 }
136
137 return kTRUE;
138}
139// --------------------------------------------------------------------------
140//
141// Apply the calibration factors to the extracted signal according to the
142// selected calibration method
143//
144Int_t MCalibrate::Process()
145{
146 /*
147 if (fCalibrations->GetNumPixels() != (UInt_t)fSignals->GetSize())
148 {
149 // FIXME: MExtractedSignal must be of variable size -
150 // like MCerPhotEvt - because we must be able
151 // to reduce size by zero supression
152 // For the moment this check could be done in ReInit...
153 *fLog << err << "MExtractedSignal and MCalibrationCam have different sizes... abort." << endl;
154 return kFALSE;
155 }
156 */
157
158 UInt_t npix = fSignals->GetSize();
159
160 Float_t hiloconv = 1.;
161 Float_t hiloconverr= 0.;
162 Float_t calibrationConversionFactor = 1.;
163 Float_t calibrationConversionFactorError = 0.;
164
165 for (UInt_t pixidx=0; pixidx<npix; pixidx++)
166 {
167 if(fCalibrationMode!=kNone)
168 {
169 const MCalibrationPix &pix = (*fCalibrations)[pixidx];
170
171 if (!pix.IsChargeFitValid())
172 continue;
173
174 hiloconv = pix.GetConversionHiLo();
175 hiloconverr= pix.GetConversionHiLoError();
176
177 switch(fCalibrationMode)
178 {
179 case kBlindPixel:
180 calibrationConversionFactor = pix.GetMeanConversionBlindPixelMethod();
181 calibrationConversionFactorError = pix.GetErrorConversionBlindPixelMethod();
182 break;
183 case kFfactor:
184 calibrationConversionFactor = pix.GetMeanConversionFFactorMethod();
185 calibrationConversionFactorError = pix.GetErrorConversionFFactorMethod();
186 break;
187 default:
188 *fLog << warn << "MCalibrate::Process Warning: Calibration mode value ("<<fCalibrationMode<<") not known" << endl;
189 break;
190 }
191 }
192
193 MExtractedSignalPix &sig = (*fSignals)[pixidx];
194
195 Float_t signal;
196 Float_t signalErr = 0.;
197 Float_t nphot,nphotErr;
198
199 if (sig.IsLoGainUsed())
200 {
201 signal = sig.GetExtractedSignalLoGain()*hiloconv;
202 signalErr = signal*hiloconverr;
203 }
204 else
205 {
206 if (sig.GetExtractedSignalHiGain() > 9999.)
207 {
208 signal = 0.;
209 signalErr = 0.;
210 }
211 else
212 signal = sig.GetExtractedSignalHiGain();
213 }
214
215 nphot = signal*calibrationConversionFactor;
216 nphotErr = signal*calibrationConversionFactorError
217 *signal*calibrationConversionFactorError
218 +signalErr*calibrationConversionFactor
219 *signalErr*calibrationConversionFactor;
220
221 nphotErr = TMath::Sqrt(nphotErr);
222
223 MCerPhotPix *cpix = fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
224
225 if (sig.GetNumLoGainSaturated() > 0)
226 cpix->SetPixelSaturated();
227 }
228
229 fCerPhotEvt->FixSize();
230 fCerPhotEvt->SetReadyToSave();
231
232 return kTRUE;
233}
Note: See TracBrowser for help on using the repository browser.