source: trunk/MagicSoft/Mars/mhistmc/MHMcCollectionArea.cc@ 2017

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