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 |
|
---|
61 | ClassImp(MMcCalibrationCalc);
|
---|
62 |
|
---|
63 | using namespace std;
|
---|
64 |
|
---|
65 | MMcCalibrationCalc::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(AddSerialNumber("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 | //
|
---|
83 | Bool_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 | //
|
---|
99 | Int_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 " << AddSerialNumber("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 | //
|
---|
148 | Bool_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 " << AddSerialNumber("MGeomCam") << "... aborting." << endl;
|
---|
158 | return kFALSE;
|
---|
159 | }
|
---|
160 |
|
---|
161 | fHeaderFadc = (MMcFadcHeader*)pList->FindObject(AddSerialNumber("MMcFadcHeader"));
|
---|
162 | if (!fHeaderFadc)
|
---|
163 | {
|
---|
164 | *fLog << err << dbginf << AddSerialNumber("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 | return kTRUE;
|
---|
179 | }
|
---|
180 |
|
---|
181 |
|
---|
182 | // --------------------------------------------------------------------------
|
---|
183 | //
|
---|
184 | // Obtain average ratio of photons in camera to image Size.
|
---|
185 | //
|
---|
186 | Int_t MMcCalibrationCalc::Process()
|
---|
187 | {
|
---|
188 |
|
---|
189 | //
|
---|
190 | // Exclude events with some saturated pixel
|
---|
191 | //
|
---|
192 | if ( fNew->GetNumSaturatedPixels() > 0 )
|
---|
193 | return kTRUE;
|
---|
194 |
|
---|
195 | //
|
---|
196 | // Exclude events with low Size (larger fluctuations)
|
---|
197 | // FIXME? The present cut (1000 "inner-pixel-counts") is somehow arbitrary.
|
---|
198 | // Might it be optimized?
|
---|
199 | //
|
---|
200 | if ( fHillas->GetSize() < 1000 )
|
---|
201 | return kTRUE;
|
---|
202 |
|
---|
203 | fADC2Phot += fMcEvt->GetPassPhotCone() / fHillas->GetSize();
|
---|
204 | fEvents ++;
|
---|
205 |
|
---|
206 | fHistRatio->Fill(log10(fMcEvt->GetPassPhotCone()/fHillas->GetSize()));
|
---|
207 |
|
---|
208 | return kTRUE;
|
---|
209 | }
|
---|
210 |
|
---|
211 | // --------------------------------------------------------------------------
|
---|
212 | //
|
---|
213 | // Fill the MCalibrationCam object
|
---|
214 | //
|
---|
215 | Int_t MMcCalibrationCalc::PostProcess()
|
---|
216 | {
|
---|
217 |
|
---|
218 | if (fEvents > 0)
|
---|
219 | fADC2Phot /= fEvents;
|
---|
220 | else
|
---|
221 | {
|
---|
222 | *fLog << err << dbginf << "No events were read! Aborting." << endl;
|
---|
223 | return kFALSE;
|
---|
224 | }
|
---|
225 |
|
---|
226 | //
|
---|
227 | // For the calibration we no longer use the mean, but thepeak of the distribution:
|
---|
228 | //
|
---|
229 |
|
---|
230 | Float_t summax = 0.;
|
---|
231 | Int_t mode = 0;
|
---|
232 | Int_t reach = 2;
|
---|
233 | for (Int_t ibin = 1+reach; ibin <= fHistRatio->GetNbinsX()-reach; ibin++)
|
---|
234 | {
|
---|
235 | Float_t sum = 0;
|
---|
236 | for(Int_t k = ibin-reach; k <= ibin+reach; k++)
|
---|
237 | sum += fHistRatio->GetBinContent(k);
|
---|
238 | if (sum > summax)
|
---|
239 | {
|
---|
240 | summax = sum;
|
---|
241 | mode = ibin;
|
---|
242 | }
|
---|
243 | }
|
---|
244 |
|
---|
245 | fADC2Phot = pow(10., fHistRatio->GetXaxis()->GetBinCenter(mode));
|
---|
246 |
|
---|
247 | const int num = fCalCam->GetSize();
|
---|
248 |
|
---|
249 | for (int i=0; i<num; i++)
|
---|
250 | {
|
---|
251 | MCalibrationPix &calpix = (*fCalCam)[i];
|
---|
252 |
|
---|
253 | Float_t factor = fADC2Phot*calpix.GetMeanConversionBlindPixelMethod();
|
---|
254 |
|
---|
255 | calpix.SetConversionBlindPixelMethod(factor, 0., 0.);
|
---|
256 |
|
---|
257 | }
|
---|
258 |
|
---|
259 | return kTRUE;
|
---|
260 |
|
---|
261 | }
|
---|