source: trunk/MagicSoft/Mars/mmuon/MHSingleMuon.cc@ 7022

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