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): Thomas Bretz, 2/2007 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2007
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MHReflector
|
---|
28 | //
|
---|
29 | /////////////////////////////////////////////////////////////////////////////
|
---|
30 | #include "MHReflector.h"
|
---|
31 |
|
---|
32 | #include <TLegend.h>
|
---|
33 | #include <TCanvas.h>
|
---|
34 |
|
---|
35 | #include "MLog.h"
|
---|
36 | #include "MLogManip.h"
|
---|
37 |
|
---|
38 | #include "MParList.h"
|
---|
39 | #include "MBinning.h"
|
---|
40 |
|
---|
41 | #include "MGeomCam.h"
|
---|
42 |
|
---|
43 | #include "MRflEvtData.h"
|
---|
44 | #include "MRflEvtHeader.h"
|
---|
45 |
|
---|
46 |
|
---|
47 | ClassImp(MHReflector);
|
---|
48 |
|
---|
49 | using namespace std;
|
---|
50 |
|
---|
51 | // --------------------------------------------------------------------------
|
---|
52 | //
|
---|
53 | // Default constructor. Creates and initializes the histograms
|
---|
54 | //
|
---|
55 | MHReflector::MHReflector(const char *name, const char *title)
|
---|
56 | {
|
---|
57 | fName = name ? name : "MHReflector";
|
---|
58 | fTitle = title ? title : "Histogram for the reflected photons";
|
---|
59 |
|
---|
60 | fHistXY.SetDirectory(NULL);
|
---|
61 | fHistXY.SetName("ReflXY");
|
---|
62 | fHistXY.SetTitle("Histogram vs X/Y and Energy");
|
---|
63 | fHistXY.SetXTitle("X [\\circ]");
|
---|
64 | fHistXY.SetYTitle("Y [\\circ]");
|
---|
65 | fHistXY.SetZTitle("E [GeV]");
|
---|
66 | fHistXY.Sumw2();
|
---|
67 |
|
---|
68 | fHistRad.SetDirectory(NULL);
|
---|
69 | fHistRad.SetName("ReflRad");
|
---|
70 | fHistRad.SetTitle("Histogram vs Radius and Energy");
|
---|
71 | fHistRad.SetXTitle("E [GeV]");
|
---|
72 | fHistRad.SetYTitle("R [\\circ]");
|
---|
73 | fHistRad.SetZTitle("Cnts/deg^{2}");
|
---|
74 | fHistRad.Sumw2();
|
---|
75 |
|
---|
76 | fHistSize.SetDirectory(NULL);
|
---|
77 | fHistSize.SetName("ReflSize");
|
---|
78 | fHistSize.SetTitle("Histogram vs Size and Energy");
|
---|
79 | fHistSize.SetXTitle("E [GeV]");
|
---|
80 | fHistSize.SetYTitle("N\\gamma");
|
---|
81 | fHistSize.SetZTitle("Cnts");
|
---|
82 | fHistSize.Sumw2();
|
---|
83 |
|
---|
84 | MBinning binse, binsd, binsr;
|
---|
85 | binse.SetEdgesLog(2*5, 10, 1000000);
|
---|
86 | binsd.SetEdges(50, -2.5, 2.5);
|
---|
87 | binsr.SetEdges(15, 0, 2.5);
|
---|
88 |
|
---|
89 | SetBinning(&fHistXY, &binsd, &binsd, &binse);
|
---|
90 | SetBinning(&fHistRad, &binse, &binsr);
|
---|
91 | SetBinning(&fHistSize, &binse, &binse);
|
---|
92 | }
|
---|
93 |
|
---|
94 | // --------------------------------------------------------------------------
|
---|
95 | //
|
---|
96 | // Search for MRflEvtData, MRflEvtHeader and MGeomCam
|
---|
97 | //
|
---|
98 | Bool_t MHReflector::SetupFill(const MParList *pList)
|
---|
99 | {
|
---|
100 | fHeader = (MRflEvtHeader*)pList->FindObject("MRflEvtHeader");
|
---|
101 | if (!fHeader)
|
---|
102 | {
|
---|
103 | *fLog << err << "MRflEvtHeader not found... abort." << endl;
|
---|
104 | return kFALSE;
|
---|
105 | }
|
---|
106 | fData = (MRflEvtData*)pList->FindObject("MRflEvtData");
|
---|
107 | if (!fData)
|
---|
108 | {
|
---|
109 | *fLog << err << "MRflEvtData not found... abort." << endl;
|
---|
110 | return kFALSE;
|
---|
111 | }
|
---|
112 | MGeomCam *geom = (MGeomCam*)pList->FindObject("MGeomCam");
|
---|
113 | if (!geom)
|
---|
114 | {
|
---|
115 | *fLog << err << "MGeomCam not found... abort." << endl;
|
---|
116 | return kFALSE;
|
---|
117 | }
|
---|
118 |
|
---|
119 | fMm2Deg = geom->GetConvMm2Deg();
|
---|
120 |
|
---|
121 | return kTRUE;
|
---|
122 | }
|
---|
123 |
|
---|
124 | // --------------------------------------------------------------------------
|
---|
125 | //
|
---|
126 | // Fill position and radius versus energy
|
---|
127 | //
|
---|
128 | #include "MRflSinglePhoton.h"
|
---|
129 | Bool_t MHReflector::Fill(const MParContainer *par, const Stat_t weight)
|
---|
130 | {
|
---|
131 | const Double_t energy = fHeader->GetEnergy();
|
---|
132 |
|
---|
133 | const Int_t n = fData->GetNumPhotons();
|
---|
134 |
|
---|
135 | fHistSize.Fill(energy, n);
|
---|
136 |
|
---|
137 | for (int i=0; i<n; i++)
|
---|
138 | {
|
---|
139 | const MRflSinglePhoton &ph = fData->GetPhoton(i);
|
---|
140 |
|
---|
141 | const Double_t x = ph.GetX()*fMm2Deg;
|
---|
142 | const Double_t y = ph.GetY()*fMm2Deg;
|
---|
143 | const Double_t r = TMath::Hypot(x, y);
|
---|
144 | const Double_t U = r*TMath::TwoPi();
|
---|
145 |
|
---|
146 | if (U==0)
|
---|
147 | continue;
|
---|
148 |
|
---|
149 | fHistRad.Fill(energy, r, weight/U);
|
---|
150 | //fHistXY.Fill(x, y, energy);
|
---|
151 | }
|
---|
152 |
|
---|
153 | //fData->FillRad(fHistRad, energy/*x*/, fMm2Deg);
|
---|
154 | //fData->Fill(fHistXY, energy/*z*/, fMm2Deg);
|
---|
155 |
|
---|
156 | return kTRUE;
|
---|
157 | }
|
---|
158 |
|
---|
159 | // --------------------------------------------------------------------------
|
---|
160 | //
|
---|
161 | // Scale radial histogram with area
|
---|
162 | //
|
---|
163 | Bool_t MHReflector::Finalize()
|
---|
164 | {
|
---|
165 | /*
|
---|
166 | const TAxis &axey = *fHistRad.GetYaxis();
|
---|
167 | for (int y=1; y<=fHistRad.GetNbinsY(); y++)
|
---|
168 | {
|
---|
169 | const Double_t lo = axey.GetBinLowEdge(y);
|
---|
170 | const Double_t hi = axey.GetBinLowEdge(y+1);
|
---|
171 |
|
---|
172 | const Double_t A = (hi*hi-lo*lo)*TMath::Pi()*TMath::Pi();
|
---|
173 |
|
---|
174 | for (int x=1; x<=fHistRad.GetNbinsX(); x++)
|
---|
175 | fHistRad.SetBinContent(x, y, fHistRad.GetBinContent(x, y)/A);
|
---|
176 | }
|
---|
177 | */
|
---|
178 | return kTRUE;
|
---|
179 | }
|
---|
180 |
|
---|
181 | #include "../mmc/MMcEvt.hxx"
|
---|
182 | void MHReflector::Draw(Option_t *o)
|
---|
183 | {
|
---|
184 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
|
---|
185 | pad->SetBorderMode(0);
|
---|
186 |
|
---|
187 | AppendPad();
|
---|
188 |
|
---|
189 | pad->Divide(3,2);
|
---|
190 |
|
---|
191 | pad->cd(1);
|
---|
192 | gPad->SetBorderMode(0);
|
---|
193 | gPad->SetLogx();
|
---|
194 | fHistRad.Draw("colz");
|
---|
195 |
|
---|
196 | pad->cd(2);
|
---|
197 | gPad->SetBorderMode(0);
|
---|
198 | TH1 *h = fHistRad.ProjectionY("ProfRad", -1, -1, "e");
|
---|
199 | h->SetTitle("RadialProfile");
|
---|
200 | h->SetDirectory(NULL);
|
---|
201 | h->SetBit(kCanDelete);
|
---|
202 | h->SetLineWidth(2);
|
---|
203 | h->SetLineColor(kBlue);
|
---|
204 | h->SetStats(kFALSE);
|
---|
205 | h->Draw("");
|
---|
206 |
|
---|
207 | pad->cd(3);
|
---|
208 | gPad->SetBorderMode(0);
|
---|
209 | gPad->SetLogx();
|
---|
210 | gPad->SetLogy();
|
---|
211 | h = fHistSize.ProjectionY("ProfSize", -1, -1, "e");
|
---|
212 | h->SetTitle("Size distribution");
|
---|
213 | h->SetDirectory(NULL);
|
---|
214 | h->SetBit(kCanDelete);
|
---|
215 | h->SetLineColor(kBlue);
|
---|
216 | h->SetLineWidth(2);
|
---|
217 | h->SetStats(kFALSE);
|
---|
218 | h->Draw("");
|
---|
219 |
|
---|
220 | pad->cd(5);
|
---|
221 | gPad->SetBorderMode(0);
|
---|
222 |
|
---|
223 | TLegend *leg = new TLegend(0.01, 0.01, 0.99, 0.99, "Energy Range");
|
---|
224 | for (int i=1; i<=fHistRad.GetNbinsX(); i++)
|
---|
225 | {
|
---|
226 | h = fHistRad.ProjectionY(Form("ProjRad%d", i), i, i, "e");
|
---|
227 | h->SetDirectory(NULL);
|
---|
228 | h->SetBit(kCanDelete);
|
---|
229 | h->SetLineWidth(2);
|
---|
230 | h->SetStats(kFALSE);
|
---|
231 | h->Draw(i==1?"":"same");
|
---|
232 | if (i==1)
|
---|
233 | h->SetTitle("Radial Profile");
|
---|
234 |
|
---|
235 | const Float_t xlo = fHistRad.GetXaxis()->GetBinLowEdge(i);
|
---|
236 | const Float_t xhi = fHistRad.GetXaxis()->GetBinUpEdge(i);
|
---|
237 |
|
---|
238 | const TString lo = MMcEvt::GetEnergyStr(xlo);
|
---|
239 | const TString hi = MMcEvt::GetEnergyStr(xhi);
|
---|
240 |
|
---|
241 | leg->AddEntry(h, Form("%s - %s", lo.Data(), hi.Data()));
|
---|
242 | }
|
---|
243 |
|
---|
244 | pad->cd(4);
|
---|
245 | gPad->SetBorderMode(0);
|
---|
246 | leg->SetBit(kCanDelete);
|
---|
247 | leg->Draw();
|
---|
248 |
|
---|
249 | pad->cd(6);
|
---|
250 | gPad->SetBorderMode(0);
|
---|
251 |
|
---|
252 | gPad->SetLogx();
|
---|
253 | gPad->SetLogy();
|
---|
254 |
|
---|
255 | for (int i=1; i<=fHistSize.GetNbinsX(); i++)
|
---|
256 | {
|
---|
257 | h = fHistSize.ProjectionY(Form("ProjSize%d", i), i, i, "e");
|
---|
258 | h->SetDirectory(NULL);
|
---|
259 | h->SetBit(kCanDelete);
|
---|
260 | h->SetLineWidth(2);
|
---|
261 | h->SetStats(kFALSE);
|
---|
262 | h->Draw(i==1?"":"same");
|
---|
263 | if (i==1)
|
---|
264 | h->SetTitle("Size distribution");
|
---|
265 | }
|
---|
266 | }
|
---|
267 |
|
---|
268 | void MHReflector::Paint(Option_t *opt)
|
---|
269 | {
|
---|
270 | TVirtualPad *pad = gPad;
|
---|
271 |
|
---|
272 | pad->cd(1);
|
---|
273 | SetPalette("pretty");
|
---|
274 |
|
---|
275 | TH1 *h=0;
|
---|
276 |
|
---|
277 | pad->cd(2);
|
---|
278 | gPad->SetBorderMode(0);
|
---|
279 | if (gPad->FindObject("ProfRad"))
|
---|
280 | {
|
---|
281 | h = fHistRad.ProjectionY("ProfRad", -1, -1, "e");
|
---|
282 | h->Scale(1./h->Integral());
|
---|
283 | }
|
---|
284 |
|
---|
285 | pad->cd(3);
|
---|
286 | gPad->SetBorderMode(0);
|
---|
287 | if (gPad->FindObject("ProfSize"))
|
---|
288 | {
|
---|
289 | h = fHistSize.ProjectionY("ProfSize", -1, -1, "e");
|
---|
290 | h->Scale(1./h->Integral());
|
---|
291 | }
|
---|
292 |
|
---|
293 | pad->cd(5);
|
---|
294 |
|
---|
295 | for (int i=1; i<=fHistRad.GetNbinsX(); i++)
|
---|
296 | {
|
---|
297 | const TString name = Form("ProjRad%d", i);
|
---|
298 | if (!gPad->FindObject(name))
|
---|
299 | continue;
|
---|
300 |
|
---|
301 | h = fHistRad.ProjectionY(name, i, i, "e");
|
---|
302 | h->SetLineColor(i);
|
---|
303 | h->Scale(1./fHistRad.Integral());
|
---|
304 | if (i==1)
|
---|
305 | h->SetMaximum(fHistRad.GetMaximum()/fHistRad.Integral()*1.05);
|
---|
306 | }
|
---|
307 |
|
---|
308 | pad->cd(6);
|
---|
309 |
|
---|
310 | for (int i=1; i<=fHistRad.GetNbinsX(); i++)
|
---|
311 | {
|
---|
312 | const TString name = Form("ProjSize%d", i);
|
---|
313 | if (!gPad->FindObject(name))
|
---|
314 | continue;
|
---|
315 |
|
---|
316 | h = fHistSize.ProjectionY(name, i, i, "e");
|
---|
317 | h->SetLineColor(i);
|
---|
318 | h->Scale(1./fHistSize.Integral());
|
---|
319 | if (i==1)
|
---|
320 | {
|
---|
321 | h->SetMaximum(TMath::Power(fHistSize.GetMaximum()/fHistSize.Integral(), 1.05));
|
---|
322 | h->SetMinimum(TMath::Power(fHistSize.GetMinimum(0)/fHistSize.Integral(), 0.95));
|
---|
323 | }
|
---|
324 | }
|
---|
325 |
|
---|
326 | }
|
---|