source: trunk/MagicSoft/Mars/mhist/MHMcCT1CollectionArea.cc@ 1823

Last change on this file since 1823 was 1823, checked in by moralejo, 22 years ago
*** empty log message ***
  • Property svn:executable set to *
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): A. Moralejo 3/2003 moralejo@pd.infn.it
19!
20! Copyright: MAGIC Software Development, 2000-2002
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26// //
27// MHMcCT1CollectionArea //
28// //
29//////////////////////////////////////////////////////////////////////////////
30
31#include "MHMcCT1CollectionArea.h"
32
33#include <TH2.h>
34#include <TCanvas.h>
35
36#include "MH.h"
37#include "MBinning.h"
38
39ClassImp(MHMcCT1CollectionArea);
40
41// --------------------------------------------------------------------------
42//
43// Creates the three necessary histograms:
44// - selected showers (input)
45// - all showers (input)
46// - collection area (result)
47//
48MHMcCT1CollectionArea::MHMcCT1CollectionArea(const char *name, const char *title)
49{
50 // initialize the histogram for the distribution r vs E
51 //
52 // we set the energy range from 10 Gev to 30000 GeV (in log 4.5 orders
53 // of magnitude) and for each order we take 10 subdivision --> 45 xbins
54 // we set the theta range from 12.5 to 48 deg, with 6 bins.
55 //
56 fName = name ? name : "MHMcCT1CollectionArea";
57 fTitle = title ? title : "Collection Area vs. Energy";
58
59 MBinning binsx;
60 MBinning binsy;
61
62 binsx.SetEdgesLog(45, 10, 30000);
63 const Double_t yedge[7] = {12.5, 17.5, 23.5, 29.5, 35.5, 42., 48.};
64 const TArrayD yed(7,yedge);
65 binsy.SetEdges(yed);
66
67 fHistAll = new TH2D;
68 fHistSel = new TH2D;
69 fHistCol = new TH2D;
70
71 MH::SetBinning(fHistAll, &binsx, &binsy);
72 MH::SetBinning(fHistSel, &binsx, &binsy);
73 MH::SetBinning(fHistCol, &binsx, &binsy);
74
75
76 fHistCol->SetName(fName);
77 fHistAll->SetName("AllEvents");
78 fHistSel->SetName("SelectedEvents");
79
80 fHistCol->SetTitle(fTitle);
81 fHistAll->SetTitle("All showers - Theta vs Energy distribution");
82 fHistSel->SetTitle("Selected showers - Theta vs Energy distribution");
83
84 fHistAll->SetDirectory(NULL);
85 fHistSel->SetDirectory(NULL);
86 fHistCol->SetDirectory(NULL);
87
88 fHistAll->SetXTitle("E [GeV]");
89 fHistAll->SetYTitle("theta [deg]");
90 fHistAll->SetZTitle("N");
91
92 fHistSel->SetXTitle("E [GeV]");
93 fHistSel->SetYTitle("theta [deg]");
94 fHistSel->SetYTitle("N");
95
96 fHistCol->SetXTitle("E [GeV]");
97 fHistCol->SetYTitle("theta [deg]");
98 fHistCol->SetZTitle("A [m^{2}]");
99}
100
101// --------------------------------------------------------------------------
102//
103// Delete the three histograms
104//
105MHMcCT1CollectionArea::~MHMcCT1CollectionArea()
106{
107 delete fHistAll;
108 delete fHistSel;
109 delete fHistCol;
110}
111
112// --------------------------------------------------------------------------
113//
114// Fill data into the histogram which contains the selected showers
115//
116void MHMcCT1CollectionArea::FillSel(Double_t energy, Double_t theta)
117{
118 fHistSel->Fill(energy, theta);
119}
120
121// --------------------------------------------------------------------------
122//
123// Draw the histogram with all showers
124//
125void MHMcCT1CollectionArea::DrawAll(Option_t* option)
126{
127 if (!gPad)
128 MH::MakeDefCanvas(fHistAll);
129
130 fHistAll->Draw(option);
131
132 gPad->SetLogx();
133
134 gPad->Modified();
135 gPad->Update();
136}
137
138// --------------------------------------------------------------------------
139//
140// Draw the histogram with the selected showers only.
141//
142void MHMcCT1CollectionArea::DrawSel(Option_t* option)
143{
144 if (!gPad)
145 MH::MakeDefCanvas(fHistSel);
146
147 fHistSel->Draw(option);
148
149 gPad->SetLogx();
150
151 gPad->Modified();
152 gPad->Update();
153}
154
155// --------------------------------------------------------------------------
156//
157// Creates a new canvas and draws the histogram into it.
158// Be careful: The histogram belongs to this object and won't get deleted
159// together with the canvas.
160//
161TObject *MHMcCT1CollectionArea::DrawClone(Option_t* option) const
162{
163 TCanvas *c = MH::MakeDefCanvas(fHistCol);
164
165 //
166 // This is necessary to get the expected behaviour of DrawClone
167 //
168 gROOT->SetSelectedPad(NULL);
169
170 fHistCol->DrawCopy(option);
171
172 gPad->SetLogx();
173
174 c->Modified();
175 c->Update();
176
177 return c;
178}
179
180void MHMcCT1CollectionArea::Draw(Option_t* option)
181{
182 if (!gPad)
183 MH::MakeDefCanvas(fHistCol);
184
185 fHistCol->Draw(option);
186
187 gPad->SetLogx();
188
189 gPad->Modified();
190 gPad->Update();
191}
192
193//
194// Calculate the Efficiency (collection area) for the CT1 MC sample
195// and set the 'ReadyToSave' flag
196//
197void MHMcCT1CollectionArea::CalcEfficiency()
198{
199 //
200 // Here we estimate the total number of showers in each energy bin
201 // from the known the energy range and spectral index of the generated
202 // showers. This procedure is intended for the CT1 MC files. The total
203 // number of generated events, collection area, spectral index etc will be
204 // set here by hand, so make sure that the MC sample you are using is the
205 // right one (check all these quantities in your files and compare with
206 // is written below. In some theta bins, there are two different
207 // productions, with different energy limits but with the same spectral
208 // slope. We account for this when calculating the original number of
209 // events in each energy bin.
210 //
211
212 for (Int_t thetabin = 1; thetabin <= fHistAll->GetNbinsY(); thetabin++)
213 {
214 // This theta is not exactly the one of the MC events, just about
215 // the same:
216 Float_t theta = fHistAll->GetYaxis()->GetBinCenter(thetabin);
217
218 Float_t emin1, emax1, emin2, emax2;
219 Float_t index, expo, k1, k2;
220 Float_t numevts1, numevts2;
221 Float_t r1, r2; // Impact parameter range (on ground).
222
223 emin1 = 0; emax1 = 0; emin2 = 0; emax2 = 0;
224 expo = 0.; k1 = 0.; k2 = 0.; r1 = 0.; r2 = 0.;
225 numevts1 = 0; numevts2 = 0;
226
227 if (theta > 14 && theta < 16) // 15 deg
228 {
229 r1 = 0.;
230 r2 = 250.; //meters
231 emin1 = 300.;
232 emax1 = 400.; // Energies in GeV.
233 emin2 = 400.;
234 emax2 = 30000.;
235 numevts1 = 4000.;
236 numevts2 = 25740.;
237 }
238 else if (theta > 20 && theta < 21) // 20.5 deg
239 {
240 r1 = 0.;
241 r2 = 263.; //meters
242 emin1 = 300.;
243 emax1 = 400.; // Energies in GeV.
244 emin2 = 400.;
245 emax2 = 30000.;
246 numevts1 = 6611.;
247 numevts2 = 24448.;
248 }
249 else if (theta > 26 && theta < 27) // 26.5 degrees
250 {
251 r1 = 0.;
252 r2 = 290.; //meters
253 emin1 = 300.;
254 emax1 = 400.; // Energies in GeV.
255 emax2 = emax1; emin2 = 400.;
256 emax2 = 30000.;
257 numevts1 = 4000.;
258 numevts2 = 26316.;
259 }
260 else if (theta > 32 && theta < 33) // 32.5 degrees
261 {
262 r1 = 0.;
263 r2 = 350.; //meters
264 emin1 = 300.;
265 emax1 = 30000.; // Energies in GeV.
266 emax2 = emax1;
267 numevts1 = 33646.;
268 }
269 else if (theta > 38 && theta < 39) // 38.75 degrees
270 {
271 r1 = 0.;
272 r2 = 380.; //meters
273 emin1 = 300.;
274 emax1 = 30000.; // Energies in GeV.
275 emax2 = emax1;
276 numevts1 = 38415.;
277 }
278 else if (theta > 44 && theta < 46) // 45 degrees
279 {
280 r1 = 0.;
281 r2 = 565.; //meters
282 emin1 = 300.;
283 emax1 = 50000.; // Energies in GeV.
284 emax2 = emax1;
285 numevts1 = 30197.;
286 }
287
288 index = 1.5; // Differential spectral Index.
289 expo = 1.-index;
290 k1 = numevts1 / (pow(emax1,expo) - pow(emin1,expo));
291 k2 = numevts2 / (pow(emax2,expo) - pow(emin2,expo));
292
293 for (Int_t i=1; i <= fHistAll->GetNbinsX(); i++)
294 {
295 const Float_t e1 = fHistAll->GetXaxis()->GetBinLowEdge(i);
296 const Float_t e2 = fHistAll->GetXaxis()->GetBinLowEdge(i+1);
297
298 if (e1 < emin1 || e2 > emax2)
299 continue;
300
301 Float_t events;
302
303 if (e2 <= emax1)
304 events = k1 * (pow(e2, expo) - pow(e1, expo));
305 else if (e1 >= emin2)
306 events = k2 * (pow(e2, expo) - pow(e1, expo));
307 else
308 events =
309 k1 * (pow(emax1, expo) - pow(e1, expo))+
310 k2 * (pow(e2, expo) - pow(emin2, expo));
311
312 fHistAll->SetBinContent(i, thetabin, events);
313 fHistAll->SetBinError(i, thetabin, sqrt(events));
314 }
315
316 // -----------------------------------------------------------
317
318 const Float_t dr = TMath::Pi() * (r2*r2 - r1*r1);
319
320 for (Int_t ix = 1; ix <= fHistAll->GetNbinsX(); ix++)
321 {
322 const Float_t Na = fHistAll->GetBinContent(ix,thetabin);
323
324 if (Na <= 0)
325 continue;
326
327 const Float_t Ns = fHistSel->GetBinContent(ix,thetabin);
328
329 // Since Na is an estimate of the total number of showers generated
330 // in the energy bin, it may happen that Ns (triggered showers) is
331 // larger than Na. In that case, the bin is skipped:
332
333 if (Na < Ns)
334 continue;
335
336 const Double_t eff = Ns/Na;
337 const Double_t err = sqrt((1.-eff)*Ns)/Na;
338
339 const Float_t area = dr * cos(theta*TMath::Pi()/180.);
340
341 fHistCol->SetBinContent(ix, thetabin, eff*area);
342 fHistCol->SetBinError(ix, thetabin, err*area);
343 }
344 }
345
346 SetReadyToSave();
347}
348
Note: See TracBrowser for help on using the repository browser.