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

Last change on this file since 2887 was 2886, checked in by moralejo, 21 years ago
*** empty log message ***
File size: 6.9 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// MMcCalibrationCalc
28//
29// Input Containers:
30// MRawRunHeader
31// MMcFadcHeader
32// MHillas
33// MNewImagePar
34// MMcEvt
35//
36// Output Containers:
37// MCalibrationCam
38//
39/////////////////////////////////////////////////////////////////////////////
40#include "MMcCalibrationCalc.h"
41
42#include <TH1.h>
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47#include "MParList.h"
48
49#include "MCalibrationPix.h"
50#include "MCalibrationCam.h"
51
52#include "MGeomCam.h"
53#include "MRawRunHeader.h"
54
55#include "MHillas.h"
56#include "MNewImagePar.h"
57
58#include "MMcEvt.hxx"
59#include "MMcFadcHeader.hxx"
60
61ClassImp(MMcCalibrationCalc);
62
63using namespace std;
64
65MMcCalibrationCalc::MMcCalibrationCalc(const char *name, const char *title)
66{
67 fName = name ? name : "MMcCalibrationCalc";
68 fTitle = title ? title : "Calculate and write conversion factors into MCalibrationCam Container";
69
70 fADC2Phot = 0.;
71 fEvents = 0;
72
73 fHistRatio = new TH1F("HistRatio", "log10(fPassPhotCone/fSize)", 1500., -3., 3.);
74 fHistRatio->GetXaxis()->SetTitle("log_{10}(fPassPhotCone / fSize) (in photons/ADC count)");
75}
76
77// --------------------------------------------------------------------------
78//
79// Check for the run type. Return kTRUE if it is a MC run or if there
80// is no MC run header (old camera files) kFALSE in case of a different
81// run type
82//
83Bool_t MMcCalibrationCalc::CheckRunType(MParList *pList) const
84{
85 const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
86 if (!run)
87 {
88 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
89 return kTRUE;
90 }
91
92 return run->GetRunType() == kRTMonteCarlo;
93}
94
95// --------------------------------------------------------------------------
96//
97// Make sure, that there is an MCalibrationCam Object in the Parameter List.
98//
99Int_t MMcCalibrationCalc::PreProcess(MParList *pList)
100{
101 //
102 // If it is no MC file display error and exit
103 //
104 if (!CheckRunType(pList))
105 {
106 *fLog << err << dbginf << "This is no MC file... aborting." << endl;
107 return kFALSE;
108 }
109
110 fCalCam = (MCalibrationCam*) pList->FindObject(AddSerialNumber("MCalibrationCam"));
111
112 if ( !fCalCam )
113 {
114 *fLog << err << dbginf << "Cannot find MCalibrationCam... aborting." << endl;
115 return kFALSE;
116 }
117
118 fHillas = (MHillas*) pList->FindCreateObj(AddSerialNumber("MHillas"));
119 if ( !fHillas)
120 {
121 *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MHillas") << "... aborting." << endl;
122 return kFALSE;
123 }
124
125 fNew = (MNewImagePar*) pList->FindCreateObj(AddSerialNumber("MNewImagePar"));
126 if ( !fNew)
127 {
128 *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MNewImagePar") << "... aborting." << endl;
129 return kFALSE;
130 }
131
132 fMcEvt = (MMcEvt*) pList->FindCreateObj(AddSerialNumber("MMcEvt"));
133 if ( !fMcEvt)
134 {
135 *fLog << err << dbginf << "Cannot find " << AddSerialNumber("MMcEvt") << "... aborting." << endl;
136 return kFALSE;
137 }
138
139 return kTRUE;
140
141}
142
143// --------------------------------------------------------------------------
144//
145// Check for the runtype.
146// Search for MGeomCam and MMcFadcHeader.
147//
148Bool_t MMcCalibrationCalc::ReInit(MParList *pList)
149{
150 //
151 // Now check the existence of all necessary containers.
152 //
153
154 fGeom = (MGeomCam*) pList->FindObject(AddSerialNumber("MGeomCam"));
155 if ( ! fGeom )
156 {
157 *fLog << err << dbginf << "Cannot find MGeomCam... aborting." << endl;
158 return kFALSE;
159 }
160
161 fHeaderFadc = (MMcFadcHeader*)pList->FindObject(AddSerialNumber("MMcFadcHeader"));
162 if (!fHeaderFadc)
163 {
164 *fLog << err << dbginf << "MMcFadcHeader not found... aborting." << endl;
165 return kFALSE;
166 }
167
168 for (UInt_t ipix = 0; ipix < fGeom->GetNumPixels(); ipix++)
169 {
170 if (fHeaderFadc->GetPedestalRmsHigh(ipix) > 0 ||
171 fHeaderFadc->GetPedestalRmsLow(ipix) > 0 )
172 {
173 *fLog << err << endl << endl << dbginf << "You are trying to calibrate the data using a Camera file produced with added noise. Please use a noiseless file for calibration. Aborting..." << endl << endl;
174 return kFALSE;
175 }
176 }
177
178 //
179 // FIXME: Check that the relevant parameters in the FADC header are the
180 // same for all the analyzed data, both Calibration and Analyzed data!
181 //
182
183 return kTRUE;
184}
185
186
187// --------------------------------------------------------------------------
188//
189// Obtain average ratio of photons in camera to image Size.
190//
191Int_t MMcCalibrationCalc::Process()
192{
193
194 //
195 // Exclude events with some saturated pixel
196 //
197 if ( fNew->GetNumSaturatedPixels() > 0 )
198 return kTRUE;
199
200 //
201 // Exclude events with low Size (larger fluctuations)
202 // FIXME? The present cut (1000 "inner-pixel-counts") is somehow arbitrary.
203 // Might it be optimized?
204 //
205 if ( fHillas->GetSize() < 1000 )
206 return kTRUE;
207
208 fADC2Phot += fMcEvt->GetPassPhotCone() / fHillas->GetSize();
209 fEvents ++;
210
211 fHistRatio->Fill(log10(fMcEvt->GetPassPhotCone()/fHillas->GetSize()));
212
213 return kTRUE;
214}
215
216// --------------------------------------------------------------------------
217//
218// Fill the MCalibrationCam object
219//
220Int_t MMcCalibrationCalc::PostProcess()
221{
222
223 if (fEvents > 0)
224 fADC2Phot /= fEvents;
225 else
226 {
227 *fLog << err << dbginf << "No events were read! Aborting." << endl;
228 return kFALSE;
229 }
230
231 //
232 // For the calibration we no longer use the mean, but thepeak of the distribution:
233 //
234
235 Float_t summax = 0.;
236 Int_t mode = 0;
237 Int_t reach = 2;
238 for (Int_t ibin = 1+reach; ibin <= fHistRatio->GetNbinsX()-reach; ibin++)
239 {
240 Float_t sum = 0;
241 for(Int_t k = ibin-reach; k <= ibin+reach; k++)
242 sum += fHistRatio->GetBinContent(k);
243 if (sum > summax)
244 {
245 summax = sum;
246 mode = ibin;
247 }
248 }
249
250 fADC2Phot = pow(10., fHistRatio->GetXaxis()->GetBinCenter(mode));
251
252 const int num = fCalCam->GetSize();
253
254 for (int i=0; i<num; i++)
255 {
256 MCalibrationPix &calpix = (*fCalCam)[i];
257
258 Float_t factor = fADC2Phot*calpix.GetMeanConversionBlindPixelMethod();
259
260 calpix.SetConversionBlindPixelMethod(factor, 0., 0.);
261
262 }
263
264 return kTRUE;
265
266}
Note: See TracBrowser for help on using the repository browser.