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 | // MCalibrationChargeCam
|
---|
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 "MCalibrationChargePix.h"
|
---|
50 | #include "MCalibrationChargeCam.h"
|
---|
51 |
|
---|
52 | #include "MCalibrationQEPix.h"
|
---|
53 | #include "MCalibrationQECam.h"
|
---|
54 |
|
---|
55 | #include "MGeomCam.h"
|
---|
56 | #include "MRawRunHeader.h"
|
---|
57 |
|
---|
58 | #include "MHillas.h"
|
---|
59 | #include "MNewImagePar.h"
|
---|
60 |
|
---|
61 | #include "MMcEvt.hxx"
|
---|
62 | #include "MMcFadcHeader.hxx"
|
---|
63 |
|
---|
64 | ClassImp(MMcCalibrationCalc);
|
---|
65 |
|
---|
66 | using namespace std;
|
---|
67 |
|
---|
68 | MMcCalibrationCalc::MMcCalibrationCalc(const char *name, const char *title)
|
---|
69 | {
|
---|
70 | fName = name ? name : "MMcCalibrationCalc";
|
---|
71 | fTitle = title ? title : "Calculate and write conversion factors into MCalibrationCam Container";
|
---|
72 |
|
---|
73 | fHistRatio = new TH1F(AddSerialNumber("HistRatio"), "log10(fPassPhotCone/fSize)", 1500, -3., 3.);
|
---|
74 | fHistRatio->SetXTitle("log_{10}(fPassPhotCone / fSize) [phot/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 | //
|
---|
83 | Bool_t MMcCalibrationCalc::CheckRunType(MParList *pList) const
|
---|
84 | {
|
---|
85 | const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
86 | if (!run)
|
---|
87 | {
|
---|
88 | *fLog << warn << "Warning - cannot check file type, MRawRunHeader not found." << endl;
|
---|
89 | return kTRUE;
|
---|
90 | }
|
---|
91 |
|
---|
92 | return run->IsMonteCarloRun();
|
---|
93 | }
|
---|
94 |
|
---|
95 | // --------------------------------------------------------------------------
|
---|
96 | //
|
---|
97 | // Make sure, that there is an MCalibrationCam Object in the Parameter List.
|
---|
98 | //
|
---|
99 | Int_t MMcCalibrationCalc::PreProcess(MParList *pList)
|
---|
100 | {
|
---|
101 | fHistRatio->Reset();
|
---|
102 | fADC2Phot = 0;
|
---|
103 |
|
---|
104 | fCalCam = (MCalibrationChargeCam*) pList->FindObject(AddSerialNumber("MCalibrationChargeCam"));
|
---|
105 | if (!fCalCam)
|
---|
106 | {
|
---|
107 | *fLog << err << AddSerialNumber("MCalibrationChargeCam") << "not found... aborting." << endl;
|
---|
108 | return kFALSE;
|
---|
109 | }
|
---|
110 |
|
---|
111 | fQECam = (MCalibrationQECam*) pList->FindObject(AddSerialNumber("MCalibrationQECam"));
|
---|
112 | if (!fQECam)
|
---|
113 | {
|
---|
114 | *fLog << err << AddSerialNumber("MCalibrationQECam") << "not found... aborting." << endl;
|
---|
115 | return kFALSE;
|
---|
116 | }
|
---|
117 |
|
---|
118 | fHillas = (MHillas*) pList->FindObject(AddSerialNumber("MHillas"));
|
---|
119 | if ( !fHillas)
|
---|
120 | {
|
---|
121 | *fLog << err << AddSerialNumber("MHillas") << "not found... aborting." << endl;
|
---|
122 | return kFALSE;
|
---|
123 | }
|
---|
124 |
|
---|
125 | fNew = (MNewImagePar*)pList->FindObject(AddSerialNumber("MNewImagePar"));
|
---|
126 | if (!fNew)
|
---|
127 | {
|
---|
128 | *fLog << err << AddSerialNumber("MNewImagePar") << "not found... aborting." << endl;
|
---|
129 | return kFALSE;
|
---|
130 | }
|
---|
131 |
|
---|
132 | fMcEvt = (MMcEvt*) pList->FindObject(AddSerialNumber("MMcEvt"));
|
---|
133 | if (!fMcEvt)
|
---|
134 | {
|
---|
135 | *fLog << err << AddSerialNumber("MMcEvt") << "not found... aborting." << endl;
|
---|
136 | return kFALSE;
|
---|
137 | }
|
---|
138 |
|
---|
139 | return kTRUE;
|
---|
140 | }
|
---|
141 |
|
---|
142 | // --------------------------------------------------------------------------
|
---|
143 | //
|
---|
144 | // Check for the runtype.
|
---|
145 | // Search for MGeomCam and MMcFadcHeader.
|
---|
146 | //
|
---|
147 | Bool_t MMcCalibrationCalc::ReInit(MParList *pList)
|
---|
148 | {
|
---|
149 | //
|
---|
150 | // If it is no MC file display error and exit
|
---|
151 | //
|
---|
152 | if (!CheckRunType(pList))
|
---|
153 | {
|
---|
154 | *fLog << err << "MMcCalibrationCalc can only be used with MC files... aborting." << endl;
|
---|
155 | return kFALSE;
|
---|
156 | }
|
---|
157 |
|
---|
158 | //
|
---|
159 | // Now check the existence of all necessary containers.
|
---|
160 | //
|
---|
161 | fGeom = (MGeomCam*) pList->FindObject(AddSerialNumber("MGeomCam"));
|
---|
162 | if (!fGeom)
|
---|
163 | {
|
---|
164 | *fLog << err << AddSerialNumber("MGeomCam") << " not found... aborting." << endl;
|
---|
165 | return kFALSE;
|
---|
166 | }
|
---|
167 |
|
---|
168 | fHeaderFadc = (MMcFadcHeader*)pList->FindObject(AddSerialNumber("MMcFadcHeader"));
|
---|
169 | if (!fHeaderFadc)
|
---|
170 | {
|
---|
171 | *fLog << err << AddSerialNumber("MMcFadcHeader") << " not found... aborting." << endl;
|
---|
172 | return kFALSE;
|
---|
173 | }
|
---|
174 |
|
---|
175 | for (UInt_t ipix = 0; ipix < fGeom->GetNumPixels(); ipix++)
|
---|
176 | {
|
---|
177 | if (fHeaderFadc->GetPedestalRmsHigh(ipix) > 0 ||
|
---|
178 | fHeaderFadc->GetPedestalRmsLow(ipix) > 0 )
|
---|
179 | {
|
---|
180 | *fLog << err << "Trying to calibrate the data using a Camera file produced with added noise." << endl;
|
---|
181 | *fLog << "Please use a noiseless file for calibration... aborting." << endl << endl;
|
---|
182 | return kFALSE;
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 | return kTRUE;
|
---|
187 | }
|
---|
188 |
|
---|
189 |
|
---|
190 | // --------------------------------------------------------------------------
|
---|
191 | //
|
---|
192 | // Obtain average ratio of photons in camera to image Size.
|
---|
193 | //
|
---|
194 | Int_t MMcCalibrationCalc::Process()
|
---|
195 | {
|
---|
196 | //
|
---|
197 | // Exclude events with some saturated pixel
|
---|
198 | //
|
---|
199 | if (fNew->GetNumSaturatedPixels()>0)
|
---|
200 | return kTRUE;
|
---|
201 |
|
---|
202 | //
|
---|
203 | // Exclude events with low Size (larger fluctuations)
|
---|
204 | // FIXME? The present cut (1000 "inner-pixel-counts") is somehow
|
---|
205 | // arbitrary. Might it be optimized?
|
---|
206 | //
|
---|
207 | if (fHillas->GetSize()<1000)
|
---|
208 | return kTRUE;
|
---|
209 |
|
---|
210 | fADC2Phot += fMcEvt->GetPassPhotCone()/fHillas->GetSize();
|
---|
211 |
|
---|
212 | fHistRatio->Fill(TMath::Log10(fMcEvt->GetPassPhotCone()/fHillas->GetSize()));
|
---|
213 |
|
---|
214 | return kTRUE;
|
---|
215 | }
|
---|
216 |
|
---|
217 | // --------------------------------------------------------------------------
|
---|
218 | //
|
---|
219 | // Fill the MCalibrationCam object
|
---|
220 | //
|
---|
221 | Int_t MMcCalibrationCalc::PostProcess()
|
---|
222 | {
|
---|
223 | const Stat_t n = fHistRatio->GetEntries();
|
---|
224 | if (n<1)
|
---|
225 | {
|
---|
226 | *fLog << err << "No events read... aborting." << endl;
|
---|
227 | return kFALSE;
|
---|
228 | }
|
---|
229 |
|
---|
230 | fADC2Phot /= n;
|
---|
231 |
|
---|
232 | //
|
---|
233 | // For the calibration we no longer use the mean,
|
---|
234 | // but the peak of the distribution:
|
---|
235 | //
|
---|
236 | const Int_t reach = 2;
|
---|
237 |
|
---|
238 | Stat_t summax = 0;
|
---|
239 | Int_t mode = 0;
|
---|
240 |
|
---|
241 | // FIXME: Is this necessary? We could use GetMaximumBin instead..
|
---|
242 | for (Int_t ibin = 1+reach; ibin <= fHistRatio->GetNbinsX()-reach; ibin++)
|
---|
243 | {
|
---|
244 | const Stat_t sum = fHistRatio->Integral(ibin-reach, ibin+reach);
|
---|
245 |
|
---|
246 | if (sum <= summax)
|
---|
247 | continue;
|
---|
248 |
|
---|
249 | summax = sum;
|
---|
250 | mode = ibin;
|
---|
251 | }
|
---|
252 |
|
---|
253 | fADC2Phot = TMath::Power(10, fHistRatio->GetBinCenter(mode));
|
---|
254 |
|
---|
255 | const Int_t num = fCalCam->GetSize();
|
---|
256 |
|
---|
257 | for (int i=0; i<num; i++)
|
---|
258 | {
|
---|
259 |
|
---|
260 | MCalibrationChargePix &calpix = (MCalibrationChargePix&)(*fCalCam)[i];
|
---|
261 | // MCalibrationQEPix &qepix = (MCalibrationQEPix&) (*fQECam) [i];
|
---|
262 |
|
---|
263 | const Float_t qe = MCalibrationQEPix::gkDefaultAverageQE;
|
---|
264 | const Float_t factor = fADC2Phot/qe*calpix.GetMeanConvFADC2Phe();
|
---|
265 | //
|
---|
266 | // FIXME: Now, only the conversion to PHe is stored, need also the quantum efficiency simulated!!!
|
---|
267 | //
|
---|
268 | calpix.SetMeanConvFADC2Phe(factor);
|
---|
269 | calpix.SetMeanConvFADC2PheVar(0.);
|
---|
270 | calpix.SetMeanFFactorFADC2Phot(0.);
|
---|
271 | }
|
---|
272 |
|
---|
273 | return kTRUE;
|
---|
274 | }
|
---|