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

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