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): Markus Meyer, 02/2005 <mailto:meyer@astro.uni-wuerzburg.de>
|
---|
19 | ! Author(s): Thomas Bretz, 04/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2005
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MHSingleMuon
|
---|
29 | //
|
---|
30 | // This class is a histogram class for a displaying muonparameters.
|
---|
31 | // The folowing histgrams will be plotted:
|
---|
32 | // - Radius (TH1F)
|
---|
33 | // - ArcWidth (TH1F)
|
---|
34 | //
|
---|
35 | // Inputcontainer:
|
---|
36 | // - MGeomCam
|
---|
37 | // - MMuonSearchPar
|
---|
38 | // - MMuonCalibPar
|
---|
39 | //
|
---|
40 | ////////////////////////////////////////////////////////////////////////////
|
---|
41 | #include "MHSingleMuon.h"
|
---|
42 |
|
---|
43 | #include <TF1.h>
|
---|
44 | #include <TMinuit.h>
|
---|
45 | #include <TPad.h>
|
---|
46 | #include <TCanvas.h>
|
---|
47 |
|
---|
48 | #include "MLog.h"
|
---|
49 | #include "MLogManip.h"
|
---|
50 |
|
---|
51 | #include "MBinning.h"
|
---|
52 | #include "MParList.h"
|
---|
53 |
|
---|
54 | #include "MGeomCam.h"
|
---|
55 | #include "MGeomPix.h"
|
---|
56 |
|
---|
57 | #include "MSignalCam.h"
|
---|
58 | #include "MSignalPix.h"
|
---|
59 |
|
---|
60 | #include "MMuonSetup.h"
|
---|
61 | #include "MMuonCalibPar.h"
|
---|
62 | #include "MMuonSearchPar.h"
|
---|
63 |
|
---|
64 | ClassImp(MHSingleMuon);
|
---|
65 |
|
---|
66 | using namespace std;
|
---|
67 |
|
---|
68 | // --------------------------------------------------------------------------
|
---|
69 | //
|
---|
70 | // Setup histograms
|
---|
71 | //
|
---|
72 | MHSingleMuon::MHSingleMuon(const char *name, const char *title) :
|
---|
73 | fSignalCam(0), fMuonSearchPar(0), fGeomCam(0), fMargin(0)
|
---|
74 | {
|
---|
75 | fName = name ? name : "MHSingleMuon";
|
---|
76 | fTitle = title ? title : "Histograms of muon parameters";
|
---|
77 |
|
---|
78 | fHistPhi.SetName("HistPhi");
|
---|
79 | fHistPhi.SetTitle("HistPhi");
|
---|
80 | fHistPhi.SetXTitle("\\phi [\\circ]");
|
---|
81 | fHistPhi.SetYTitle("sum of ADC");
|
---|
82 | fHistPhi.SetDirectory(NULL);
|
---|
83 | fHistPhi.SetFillStyle(4000);
|
---|
84 | fHistPhi.UseCurrentStyle();
|
---|
85 |
|
---|
86 | fHistWidth.SetName("HistWidth");
|
---|
87 | fHistWidth.SetTitle("HistWidth");
|
---|
88 | fHistWidth.SetXTitle("distance from the ring center [\\circ]");
|
---|
89 | fHistWidth.SetYTitle("sum of ADC");
|
---|
90 | fHistWidth.SetDirectory(NULL);
|
---|
91 | fHistWidth.SetFillStyle(4000);
|
---|
92 | fHistWidth.UseCurrentStyle();
|
---|
93 |
|
---|
94 | MBinning bins;
|
---|
95 | bins.SetEdges(21, -180, 180);
|
---|
96 | bins.Apply(fHistPhi);
|
---|
97 |
|
---|
98 | bins.SetEdges(28, 0.3, 1.7);
|
---|
99 | bins.Apply(fHistWidth);
|
---|
100 | }
|
---|
101 |
|
---|
102 | // --------------------------------------------------------------------------
|
---|
103 | //
|
---|
104 | // Setup the Binning for the histograms automatically if the correct
|
---|
105 | // instances of MBinning
|
---|
106 | //
|
---|
107 | Bool_t MHSingleMuon::SetupFill(const MParList *plist)
|
---|
108 | {
|
---|
109 | fGeomCam = (MGeomCam*)plist->FindObject("MGeomCam");
|
---|
110 | if (!fGeomCam)
|
---|
111 | {
|
---|
112 | *fLog << warn << "MGeomCam not found... abort." << endl;
|
---|
113 | return kFALSE;
|
---|
114 | }
|
---|
115 | fMuonSearchPar = (MMuonSearchPar*)plist->FindObject("MMuonSearchPar");
|
---|
116 | if (!fMuonSearchPar)
|
---|
117 | {
|
---|
118 | *fLog << warn << "MMuonSearchPar not found... abort." << endl;
|
---|
119 | return kFALSE;
|
---|
120 | }
|
---|
121 | fSignalCam = (MSignalCam*)plist->FindObject("MSignalCam");
|
---|
122 | if (!fSignalCam)
|
---|
123 | {
|
---|
124 | *fLog << warn << "MSignalCam not found... abort." << endl;
|
---|
125 | return kFALSE;
|
---|
126 | }
|
---|
127 |
|
---|
128 | MMuonSetup *setup = (MMuonSetup*)plist->FindObject("MMuonSetup");
|
---|
129 | if (!setup)
|
---|
130 | {
|
---|
131 | *fLog << warn << "MMuonSetup not found... abort." << endl;
|
---|
132 | return kFALSE;
|
---|
133 | }
|
---|
134 | fMargin = setup->GetMargin()/fGeomCam->GetConvMm2Deg();
|
---|
135 |
|
---|
136 | ApplyBinning(*plist, "ArcPhi", &fHistPhi);
|
---|
137 | ApplyBinning(*plist, "MuonWidth", &fHistWidth);
|
---|
138 |
|
---|
139 | return kTRUE;
|
---|
140 | }
|
---|
141 |
|
---|
142 | // --------------------------------------------------------------------------
|
---|
143 | //
|
---|
144 | // Fill the histograms with data from a MMuonCalibPar and
|
---|
145 | // MMuonSearchPar container.
|
---|
146 | //
|
---|
147 | Bool_t MHSingleMuon::Fill(const MParContainer *par, const Stat_t w)
|
---|
148 | {
|
---|
149 | fHistPhi.Reset();
|
---|
150 | fHistWidth.Reset();
|
---|
151 |
|
---|
152 | const Int_t entries = fSignalCam->GetNumPixels();
|
---|
153 |
|
---|
154 | // the position of the center of a muon ring
|
---|
155 | const Float_t cenx = fMuonSearchPar->GetCenterX();
|
---|
156 | const Float_t ceny = fMuonSearchPar->GetCenterY();
|
---|
157 |
|
---|
158 | for (Int_t i=0; i<entries; i++)
|
---|
159 | {
|
---|
160 | const MSignalPix &pix = (*fSignalCam)[i];
|
---|
161 | const MGeomPix &gpix = (*fGeomCam)[i];
|
---|
162 |
|
---|
163 | const Float_t dx = gpix.GetX() - cenx;
|
---|
164 | const Float_t dy = gpix.GetY() - ceny;
|
---|
165 |
|
---|
166 | const Float_t dist = TMath::Hypot(dx, dy);
|
---|
167 |
|
---|
168 | // if the signal is not near the estimated circle, it is ignored.
|
---|
169 | if (dist < fMuonSearchPar->GetRadius() + fMargin &&
|
---|
170 | dist > fMuonSearchPar->GetRadius() - fMargin)
|
---|
171 | fHistPhi.Fill(TMath::ATan2(dx, dy)*TMath::RadToDeg(), pix.GetNumPhotons());
|
---|
172 |
|
---|
173 | // use only the inner pixles. This is geometry dependent. This has to
|
---|
174 | // be fixed!
|
---|
175 | if(i>397)
|
---|
176 | continue;
|
---|
177 |
|
---|
178 | fHistWidth.Fill(dist*fGeomCam->GetConvMm2Deg(), pix.GetNumPhotons());
|
---|
179 | }
|
---|
180 |
|
---|
181 | // error estimation (temporaly)
|
---|
182 | // The error is estimated from the signal. In order to do so, we have to
|
---|
183 | // once convert the signal from ADC to photo-electron. Then we can get
|
---|
184 | // the fluctuation such as F-factor*sqrt(phe).
|
---|
185 | // Up to now, the error of pedestal is not taken into accout. This is not
|
---|
186 | // of course correct. We will include this soon.
|
---|
187 | Double_t ADC2PhEl = 0.14;
|
---|
188 | Double_t Ffactor = 1.4;
|
---|
189 | for (Int_t i=0; i<fHistPhi.GetNbinsX()+1; i++)
|
---|
190 | {
|
---|
191 | const Float_t abs = TMath::Abs(fHistPhi.GetBinContent(i));
|
---|
192 | const Float_t rougherr = TMath::Sqrt(abs/ADC2PhEl)*Ffactor;
|
---|
193 |
|
---|
194 | fHistPhi.SetBinError(i, rougherr);
|
---|
195 | }
|
---|
196 |
|
---|
197 | for (Int_t i=0; i<fHistWidth.GetNbinsX()+1; i++)
|
---|
198 | {
|
---|
199 | const Float_t abs = TMath::Abs(fHistWidth.GetBinContent(i));
|
---|
200 | const Float_t rougherr = TMath::Sqrt(abs/ADC2PhEl)*Ffactor;
|
---|
201 |
|
---|
202 | fHistWidth.SetBinError(i, rougherr);
|
---|
203 | }
|
---|
204 |
|
---|
205 | return kTRUE;
|
---|
206 | }
|
---|
207 |
|
---|
208 | // --------------------------------------------------------------------------
|
---|
209 | //
|
---|
210 | // Find the first bins starting at the bin with maximum content in both
|
---|
211 | // directions which are below threshold.
|
---|
212 | // If in a range of half the histogram size in both directions no bin
|
---|
213 | // below the threshold is found, kFALSE is returned.
|
---|
214 | //
|
---|
215 | Bool_t MHSingleMuon::FindRangeAboveThreshold(const TH1F &h, Float_t thres, Int_t &first, Int_t &last) const
|
---|
216 | {
|
---|
217 | const Int_t n = h.GetNbinsX();
|
---|
218 | const Int_t maxbin = h.GetMaximumBin();
|
---|
219 | const Int_t edge = maxbin+n/2;
|
---|
220 |
|
---|
221 | // Search from the peak to the right
|
---|
222 | last = -1;
|
---|
223 | for (Int_t i=maxbin; i<edge; i++)
|
---|
224 | {
|
---|
225 | const Float_t val = h.GetBinContent(i%n + 1);
|
---|
226 | if (val<thres && last<0)
|
---|
227 | last = i%n+1;
|
---|
228 | }
|
---|
229 |
|
---|
230 | // Search from the peak to the left
|
---|
231 | first = -1;
|
---|
232 | for (Int_t i=maxbin+n-1; i>=edge; i--)
|
---|
233 | {
|
---|
234 | const Float_t val = h.GetBinContent(i%n + 1);
|
---|
235 | if (val<thres && first<0)
|
---|
236 | first = i%n+1;
|
---|
237 | }
|
---|
238 |
|
---|
239 | return first>=0 && last>=0;
|
---|
240 | }
|
---|
241 |
|
---|
242 | // --------------------------------------------------------------------------
|
---|
243 | //
|
---|
244 | // Photon distribution along the estimated circle is fitted with theoritical
|
---|
245 | // function in order to get some more information such as Arc Phi and Arc
|
---|
246 | // Length.
|
---|
247 | //
|
---|
248 | Bool_t MHSingleMuon::CalcPhi(Double_t thres, Double_t &peakphi, Double_t &arcphi) const
|
---|
249 | {
|
---|
250 | peakphi = 180.-fHistPhi.GetBinCenter(fHistPhi.GetMaximumBin());
|
---|
251 |
|
---|
252 | // Now find the position at which the peak edges crosses the threshold
|
---|
253 | Int_t first, last;
|
---|
254 |
|
---|
255 | if (!FindRangeAboveThreshold(fHistPhi, thres, first, last))
|
---|
256 | return kFALSE;
|
---|
257 |
|
---|
258 | //cout << "P: " << first << " " << last << " " << last-first << endl;
|
---|
259 |
|
---|
260 | const Float_t startfitval = fHistPhi.GetBinLowEdge(first+1);
|
---|
261 | const Float_t endfitval = fHistPhi.GetBinLowEdge(last);
|
---|
262 |
|
---|
263 | //Int_t effbinnum = TMath::Nint((endfitval-startfitval)/convbin2val);
|
---|
264 |
|
---|
265 | arcphi = last<first ? 360+(endfitval-startfitval) : endfitval-startfitval;
|
---|
266 |
|
---|
267 | //if (fEnableImpactCalc)
|
---|
268 | // CalcImpact(effbinnum, startfitval, endfitval);
|
---|
269 |
|
---|
270 | return kTRUE;
|
---|
271 | }
|
---|
272 |
|
---|
273 | // --------------------------------------------------------------------------
|
---|
274 | //
|
---|
275 | // Photon distribution of distance from the center of estimated ring is
|
---|
276 | // fitted in order to get some more information such as ARC WIDTH which
|
---|
277 | // can represent to the PSF of our reflector.
|
---|
278 | //
|
---|
279 | // thres: Threshold above zero to determin the edges of the peak which
|
---|
280 | // is used as fit range
|
---|
281 | // width: ArcWidth returned in deg
|
---|
282 | // chi: Chi^2/NDF of the fit
|
---|
283 | //
|
---|
284 | Bool_t MHSingleMuon::CalcWidth(Double_t thres, Double_t &width, Double_t &chi)
|
---|
285 | {
|
---|
286 | Int_t first, last;
|
---|
287 |
|
---|
288 | if (!FindRangeAboveThreshold(fHistWidth, thres, first, last))
|
---|
289 | return kFALSE;
|
---|
290 |
|
---|
291 | // This happens in some cases
|
---|
292 | const Int_t n = fHistWidth.GetNbinsX()/2;
|
---|
293 | const Int_t m = fHistWidth.GetMaximumBin();
|
---|
294 | if (first>last)
|
---|
295 | if (m>n) // If maximum is on the right side of histogram
|
---|
296 | last = n;
|
---|
297 | else
|
---|
298 | first = 0; // If maximum is on the left side of histogram
|
---|
299 |
|
---|
300 | // Now get the fit range
|
---|
301 | const Float_t startfitval = fHistWidth.GetBinLowEdge(first+1);
|
---|
302 | const Float_t endfitval = fHistWidth.GetBinLowEdge(last);
|
---|
303 |
|
---|
304 | // Setup the function and perform the fit
|
---|
305 | TF1 f1("f1", "gaus", startfitval, endfitval);
|
---|
306 |
|
---|
307 | // Choose starting values as accurate as possible
|
---|
308 | f1.SetParameter(0, fHistWidth.Integral(first+1, last));
|
---|
309 | f1.SetParameter(1, fHistWidth.GetBinCenter(m));
|
---|
310 | f1.SetParameter(2, (endfitval-startfitval)/2);
|
---|
311 |
|
---|
312 | // options : N do not store the function, do not draw
|
---|
313 | // I use integral of function in bin rather than value at bin center
|
---|
314 | // R use the range specified in the function range
|
---|
315 | // Q quiet mode
|
---|
316 | fHistWidth.Fit(&f1, "NQR");
|
---|
317 |
|
---|
318 | if (last-first>3)
|
---|
319 | chi = f1.GetChisquare()/(last-first-3);
|
---|
320 |
|
---|
321 | Double_t err;
|
---|
322 | gMinuit->GetParameter(2, width, err); // get the sigma value
|
---|
323 |
|
---|
324 | return kTRUE;
|
---|
325 | }
|
---|
326 |
|
---|
327 | /*
|
---|
328 | // --------------------------------------------------------------------------
|
---|
329 | //
|
---|
330 | // An impact parameter is calculated by fitting the histogram of photon
|
---|
331 | // distribution along the circle with a theoritical model.
|
---|
332 | // (See G. Vacanti et. al., Astroparticle Physics 2, 1994, 1-11.
|
---|
333 | // The function (6) is used here.)
|
---|
334 | //
|
---|
335 | // By default this calculation is suppressed because this calculation is
|
---|
336 | // very time consuming. If you want to calculate an impact parameter,
|
---|
337 | // you can call the function of EnableImpactCalc().
|
---|
338 | //
|
---|
339 | void MMuonCalibParCalc::CalcImpact(Int_t effbinnum, Float_t startfitval, Float_t endfitval)
|
---|
340 | {
|
---|
341 | // Fit the distribution with Vacanti function. The function is different
|
---|
342 | // for the impact parameter of inside or outside of our reflector.
|
---|
343 | // Then two different functions are applied to the photon distribution,
|
---|
344 | // and the one which give us smaller chisquare value is taken as a
|
---|
345 | // proper one.
|
---|
346 |
|
---|
347 | Double_t val1,err1,val2,err2;
|
---|
348 | // impact parameter inside mirror radius (8.5m)
|
---|
349 | TString func1;
|
---|
350 | Float_t tmpval = (*fMuonSearchPar).GetRadius()*(*fGeomCam).GetConvMm2Deg()*TMath::DegToRad();
|
---|
351 | tmpval = sin(2.*tmpval)*8.5;
|
---|
352 | func1 += "[0]*";
|
---|
353 | func1 += tmpval;
|
---|
354 | func1 += "*(sqrt(1.-([1]/8.5)**2*sin((x-[2])*3.1415926/180.)**2)+([1]/8.5)*cos((x-[2])*3.1415926/180.))";
|
---|
355 |
|
---|
356 | TF1 f1("f1",func1,startfitval,endfitval);
|
---|
357 | f1.SetParameters(2000,3,0);
|
---|
358 | f1.SetParLimits(1,0,8.5);
|
---|
359 | f1.SetParLimits(2,-180.,180.);
|
---|
360 |
|
---|
361 | fMuonCalibPar->fHistPhi->Fit("f1","RQEM");
|
---|
362 |
|
---|
363 | Float_t chi1 = -1;
|
---|
364 | Float_t chi2 = -1;
|
---|
365 | if(effbinnum>3)
|
---|
366 | chi1 = f1.GetChisquare()/((Float_t)(effbinnum-3));
|
---|
367 |
|
---|
368 | gMinuit->GetParameter(1,val1,err1); // get the estimated IP
|
---|
369 | Float_t estip1 = val1;
|
---|
370 |
|
---|
371 | // impact parameter beyond mirror area (8.5m)
|
---|
372 | TString func2;
|
---|
373 | Float_t tmpval2 = (*fMuonSearchPar).GetRadius()*(*fGeomCam).GetConvMm2Deg()*TMath::DegToRad();
|
---|
374 | tmpval2 = sin(2.*tmpval2)*8.5*2.;
|
---|
375 | func2 += "[0]*";
|
---|
376 | func2 += tmpval2;
|
---|
377 | func2 += "*sqrt(1.-(([1]/8.5)*sin((x-[2])*3.1415926/180.))**2)";
|
---|
378 |
|
---|
379 | TF1 f2("f2",func2,startfitval,endfitval);
|
---|
380 | f2.SetParameters(2000,20,0);
|
---|
381 | f2.SetParLimits(1,8.5,300.);
|
---|
382 | f2.SetParLimits(2,-180.,180.);
|
---|
383 |
|
---|
384 | fMuonCalibPar->fHistPhi->Fit("f2","RQEM+");
|
---|
385 |
|
---|
386 | if(effbinnum>3)
|
---|
387 | chi2 = f2.GetChisquare()/((Float_t)(effbinnum-3));
|
---|
388 |
|
---|
389 | gMinuit->GetParameter(1,val2,err2); // get the estimated IP
|
---|
390 | Float_t estip2 = val2;
|
---|
391 |
|
---|
392 | if(effbinnum<=3)
|
---|
393 | {
|
---|
394 | fMuonCalibPar->SetEstImpact(-1.);
|
---|
395 | }
|
---|
396 | if(chi2 > chi1)
|
---|
397 | {
|
---|
398 | fMuonCalibPar->SetEstImpact(estip1);
|
---|
399 | fMuonCalibPar->SetChiArcPhi(chi1);
|
---|
400 | }
|
---|
401 | else
|
---|
402 | {
|
---|
403 | fMuonCalibPar->SetEstImpact(estip2);
|
---|
404 | fMuonCalibPar->SetChiArcPhi(chi2);
|
---|
405 | }
|
---|
406 | }
|
---|
407 | */
|
---|