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