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 "MBinning.h"
|
---|
39 | #include "MHMcEfficiency.h"
|
---|
40 | #include "MHMcEnergyImpact.h"
|
---|
41 |
|
---|
42 | #include "MLog.h"
|
---|
43 | #include "MLogManip.h"
|
---|
44 |
|
---|
45 | ClassImp(MHMcCollectionArea);
|
---|
46 |
|
---|
47 | using namespace std;
|
---|
48 |
|
---|
49 | // --------------------------------------------------------------------------
|
---|
50 | //
|
---|
51 | // Creates the three necessary histograms:
|
---|
52 | // - selected showers (input)
|
---|
53 | // - all showers (input)
|
---|
54 | // - collection area (result)
|
---|
55 | //
|
---|
56 | MHMcCollectionArea::MHMcCollectionArea(const char *name, const char *title)
|
---|
57 | {
|
---|
58 | // initialize the histogram for the distribution r vs E
|
---|
59 | //
|
---|
60 | // we set the energy range from 2 Gev to 20000 GeV (in log 4 orders
|
---|
61 | // of magnitude) and for each order we take 25 subdivision --> 100 xbins
|
---|
62 | //
|
---|
63 | // we set the radius range from 0 m to 500 m with 10 m bin --> 50 ybins
|
---|
64 | //
|
---|
65 | fName = name ? name : "MHMcCollectionArea";
|
---|
66 | fTitle = title ? title : "Collection Area vs. Energy";
|
---|
67 |
|
---|
68 | MBinning binsx;
|
---|
69 | MBinning binsy;
|
---|
70 | binsx.SetEdgesLog(100, 2., 20000);
|
---|
71 | binsy.SetEdges (50, 0, 500);
|
---|
72 |
|
---|
73 | fHistAll = new TH2D;
|
---|
74 | fHistSel = new TH2D;
|
---|
75 | fHistCol = new TH1D;
|
---|
76 |
|
---|
77 | MH::SetBinning(fHistAll, &binsx, &binsy);
|
---|
78 | MH::SetBinning(fHistSel, &binsx, &binsy);
|
---|
79 |
|
---|
80 | fHistCol->SetName(fName);
|
---|
81 | fHistAll->SetName("AllEvents");
|
---|
82 | fHistSel->SetName("SelectedEvents");
|
---|
83 |
|
---|
84 | fHistCol->SetTitle(fTitle);
|
---|
85 | fHistAll->SetTitle("All showers - Radius vs Energy distribution");
|
---|
86 | fHistSel->SetTitle("Selected showers - Radius vs Energy distribution");
|
---|
87 |
|
---|
88 | fHistAll->SetDirectory(NULL);
|
---|
89 | fHistSel->SetDirectory(NULL);
|
---|
90 | fHistCol->SetDirectory(NULL);
|
---|
91 |
|
---|
92 | fHistAll->UseCurrentStyle();
|
---|
93 | fHistSel->UseCurrentStyle();
|
---|
94 | fHistCol->UseCurrentStyle();
|
---|
95 |
|
---|
96 | fHistAll->SetXTitle("E [GeV]");
|
---|
97 | fHistAll->SetYTitle("r [m]");
|
---|
98 | fHistAll->SetZTitle("N");
|
---|
99 |
|
---|
100 | fHistSel->SetXTitle("E [GeV]");
|
---|
101 | fHistSel->SetYTitle("r [m]");
|
---|
102 | fHistSel->SetYTitle("N");
|
---|
103 |
|
---|
104 | fHistCol->SetXTitle("E [GeV]");
|
---|
105 | fHistCol->SetYTitle("A [m^{2}]");
|
---|
106 | }
|
---|
107 |
|
---|
108 | // --------------------------------------------------------------------------
|
---|
109 | //
|
---|
110 | // Delete the three histograms
|
---|
111 | //
|
---|
112 | MHMcCollectionArea::~MHMcCollectionArea()
|
---|
113 | {
|
---|
114 | delete fHistAll;
|
---|
115 | delete fHistSel;
|
---|
116 | delete fHistCol;
|
---|
117 | }
|
---|
118 |
|
---|
119 | // --------------------------------------------------------------------------
|
---|
120 | //
|
---|
121 | // Fill data into the histogram which contains all showers
|
---|
122 | //
|
---|
123 | void MHMcCollectionArea::FillAll(Double_t energy, Double_t radius)
|
---|
124 | {
|
---|
125 | fHistAll->Fill(energy, radius);
|
---|
126 | }
|
---|
127 |
|
---|
128 | // --------------------------------------------------------------------------
|
---|
129 | //
|
---|
130 | // Fill data into the histogram which contains the selected showers
|
---|
131 | //
|
---|
132 | void MHMcCollectionArea::FillSel(Double_t energy, Double_t radius)
|
---|
133 | {
|
---|
134 | fHistSel->Fill(energy, radius);
|
---|
135 | }
|
---|
136 |
|
---|
137 | // --------------------------------------------------------------------------
|
---|
138 | //
|
---|
139 | // Draw the histogram with all showers
|
---|
140 | //
|
---|
141 | void MHMcCollectionArea::DrawAll(Option_t* option)
|
---|
142 | {
|
---|
143 | if (!gPad)
|
---|
144 | MH::MakeDefCanvas(fHistAll);
|
---|
145 |
|
---|
146 | fHistAll->Draw(option);
|
---|
147 |
|
---|
148 | gPad->SetLogx();
|
---|
149 |
|
---|
150 | gPad->Modified();
|
---|
151 | gPad->Update();
|
---|
152 | }
|
---|
153 |
|
---|
154 | // --------------------------------------------------------------------------
|
---|
155 | //
|
---|
156 | // Draw the histogram with the selected showers only.
|
---|
157 | //
|
---|
158 | void MHMcCollectionArea::DrawSel(Option_t* option)
|
---|
159 | {
|
---|
160 | if (!gPad)
|
---|
161 | MH::MakeDefCanvas(fHistSel);
|
---|
162 |
|
---|
163 | fHistSel->Draw(option);
|
---|
164 |
|
---|
165 | gPad->SetLogx();
|
---|
166 |
|
---|
167 | gPad->Modified();
|
---|
168 | gPad->Update();
|
---|
169 | }
|
---|
170 |
|
---|
171 | void MHMcCollectionArea::Draw(Option_t* option)
|
---|
172 | {
|
---|
173 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
|
---|
174 | pad->SetBorderMode(0);
|
---|
175 |
|
---|
176 | fHistCol->Draw(option);
|
---|
177 |
|
---|
178 | pad->SetLogx();
|
---|
179 |
|
---|
180 | pad->Modified();
|
---|
181 | pad->Update();
|
---|
182 | }
|
---|
183 |
|
---|
184 | // --------------------------------------------------------------------------
|
---|
185 | //
|
---|
186 | // Calculate the Efficiency (collection area) and set the 'ReadyToSave'
|
---|
187 | // flag
|
---|
188 | //
|
---|
189 | void MHMcCollectionArea::CalcEfficiency()
|
---|
190 | {
|
---|
191 | Calc(*fHistSel, *fHistAll);
|
---|
192 | }
|
---|
193 |
|
---|
194 | // --------------------------------------------------------------------------
|
---|
195 | //
|
---|
196 | // Calculate the Efficiency (collection area) and set the 'ReadyToSave'
|
---|
197 | // flag
|
---|
198 | //
|
---|
199 | void MHMcCollectionArea::Calc(const MHMcEnergyImpact &mcsel, const MHMcEnergyImpact &mcall)
|
---|
200 | {
|
---|
201 | Calc((TH2D&)*mcsel.GetHist(), (TH2D&)*mcall.GetHist());
|
---|
202 | }
|
---|
203 |
|
---|
204 | // --------------------------------------------------------------------------
|
---|
205 | //
|
---|
206 | // Calculate the Efficiency (collection area) and set the 'ReadyToSave'
|
---|
207 | // flag
|
---|
208 | //
|
---|
209 | void MHMcCollectionArea::Calc(TH2D &hsel, TH2D &hall)
|
---|
210 | {
|
---|
211 | MH::SetBinning(fHistCol, hsel.GetXaxis());
|
---|
212 |
|
---|
213 | fHistCol->Sumw2();
|
---|
214 |
|
---|
215 | TH1D &psel = *hsel.ProjectionX();
|
---|
216 | TH1D &pall = *hall.ProjectionX();
|
---|
217 |
|
---|
218 | TH1D &pally = *hall.ProjectionY();
|
---|
219 |
|
---|
220 | Double_t max = 0.;
|
---|
221 | for (Int_t i = hall.GetNbinsY(); i > 0; i--)
|
---|
222 | if (pally.GetBinContent(i) > 0)
|
---|
223 | {
|
---|
224 | max = pally.GetBinLowEdge(i+1);
|
---|
225 | break;
|
---|
226 | }
|
---|
227 |
|
---|
228 | fHistCol->Divide(&psel, &pall, TMath::Pi()*max*max, 1);
|
---|
229 | fHistCol->SetEntries(hsel.GetEntries());
|
---|
230 |
|
---|
231 | delete &psel;
|
---|
232 | delete &pall;
|
---|
233 | delete &pally;
|
---|
234 |
|
---|
235 | SetReadyToSave();
|
---|
236 | }
|
---|
237 |
|
---|
238 | // --------------------------------------------------------------------------
|
---|
239 | //
|
---|
240 | // Calculate the Efficiency (collection area) and set the 'ReadyToSave'
|
---|
241 | // flag
|
---|
242 | //
|
---|
243 | void MHMcCollectionArea::CalcEfficiency2()
|
---|
244 | {
|
---|
245 | // Here we estimate the total number of showers in each energy bin
|
---|
246 | // known the energy range and spectral index of the generated showers
|
---|
247 | // (set now by hand since the info is not available in the header!)
|
---|
248 |
|
---|
249 | TH1D &histsel = *fHistSel->ProjectionX();
|
---|
250 | TH1D &histall = *fHistAll->ProjectionX();
|
---|
251 |
|
---|
252 | TAxis &xaxis = *histsel.GetXaxis();
|
---|
253 | MH::SetBinning(fHistCol, &xaxis);
|
---|
254 | const Int_t nbinx = xaxis.GetNbins();
|
---|
255 |
|
---|
256 | // -----------------------------------------------------------
|
---|
257 | //
|
---|
258 | // Impact parameter range: TO BE FIXED! Impact parameter shoud be
|
---|
259 | // read from run header, but it is not yet in!!
|
---|
260 | //
|
---|
261 | const Float_t r1 = 0;
|
---|
262 | const Float_t r2 = 300;
|
---|
263 |
|
---|
264 | *fLog << warn << endl << dbginf << "WARNING! I will assume a maximum impact parameter of 300 meters for the MC events. Check that this is the true one!" <<endl<<endl;
|
---|
265 | const Float_t total_area = TMath::Pi() * (r2*r2 - r1*r1);
|
---|
266 |
|
---|
267 | for (Int_t ix=1; ix<=nbinx; ix++)
|
---|
268 | {
|
---|
269 | const Float_t Na = histall.GetBinContent(ix);
|
---|
270 |
|
---|
271 | if (Na <= 0)
|
---|
272 | continue;
|
---|
273 |
|
---|
274 | const Float_t Ns = histsel.GetBinContent(ix);
|
---|
275 |
|
---|
276 | // Since Na is an estimate of the total number of showers generated
|
---|
277 | // in the energy bin, it may happen that Ns (triggered showers) is
|
---|
278 | // larger than Na. In that case, the bin is skipped:
|
---|
279 |
|
---|
280 | if (Na < Ns)
|
---|
281 | continue;
|
---|
282 |
|
---|
283 | const Double_t eff = Ns/Na;
|
---|
284 |
|
---|
285 | const Double_t efferr = sqrt((1.-eff)*Ns)/Na;
|
---|
286 |
|
---|
287 | const Float_t col_area = eff * total_area;
|
---|
288 | const Float_t col_area_error = efferr * total_area;
|
---|
289 |
|
---|
290 | fHistCol->SetBinContent(ix, col_area);
|
---|
291 | fHistCol->SetBinError(ix, col_area_error);
|
---|
292 | }
|
---|
293 |
|
---|
294 | delete &histsel;
|
---|
295 |
|
---|
296 | SetReadyToSave();
|
---|
297 | }
|
---|
298 |
|
---|
299 | // --------------------------------------------------------------------------
|
---|
300 | //
|
---|
301 | // Calculate the Efficiency (collection area) and set the 'ReadyToSave'
|
---|
302 | // flag
|
---|
303 | //
|
---|
304 | void MHMcCollectionArea::Calc(const MHMcEfficiency &heff)
|
---|
305 | {
|
---|
306 | //
|
---|
307 | // now calculate the Collection area for different
|
---|
308 | // energies
|
---|
309 | //
|
---|
310 | TH2D &h = (TH2D&)*heff.GetHist();
|
---|
311 |
|
---|
312 | MH::SetBinning(fHistCol, h.GetXaxis());
|
---|
313 |
|
---|
314 | const Int_t nbinx = h.GetXaxis()->GetNbins();
|
---|
315 | const Int_t nbiny = h.GetYaxis()->GetNbins();
|
---|
316 |
|
---|
317 | for (Int_t ix=1; ix<=nbinx; ix++)
|
---|
318 | {
|
---|
319 | Double_t errA = 0;
|
---|
320 | Double_t colA = 0;
|
---|
321 |
|
---|
322 | for (Int_t iy=1; iy<=nbiny; iy++)
|
---|
323 | {
|
---|
324 | TAxis *yaxis = h.GetYaxis();
|
---|
325 |
|
---|
326 | const Double_t r1 = yaxis->GetBinLowEdge(iy);
|
---|
327 | const Double_t r2 = yaxis->GetBinLowEdge(iy+1);
|
---|
328 |
|
---|
329 | const Double_t A = TMath::Pi() * (r2*r2 - r1*r1);
|
---|
330 |
|
---|
331 | const Double_t eff = h.GetCellContent(ix, iy);
|
---|
332 | const Double_t efferr = h.GetCellError(ix, iy);
|
---|
333 |
|
---|
334 | colA += eff*A;
|
---|
335 | errA += A*A * efferr*efferr;
|
---|
336 | }
|
---|
337 |
|
---|
338 | fHistCol->SetBinContent(ix, colA);
|
---|
339 | fHistCol->SetBinError(ix, sqrt(errA));
|
---|
340 | }
|
---|
341 |
|
---|
342 | SetReadyToSave();
|
---|
343 | }
|
---|