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 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | ! Author(s): Harald Kornmayer 1/2001
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2002
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | //////////////////////////////////////////////////////////////////////////////
|
---|
27 | // //
|
---|
28 | // MHMcCollectionArea //
|
---|
29 | // //
|
---|
30 | //////////////////////////////////////////////////////////////////////////////
|
---|
31 |
|
---|
32 | #include "MHMcCollectionArea.h"
|
---|
33 |
|
---|
34 | #include <TH2.h>
|
---|
35 | #include <TCanvas.h>
|
---|
36 |
|
---|
37 | #include "MH.h"
|
---|
38 | #include "MHMcEfficiency.h"
|
---|
39 | #include "MHMcEnergyImpact.h"
|
---|
40 |
|
---|
41 | ClassImp(MHMcCollectionArea);
|
---|
42 |
|
---|
43 | // --------------------------------------------------------------------------
|
---|
44 | //
|
---|
45 | // Creates the three necessary histograms:
|
---|
46 | // - selected showers (input)
|
---|
47 | // - all showers (input)
|
---|
48 | // - collection area (result)
|
---|
49 | //
|
---|
50 | MHMcCollectionArea::MHMcCollectionArea(const char *name, const char *title)
|
---|
51 | {
|
---|
52 | // initialize the histogram for the distribution r vs E
|
---|
53 | //
|
---|
54 | // we set the energy range from 1 Gev to 10000 GeV (in log 5 orders
|
---|
55 | // of magnitude) and for each order we take 10 subdivision --> 50 xbins
|
---|
56 | //
|
---|
57 | // we set the radius range from 0 m to 500 m with 10 m bin --> 50 ybins
|
---|
58 |
|
---|
59 |
|
---|
60 | fName = name ? name : "MHMcCollectionArea";
|
---|
61 | fTitle = title ? title : "Collection Area vs. Energy";
|
---|
62 |
|
---|
63 | const Int_t nbins = 50;
|
---|
64 | const Float_t maxx = 5;
|
---|
65 | const Float_t maxy = 500;
|
---|
66 |
|
---|
67 | Float_t *binsx = new Float_t[nbins+1];
|
---|
68 | for (int i=0; i<nbins+1; i++)
|
---|
69 | binsx[i] = pow(10, maxx*i/nbins);
|
---|
70 |
|
---|
71 | Float_t *binsy = new Float_t[nbins+1];
|
---|
72 | for (int i=0; i<nbins+1; i++)
|
---|
73 | binsy[i] = maxy*i/nbins;
|
---|
74 |
|
---|
75 | fHistAll = new TH2D("AllEvents", "All showers - Radius vs Energy distribution",
|
---|
76 | nbins, binsx, nbins, binsy);
|
---|
77 | fHistSel = new TH2D("SelectedEvents", "Selected showers - Radius vs Energy distribution",
|
---|
78 | nbins, binsx, nbins, binsy);
|
---|
79 |
|
---|
80 | delete binsx;
|
---|
81 | delete binsy;
|
---|
82 |
|
---|
83 | fHistCol = new TH1D;
|
---|
84 | fHistCol->SetName(fName);
|
---|
85 | fHistCol->SetTitle(fTitle);
|
---|
86 |
|
---|
87 | fHistAll->SetDirectory(NULL);
|
---|
88 | fHistSel->SetDirectory(NULL);
|
---|
89 | fHistCol->SetDirectory(NULL);
|
---|
90 |
|
---|
91 | fHistAll->SetXTitle("E [GeV]");
|
---|
92 | fHistAll->SetYTitle("r [m]");
|
---|
93 | fHistAll->SetZTitle("N");
|
---|
94 |
|
---|
95 | fHistSel->SetXTitle("E [GeV]");
|
---|
96 | fHistSel->SetYTitle("r [m]");
|
---|
97 | fHistSel->SetYTitle("N");
|
---|
98 |
|
---|
99 | fHistCol->SetXTitle("E [GeV]");
|
---|
100 | fHistCol->SetYTitle("A [m^{2}]");
|
---|
101 | }
|
---|
102 |
|
---|
103 | // --------------------------------------------------------------------------
|
---|
104 | //
|
---|
105 | // Delete the three histograms
|
---|
106 | //
|
---|
107 | MHMcCollectionArea::~MHMcCollectionArea()
|
---|
108 | {
|
---|
109 | delete fHistAll;
|
---|
110 | delete fHistSel;
|
---|
111 | delete fHistCol;
|
---|
112 | }
|
---|
113 |
|
---|
114 | // --------------------------------------------------------------------------
|
---|
115 | //
|
---|
116 | // Fill data into the histogram which contains all showers
|
---|
117 | //
|
---|
118 | void MHMcCollectionArea::FillAll(Float_t energy, Float_t radius)
|
---|
119 | {
|
---|
120 | fHistAll->Fill(energy, radius);
|
---|
121 | }
|
---|
122 |
|
---|
123 | // --------------------------------------------------------------------------
|
---|
124 | //
|
---|
125 | // Fill data into the histogram which contains the selected showers
|
---|
126 | //
|
---|
127 | void MHMcCollectionArea::FillSel(Float_t energy, Float_t radius)
|
---|
128 | {
|
---|
129 | fHistSel->Fill(energy, radius);
|
---|
130 | }
|
---|
131 |
|
---|
132 | // --------------------------------------------------------------------------
|
---|
133 | //
|
---|
134 | // Draw the histogram with all showers
|
---|
135 | //
|
---|
136 | void MHMcCollectionArea::DrawAll(Option_t* option)
|
---|
137 | {
|
---|
138 | if (!gPad)
|
---|
139 | MH::MakeDefCanvas(fHistAll);
|
---|
140 |
|
---|
141 | fHistAll->Draw(option);
|
---|
142 |
|
---|
143 | gPad->SetLogx();
|
---|
144 |
|
---|
145 | gPad->Modified();
|
---|
146 | gPad->Update();
|
---|
147 | }
|
---|
148 |
|
---|
149 | // --------------------------------------------------------------------------
|
---|
150 | //
|
---|
151 | // Draw the histogram with the selected showers only.
|
---|
152 | //
|
---|
153 | void MHMcCollectionArea::DrawSel(Option_t* option)
|
---|
154 | {
|
---|
155 | if (!gPad)
|
---|
156 | MH::MakeDefCanvas(fHistSel);
|
---|
157 |
|
---|
158 | fHistSel->Draw(option);
|
---|
159 |
|
---|
160 | gPad->SetLogx();
|
---|
161 |
|
---|
162 | gPad->Modified();
|
---|
163 | gPad->Update();
|
---|
164 | }
|
---|
165 |
|
---|
166 | // --------------------------------------------------------------------------
|
---|
167 | //
|
---|
168 | // Creates a new canvas and draws the histogram into it.
|
---|
169 | // Be careful: The histogram belongs to this object and won't get deleted
|
---|
170 | // together with the canvas.
|
---|
171 | //
|
---|
172 | TObject *MHMcCollectionArea::DrawClone(Option_t* option) const
|
---|
173 | {
|
---|
174 | TCanvas *c = MH::MakeDefCanvas(fHistCol);
|
---|
175 |
|
---|
176 | //
|
---|
177 | // This is necessary to get the expected bahviour of DrawClone
|
---|
178 | //
|
---|
179 | gROOT->SetSelectedPad(NULL);
|
---|
180 |
|
---|
181 | fHistCol->DrawCopy(option);
|
---|
182 |
|
---|
183 | gPad->SetLogx();
|
---|
184 |
|
---|
185 | c->Modified();
|
---|
186 | c->Update();
|
---|
187 |
|
---|
188 | return c;
|
---|
189 | }
|
---|
190 |
|
---|
191 | void MHMcCollectionArea::Draw(Option_t* option)
|
---|
192 | {
|
---|
193 | if (!gPad)
|
---|
194 | MH::MakeDefCanvas(fHistCol);
|
---|
195 |
|
---|
196 | fHistCol->Draw(option);
|
---|
197 |
|
---|
198 | gPad->SetLogx();
|
---|
199 |
|
---|
200 | gPad->Modified();
|
---|
201 | gPad->Update();
|
---|
202 | }
|
---|
203 |
|
---|
204 | // --------------------------------------------------------------------------
|
---|
205 | //
|
---|
206 | // Calculate the Efficiency (collection area) and set the 'ReadyToSave'
|
---|
207 | // flag
|
---|
208 | //
|
---|
209 | void MHMcCollectionArea::CalcEfficiency()
|
---|
210 | {
|
---|
211 | Calc(*fHistSel, *fHistAll);
|
---|
212 | }
|
---|
213 |
|
---|
214 | // --------------------------------------------------------------------------
|
---|
215 | //
|
---|
216 | // Calculate the Efficiency (collection area) and set the 'ReadyToSave'
|
---|
217 | // flag
|
---|
218 | //
|
---|
219 | void MHMcCollectionArea::Calc(const MHMcEnergyImpact &mcsel, const MHMcEnergyImpact &mcall)
|
---|
220 | {
|
---|
221 | Calc((TH2D&)*mcsel.GetHist(), (TH2D&)*mcall.GetHist());
|
---|
222 | }
|
---|
223 |
|
---|
224 | // --------------------------------------------------------------------------
|
---|
225 | //
|
---|
226 | // Calculate the Efficiency (collection area) and set the 'ReadyToSave'
|
---|
227 | // flag
|
---|
228 | //
|
---|
229 | void MHMcCollectionArea::Calc(TH2D &hsel, TH2D &hall)
|
---|
230 | {
|
---|
231 | MH::SetBinning(fHistCol, hsel.GetXaxis());
|
---|
232 |
|
---|
233 | fHistCol->Sumw2();
|
---|
234 |
|
---|
235 | TH1D &psel = *hsel.ProjectionX();
|
---|
236 | TH1D &pall = *hall.ProjectionX();
|
---|
237 |
|
---|
238 | const Double_t max = psel.GetYaxis()->GetXmax();
|
---|
239 |
|
---|
240 | fHistCol->Divide(&psel, &pall, TMath::Pi()*max*max, 1);
|
---|
241 | fHistCol->SetEntries(hsel.GetEntries());
|
---|
242 |
|
---|
243 | delete &psel;
|
---|
244 | delete &pall;
|
---|
245 |
|
---|
246 | SetReadyToSave();
|
---|
247 | }
|
---|
248 |
|
---|
249 | // --------------------------------------------------------------------------
|
---|
250 | //
|
---|
251 | // Calculate the Efficiency (collection area) and set the 'ReadyToSave'
|
---|
252 | // flag
|
---|
253 | //
|
---|
254 | void MHMcCollectionArea::CalcEfficiency(UInt_t numevts, Float_t angle)
|
---|
255 | {
|
---|
256 | // Here we estimate the total number of showers in each energy bin
|
---|
257 | // known the energy range and spectral index of the generated showers
|
---|
258 | // (set now by hand since the info is not available in the header!)
|
---|
259 |
|
---|
260 | TH1D &histsel = *fHistSel->ProjectionX();
|
---|
261 |
|
---|
262 | TH1D histall;
|
---|
263 |
|
---|
264 | TAxis &xaxis = *histsel.GetXaxis();
|
---|
265 |
|
---|
266 | MH::SetBinning(&histall, &xaxis);
|
---|
267 | MH::SetBinning(fHistCol, &xaxis);
|
---|
268 |
|
---|
269 | const Float_t emin = 10.;
|
---|
270 | const Float_t emax = 30000.; // Energies in GeV.
|
---|
271 | const Float_t index = 2.6; // Differential spectral Index.
|
---|
272 |
|
---|
273 | const Float_t expo = 1.-index;
|
---|
274 |
|
---|
275 | const Float_t k = (Float_t)numevts / (pow(emax,expo) - pow(emin,expo));
|
---|
276 |
|
---|
277 | const Int_t nbinx = xaxis.GetNbins();
|
---|
278 |
|
---|
279 | for (Int_t i=1; i<=nbinx; i++)
|
---|
280 | {
|
---|
281 | const Float_t e1 = histall.GetBinLowEdge(i);
|
---|
282 | const Float_t e2 = histall.GetBinLowEdge(i+1);
|
---|
283 |
|
---|
284 | if (e1 < emin || e2 > emax)
|
---|
285 | continue;
|
---|
286 |
|
---|
287 | const Float_t events = k * (pow(e2, expo) - pow(e1, expo));
|
---|
288 |
|
---|
289 | histall.SetBinContent(i, events);
|
---|
290 | histall.SetBinError(i, sqrt(events));
|
---|
291 |
|
---|
292 | }
|
---|
293 |
|
---|
294 | // -----------------------------------------------------------
|
---|
295 |
|
---|
296 | // Impact parameter range:
|
---|
297 | const Float_t r1 = 0;
|
---|
298 | const Float_t r2 = 400;
|
---|
299 |
|
---|
300 | const Float_t dr = TMath::Pi() * (r2*r2 - r1*r1);
|
---|
301 |
|
---|
302 | angle *= TMath::Pi()/180;
|
---|
303 |
|
---|
304 | for (Int_t ix=1; ix<=nbinx; ix++)
|
---|
305 | {
|
---|
306 | const Float_t Na = histall.GetBinContent(ix);
|
---|
307 |
|
---|
308 | if (Na <= 0)
|
---|
309 | continue;
|
---|
310 |
|
---|
311 | const Float_t Ns = histsel.GetBinContent(ix);
|
---|
312 |
|
---|
313 | // Since Na is an estimate of the total number of showers generated
|
---|
314 | // in the energy bin, it may happen that Ns (triggered showers) is
|
---|
315 | // larger than Na. In that case, the bin is skipped:
|
---|
316 |
|
---|
317 | if (Na < Ns)
|
---|
318 | continue;
|
---|
319 |
|
---|
320 | const Double_t eff = Ns/Na;
|
---|
321 |
|
---|
322 | const Double_t err = sqrt((1.-eff)*Ns)/Na;
|
---|
323 |
|
---|
324 | const Float_t area = dr * cos(angle);
|
---|
325 |
|
---|
326 | fHistCol->SetBinContent(ix, eff*area);
|
---|
327 | fHistCol->SetBinError(ix, err*area);
|
---|
328 | }
|
---|
329 |
|
---|
330 | delete &histsel;
|
---|
331 |
|
---|
332 | SetReadyToSave();
|
---|
333 | }
|
---|
334 |
|
---|
335 | // --------------------------------------------------------------------------
|
---|
336 | //
|
---|
337 | // Calculate the Efficiency (collection area) and set the 'ReadyToSave'
|
---|
338 | // flag
|
---|
339 | //
|
---|
340 | void MHMcCollectionArea::Calc(const MHMcEfficiency &heff)
|
---|
341 | {
|
---|
342 | //
|
---|
343 | // now calculate the Collection area for different
|
---|
344 | // energies
|
---|
345 | //
|
---|
346 | TH2D &h = (TH2D&)*heff.GetHist();
|
---|
347 |
|
---|
348 | MH::SetBinning(fHistCol, h.GetXaxis());
|
---|
349 |
|
---|
350 | const Int_t nbinx = h.GetXaxis()->GetNbins();
|
---|
351 | const Int_t nbiny = h.GetYaxis()->GetNbins();
|
---|
352 |
|
---|
353 | for (Int_t ix=1; ix<=nbinx; ix++)
|
---|
354 | {
|
---|
355 | Double_t errA = 0;
|
---|
356 | Double_t colA = 0;
|
---|
357 |
|
---|
358 | for (Int_t iy=1; iy<=nbiny; iy++)
|
---|
359 | {
|
---|
360 | TAxis *yaxis = h.GetYaxis();
|
---|
361 |
|
---|
362 | const Double_t r1 = yaxis->GetBinLowEdge(iy);
|
---|
363 | const Double_t r2 = yaxis->GetBinLowEdge(iy+1);
|
---|
364 |
|
---|
365 | const Double_t A = TMath::Pi() * (r2*r2 - r1*r1);
|
---|
366 |
|
---|
367 | const Double_t eff = h.GetCellContent(ix, iy);
|
---|
368 | const Double_t err = h.GetCellError(ix, iy);
|
---|
369 |
|
---|
370 | colA += eff*A;
|
---|
371 | errA += A*A * err*err;
|
---|
372 | }
|
---|
373 |
|
---|
374 | fHistCol->SetBinContent(ix, colA);
|
---|
375 | fHistCol->SetBinError(ix, sqrt(errA));
|
---|
376 | }
|
---|
377 |
|
---|
378 | SetReadyToSave();
|
---|
379 | }
|
---|