source: trunk/MagicSoft/Mars/mreflector/MHReflector.cc@ 9211

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