source: trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTime.cc@ 3666

Last change on this file since 3666 was 2461, 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 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): Thomas Bretz 1/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Wolfgang Wittek 1/2002 <mailto:wittek@mppmu.mpg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2002
22!
23!
24\* ======================================================================== */
25
26//////////////////////////////////////////////////////////////////////////////
27// //
28// MHAlphaEnergyTime //
29// //
30// 3D-histogram in alpha, E-est and time //
31// //
32//////////////////////////////////////////////////////////////////////////////
33
34#include "MHAlphaEnergyTime.h"
35
36#include <TCanvas.h>
37
38#include <math.h>
39
40#include "MHillasSrc.h"
41#include "MEnergyEst.h"
42#include "MTime.h"
43
44#include "MBinning.h"
45#include "MParList.h"
46
47#include "MLog.h"
48#include "MLogManip.h"
49
50ClassImp(MHAlphaEnergyTime);
51
52using namespace std;
53
54// --------------------------------------------------------------------------
55//
56// Default Constructor. It sets name and title of the histogram.
57//
58MHAlphaEnergyTime::MHAlphaEnergyTime(const char *name, const char *title)
59 : fHist()
60{
61 //
62 // set the name and title of this object
63 //
64 fName = name ? name : "MHAlphaEnergyTime";
65 fTitle = title ? title : "3-D histogram in alpha, energy and time";
66
67 fHist.SetDirectory(NULL);
68
69 fHist.SetTitle("3D-plot of alpha, E-est, time");
70 fHist.SetXTitle("\\alpha [\\circ]");
71 fHist.SetYTitle("E-est [GeV] ");
72 fHist.SetZTitle("time [s]");
73}
74
75// --------------------------------------------------------------------------
76//
77// Set binnings and prepare filling of the histogram
78//
79Bool_t MHAlphaEnergyTime::SetupFill(const MParList *plist)
80{
81 fEnergy = (MEnergyEst*)plist->FindObject("MEnergyEst");
82 if (!fEnergy)
83 {
84 *fLog << err << dbginf << "MHAlphaEnergyTime : MEnergyEst not found... aborting." << endl;
85 return kFALSE;
86 }
87
88 fTime = (MTime*)plist->FindObject("MTime");
89 if (!fTime)
90 {
91 *fLog << err << dbginf << "MHAlphaEnergyTime : MTime not found... aborting." << endl;
92 return kFALSE;
93 }
94
95 MBinning* binsenergy = (MBinning*)plist->FindObject("BinningE");
96 MBinning* binsalphaflux = (MBinning*)plist->FindObject("BinningAlphaFlux");
97 MBinning* binstime = (MBinning*)plist->FindObject("BinningTime");
98 if (!binsenergy || !binsalphaflux || !binstime)
99 {
100 *fLog << err << dbginf << "MHAlphaEnergyTime : At least one MBinning not found... aborting." << endl;
101 return kFALSE;
102 }
103
104 SetBinning(&fHist, binsalphaflux, binsenergy, binstime);
105
106 fHist.Sumw2();
107
108 return kTRUE;
109}
110
111// --------------------------------------------------------------------------
112//
113// Fill the histogram
114//
115Bool_t MHAlphaEnergyTime::Fill(const MParContainer *par, const Stat_t w)
116{
117 MHillasSrc &hil = *(MHillasSrc*)par;
118
119 fHist.Fill(fabs(hil.GetAlpha()), fEnergy->GetEnergy(), *fTime, w);
120 return kTRUE;
121}
122
123// --------------------------------------------------------------------------
124//
125// Draw the histogram
126//
127void MHAlphaEnergyTime::Draw(Option_t *opt)
128{
129 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
130 pad->SetBorderMode(0);
131
132 pad->Divide(2,2);
133
134 TH1 *h;
135
136 pad->cd(1);
137 gPad->SetBorderMode(0);
138 h = fHist.Project3D("ex");
139 h->SetTitle("Distribution of \\alpha [\\circ]");
140 h->SetXTitle("\\alpha [\\circ]");
141 h->SetYTitle("Counts");
142 h->Draw(opt);
143 h->SetBit(kCanDelete);
144
145 pad->cd(2);
146 gPad->SetBorderMode(0);
147 gPad->SetLogx();
148 h = fHist.Project3D("ey");
149 h->SetTitle("Distribution of E-est [GeV]");
150 h->SetXTitle("E-est [GeV] ");
151 h->SetYTitle("Counts");
152 h->Draw(opt);
153 h->SetBit(kCanDelete);
154
155 pad->cd(3);
156 gPad->SetBorderMode(0);
157 h = fHist.Project3D("ez");
158 h->SetTitle("Distribution of time [s]");
159 h->SetXTitle("time [s]");
160 h->SetYTitle("Counts");
161 h->Draw(opt);
162 h->SetBit(kCanDelete);
163
164 pad->cd(4);
165 gPad->SetBorderMode(0);
166 fHist.Draw(opt);
167
168 pad->Modified();
169 pad->Update();
170
171}
172
173// --------------------------------------------------------------------------
174//
175// Integrate fHist (Alpha,E-est,Time) over the Time to get
176// fAlphaEest(Alpha,E-est)
177//
178TH2D *MHAlphaEnergyTime::IntegrateTime(const char *title, Bool_t draw)
179{
180 Int_t nzbins = fHist.GetNbinsZ();
181 TAxis &axez = *fHist.GetZaxis();
182 axez.SetRange(1,nzbins);
183
184 TH2D &fAlphaEest = *(TH2D *)fHist.Project3D("exy");
185
186 fAlphaEest.SetTitle(title);
187 fAlphaEest.SetXTitle("E-est [GeV] ");
188 fAlphaEest.SetYTitle("\\alpha [ \\circ]");
189
190 if (draw == kTRUE)
191 {
192 TCanvas &c = *MakeDefCanvas(title, title);
193
194 gROOT->SetSelectedPad(NULL);
195
196 fAlphaEest.DrawCopy();
197 gPad->SetLogx();
198
199 c.Modified();
200 c.Update();
201 }
202
203 return &fAlphaEest;
204}
205
206// --------------------------------------------------------------------------
207//
208// Integrate fHist (Alpha,E-est,Time) over E-est to get
209// fAlphaTime(Alpha,Time)
210//
211TH2D *MHAlphaEnergyTime::IntegrateEest(const char *title, Bool_t draw)
212{
213 Int_t nybins = fHist.GetNbinsY();
214 TAxis &axey = *fHist.GetYaxis();
215 axey.SetRange(1,nybins);
216
217 TH2D &fAlphaTime = *(TH2D *)fHist.Project3D("exz");
218
219 fAlphaTime.SetTitle(title);
220 fAlphaTime.SetXTitle("Time [s]");
221 fAlphaTime.SetYTitle("\\alpha [ \\circ]");
222
223 if (draw == kTRUE)
224 {
225 TCanvas &c = *MakeDefCanvas(title, title);
226
227 gROOT->SetSelectedPad(NULL);
228
229 fAlphaTime.DrawCopy();
230
231 c.Modified();
232 c.Update();
233 }
234
235 return &fAlphaTime;
236}
237
238// --------------------------------------------------------------------------
239//
240// Integrate fHist (Alpha,E-est,Time) over Eest and Time to get
241// fAlpha(Alpha)
242//
243TH1D *MHAlphaEnergyTime::IntegrateEestTime(const char *title, Bool_t draw)
244{
245 Int_t nybins = fHist.GetNbinsY();
246 TAxis &axey = *fHist.GetYaxis();
247 axey.SetRange(1,nybins);
248
249 Int_t nzbins = fHist.GetNbinsZ();
250 TAxis &axez = *fHist.GetZaxis();
251 axez.SetRange(1,nzbins);
252
253 TH1D &fAlpha = *(TH1D *)fHist.Project3D("ex");
254
255 fAlpha.SetTitle(title);
256 fAlpha.SetXTitle("\\alpha [ \\circ]");
257 fAlpha.SetYTitle("Counts");
258
259 if (draw == kTRUE)
260 {
261 TCanvas &c = *MakeDefCanvas(title, title);
262
263 gROOT->SetSelectedPad(NULL);
264
265 fAlpha.DrawCopy();
266
267 c.Modified();
268 c.Update();
269 }
270
271 return &fAlpha;
272}
273
274
275
276
277
278
279
Note: See TracBrowser for help on using the repository browser.