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): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
|
---|
19 | ! Thomas Bretz 12/2000 (tbretz@uni-sw.gwdg.de)
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2001
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | #include "MHMcCollectionArea.h"
|
---|
27 |
|
---|
28 | #include <TH2.h>
|
---|
29 | #include <TCanvas.h>
|
---|
30 |
|
---|
31 | #include "MH.h"
|
---|
32 |
|
---|
33 | ClassImp(MHMcCollectionArea);
|
---|
34 |
|
---|
35 | // --------------------------------------------------------------------------
|
---|
36 | //
|
---|
37 | // Creates the three necessary histograms:
|
---|
38 | // - selected showers (input)
|
---|
39 | // - all showers (input)
|
---|
40 | // - collection area (result)
|
---|
41 | //
|
---|
42 | MHMcCollectionArea::MHMcCollectionArea(const char *name, const char *title)
|
---|
43 | {
|
---|
44 | // initialize the histogram for the distribution r vs E
|
---|
45 | //
|
---|
46 | // we set the energy range from 1 Gev to 10000 GeV (in log 5 orders
|
---|
47 | // of magnitude) and for each order we take 10 subdivision --> 50 xbins
|
---|
48 | //
|
---|
49 | // we set the radius range from 0 m to 500 m with 10 m bin --> 50 ybins
|
---|
50 |
|
---|
51 |
|
---|
52 | fName = name ? name : "MHMcCollectionArea";
|
---|
53 | fTitle = title ? title : "Data to Calculate Collection Area";
|
---|
54 |
|
---|
55 | const Int_t nbins = 50;
|
---|
56 | const Float_t maxx = 5;
|
---|
57 | const Float_t maxy = 500;
|
---|
58 |
|
---|
59 | Float_t *binsx = new Float_t[nbins+1];
|
---|
60 | for (int i=0; i<nbins+1; i++)
|
---|
61 | binsx[i] = pow(10, maxx*i/nbins);
|
---|
62 |
|
---|
63 | Float_t *binsy = new Float_t[nbins+1];
|
---|
64 | for (int i=0; i<nbins+1; i++)
|
---|
65 | binsy[i] = maxy*i/nbins;
|
---|
66 |
|
---|
67 | fHistAll = new TH2D("AllEvents", "All showers - Radius vs Energy distribution",
|
---|
68 | nbins, binsx, nbins, binsy);
|
---|
69 | fHistSel = new TH2D("SelectedEvents", "Selected showers - Radius vs Energy distribution",
|
---|
70 | nbins, binsx, nbins, binsy);
|
---|
71 | fHistCol = new TH1D("CollectionArea", "Collection Area vs. Energy",
|
---|
72 | nbins, binsx);
|
---|
73 |
|
---|
74 | delete binsx;
|
---|
75 | delete binsy;
|
---|
76 |
|
---|
77 | fHistAll->SetDirectory(NULL);
|
---|
78 | fHistSel->SetDirectory(NULL);
|
---|
79 | fHistCol->SetDirectory(NULL);
|
---|
80 |
|
---|
81 | fHistAll->SetXTitle("E [GeV]");
|
---|
82 | fHistAll->SetYTitle("r [m]");
|
---|
83 | fHistAll->SetZTitle("N");
|
---|
84 |
|
---|
85 | fHistSel->SetXTitle("E [GeV]");
|
---|
86 | fHistSel->SetYTitle("r [m]");
|
---|
87 | fHistSel->SetYTitle("N");
|
---|
88 |
|
---|
89 | fHistCol->SetXTitle("E [GeV]");
|
---|
90 | fHistCol->SetYTitle("A [m^{2}]");
|
---|
91 | }
|
---|
92 |
|
---|
93 | // --------------------------------------------------------------------------
|
---|
94 | //
|
---|
95 | // Delete the three histograms
|
---|
96 | //
|
---|
97 | MHMcCollectionArea::~MHMcCollectionArea()
|
---|
98 | {
|
---|
99 | delete fHistAll;
|
---|
100 | delete fHistSel;
|
---|
101 | delete fHistCol;
|
---|
102 | }
|
---|
103 |
|
---|
104 | // --------------------------------------------------------------------------
|
---|
105 | //
|
---|
106 | // Fill data into the histogram which contains all showers
|
---|
107 | //
|
---|
108 | void MHMcCollectionArea::FillAll(Float_t energy, Float_t radius)
|
---|
109 | {
|
---|
110 | fHistAll->Fill(energy, radius);
|
---|
111 | }
|
---|
112 |
|
---|
113 | // --------------------------------------------------------------------------
|
---|
114 | //
|
---|
115 | // Fill data into the histogram which contains the selected showers
|
---|
116 | //
|
---|
117 | void MHMcCollectionArea::FillSel(Float_t energy, Float_t radius)
|
---|
118 | {
|
---|
119 | fHistSel->Fill(energy, radius);
|
---|
120 | }
|
---|
121 |
|
---|
122 | // --------------------------------------------------------------------------
|
---|
123 | //
|
---|
124 | // Draw the histogram with all showers
|
---|
125 | //
|
---|
126 | void MHMcCollectionArea::DrawAll(Option_t* option)
|
---|
127 | {
|
---|
128 | if (!gPad)
|
---|
129 | MH::MakeDefCanvas(fHistAll);
|
---|
130 |
|
---|
131 | fHistAll->Draw(option);
|
---|
132 |
|
---|
133 | gPad->SetLogx();
|
---|
134 |
|
---|
135 | gPad->Modified();
|
---|
136 | gPad->Update();
|
---|
137 | }
|
---|
138 |
|
---|
139 | // --------------------------------------------------------------------------
|
---|
140 | //
|
---|
141 | // Draw the histogram with the selected showers only.
|
---|
142 | //
|
---|
143 | void MHMcCollectionArea::DrawSel(Option_t* option)
|
---|
144 | {
|
---|
145 | if (!gPad)
|
---|
146 | MH::MakeDefCanvas(fHistSel);
|
---|
147 |
|
---|
148 | fHistSel->Draw(option);
|
---|
149 |
|
---|
150 | gPad->SetLogx();
|
---|
151 |
|
---|
152 | gPad->Modified();
|
---|
153 | gPad->Update();
|
---|
154 | }
|
---|
155 |
|
---|
156 | // --------------------------------------------------------------------------
|
---|
157 | //
|
---|
158 | // Creates a new canvas and draws the histogram into it.
|
---|
159 | // Be careful: The histogram belongs to this object and won't get deleted
|
---|
160 | // together with the canvas.
|
---|
161 | //
|
---|
162 | TObject *MHMcCollectionArea::DrawClone(Option_t* option) const
|
---|
163 | {
|
---|
164 | TCanvas *c = MH::MakeDefCanvas(fHistCol);
|
---|
165 |
|
---|
166 | //
|
---|
167 | // This is necessary to get the expected bahviour of DrawClone
|
---|
168 | //
|
---|
169 | gROOT->SetSelectedPad(NULL);
|
---|
170 |
|
---|
171 | fHistCol->DrawCopy(option);
|
---|
172 |
|
---|
173 | gPad->SetLogx();
|
---|
174 |
|
---|
175 | c->Modified();
|
---|
176 | c->Update();
|
---|
177 |
|
---|
178 | return c;
|
---|
179 | }
|
---|
180 |
|
---|
181 | void MHMcCollectionArea::Draw(Option_t* option)
|
---|
182 | {
|
---|
183 | if (!gPad)
|
---|
184 | MH::MakeDefCanvas(fHistCol);
|
---|
185 |
|
---|
186 | fHistCol->Draw(option);
|
---|
187 |
|
---|
188 | gPad->SetLogx();
|
---|
189 |
|
---|
190 | gPad->Modified();
|
---|
191 | gPad->Update();
|
---|
192 | }
|
---|
193 |
|
---|
194 | // --------------------------------------------------------------------------
|
---|
195 | //
|
---|
196 | // Calculate the Efficiency (collection area)
|
---|
197 | //
|
---|
198 | void MHMcCollectionArea::CalcEfficiency()
|
---|
199 | {
|
---|
200 | // Description!
|
---|
201 |
|
---|
202 | //
|
---|
203 | // first of all calculate the efficency
|
---|
204 | // do it here by hand to get the right error of efficency
|
---|
205 | //
|
---|
206 | const Int_t nbinx = fHistSel->GetXaxis()->GetNbins();
|
---|
207 | const Int_t nbiny = fHistSel->GetYaxis()->GetNbins();
|
---|
208 |
|
---|
209 | for (Int_t ix=1; ix<=nbinx; ix++)
|
---|
210 | {
|
---|
211 | for (Int_t iy=1; iy<=nbiny; iy++)
|
---|
212 | {
|
---|
213 | const Float_t Na = fHistAll->GetCellContent(ix, iy);
|
---|
214 |
|
---|
215 | if (Na <= 0)
|
---|
216 | continue;
|
---|
217 |
|
---|
218 | const Float_t Ns = fHistSel->GetCellContent(ix, iy);
|
---|
219 |
|
---|
220 | const Double_t eff = Ns/Na;
|
---|
221 | const Double_t err = sqrt((1.-eff)*Ns)/Na;
|
---|
222 |
|
---|
223 | // old calculation from Harald:
|
---|
224 | // const Double_t eff = Ns/Na;
|
---|
225 | // const Double_t err = sqrt(Na + Na*Ns - Ns*Ns - Ns) / (Na*Na);
|
---|
226 |
|
---|
227 | fHistSel->SetCellContent(ix, iy, eff);
|
---|
228 | fHistSel->SetCellError(ix, iy, err);
|
---|
229 | }
|
---|
230 | }
|
---|
231 |
|
---|
232 | //
|
---|
233 | // now calculate the Collection area for different
|
---|
234 | // energies
|
---|
235 | //
|
---|
236 | for (Int_t ix=1; ix<=nbinx; ix++)
|
---|
237 | {
|
---|
238 | Double_t errA = 0;
|
---|
239 | Double_t colA = 0;
|
---|
240 |
|
---|
241 | for (Int_t iy=1; iy<=nbiny; iy++)
|
---|
242 | {
|
---|
243 | TAxis *yaxis = fHistSel->GetYaxis();
|
---|
244 |
|
---|
245 | const Double_t r1 = yaxis->GetBinLowEdge(iy);
|
---|
246 | const Double_t r2 = yaxis->GetBinLowEdge(iy+1);
|
---|
247 |
|
---|
248 | const Double_t A = TMath::Pi() * (r2*r2 - r1*r1);
|
---|
249 |
|
---|
250 | const Double_t eff = fHistSel->GetCellContent(ix, iy);
|
---|
251 | const Double_t err = fHistSel->GetCellError(ix, iy);
|
---|
252 |
|
---|
253 | colA += eff*A;
|
---|
254 | errA += A*A * err*err;
|
---|
255 | }
|
---|
256 |
|
---|
257 | fHistCol->SetBinContent(ix, colA);
|
---|
258 | fHistCol->SetBinError(ix, sqrt(errA));
|
---|
259 | }
|
---|
260 | }
|
---|