source: trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc@ 3768

Last change on this file since 3768 was 3768, checked in by moralejo, 20 years ago
*** empty log message ***
File size: 8.1 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-2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MMcCalibrationCalc
28//
29// Input Containers:
30// MRawRunHeader
31// MMcFadcHeader
32// MHillas
33// MNewImagePar
34// MMcEvt
35//
36// Output Containers:
37// (containers mus exist already, they are filled with new values).
38// MCalibrationChargeCam
39// MCalibrationQECam
40//
41/////////////////////////////////////////////////////////////////////////////
42#include "MMcCalibrationCalc.h"
43
44#include <TH1.h>
45
46#include "MLog.h"
47#include "MLogManip.h"
48
49#include "MParList.h"
50
51#include "MCalibrationChargePix.h"
52#include "MCalibrationChargeCam.h"
53
54#include "MCalibrationQEPix.h"
55#include "MCalibrationQECam.h"
56
57#include "MGeomCam.h"
58#include "MRawRunHeader.h"
59
60#include "MHillas.h"
61#include "MNewImagePar.h"
62
63#include "MMcEvt.hxx"
64#include "MMcFadcHeader.hxx"
65
66ClassImp(MMcCalibrationCalc);
67
68using namespace std;
69
70MMcCalibrationCalc::MMcCalibrationCalc(const char *name, const char *title)
71{
72 fName = name ? name : "MMcCalibrationCalc";
73 fTitle = title ? title : "Calculate and write conversion factors into MCalibrationChargeCam and MCalibrationQECam containers";
74
75 fHistRatio = new TH1F(AddSerialNumber("HistRatio"), "log10(fPhotElfromShower/fSize)", 1500, -3., 3.);
76 fHistRatio->SetXTitle("log_{10}(fPhotElfromShower / fSize) [photel/ADC count]");
77}
78
79// --------------------------------------------------------------------------
80//
81// Check for the run type. Return kTRUE if it is a MC run or if there
82// is no MC run header (old camera files) kFALSE in case of a different
83// run type
84//
85Bool_t MMcCalibrationCalc::CheckRunType(MParList *pList) const
86{
87 const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
88 if (!run)
89 {
90 *fLog << warn << "Warning - cannot check file type, MRawRunHeader not found." << endl;
91 return kTRUE;
92 }
93
94 return run->IsMonteCarloRun();
95}
96
97// --------------------------------------------------------------------------
98//
99// Make sure, that there is an MCalibrationCam Object in the Parameter List.
100//
101Int_t MMcCalibrationCalc::PreProcess(MParList *pList)
102{
103 fHistRatio->Reset();
104 fADC2PhotEl = 0;
105 fPhot2PhotEl = 0;
106
107 fCalCam = (MCalibrationChargeCam*) pList->FindObject(AddSerialNumber("MCalibrationChargeCam"));
108 if (!fCalCam)
109 {
110 *fLog << err << AddSerialNumber("MCalibrationChargeCam") << "not found... aborting." << endl;
111 return kFALSE;
112 }
113
114 fQECam = (MCalibrationQECam*) pList->FindObject(AddSerialNumber("MCalibrationQECam"));
115 if (!fQECam)
116 {
117 *fLog << err << AddSerialNumber("MCalibrationQECam") << "not found... aborting." << endl;
118 return kFALSE;
119 }
120
121 fHillas = (MHillas*) pList->FindObject(AddSerialNumber("MHillas"));
122 if ( !fHillas)
123 {
124 *fLog << err << AddSerialNumber("MHillas") << "not found... aborting." << endl;
125 return kFALSE;
126 }
127
128 fNew = (MNewImagePar*)pList->FindObject(AddSerialNumber("MNewImagePar"));
129 if (!fNew)
130 {
131 *fLog << err << AddSerialNumber("MNewImagePar") << "not found... aborting." << endl;
132 return kFALSE;
133 }
134
135 fMcEvt = (MMcEvt*) pList->FindObject(AddSerialNumber("MMcEvt"));
136 if (!fMcEvt)
137 {
138 *fLog << err << AddSerialNumber("MMcEvt") << "not found... aborting." << endl;
139 return kFALSE;
140 }
141
142 return kTRUE;
143}
144
145// --------------------------------------------------------------------------
146//
147// Check for the runtype.
148// Search for MGeomCam and MMcFadcHeader.
149//
150Bool_t MMcCalibrationCalc::ReInit(MParList *pList)
151{
152 //
153 // If it is no MC file display error and exit
154 //
155 if (!CheckRunType(pList))
156 {
157 *fLog << err << "MMcCalibrationCalc can only be used with MC files... aborting." << endl;
158 return kFALSE;
159 }
160
161 //
162 // Now check the existence of all necessary containers.
163 //
164 fGeom = (MGeomCam*) pList->FindObject(AddSerialNumber("MGeomCam"));
165 if (!fGeom)
166 {
167 *fLog << err << AddSerialNumber("MGeomCam") << " not found... aborting." << endl;
168 return kFALSE;
169 }
170
171 fHeaderFadc = (MMcFadcHeader*)pList->FindObject(AddSerialNumber("MMcFadcHeader"));
172 if (!fHeaderFadc)
173 {
174 *fLog << err << AddSerialNumber("MMcFadcHeader") << " not found... aborting." << endl;
175 return kFALSE;
176 }
177
178 for (UInt_t ipix = 0; ipix < fGeom->GetNumPixels(); ipix++)
179 {
180 if (fHeaderFadc->GetPedestalRmsHigh(ipix) > 0 ||
181 fHeaderFadc->GetPedestalRmsLow(ipix) > 0 )
182 {
183 *fLog << err << "Trying to calibrate the data using a Camera file produced with added noise." << endl;
184 *fLog << "Please use a noiseless file for calibration... aborting." << endl << endl;
185 return kFALSE;
186 }
187 }
188
189 return kTRUE;
190}
191
192
193// --------------------------------------------------------------------------
194//
195// Obtain average ratio of photons in camera to image Size.
196//
197Int_t MMcCalibrationCalc::Process()
198{
199 //
200 // Exclude events with some saturated pixel
201 //
202 if (fNew->GetNumSaturatedPixels()>0)
203 return kTRUE;
204
205 //
206 // Exclude events with low Size (larger fluctuations)
207 // FIXME? The present cut (1000 "inner-pixel-counts") is somehow
208 // arbitrary. Might it be optimized?
209 //
210
211 const Float_t size = fHillas->GetSize();
212 // Size will at this point be in ADC counts (still uncalibrated)
213
214 if (size < 1000)
215 return kTRUE;
216
217 fPhot2PhotEl += (Float_t) fMcEvt->GetPhotElfromShower() /
218 (Float_t) fMcEvt->GetPassPhotCone();
219
220 fHistRatio->Fill(TMath::Log10(fMcEvt->GetPhotElfromShower()/size));
221
222 return kTRUE;
223}
224
225// --------------------------------------------------------------------------
226//
227// Fill the MCalibrationCam object
228//
229Int_t MMcCalibrationCalc::PostProcess()
230{
231 const Stat_t n = fHistRatio->GetEntries();
232 if (n<1)
233 {
234 *fLog << err << "No events read... aborting." << endl;
235 return kFALSE;
236 }
237
238 fPhot2PhotEl /= n; // Average quantum efficiency
239
240 //
241 // Find peak of log10(photel/Size) histogram:
242 //
243 const Int_t reach = 2;
244 Stat_t summax = 0;
245 Int_t mode = 0;
246 for (Int_t ibin = 1+reach; ibin <= fHistRatio->GetNbinsX()-reach; ibin++)
247 {
248 const Stat_t sum = fHistRatio->Integral(ibin-reach, ibin+reach);
249
250 if (sum <= summax)
251 continue;
252
253 summax = sum;
254 mode = ibin;
255 }
256
257 fADC2PhotEl = TMath::Power(10, fHistRatio->GetBinCenter(mode));
258
259 const Int_t num = fCalCam->GetSize();
260
261 for (int i=0; i<num; i++)
262 {
263 MCalibrationChargePix &calpix = (MCalibrationChargePix&)(*fCalCam)[i];
264 MCalibrationQEPix &qepix = (MCalibrationQEPix&) (*fQECam) [i];
265
266 qepix.SetAverageQE(fPhot2PhotEl);
267
268 qepix.SetAvNormFFactor(1.);
269 // This factor should convert the default average QE for different colors to
270 // average QE for a spectrum like that of Cherenkov light (see the documentration
271 // of MCalibrationQEPix).
272 // Here we obtain average QE using already a Cherenkov spectrum so AvNormFFacto
273 // must be 1.
274
275
276 Float_t factor = fADC2PhotEl;
277
278 //
279 // We take into account the (possibly) different gain of outer pixels:
280 //
281 if (fGeom->GetPixRatio(i) < 1.)
282 factor *= fHeaderFadc->GetAmplitud()/fHeaderFadc->GetAmplitudOuter();
283
284 calpix.SetMeanConvFADC2Phe(factor);
285 calpix.SetMeanConvFADC2PheVar(0.);
286
287 calpix.SetMeanFFactorFADC2Phot(0.);
288 }
289
290 return kTRUE;
291}
Note: See TracBrowser for help on using the repository browser.