source: trunk/MagicSoft/Mars/mhist/MHMcCollectionArea.cc@ 954

Last change on this file since 954 was 954, checked in by tbretz, 23 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 5.0 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): 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
31ClassImp(MHMcCollectionArea);
32
33MHMcCollectionArea::MHMcCollectionArea(const char *name, const char *title)
34{
35 //
36 // default constructor
37 //
38
39 // initialize the histogram for the distribution r vs E
40 //
41 // we set the energy range from 1 Gev to 10000 GeV (in log 5 orders
42 // of magnitude) and for each order we take 10 subdivision --> 50 xbins
43 //
44 // we set the radius range from 0 m to 500 m with 10 m bin --> 50 ybins
45
46
47 *fName = name ? name : "MHMcCollectionArea";
48 *fTitle = title ? title : "Data to Calculate Coll-Area";
49
50
51 fHistAll = new TH2D("All Events", "All showers - Radius vs log(E) distribution",
52 50, 0., 5.,
53 50, 0., 500.);
54
55 fHistAll->SetXTitle("log(E/GeV)");
56 fHistAll->SetYTitle("r/m");
57 fHistAll->SetZTitle("N");
58
59 fHistSel = new TH2D("Selected Events", "Selected showers - Radius vs log(E) distribution",
60 50, 0., 5.,
61 50, 0., 500.);
62
63 fHistSel->SetXTitle("log(E/GeV)");
64 fHistSel->SetYTitle("r/m");
65 fHistSel->SetYTitle("N");
66
67 fHistCol = new TH1D("Area", "Collection Area vs. log(E)",
68 50, 0., 5.);
69
70 fHistCol->SetXTitle("log(E/GeV)");
71 fHistCol->SetYTitle("A/m^2");
72}
73
74MHMcCollectionArea::~MHMcCollectionArea()
75{
76 delete fHistAll;
77 delete fHistSel;
78 delete fHistCol;
79}
80
81void MHMcCollectionArea::FillAll(Float_t log10E, Float_t radius)
82{
83 fHistAll->Fill(log10E, radius);
84}
85
86void MHMcCollectionArea::FillSel(Float_t log10E, Float_t radius)
87{
88 fHistSel->Fill(log10E, radius);
89}
90
91void MHMcCollectionArea::DrawAll(Option_t* option)
92{
93 TCanvas *c=new TCanvas(fHistAll->GetName(), fHistAll->GetTitle());
94
95 fHistSel->Draw(option);
96
97 c->Modified();
98 c->Update();
99}
100
101void MHMcCollectionArea::DrawSel(Option_t* option)
102{
103 TCanvas *c=new TCanvas(fHistSel->GetName(), fHistSel->GetTitle());
104
105 fHistSel->Draw(option);
106
107 c->Modified();
108 c->Update();
109}
110
111TObject *MHMcCollectionArea::DrawClone(Option_t* option)
112{
113 TCanvas *c=new TCanvas(fHistCol->GetName(), fHistCol->GetTitle());
114
115 //
116 // This is necessary to get the expected bahviour of DrawClone
117 //
118 gROOT->SetSelectedPad(NULL);
119
120 fHistCol->DrawClone(option);
121
122 c->Modified();
123 c->Update();
124
125 return c;
126}
127
128void MHMcCollectionArea::Draw(Option_t* option)
129{
130 TCanvas *c=new TCanvas(fHistCol->GetName(), fHistCol->GetTitle());
131
132 fHistCol->Draw(option);
133
134 c->Modified();
135 c->Update();
136}
137
138void MHMcCollectionArea::CalcEfficiency()
139{
140 // Description!
141
142 //
143 // first of all calculate the efficency
144 // do it here by hand to get the right error of efficency
145 //
146 const Int_t nbinx = fHistSel->GetXaxis()->GetNbins();
147 const Int_t nbiny = fHistSel->GetYaxis()->GetNbins();
148
149 for (Int_t ix=1; ix<=nbinx; ix++)
150 {
151 for (Int_t iy=1; iy<=nbiny; iy++)
152 {
153 const Float_t Ns = fHistSel->GetCellContent(ix, iy);
154 const Float_t Na = fHistAll->GetCellContent(ix, iy);
155
156 if (Na <= 0)
157 continue;
158
159 const Double_t eff = Ns/Na;
160 const Double_t err = sqrt(Na + Na*Ns - Ns*Ns - Ns) / (Na*Na);
161
162 fHistSel->SetCellContent(ix, iy, eff);
163 fHistSel->SetCellError(ix, iy, err);
164 }
165 }
166
167 //
168 // now calculate the Collection area for different
169 // energies
170 //
171 for (Int_t ix=1; ix<=nbinx; ix++)
172 {
173 Double_t errA = 0;
174 Double_t colA = 0;
175
176 for (Int_t iy=1; iy<=nbiny; iy++)
177 {
178 const Double_t r1 = fHistSel->GetYaxis()->GetBinLowEdge(iy);
179 const Double_t r2 = fHistSel->GetYaxis()->GetBinLowEdge(iy+1);
180
181 const Double_t A = TMath::Pi() * (r2*r2 - r1*r1);
182
183 const Double_t eff = fHistSel->GetCellContent(ix, iy);
184 const Double_t err = fHistSel->GetCellError(ix, iy);
185
186 colA += eff*A;
187 errA += A*A * err*err;
188 }
189
190 fHistCol->SetBinContent(ix, colA);
191 fHistCol->SetBinError(ix, sqrt(errA));
192 }
193}
Note: See TracBrowser for help on using the repository browser.