source: trunk/MagicSoft/Mars/mhistmc/MHMcCT1CollectionArea.cc@ 2242

Last change on this file since 2242 was 2242, checked in by moralejo, 23 years ago
*** empty log message ***
File size: 11.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 <mailto:moralejo@pd.infn.it>
19!
20! Copyright: MAGIC Software Development, 2000-2003
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 "MMcEvt.hxx"
37#include "MH.h"
38#include "MBinning.h"
39#include "MParList.h"
40#include "MLog.h"
41#include "MLogManip.h"
42
43ClassImp(MHMcCT1CollectionArea);
44
45using namespace std;
46
47// --------------------------------------------------------------------------
48//
49// Creates the three necessary histograms:
50// - selected showers (input)
51// - all showers (input)
52// - collection area (result)
53//
54MHMcCT1CollectionArea::MHMcCT1CollectionArea(const char *name, const char *title)
55{
56 //
57 // nbins, minEnergy, maxEnergy defaults:
58 // we set the energy range from 100 Gev to 30000 GeV (in log, 3.5 orders
59 // of magnitude) and for each order we take 10 subdivisions --> 35 xbins
60 // we set the theta range from 12.5 to 48 deg, with 6 bins (the latter
61 // choice has been done to make the bin centers as close as possible to
62 // the actual zenith angles in the CT1 MC sample).
63 //
64
65 fName = name ? name : "MHMcCT1CollectionArea";
66 fTitle = title ? title : "Collection Area vs. log10 Energy";
67
68 fHistAll = new TH2D;
69 fHistSel = new TH2D;
70 fHistCol = new TH2D;
71
72 fHistCol->SetName(fName);
73 fHistAll->SetName("AllEvents");
74 fHistSel->SetName("SelectedEvents");
75
76 fHistCol->SetTitle(fTitle);
77 fHistAll->SetTitle("All showers - Theta vs log10 Energy distribution");
78 fHistSel->SetTitle("Selected showers - Theta vs log10 Energy distribution");
79
80 fHistAll->SetDirectory(NULL);
81 fHistSel->SetDirectory(NULL);
82 fHistCol->SetDirectory(NULL);
83
84 fHistAll->SetXTitle("log10 E [GeV]");
85 fHistAll->SetYTitle("theta [deg]");
86 fHistAll->SetZTitle("N");
87
88 fHistSel->SetXTitle("log10 E [GeV]");
89 fHistSel->SetYTitle("theta [deg]");
90 fHistSel->SetZTitle("N");
91
92 fHistCol->SetXTitle("log10 E [GeV]");
93 fHistCol->SetYTitle("theta [deg]");
94 fHistCol->SetZTitle("A [m^{2}]");
95}
96
97// --------------------------------------------------------------------------
98//
99// Delete the three histograms
100//
101MHMcCT1CollectionArea::~MHMcCT1CollectionArea()
102{
103 delete fHistAll;
104 delete fHistSel;
105 delete fHistCol;
106}
107
108// --------------------------------------------------------------------------
109//
110// Set the binnings and prepare the filling of the histograms
111//
112Bool_t MHMcCT1CollectionArea::SetupFill(const MParList *plist)
113{
114 const MBinning* binsenergy = (MBinning*)plist->FindObject("BinningE");
115 const MBinning* binstheta = (MBinning*)plist->FindObject("BinningTheta");
116
117 if (!binsenergy || !binstheta)
118 {
119 *fLog << err << dbginf << "At least one MBinning not found... aborting.";
120 *fLog << endl;
121 return kFALSE;
122 }
123
124 SetBinning(fHistAll, binsenergy, binstheta);
125 SetBinning(fHistSel, binsenergy, binstheta);
126 SetBinning(fHistCol, binsenergy, binstheta);
127
128 fHistAll->Sumw2();
129 fHistSel->Sumw2();
130 fHistCol->Sumw2();
131
132 return kTRUE;
133}
134
135
136// --------------------------------------------------------------------------
137//
138// Fill data into the histogram which contains the selected showers
139//
140Bool_t MHMcCT1CollectionArea::Fill(const MParContainer *par, const Stat_t w)
141{
142 MMcEvt &mcevt = *(MMcEvt*)par;
143
144 fHistSel->Fill(log10(mcevt.GetEnergy()), kRad2Deg*mcevt.GetTelescopeTheta(), w);
145 return kTRUE;
146}
147
148// --------------------------------------------------------------------------
149//
150// Draw the histogram with all showers
151//
152void MHMcCT1CollectionArea::DrawAll(Option_t* option)
153{
154 if (!gPad)
155 MH::MakeDefCanvas(fHistAll);
156
157 fHistAll->Draw(option);
158
159 gPad->Modified();
160 gPad->Update();
161}
162
163// --------------------------------------------------------------------------
164//
165// Draw the histogram with the selected showers only.
166//
167void MHMcCT1CollectionArea::DrawSel(Option_t* option)
168{
169 if (!gPad)
170 MH::MakeDefCanvas(fHistSel);
171
172 fHistSel->Draw(option);
173
174 gPad->Modified();
175 gPad->Update();
176}
177
178// --------------------------------------------------------------------------
179//
180// Creates a new canvas and draws the histogram into it.
181// Be careful: The histogram belongs to this object and won't get deleted
182// together with the canvas.
183//
184TObject *MHMcCT1CollectionArea::DrawClone(Option_t* option) const
185{
186 TCanvas &c = *MakeDefCanvas("CollArea", "Collection area plots", 600, 600);
187 c.Divide(2,2);
188
189 //
190 // This is necessary to get the expected behaviour of DrawClone
191 //
192 gROOT->SetSelectedPad(NULL);
193
194 c.cd(1);
195 fHistCol->SetDirectory(NULL);
196 fHistCol->DrawCopy(option);
197
198 c.cd(2);
199 fHistSel->SetDirectory(NULL);
200 fHistSel->DrawCopy(option);
201
202 c.cd(3);
203 fHistAll->SetDirectory(NULL);
204 fHistAll->DrawCopy(option);
205
206
207 c.Modified();
208 c.Update();
209
210 return &c;
211}
212
213void MHMcCT1CollectionArea::Draw(Option_t* option)
214{
215 if (!gPad)
216 MH::MakeDefCanvas(fHistCol);
217
218 fHistCol->Draw(option);
219
220 gPad->Modified();
221 gPad->Update();
222}
223
224//
225// Calculate the Efficiency (collection area) for the CT1 MC sample
226// and set the 'ReadyToSave' flag
227//
228void MHMcCT1CollectionArea::CalcEfficiency()
229{
230 //
231 // Here we estimate the total number of showers in each energy bin
232 // from the known the energy range and spectral index of the generated
233 // showers. This procedure is intended for the CT1 MC files. The total
234 // number of generated events, collection area, spectral index etc will be
235 // set here by hand, so make sure that the MC sample you are using is the
236 // right one (check all these quantities in your files and compare with
237 // what is written below. In some theta bins, there are two different
238 // productions, with different energy limits but with the same spectral
239 // slope. We account for this when calculating the original number of
240 // events in each energy bin.
241 //
242 // The theta angle with which the MC data (from D. Kranich) were produced
243 // is not exactly the center of the theta bins we are using (the bin limits
244 // should be 0.0, 17.5, 23.5, 29.5, 35.5, 42., 50.). The theta variable in
245 // the MC root file has nevertheless been changed (W.Wittek) to correspond
246 // to the centers of these bins. Only in the first bin is the difference big:
247 // the data were produced at theta = 15 degrees, whreas the bin center is at
248 // 8.75 degrees. Howeverm at such low z.a. the shower characteristics change
249 // very slowly with theta.
250 //
251 //
252
253 for (Int_t thetabin = 1; thetabin <= fHistAll->GetNbinsY(); thetabin++)
254 {
255 // This theta is not exactly the one of the MC events, just about
256 // the same:
257 Float_t theta = fHistAll->GetYaxis()->GetBinCenter(thetabin);
258
259 Float_t emin1, emax1, emin2, emax2;
260 Float_t index, expo, k1, k2;
261 Float_t numevts1, numevts2;
262 Float_t r1, r2; // Impact parameter range (on ground).
263
264 emin1 = 0; emax1 = 0; emin2 = 0; emax2 = 0;
265 expo = 0.; k1 = 0.; k2 = 0.; r1 = 0.; r2 = 0.;
266 numevts1 = 0; numevts2 = 0;
267
268 if (theta > 8 && theta < 9) // 8.75 deg
269 {
270 r1 = 0.;
271 r2 = 250.; //meters
272 emin1 = 300.;
273 emax1 = 400.; // Energies in GeV.
274 emin2 = 400.;
275 emax2 = 30000.;
276 numevts1 = 4000.;
277 numevts2 = 25740.;
278 }
279 else if (theta > 20 && theta < 21) // 20.5 deg
280 {
281 r1 = 0.;
282 r2 = 263.; //meters
283 emin1 = 300.;
284 emax1 = 400.; // Energies in GeV.
285 emin2 = 400.;
286 emax2 = 30000.;
287 numevts1 = 6611.;
288 numevts2 = 24448.;
289 }
290 else if (theta > 26 && theta < 27) // 26.5 degrees
291 {
292 r1 = 0.;
293 r2 = 290.; //meters
294 emin1 = 300.;
295 emax1 = 400.; // Energies in GeV.
296 emax2 = emax1; emin2 = 400.;
297 emax2 = 30000.;
298 numevts1 = 4000.;
299 numevts2 = 26316.;
300 }
301 else if (theta > 32 && theta < 33) // 32.5 degrees
302 {
303 r1 = 0.;
304 r2 = 350.; //meters
305 emin1 = 300.;
306 emax1 = 30000.; // Energies in GeV.
307 emax2 = emax1;
308 numevts1 = 33646.;
309 }
310 else if (theta > 38 && theta < 39) // 38.75 degrees
311 {
312 r1 = 0.;
313 r2 = 380.; //meters
314 emin1 = 300.;
315 emax1 = 30000.; // Energies in GeV.
316 emax2 = emax1;
317 numevts1 = 38415.;
318 }
319 else if (theta > 45 && theta < 47) // 46 degrees
320 {
321 r1 = 0.;
322 r2 = 565.; //meters
323 emin1 = 300.;
324 emax1 = 50000.; // Energies in GeV.
325 emax2 = emax1;
326 numevts1 = 30197.;
327 }
328
329 index = 1.5; // Differential spectral Index.
330 expo = 1.-index;
331 k1 = numevts1 / (pow(emax1,expo) - pow(emin1,expo));
332 k2 = numevts2 / (pow(emax2,expo) - pow(emin2,expo));
333
334 for (Int_t i=1; i <= fHistAll->GetNbinsX(); i++)
335 {
336 const Float_t e1 = pow(10.,fHistAll->GetXaxis()->GetBinLowEdge(i));
337 const Float_t e2 = pow(10.,fHistAll->GetXaxis()->GetBinLowEdge(i+1));
338
339 if (e1 < emin1 || e2 > emax2)
340 continue;
341
342 Float_t events;
343
344 if (e2 <= emax1)
345 events = k1 * (pow(e2, expo) - pow(e1, expo));
346 else if (e1 >= emin2)
347 events = k2 * (pow(e2, expo) - pow(e1, expo));
348 else
349 events =
350 k1 * (pow(emax1, expo) - pow(e1, expo))+
351 k2 * (pow(e2, expo) - pow(emin2, expo));
352
353 fHistAll->SetBinContent(i, thetabin, events);
354 fHistAll->SetBinError(i, thetabin, sqrt(events));
355 }
356
357 // -----------------------------------------------------------
358
359 const Float_t dr = TMath::Pi() * (r2*r2 - r1*r1);
360
361 for (Int_t ix = 1; ix <= fHistAll->GetNbinsX(); ix++)
362 {
363 const Float_t Na = fHistAll->GetBinContent(ix,thetabin);
364
365 if (Na <= 0)
366 {
367 //
368 // If energy is large, this case means that no or very few events
369 // were generated at this energy bin. In this case we assign it
370 // the effective area of the bin below it in energy. If energy is
371 // below 1E4, it means that no events triggered -> eff area = 0
372 //
373
374 if (fHistSel->GetXaxis()->GetBinLowEdge(ix) > 4.)
375 {
376 fHistCol->SetBinContent(ix, thetabin, fHistCol->GetBinContent(ix-1, thetabin));
377 fHistCol->SetBinError(ix, thetabin, fHistCol->GetBinError(ix-1, thetabin));
378 }
379 continue;
380 }
381
382 const Float_t Ns = fHistSel->GetBinContent(ix,thetabin);
383
384 // Since Na is an estimate of the total number of showers generated
385 // in the energy bin, it may happen that Ns (triggered showers) is
386 // larger than Na. In that case, the bin is skipped:
387
388 if (Na < Ns)
389 continue;
390
391 const Double_t eff = Ns/Na;
392 const Double_t efferr = sqrt((1.-eff)*Ns)/Na;
393
394
395 const Float_t area = dr * cos(theta*TMath::Pi()/180.);
396
397 fHistCol->SetBinContent(ix, thetabin, eff*area);
398 fHistCol->SetBinError(ix, thetabin, efferr*area);
399
400 }
401 }
402
403 SetReadyToSave();
404}
Note: See TracBrowser for help on using the repository browser.