source: trunk/Mars/mmuon/MHMuonPar.cc@ 18750

Last change on this file since 18750 was 9851, checked in by tbretz, 14 years ago
Changed MH::SetBinning and similar functions to take references instead of pointers as arguments. For convenience wrappers for the old style functions are provided.
File size: 8.4 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): 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// MHMuonPar
29//
30// This class is a histogram class for displaying muonparameters.
31// The folowing histgrams will be plotted:
32// - Radius (TH1F)
33// - ArcWidth (TH1F)
34// - ArcWidth/Radius vs Radius (TProfile) (it is the energy dependent
35// relative broadening of the muon ring)
36// - Size Vs Radius
37//
38//
39// Inputcontainer:
40// - MGeomCam
41// - MMuonSearchPar
42// - MMuonCalibPar
43//
44//
45// Class Version 2:
46// ----------------
47// - fMm2Deg
48//
49////////////////////////////////////////////////////////////////////////////
50#include "MHMuonPar.h"
51
52#include <TH1.h>
53#include <TF1.h>
54#include <TPad.h>
55#include <TLatex.h>
56#include <TCanvas.h>
57#include <TProfile.h>
58
59#include "MLog.h"
60#include "MLogManip.h"
61
62#include "MString.h"
63
64#include "MGeomCam.h"
65#include "MBinning.h"
66#include "MParList.h"
67
68#include "MMuonSearchPar.h"
69#include "MMuonCalibPar.h"
70
71ClassImp(MHMuonPar);
72
73using namespace std;
74
75const Float_t MHMuonPar::fgIntegralLoLim = 0.751;
76const Float_t MHMuonPar::fgIntegralUpLim = 1.199;
77
78// --------------------------------------------------------------------------
79//
80// Setup histograms
81//
82MHMuonPar::MHMuonPar(const char *name, const char *title) :
83 fMuonSearchPar(NULL), fMuonCalibPar(NULL), fGeom(NULL)
84{
85 fName = name ? name : "MHMuonPar";
86 fTitle = title ? title : "Histograms of muon parameters";
87
88 fHistRadius.SetName("Radius");
89 fHistRadius.SetTitle("Distribution of Radius'");
90 fHistRadius.SetXTitle("R [\\circ]");
91 fHistRadius.SetYTitle("Counts");
92 fHistRadius.GetXaxis()->SetTitleOffset(1.2);
93 fHistRadius.SetDirectory(NULL);
94 fHistRadius.UseCurrentStyle();
95 fHistRadius.SetFillStyle(4000);
96
97 fHistArcWidth.SetName("ArcWidth");
98 fHistArcWidth.SetTitle("Distribution of ArcWidth");
99 fHistArcWidth.SetXTitle("W [\\circ]");
100 fHistArcWidth.GetXaxis()->SetTitleOffset(1.2);
101 fHistArcWidth.SetYTitle("Counts");
102 fHistArcWidth.SetDirectory(NULL);
103 fHistArcWidth.UseCurrentStyle();
104 fHistArcWidth.SetFillStyle(4000);
105
106 fHistBroad.SetName("RingBroadening");
107 fHistBroad.SetTitle("Profile ArcWidth vs Radius");
108 fHistBroad.SetXTitle("R [\\circ]");
109 fHistBroad.SetYTitle("W/R [1]");
110 fHistBroad.GetXaxis()->SetTitleOffset(1.2);
111 fHistBroad.SetDirectory(NULL);
112 fHistBroad.UseCurrentStyle();
113 fHistBroad.SetFillStyle(4000);
114
115 fHistSize.SetName("SizeVsRadius");
116 fHistSize.SetTitle("Profile MuonSize vs Radius");
117 fHistSize.SetXTitle("R [\\circ]");
118 fHistSize.SetYTitle("S [phe]");
119 fHistSize.GetXaxis()->SetTitleOffset(1.2);
120 fHistSize.SetDirectory(NULL);
121 fHistSize.UseCurrentStyle();
122 fHistSize.SetFillStyle(4000);
123
124 MBinning bins;
125
126 bins.SetEdges(20, 0.5, 1.5);
127 bins.Apply(fHistRadius);
128
129 bins.SetEdges(60, 0., 0.3);
130 bins.Apply(fHistArcWidth);
131
132 bins.SetEdges(20, 0.5, 1.5);
133 bins.Apply(fHistBroad);
134
135 bins.SetEdges(20, 0.5, 1.5);
136 bins.Apply(fHistSize);
137}
138
139// --------------------------------------------------------------------------
140//
141// Setup the Binning for the histograms automatically if the correct
142// instances of MBinning
143//
144Bool_t MHMuonPar::SetupFill(const MParList *plist)
145{
146 fGeom = (MGeomCam*)plist->FindObject("MGeomCam");
147 if (!fGeom)
148 {
149 *fLog << warn << "MGeomCam not found... abort." << endl;
150 return kFALSE;
151 }
152
153 fMuonSearchPar = (MMuonSearchPar*)plist->FindObject("MMuonSearchPar");
154 if (!fMuonSearchPar)
155 {
156 *fLog << warn << "MMuonSearchPar not found... abort." << endl;
157 return kFALSE;
158 }
159 fMuonCalibPar = (MMuonCalibPar*)plist->FindObject("MMuonCalibPar");
160 if (!fMuonCalibPar)
161 {
162 *fLog << warn << "MMuonCalibPar not found... abort." << endl;
163 return kFALSE;
164 }
165
166 ApplyBinning(*plist, "Radius", fHistRadius);
167 ApplyBinning(*plist, "ArcWidth", fHistArcWidth);
168 ApplyBinning(*plist, "RingBroadening", fHistBroad);
169 ApplyBinning(*plist, "SizeVsRadius", fHistSize);
170
171 return kTRUE;
172}
173
174// --------------------------------------------------------------------------
175//
176// Fill the histograms with data from a MMuonCalibPar and
177// MMuonSearchPar container.
178//
179Int_t MHMuonPar::Fill(const MParContainer *par, const Stat_t w)
180{
181 const Double_t fMm2Deg = fGeom->GetConvMm2Deg();
182
183 fHistRadius.Fill(fMm2Deg*fMuonSearchPar->GetRadius(), w);
184
185 fHistArcWidth.Fill(fMuonCalibPar->GetArcWidth(), w);
186
187 fHistBroad.Fill(fMm2Deg*fMuonSearchPar->GetRadius(),
188 fMuonCalibPar->GetArcWidth(), w);
189
190 fHistSize.Fill(fMm2Deg*fMuonSearchPar->GetRadius(),
191 fMuonCalibPar->GetMuonSize(), w);
192
193 return kTRUE;
194}
195// --------------------------------------------------------------------------
196//
197// Creates a new canvas and draws the two histograms into it.
198// Be careful: The histograms belongs to this object and won't get deleted
199// together with the canvas.
200//
201void MHMuonPar::Draw(Option_t *)
202{
203 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
204 pad->SetBorderMode(0);
205
206 AppendPad("");
207
208 pad->Divide(2,2);
209
210 pad->cd(1);
211 gPad->SetBorderMode(0);
212 gPad->SetGridx();
213 gPad->SetGridy();
214 fHistRadius.Draw();
215
216 pad->cd(2);
217 gPad->SetBorderMode(0);
218 gPad->SetGridx();
219 gPad->SetGridy();
220 fHistArcWidth.Draw();
221
222 pad->cd(3);
223 gPad->SetBorderMode(0);
224 gPad->SetGridx();
225 gPad->SetGridy();
226 fHistSize.Draw();
227
228 TText txt;
229 txt.SetTextColor(kBlue);
230
231 TF1 ref("RefShape100%", "-77.07+1249.3*x-351.2*x*x", fgIntegralLoLim, fgIntegralUpLim);
232 // old: 573*x + 430
233 ref.SetLineColor(kBlue);
234 ref.SetLineWidth(1);
235 ref.SetLineStyle(kDashed);
236 gROOT->GetListOfFunctions()->Remove(ref.DrawCopy("same"));
237
238 txt.SetTextAlign(31);
239 txt.DrawText(fgIntegralLoLim, ref.Eval(fgIntegralLoLim+0.05), "100%");
240
241 AppendPad("pad3");
242
243 pad->cd(4);
244 gPad->SetBorderMode(0);
245 gPad->SetGridx();
246 gPad->SetGridy();
247 fHistBroad.Draw();
248
249 ref.SetName("RefShape12mm");
250 ref.Compile("- 0.02711*x + 0.09359");
251 gROOT->GetListOfFunctions()->Remove(ref.DrawCopy("same"));
252
253 txt.SetTextAlign(11);
254 txt.DrawText(fgIntegralLoLim, ref.Eval(fgIntegralLoLim-0.05), "12mm");
255
256 AppendPad("pad4");
257}
258/*
259Double_t MHMuonPar::Integral(const TProfile &p, Int_t a, Int_t b) const
260{
261 Float_t numerator = 0;
262 Float_t denominator = 0;
263
264 for (Int_t i=a; i<b; i++)
265 {
266 numerator += p.GetBinContent(i)*p.GetBinEntries(i);
267 denominator += p.GetBinEntries(i);
268 }
269
270 return denominator==0 ? 0 : numerator/denominator;
271}
272*/
273Double_t MHMuonPar::Integral(const TProfile &p, Float_t a, Float_t b) const
274{
275 const Int_t bin1 = p.GetXaxis()->FindFixBin(a);
276 const Int_t bin2 = p.GetXaxis()->FindFixBin(b);
277
278 return p.Integral(bin1, bin2);
279}
280
281void MHMuonPar::Paint(Option_t *opt)
282{
283 if (TString(opt)==TString("pad4"))
284 {
285 const TString txt = MString::Format("\\Sigma_{%.2f\\circ}^{%.2f\\circ} = %.3f",
286 fgIntegralLoLim, fgIntegralUpLim, Integral(fHistBroad));
287
288 TLatex text(0.55, 0.93, txt);
289 text.SetBit(TLatex::kTextNDC);
290 text.SetTextSize(0.055);
291 text.Paint();
292 }
293
294 if (TString(opt)==TString("pad3"))
295 {
296 const TString txt = MString::Format("\\Sigma_{%.2f\\circ}^{%.2f\\circ} = %.f",
297 fgIntegralLoLim, fgIntegralUpLim, Integral(fHistSize));
298
299 TLatex text(0.47, 0.93, txt);
300 text.SetBit(TLatex::kTextNDC);
301 text.SetTextSize(0.055);
302 text.Paint();
303 }
304}
Note: See TracBrowser for help on using the repository browser.