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

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