source: trunk/MagicSoft/Mars/mhist/MHSigmaTheta.cc@ 2230

Last change on this file since 2230 was 2209, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 9.8 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): Wolfgang Wittek 1/2003 <mailto:wittek@mppmu.mpg.de>
19! Author(s): Thomas Bretz 4/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2003
22!
23!
24\* ======================================================================== */
25
26//////////////////////////////////////////////////////////////////////////////
27// //
28// MHSigmaTheta (extension of Robert's MHSigmabarTheta) //
29// //
30// calculates - the 2D-histogram sigmabar vs. Theta, and //
31// - the 3D-histogram sigma, pixel no., Theta //
32// - the 3D-histogram (sigma^2-sigmabar^2), pixel no., Theta //
33// //
34//////////////////////////////////////////////////////////////////////////////
35
36#include "MHSigmaTheta.h"
37
38#include <TCanvas.h>
39
40#include "MTime.h"
41#include "MMcEvt.hxx"
42
43#include "MBinning.h"
44#include "MParList.h"
45#include "MSigmabar.h"
46
47#include "MGeomCam.h"
48
49#include "MPedestalCam.h"
50#include "MPedestalPix.h"
51
52#include "MCerPhotEvt.h"
53#include "MCerPhotPix.h"
54
55#include "MLog.h"
56#include "MLogManip.h"
57
58ClassImp(MHSigmaTheta);
59
60using namespace std;
61
62// --------------------------------------------------------------------------
63//
64// Default Constructor. It sets name and title of the histogram.
65//
66MHSigmaTheta::MHSigmaTheta(const char *name, const char *title)
67{
68 fName = name ? name : "MHSigmaTheta";
69 fTitle = title ? title : "2D histogram sigmabar vs. Theta";
70
71 fSigmaTheta.SetDirectory(NULL);
72 fSigmaTheta.SetName("2D-ThetaSigmabar");
73 fSigmaTheta.SetTitle("2D: \\bar{\\sigma}, \\Theta");
74 fSigmaTheta.SetXTitle("\\Theta [\\circ]");
75 fSigmaTheta.SetYTitle("Sigmabar");
76
77 fSigmaPixTheta.SetDirectory(NULL);
78 fSigmaPixTheta.SetName("3D-ThetaPixSigma");
79 fSigmaPixTheta.SetTitle("3D: \\Theta, Pixel Id, \\sigma");
80 fSigmaPixTheta.SetXTitle("\\Theta [\\circ]");
81 fSigmaPixTheta.SetYTitle("Pixel Id");
82 fSigmaPixTheta.SetZTitle("\\sigma");
83
84 fDiffPixTheta.SetDirectory(NULL);
85 fDiffPixTheta.SetName("3D-ThetaPixDiff");
86 fDiffPixTheta.SetTitle("3D: \\Theta, Pixel Id, {\\sigma}^{2}-\\bar{\\sigma}^{2}");
87 fDiffPixTheta.SetXTitle("\\Theta [\\circ]");
88 fDiffPixTheta.SetYTitle("Pixel Id");
89 fDiffPixTheta.SetZTitle("{\\sigma}^{2}-\\bar{\\sigma}^{2}");
90
91 // Set default binning
92 // FIXME: Maybe ist's necessary to adapt the value to the
93 // Magic default values
94 MBinning binsb;
95 MBinning binst;
96 MBinning binsd;
97 binsd.SetEdges(100, -5, 20);
98 binsb.SetEdges(100, 0, 5);
99 binst.SetEdgesCos(10, 0, 90);
100
101 MBinning binspix("BinningPixel");
102 binspix.SetEdges(578, -0.5, 577.5);
103
104 SetBinning(&fSigmaTheta, &binst, &binsb);
105 SetBinning(&fSigmaPixTheta, &binst, &binspix, &binsb);
106 SetBinning(&fDiffPixTheta, &binst, &binspix, &binsd);
107}
108
109// --------------------------------------------------------------------------
110//
111// Set the binnings and prepare the filling of the histogram
112//
113Bool_t MHSigmaTheta::SetupFill(const MParList *plist)
114{
115 fMcEvt = (MMcEvt*)plist->FindObject("MMcEvt");
116 if (!fMcEvt)
117 *fLog << warn << "MMcEvt not found... aborting." << endl;
118
119 fPed = (MPedestalCam*)plist->FindObject("MPedestalCam");
120 if (!fPed)
121 {
122 *fLog << err << "MPedestalCam not found... aborting." << endl;
123 return kFALSE;
124 }
125
126 fCam = (MGeomCam*)plist->FindObject("MGeomCam");
127 if (!fCam)
128 {
129 *fLog << err << "MGeomCam not found (no geometry information available)... aborting." << endl;
130 return kFALSE;
131 }
132
133 fEvt = (MCerPhotEvt*)plist->FindObject("MCerPhotEvt");
134 if (!fEvt)
135 {
136 *fLog << err << "MCerPhotEvt not found... aborting." << endl;
137 return kFALSE;
138 }
139
140 fSigmabar = (MSigmabar*)plist->FindObject("MSigmabar");
141 if (!fSigmabar)
142 {
143 *fLog << err << "MSigmabar not found... aborting." << endl;
144 return kFALSE;
145 }
146
147 // Get Theta Binning
148 MBinning* binstheta = (MBinning*)plist->FindObject("BinningTheta", "MBinning");
149 if (!binstheta)
150 {
151 *fLog << warn << "Object 'BinningTheta' [MBinning] not found... no binning applied." << endl;
152 return kTRUE;
153 }
154
155 // Get Sigmabar binning
156 MBinning* binssigma = (MBinning*)plist->FindObject("BinningSigmabar", "MBinning");
157 if (!binssigma)
158 *fLog << warn << "Object 'BinningSigmabar' [MBinning] not found... no binning applied." << endl;
159
160 // Get binning for (sigma^2-sigmabar^2)
161 MBinning* binsdiff = (MBinning*)plist->FindObject("BinningDiffsigma2", "MBinning");
162 if (!binsdiff)
163 *fLog << warn << "Object 'BinningDiffsigma2' [MBinning] not found... no binning applied." << endl;
164
165 //FIXME: Missing: Apply new binning to only one axis!
166
167 // Get binning for pixel number
168 const UInt_t npix1 = fPed->GetSize()+1;
169
170 MBinning binspix("BinningPixel");
171 binspix.SetEdges(npix1, -0.5, npix1-0.5);
172
173 // Set binnings in histograms
174 if (binssigma)
175 {
176 SetBinning(&fSigmaTheta, binstheta, binssigma);
177 SetBinning(&fSigmaPixTheta, binstheta, &binspix, binssigma);
178 }
179
180 if (binsdiff)
181 SetBinning(&fDiffPixTheta, binstheta, &binspix, binsdiff);
182
183 return kTRUE;
184}
185
186// --------------------------------------------------------------------------
187//
188// Fill the histograms
189//
190Bool_t MHSigmaTheta::Fill(const MParContainer *par, const Stat_t w)
191{
192 Double_t theta = fMcEvt ? fMcEvt->GetTelescopeTheta()*kRad2Deg : 0;
193 Double_t mysig = fSigmabar->Calc(*fCam, *fPed, *fEvt);
194
195 fSigmaTheta.Fill(theta, mysig);
196
197 const UInt_t npix = fEvt->GetNumPixels();
198
199 for (UInt_t i=0; i<npix; i++)
200 {
201 MCerPhotPix cerpix = (*fEvt)[i];
202 if (!cerpix.IsPixelUsed())
203 continue;
204
205 const Int_t id = cerpix.GetPixId();
206 const MPedestalPix &pix = (*fPed)[id];
207
208 const Double_t sigma = pix.GetMeanRms();
209 const Double_t area = fCam->GetPixRatio(id);
210
211 fSigmaPixTheta.Fill(theta, (Double_t)id, sigma);
212
213 const Double_t diff = sigma*sigma/area - mysig*mysig;
214 fDiffPixTheta.Fill(theta, (Double_t)id, diff);
215 }
216
217 return kTRUE;
218}
219
220// --------------------------------------------------------------------------
221//
222// Update the projections and (if possible) set log scales before painting
223//
224void MHSigmaTheta::Paint(Option_t *opt)
225{
226 TVirtualPad *padsave = gPad;
227
228 TH1D* h;
229
230 padsave->cd(1);
231 if ((h = (TH1D*)gPad->FindObject("ProjX-Theta")))
232 {
233 ProjectionX(*h, fSigmaTheta);
234 if (h->GetEntries()!=0)
235 gPad->SetLogy();
236 }
237
238 padsave->cd(4);
239 if ((h = (TH1D*)gPad->FindObject("ProjY-sigma")))
240 ProjectionY(*h, fSigmaTheta);
241
242 gPad = padsave;
243}
244
245// --------------------------------------------------------------------------
246//
247// Draw the histogram
248//
249void MHSigmaTheta::Draw(Option_t *opt)
250{
251 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
252 pad->SetBorderMode(0);
253
254 AppendPad("");
255
256 pad->Divide(3, 2);
257
258 // draw the 2D histogram Sigmabar versus Theta
259 TH1 *h;
260
261 pad->cd(1);
262 gPad->SetBorderMode(0);
263 h = fSigmaTheta.ProjectionX("ProjX-Theta", -1, 9999, "E");
264 h->SetDirectory(NULL);
265 h->SetTitle("Distribution of \\Theta");
266 h->SetXTitle("\\Theta [\\circ]");
267 h->SetYTitle("No.of events");
268 h->Draw(opt);
269 h->SetBit(kCanDelete);
270
271 pad->cd(2);
272 gPad->SetBorderMode(0);
273 h = fDiffPixTheta.Project3D("zx");
274 h->SetDirectory(NULL);
275 h->SetTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2} vs. \\Theta (all pixels)");
276 h->SetXTitle("\\Theta [\\circ]");
277 h->SetYTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2}");
278 h->Draw("box");
279 h->SetBit(kCanDelete);
280
281 pad->cd(3);
282 gPad->SetBorderMode(0);
283 h = fSigmaPixTheta.Project3D("zx");
284 h->SetDirectory(NULL);
285 h->SetTitle("\\sigma_{ped} vs. \\Theta (all pixels)");
286 h->SetXTitle("\\Theta [\\circ]");
287 h->SetYTitle("\\sigma_{ped}");
288 h->Draw("box");
289 h->SetBit(kCanDelete);
290
291 //pad->cd(7);
292 //gPad->SetBorderMode(0);
293 //h = fSigmaTheta.ProjectionY("ProjY-sigma", -1, 9999, "E");
294 //h->SetDirectory(NULL);
295 //h->SetTitle("Distribution of \\bar{\\sigma}_{ped}");
296 //h->SetXTitle("\\bar{\\sigma}_{ped}");
297 //h->SetYTitle("No.of events");
298 //h->Draw(opt);
299 //h->SetBit(kCanDelete);
300
301 pad->cd(5);
302 gPad->SetBorderMode(0);
303 h = fDiffPixTheta.Project3D("zy");
304 h->SetDirectory(NULL);
305 h->SetTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2} vs. pixel Id (all \\Theta)");
306 h->SetXTitle("Pixel Id");
307 h->SetYTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2}");
308 h->Draw("box");
309 h->SetBit(kCanDelete);
310
311 pad->cd(6);
312 gPad->SetBorderMode(0);
313 h = fSigmaPixTheta.Project3D("zy");
314 h->SetDirectory(NULL);
315 h->SetTitle("\\sigma_{ped} vs. pixel Id (all \\Theta)");
316 h->SetXTitle("Pixel Id");
317 h->SetYTitle("\\sigma_{ped}");
318 h->Draw("box");
319 h->SetBit(kCanDelete);
320
321 pad->cd(4);
322 fSigmaTheta.Draw(opt);
323
324 //pad->cd(8);
325 //fDiffPixTheta.Draw(opt);
326
327 //pad->cd(9);
328 //fSigmaPixTheta.Draw(opt);
329}
330
331
332
333
334
Note: See TracBrowser for help on using the repository browser.