source: trunk/MagicSoft/Mars/mhist/MHGamma.cc@ 2057

Last change on this file since 2057 was 1992, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 7.2 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 time saving 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): Wolfgang Wittek 6/2002 <mailto:wittek@mppmu.mpg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2002
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26// //
27// MHGamma //
28// //
29// manipulation of alpha distributions //
30// //
31//////////////////////////////////////////////////////////////////////////////
32
33#include "MHGamma.h"
34
35#include <TCanvas.h>
36#include <TPad.h>
37
38#include <math.h>
39
40#include <TH2.h>
41#include <TH3.h>
42
43#include "MHAlphaEnergyTheta.h"
44
45#include "MLog.h"
46#include "MLogManip.h"
47
48ClassImp(MHGamma);
49
50
51// --------------------------------------------------------------------------
52//
53// Default Constructor.
54//
55MHGamma::MHGamma(const TString &name, const TString &title)
56 : fHist(NULL), fProject(NULL)
57{
58 fName = name.IsNull() ? (TString)"MHGamma" : name;
59 fTitle = title.IsNull() ? (TString)"3D-histogram of Alpha, E_est, Theta (Gamma sample)" : title;
60}
61
62TH3D *MHGamma::Subtract(const MHAlphaEnergyTheta &h1, const MHAlphaEnergyTheta &h2)
63{
64 return Subtract(h1.GetHist(), h2.GetHist());
65}
66
67TObject *MHGamma::DrawClone(Option_t *opt) const
68{
69 DrawClone1();
70 DrawClone2();
71
72 return NULL;
73}
74
75void MHGamma::DrawClone1() const
76{
77 if (!fHist)
78 return;
79
80 //
81 // ------------- Part 1 ---------------------
82 //
83 TString titlex = fHist->GetXaxis()->GetTitle();
84 TString titley = fHist->GetYaxis()->GetTitle();
85 TString titlez = fHist->GetYaxis()->GetTitle();
86
87 TString canvtitle = "3D-plot "; //of ";
88 /*
89 canvtitle += titlex;
90 canvtitle += ", ";
91 canvtitle += titley;
92 canvtitle += ", ";
93 canvtitle += titlez+" ";
94 */
95 canvtitle += "for 'gamma' sample";
96
97 TCanvas &c = *MakeDefCanvas("Alpha", canvtitle);
98
99 c.Divide(2, 2);
100
101 gROOT->SetSelectedPad(NULL);
102
103 TH1 *h;
104
105 c.cd(1);
106 h = ((TH3D*)(fHist))->Project3D(fName+"_ex");
107
108 TString title= "Source-Antisource: ";
109 h->SetTitle(title + titlex);
110 h->SetXTitle(titlex);
111 h->SetYTitle("Counts");
112
113 h->Draw();
114 h->SetBit(kCanDelete);
115
116 c.cd(2);
117 h = ((TH3D*)(fHist))->Project3D(fName+"_ey");
118
119 h->SetTitle(title + titley);
120 h->SetXTitle(titley);
121 h->SetYTitle("Counts");
122
123 h->Draw();
124 h->SetBit(kCanDelete);
125 gPad->SetLogx();
126
127 c.cd(3);
128 h = ((TH3D*)(fHist))->Project3D(fName+"_ez");
129
130 h->SetTitle(title + titlez);
131 h->SetXTitle(titlez);
132 h->SetYTitle("Counts");
133
134 h->Draw();
135 h->SetBit(kCanDelete);
136
137 c.cd(4);
138 ((TH3D*)fHist)->DrawCopy();
139
140 c.Modified();
141 c.Update();
142}
143
144
145// --------------------------------------------------------------------------
146//
147// Calculate the histogram as the difference of two histograms :
148// fHist(gamma) = h1(source) - h2(antisource)
149//
150TH3D *MHGamma::Subtract(const TH3D *h1, const TH3D *h2)
151{
152 if (fHist)
153 delete fHist;
154
155 fHist = new TH3D;
156 fHist->SetName(fName);
157 fHist->SetTitle(fTitle);
158 fHist->SetDirectory(NULL);
159
160 SetBinning((TH1*)fHist, (TH1*)h1);
161
162 fHist->SetXTitle((((TH1*)h1)->GetXaxis())->GetTitle());
163 fHist->SetYTitle((((TH1*)h1)->GetYaxis())->GetTitle());
164 fHist->SetZTitle((((TH1*)h1)->GetZaxis())->GetTitle());
165
166 fHist->Add((TH1*)h1, (TH1*)h2, 1, -1); // ROOT: FIXME!
167
168 return fHist;
169}
170
171// --------------------------------------------------------------------------
172//
173// Integrate fHist(gamma) in the alpha range (lo, up)
174//
175TH2D *MHGamma::GetAlphaProjection(Axis_t lo, Axis_t up)
176{
177 if (up < lo)
178 {
179 *fLog << err << fName << "MHGamma : Alpha projection not possible: lo=" << lo << " up=" << up << endl;
180 return NULL;
181 }
182
183 TAxis &axe = *fHist->GetXaxis();
184
185 Int_t ilo = axe.FindFixBin(lo);
186 Int_t iup = axe.FindFixBin(up);
187
188 const Double_t epslo1 = lo-axe.GetBinLowEdge(ilo);
189 const Double_t epslo2 = axe.GetBinUpEdge(ilo)-lo;
190
191 const Double_t epsup1 = up-axe.GetBinLowEdge(iup);
192 const Double_t epsup2 = axe.GetBinUpEdge(iup)-up;
193
194 const Double_t epslo = epslo1<epslo2 ? epslo1 : epslo2;
195 const Double_t epsup = epsup1<epsup2 ? epsup1 : epsup2;
196
197 if (epslo1>epslo2)
198 ilo++;
199
200 if (epsup1<epsup2)
201 iup--;
202
203 if (epslo>0.01*axe.GetBinWidth(ilo) || epsup>0.01*axe.GetBinWidth(iup))
204 {
205 *fLog << err << fName << "MHGamma : binning is not adequate for the requested projection:" << endl;
206 *fLog << "Please specify a lower or upper limit which is not more than 1% away from a bin edge" << endl;
207 *fLog << " epslo = " << epslo << endl;
208 *fLog << " epsup = " << epsup << endl;
209 *fLog << " dwl = " << axe.GetBinWidth(ilo) << endl;
210 *fLog << " dwu = " << axe.GetBinWidth(iup) << endl;
211 return NULL;
212 }
213
214 axe.SetRange(ilo, iup);
215
216 fLo = lo;
217 fHi = up;
218
219 if (fProject)
220 delete fProject;
221 fProject = (TH2D*)fHist->Project3D(fName+"_ezy");
222
223 const TString title = "2D-plot of ";
224 const TString titley = fHist->GetYaxis()->GetTitle();
225 const TString titlez = fHist->GetZaxis()->GetTitle();
226
227 fProject->SetTitle(title + titley + " vs. " + titlez);
228 fProject->SetXTitle(titley);
229 fProject->SetYTitle(titlez);
230
231 return fProject;
232}
233
234void MHGamma::DrawClone2() const
235{
236 if (!fProject)
237 return;
238
239 const TString titley = fHist->GetYaxis()->GetTitle();
240 const TString titlez = fHist->GetZaxis()->GetTitle();
241
242 TString canvtitle = "No.of Gammas ";//vs. ";
243 /*
244 canvtitle += titley;
245 canvtitle += " and ";
246 canvtitle += titlez;
247 */
248 canvtitle += Form("(%.1f < alpha < %.1f deg)", fLo, fHi);
249
250 TCanvas &c = *MakeDefCanvas("Gamma", canvtitle);
251
252 c.Divide(2, 2);
253
254 gROOT->SetSelectedPad(NULL);
255
256 TH1 *h;
257
258 c.cd(1);
259 h = fProject->ProjectionX(fName+"_xpro", -1, 9999, "E");
260 TString title = "No.of gammas: ";
261 h->SetTitle(title+titley);
262 h->SetXTitle(titley);
263 h->SetYTitle("Counts");
264
265 h->Draw();
266 h->SetBit(kCanDelete);
267 gPad->SetLogx();
268
269 c.cd(2);
270 h = fProject->ProjectionY(fName+"_ypro", -1, 9999, "E");
271 h->SetTitle(title+titlez);
272 h->SetXTitle(titlez);
273 h->SetYTitle("Counts");
274
275 h->Draw();
276 h->SetBit(kCanDelete);
277
278 c.cd(3);
279
280 fProject->DrawCopy();
281 gPad->SetLogx();
282
283 c.Modified();
284 c.Update();
285}
Note: See TracBrowser for help on using the repository browser.