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 1/2002 <mailto:tbretz@uni-sw.gwdg.de>
|
---|
19 | ! Author(s): Wolfgang Wittek 1/2002 <mailto:wittek@mppmu.mpg.de>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2002
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | //////////////////////////////////////////////////////////////////////////////
|
---|
27 | // //
|
---|
28 | // MHAlphaEnergyTheta //
|
---|
29 | // //
|
---|
30 | // 3D-histogram in alpha, E-est and Theta //
|
---|
31 | // //
|
---|
32 | //////////////////////////////////////////////////////////////////////////////
|
---|
33 |
|
---|
34 | #include "MHAlphaEnergyTheta.h"
|
---|
35 |
|
---|
36 | #include <TCanvas.h>
|
---|
37 |
|
---|
38 | #include <math.h>
|
---|
39 |
|
---|
40 | #include "MMcEvt.hxx"
|
---|
41 | #include "MHillasSrc.h"
|
---|
42 | #include "MEnergyEst.h"
|
---|
43 |
|
---|
44 | #include "MBinning.h"
|
---|
45 | #include "MParList.h"
|
---|
46 |
|
---|
47 | #include "MLog.h"
|
---|
48 | #include "MLogManip.h"
|
---|
49 |
|
---|
50 | ClassImp(MHAlphaEnergyTheta);
|
---|
51 |
|
---|
52 | // --------------------------------------------------------------------------
|
---|
53 | //
|
---|
54 | // Default Constructor. It sets name and title of the histogram.
|
---|
55 | //
|
---|
56 | MHAlphaEnergyTheta::MHAlphaEnergyTheta(const char *name, const char *title)
|
---|
57 | {
|
---|
58 | //
|
---|
59 | // set the name and title of this object
|
---|
60 | //
|
---|
61 | fName = name ? name : "MHAlphaEnergyTheta";
|
---|
62 | fTitle = title ? title : "3-D histogram in alpha, energy and theta";
|
---|
63 |
|
---|
64 | fHist.SetDirectory(NULL);
|
---|
65 |
|
---|
66 | fHist.SetTitle("3D-plot of alpha, E-est, Theta");
|
---|
67 | fHist.SetXTitle("\\alpha [\\circ]");
|
---|
68 | fHist.SetYTitle("E-est [GeV] ");
|
---|
69 | fHist.SetZTitle("\\Theta [\\circ]");
|
---|
70 | }
|
---|
71 |
|
---|
72 | // --------------------------------------------------------------------------
|
---|
73 | //
|
---|
74 | // Set binnings and prepare filling of the histogram
|
---|
75 | //
|
---|
76 | Bool_t MHAlphaEnergyTheta::SetupFill(const MParList *plist)
|
---|
77 | {
|
---|
78 | fEnergy = (MEnergyEst*)plist->FindObject("MEnergyEst");
|
---|
79 | if (!fEnergy)
|
---|
80 | {
|
---|
81 | *fLog << err << dbginf << "MEnergyEst not found... aborting." << endl;
|
---|
82 | return kFALSE;
|
---|
83 | }
|
---|
84 |
|
---|
85 | fMcEvt = (MMcEvt*)plist->FindObject("MMcEvt");
|
---|
86 | if (!fMcEvt)
|
---|
87 | {
|
---|
88 | *fLog << err << dbginf << "MMcEvt not found... aborting." << endl;
|
---|
89 | return kFALSE;
|
---|
90 | }
|
---|
91 |
|
---|
92 | MBinning* binsenergy = (MBinning*)plist->FindObject("BinningE");
|
---|
93 | MBinning* binsalpha = (MBinning*)plist->FindObject("BinningAlpha");
|
---|
94 | MBinning* binstheta = (MBinning*)plist->FindObject("BinningTheta");
|
---|
95 | if (!binsenergy || !binsalpha || !binstheta)
|
---|
96 | {
|
---|
97 | *fLog << err << dbginf << "At least one MBinning not found... aborting." << endl;
|
---|
98 | return kFALSE;
|
---|
99 | }
|
---|
100 |
|
---|
101 | SetBinning(&fHist, binsalpha, binsenergy, binstheta);
|
---|
102 |
|
---|
103 | fHist.Sumw2();
|
---|
104 |
|
---|
105 | return kTRUE;
|
---|
106 | }
|
---|
107 |
|
---|
108 | // --------------------------------------------------------------------------
|
---|
109 | //
|
---|
110 | // Fill the histogram
|
---|
111 | //
|
---|
112 | Bool_t MHAlphaEnergyTheta::Fill(const MParContainer *par)
|
---|
113 | {
|
---|
114 | MHillasSrc &hil = *(MHillasSrc*)par;
|
---|
115 |
|
---|
116 | fHist.Fill(hil.GetAlpha(), fEnergy->GetEnergy(), fMcEvt->GetTheta()*kRad2Deg);
|
---|
117 |
|
---|
118 | return kTRUE;
|
---|
119 | }
|
---|
120 |
|
---|
121 | // --------------------------------------------------------------------------
|
---|
122 | //
|
---|
123 | // Draw the histogram
|
---|
124 | //
|
---|
125 | void MHAlphaEnergyTheta::Draw(Option_t *opt)
|
---|
126 | {
|
---|
127 | if (!gPad)
|
---|
128 | MakeDefCanvas("AlphaEnergyTheta", fTitle);
|
---|
129 |
|
---|
130 | gPad->Divide(2,2);
|
---|
131 |
|
---|
132 | TH1 *h;
|
---|
133 |
|
---|
134 | gPad->cd(1);
|
---|
135 | h = fHist.Project3D("expro");
|
---|
136 |
|
---|
137 | h->SetTitle("Distribution of \\alpha [\\circ]");
|
---|
138 | h->SetXTitle("\\alpha [\\circ]");
|
---|
139 | h->SetYTitle("Counts");
|
---|
140 |
|
---|
141 | h->Draw(opt);
|
---|
142 | h->SetBit(kCanDelete);
|
---|
143 |
|
---|
144 | gPad->cd(2);
|
---|
145 | h = fHist.Project3D("eypro");
|
---|
146 |
|
---|
147 | h->SetTitle("Distribution of E-est [GeV]");
|
---|
148 | h->SetXTitle("E-est [GeV] ");
|
---|
149 | h->SetYTitle("Counts");
|
---|
150 |
|
---|
151 | h->Draw(opt);
|
---|
152 | h->SetBit(kCanDelete);
|
---|
153 | gPad->SetLogx();
|
---|
154 |
|
---|
155 | gPad->cd(3);
|
---|
156 | h = fHist.Project3D("ezpro");
|
---|
157 |
|
---|
158 | h->SetTitle("Distribution of \\Theta [\\circ]");
|
---|
159 | h->SetXTitle("\\Theta [\\circ]");
|
---|
160 | h->SetYTitle("Counts");
|
---|
161 |
|
---|
162 | h->Draw(opt);
|
---|
163 | h->SetBit(kCanDelete);
|
---|
164 |
|
---|
165 | gPad->cd(4);
|
---|
166 | fHist.Draw(opt);
|
---|
167 |
|
---|
168 | gPad->Modified();
|
---|
169 | gPad->Update();
|
---|
170 | }
|
---|
171 |
|
---|
172 | // --------------------------------------------------------------------------
|
---|
173 | //
|
---|
174 | // Draw copies of the histogram
|
---|
175 | //
|
---|
176 | TObject *MHAlphaEnergyTheta::DrawClone(Option_t *opt) const
|
---|
177 | {
|
---|
178 | TCanvas &c = *MakeDefCanvas("AlphaEnergyTheta", fTitle);
|
---|
179 | c.Divide(2, 2);
|
---|
180 |
|
---|
181 | gROOT->SetSelectedPad(NULL);
|
---|
182 |
|
---|
183 | TH1 *h;
|
---|
184 |
|
---|
185 | c.cd(1);
|
---|
186 | h = ((TH3*)(&fHist))->Project3D("expro");
|
---|
187 |
|
---|
188 | h->SetTitle("Distribution of \\alpha [\\circ]");
|
---|
189 | h->SetXTitle("\\alpha [\\circ]");
|
---|
190 | h->SetYTitle("Counts");
|
---|
191 |
|
---|
192 | h->Draw(opt);
|
---|
193 | h->SetBit(kCanDelete);
|
---|
194 |
|
---|
195 | c.cd(2);
|
---|
196 | h = ((TH3*)(&fHist))->Project3D("eypro");
|
---|
197 |
|
---|
198 | h->SetTitle("Distribution of E-est [GeV]");
|
---|
199 | h->SetXTitle("E-est [GeV] ");
|
---|
200 | h->SetYTitle("Counts");
|
---|
201 |
|
---|
202 | h->Draw(opt);
|
---|
203 | h->SetBit(kCanDelete);
|
---|
204 | gPad->SetLogx();
|
---|
205 |
|
---|
206 | c.cd(3);
|
---|
207 | h = ((TH3*)(&fHist))->Project3D("ezpro");
|
---|
208 |
|
---|
209 | h->SetTitle("Distribution of \\Theta [\\circ]");
|
---|
210 | h->SetXTitle("\\Theta [\\circ]");
|
---|
211 | h->SetYTitle("Counts");
|
---|
212 |
|
---|
213 | h->Draw(opt);
|
---|
214 | h->SetBit(kCanDelete);
|
---|
215 |
|
---|
216 | c.cd(4);
|
---|
217 | ((TH3&)fHist).DrawCopy(opt);
|
---|
218 |
|
---|
219 | c.Modified();
|
---|
220 | c.Update();
|
---|
221 |
|
---|
222 | return &c;
|
---|
223 | }
|
---|
224 |
|
---|
225 | // --------------------------------------------------------------------------
|
---|
226 | //
|
---|
227 | // Calculate the histogram as the difference of two histograms :
|
---|
228 | // fHist(gamma) = h1(source) - h2(antisource)
|
---|
229 | //
|
---|
230 | void MHAlphaEnergyTheta::Subtract(const TH3D *h1, const TH3D *h2)
|
---|
231 | {
|
---|
232 | // MH::SetBinning(&fHist, (TH1*)h1);
|
---|
233 |
|
---|
234 | // fHist.Sumw2();
|
---|
235 | fHist.Add((TH1*)h1, (TH1*)h2, 1, -1); // Root: FIXME
|
---|
236 | }
|
---|
237 |
|
---|
238 |
|
---|
239 | // --------------------------------------------------------------------------
|
---|
240 | //
|
---|
241 | // Integrate fHist(gamma) in the alpha range (lo, up)
|
---|
242 | //
|
---|
243 | TH2D *MHAlphaEnergyTheta::GetAlphaProjection(Axis_t lo, Axis_t up)
|
---|
244 | {
|
---|
245 | if (up < lo)
|
---|
246 | {
|
---|
247 | *fLog << err << fName << ": Alpha projection not possible: lo=" << lo << " up=" << up << endl;
|
---|
248 | return NULL;
|
---|
249 | }
|
---|
250 |
|
---|
251 | TAxis &axe = *fHist.GetXaxis();
|
---|
252 |
|
---|
253 | Int_t ilo = axe.FindFixBin(lo);
|
---|
254 | Int_t iup = axe.FindFixBin(up);
|
---|
255 |
|
---|
256 | const Double_t epslo1 = lo-axe.GetBinLowEdge(ilo);
|
---|
257 | const Double_t epslo2 = axe.GetBinUpEdge(ilo)-lo;
|
---|
258 |
|
---|
259 | const Double_t epsup1 = up-axe.GetBinLowEdge(iup);
|
---|
260 | const Double_t epsup2 = axe.GetBinUpEdge(iup)-up;
|
---|
261 |
|
---|
262 | const Double_t epslo = epslo1<epslo2 ? epslo1 : epslo2;
|
---|
263 | const Double_t epsup = epsup1<epsup2 ? epsup1 : epsup2;
|
---|
264 |
|
---|
265 | if (epslo1>epslo2)
|
---|
266 | ilo++;
|
---|
267 |
|
---|
268 | if (epsup1<epsup2)
|
---|
269 | iup--;
|
---|
270 |
|
---|
271 | if (epslo>0.01*axe.GetBinWidth(ilo) || epsup>0.01*axe.GetBinWidth(iup))
|
---|
272 | {
|
---|
273 | *fLog << err << fName << ": binning is not adequate for the requested projection:" << endl;
|
---|
274 | *fLog << "Please specify a lower or upper limit which is not more than 1% away from a bin edge" << endl;
|
---|
275 | *fLog << " epslo = " << epslo << endl;
|
---|
276 | *fLog << " epsup = " << epsup << endl;
|
---|
277 | *fLog << " dwl = " << axe.GetBinWidth(ilo) << endl;
|
---|
278 | *fLog << " dwu = " << axe.GetBinWidth(iup) << endl;
|
---|
279 | return NULL;
|
---|
280 | }
|
---|
281 |
|
---|
282 | axe.SetRange(ilo, iup);
|
---|
283 |
|
---|
284 | TH2D &h2D = *(TH2D *)fHist.Project3D("ezypro");
|
---|
285 |
|
---|
286 | h2D.SetTitle("2D-plot of Theta vs. E-est");
|
---|
287 | h2D.SetXTitle("E-est [GeV] ");
|
---|
288 | h2D.SetYTitle("\\Theta [\\circ]");
|
---|
289 |
|
---|
290 | return &h2D;
|
---|
291 | }
|
---|
292 |
|
---|
293 | // --------------------------------------------------------------------------
|
---|
294 | //
|
---|
295 | // Draw the integrated histogram
|
---|
296 | //
|
---|
297 | TH2D *MHAlphaEnergyTheta::DrawAlphaProjection(Axis_t lo, Axis_t up, Option_t *opt)
|
---|
298 | {
|
---|
299 | TH2D *h2D = GetAlphaProjection(lo, up);
|
---|
300 |
|
---|
301 | if (!h2D)
|
---|
302 | return NULL;
|
---|
303 |
|
---|
304 | char txt[100];
|
---|
305 | sprintf(txt, "No.of Gammas vs. E-est and Theta (%.1f < alpha < %.1f deg)", lo, up);
|
---|
306 |
|
---|
307 | // TCanvas *c = MakeDefCanvas("AlphaEnergyTheta", "2D histogram of gamma signal in energy and theta");
|
---|
308 | TCanvas &c = *MakeDefCanvas("AlphaEnergyTheta", txt);
|
---|
309 |
|
---|
310 | c.Divide(2, 2);
|
---|
311 |
|
---|
312 | gROOT->SetSelectedPad(NULL);
|
---|
313 |
|
---|
314 | TH1 *h;
|
---|
315 |
|
---|
316 | c.cd(1);
|
---|
317 | h = h2D->ProjectionX("Eest", -1, 9999, "E");
|
---|
318 | h->SetTitle("Distribution of E-est [GeV]");
|
---|
319 | h->SetXTitle("E-est [GeV] ");
|
---|
320 | h->SetYTitle("Counts");
|
---|
321 |
|
---|
322 | h->Draw(opt);
|
---|
323 | h->SetBit(kCanDelete);
|
---|
324 | gPad->SetLogx();
|
---|
325 |
|
---|
326 | c.cd(2);
|
---|
327 | h = h2D->ProjectionY("theta", -1, 9999, "E");
|
---|
328 | h->SetTitle("Distribution of \\Theta [\\circ]");
|
---|
329 | h->SetXTitle("\\Theta [\\circ]");
|
---|
330 | h->SetYTitle("Counts");
|
---|
331 |
|
---|
332 | h->Draw(opt);
|
---|
333 | h->SetBit(kCanDelete);
|
---|
334 |
|
---|
335 | c.cd(3);
|
---|
336 |
|
---|
337 | h2D->DrawCopy(opt);
|
---|
338 | gPad->SetLogx();
|
---|
339 |
|
---|
340 | c.Modified();
|
---|
341 | c.Update();
|
---|
342 |
|
---|
343 | return h2D;
|
---|
344 | }
|
---|
345 |
|
---|
346 |
|
---|
347 |
|
---|
348 |
|
---|
349 |
|
---|
350 |
|
---|
351 |
|
---|
352 |
|
---|
353 |
|
---|
354 |
|
---|
355 |
|
---|
356 |
|
---|