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

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