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

Last change on this file since 1413 was 1413, checked in by wittek, 22 years ago
*** empty log message ***
File size: 7.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 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 <TH1.h>
41#include <TH2.h>
42#include <TH3.h>
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47ClassImp(MHGamma);
48
49
50// --------------------------------------------------------------------------
51//
52// Default Constructor.
53//
54MHGamma::MHGamma()
55{
56}
57
58// --------------------------------------------------------------------------
59//
60// Dummy Fill
61//
62Bool_t MHGamma::Fill(const MParContainer *par)
63{
64 return kTRUE;
65}
66
67// --------------------------------------------------------------------------
68//
69// Calculate the histogram as the difference of two histograms :
70// fHist(gamma) = h1(source) - h2(antisource)
71//
72TH3D *MHGamma::Subtract(const TH3D *h1, const TH3D *h2,
73 const char *name, const char *title,
74 Bool_t Draw)
75{
76 TH3D *fHist;
77 fHist = new TH3D();
78 fHist->SetName(name);
79 fHist->SetTitle(title);
80
81 fHist->SetDirectory(NULL);
82
83 SetBinning((TH3D*)fHist, (TH3D*)h1);
84
85 TString strg1 = (((TH1*)h1)->GetXaxis())->GetTitle();
86 TString strg2 = (((TH1*)h1)->GetYaxis())->GetTitle();
87 TString strg3 = (((TH1*)h1)->GetZaxis())->GetTitle();
88 fHist->SetXTitle(strg1);
89 fHist->SetYTitle(strg2);
90 fHist->SetZTitle(strg3);
91
92 fHist->Add((TH1*)h1, (TH1*)h2, 1, -1); // ROOT: FIXME!
93
94 //...........................................................
95 // draw histogram
96 if (Draw == kTRUE)
97 {
98 TString strg7 = "3D-plot of ";
99 strg7 += strg1;
100 strg7 += ",";
101 strg7 += strg2;
102 strg7 += ",";
103 strg7 += strg3;
104 strg7 += " for \'gamma\' sample";
105
106 TCanvas &c = *MakeDefCanvas("Alpha", strg7);
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("ex");
116
117 TString strg0 = "SRC-ASRC : ";
118 TString strg4 = strg0 + strg1;
119 h->SetTitle(strg4);
120 h->SetXTitle(strg1);
121 h->SetYTitle("Counts");
122
123 h->Draw();
124 h->SetBit(kCanDelete);
125
126 c.cd(2);
127 h = ((TH3D*)(fHist))->Project3D("ey");
128
129 TString strg5 = strg0 + strg2;
130 h->SetTitle(strg5);
131 h->SetXTitle(strg2);
132 h->SetYTitle("Counts");
133
134 h->Draw();
135 h->SetBit(kCanDelete);
136 gPad->SetLogx();
137
138 c.cd(3);
139 h = ((TH3D*)(fHist))->Project3D("ez");
140
141 TString strg6 = strg0 + strg3;
142 h->SetTitle(strg6);
143 h->SetXTitle(strg3);
144 h->SetYTitle("Counts");
145
146 h->Draw();
147 h->SetBit(kCanDelete);
148
149 c.cd(4);
150 ((TH3D*)fHist)->DrawCopy();
151
152 c.Modified();
153 c.Update();
154 }
155
156 return fHist;
157}
158
159// --------------------------------------------------------------------------
160//
161// Integrate fHist(gamma) in the alpha range (lo, up)
162//
163TH2D *MHGamma::GetAlphaProjection(TH3D *fHist, Axis_t lo, Axis_t up,
164 Bool_t Drawp)
165{
166 if (up < lo)
167 {
168 *fLog << err << fName << "MHGamma : Alpha projection not possible: lo=" << lo << " up=" << up << endl;
169 return NULL;
170 }
171
172 TAxis &axe = *fHist->GetXaxis();
173
174 Int_t ilo = axe.FindFixBin(lo);
175 Int_t iup = axe.FindFixBin(up);
176
177 const Double_t epslo1 = lo-axe.GetBinLowEdge(ilo);
178 const Double_t epslo2 = axe.GetBinUpEdge(ilo)-lo;
179
180 const Double_t epsup1 = up-axe.GetBinLowEdge(iup);
181 const Double_t epsup2 = axe.GetBinUpEdge(iup)-up;
182
183 const Double_t epslo = epslo1<epslo2 ? epslo1 : epslo2;
184 const Double_t epsup = epsup1<epsup2 ? epsup1 : epsup2;
185
186 if (epslo1>epslo2)
187 ilo++;
188
189 if (epsup1<epsup2)
190 iup--;
191
192 if (epslo>0.01*axe.GetBinWidth(ilo) || epsup>0.01*axe.GetBinWidth(iup))
193 {
194 *fLog << err << fName << "MHGamma : binning is not adequate for the requested projection:" << endl;
195 *fLog << "Please specify a lower or upper limit which is not more than 1% away from a bin edge" << endl;
196 *fLog << " epslo = " << epslo << endl;
197 *fLog << " epsup = " << epsup << endl;
198 *fLog << " dwl = " << axe.GetBinWidth(ilo) << endl;
199 *fLog << " dwu = " << axe.GetBinWidth(iup) << endl;
200 return NULL;
201 }
202
203 axe.SetRange(ilo, iup);
204
205 TH2D &h2D = *(TH2D *)fHist->Project3D("ezy");
206
207 TString strg0 = "2D-plot of ";
208 TString strg1 = (fHist->GetYaxis())->GetTitle();
209 TString strg2 = (fHist->GetZaxis())->GetTitle();
210 strg0 += strg2;
211 strg0 += " vs. ";
212 strg0 += strg1;
213 h2D.SetTitle(strg0);
214 h2D.SetXTitle(strg1);
215 h2D.SetYTitle(strg2);
216
217
218 //...........................................................
219 // draw histogram
220 if (Drawp == kTRUE)
221 {
222 char txt[100];
223 TString strg3 = "No.of Gammas vs. ";
224 strg3 += strg1;
225 strg3 += " and ";
226 strg3 += strg2;
227 sprintf(txt, " (%.1f < alpha < %.1f deg)", lo, up);
228 strg3 += txt;
229
230 TCanvas &c = *MakeDefCanvas("Gamma", strg3);
231
232 c.Divide(2, 2);
233
234 gROOT->SetSelectedPad(NULL);
235
236 TH1 *h;
237
238 c.cd(1);
239 h = h2D.ProjectionX("xpro", -1, 9999, "E");
240 TString strg0 = "No.of gammas : ";
241 TString strg7 = strg0 + strg1;
242 h->SetTitle(strg7);
243 h->SetXTitle(strg1);
244 h->SetYTitle("Counts");
245
246 h->Draw();
247 h->SetBit(kCanDelete);
248 gPad->SetLogx();
249
250 c.cd(2);
251 h = h2D.ProjectionY("ypro", -1, 9999, "E");
252 TString strg8 = strg0 + strg2;
253 h->SetTitle(strg8);
254 h->SetXTitle(strg2);
255 h->SetYTitle("Counts");
256
257 h->Draw();
258 h->SetBit(kCanDelete);
259
260 c.cd(3);
261
262 h2D.DrawCopy();
263 gPad->SetLogx();
264
265 c.Modified();
266 c.Update();
267 }
268 //...........................................................
269
270 return &h2D;
271}
Note: See TracBrowser for help on using the repository browser.