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

Last change on this file since 2894 was 2798, checked in by wittek, 21 years ago
*** empty log message ***
File size: 9.9 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 "MPedPhotCam.h"
50#include "MPedPhotPix.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 = (MPedPhotCam*)plist->FindObject("MPedPhotCam");
120 if (!fPed)
121 {
122 *fLog << err << "MPedPhotCam 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 MPedPhotPix &pix = (*fPed)[id];
207
208 // ratio is the area of pixel 0
209 // divided by the area of the current pixel
210 const Double_t ratio = fCam->GetPixRatio(id);
211 const Double_t sigma = pix.GetRms();
212
213 fSigmaPixTheta.Fill(theta, (Double_t)id, sigma);
214
215 const Double_t diff = sigma*sigma*ratio - mysig*mysig;
216 fDiffPixTheta.Fill(theta, (Double_t)id, diff);
217 }
218
219 return kTRUE;
220}
221
222// --------------------------------------------------------------------------
223//
224// Update the projections and (if possible) set log scales before painting
225//
226void MHSigmaTheta::Paint(Option_t *opt)
227{
228 TVirtualPad *padsave = gPad;
229
230 TH1D* h;
231
232 padsave->cd(1);
233 if ((h = (TH1D*)gPad->FindObject("ProjX-Theta")))
234 {
235 ProjectionX(*h, fSigmaTheta);
236 if (h->GetEntries()!=0)
237 gPad->SetLogy();
238 }
239
240 padsave->cd(4);
241 if ((h = (TH1D*)gPad->FindObject("ProjY-sigma")))
242 ProjectionY(*h, fSigmaTheta);
243
244 gPad = padsave;
245}
246
247// --------------------------------------------------------------------------
248//
249// Draw the histogram
250//
251void MHSigmaTheta::Draw(Option_t *opt)
252{
253 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
254 pad->SetBorderMode(0);
255
256 AppendPad("");
257
258 pad->Divide(3, 2);
259
260 // draw the 2D histogram Sigmabar versus Theta
261 TH1 *h;
262
263 pad->cd(1);
264 gPad->SetBorderMode(0);
265 h = fSigmaTheta.ProjectionX("ProjX-Theta", -1, 9999, "E");
266 h->SetDirectory(NULL);
267 h->SetTitle("Distribution of \\Theta");
268 h->SetXTitle("\\Theta [\\circ]");
269 h->SetYTitle("No.of events");
270 h->Draw(opt);
271 h->SetBit(kCanDelete);
272
273 pad->cd(2);
274 gPad->SetBorderMode(0);
275 h = fDiffPixTheta.Project3D("zx");
276 h->SetDirectory(NULL);
277 h->SetTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2} vs. \\Theta (all pixels)");
278 h->SetXTitle("\\Theta [\\circ]");
279 h->SetYTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2}");
280 h->Draw("box");
281 h->SetBit(kCanDelete);
282
283 pad->cd(3);
284 gPad->SetBorderMode(0);
285 h = fSigmaPixTheta.Project3D("zx");
286 h->SetDirectory(NULL);
287 h->SetTitle("\\sigma_{ped} vs. \\Theta (all pixels)");
288 h->SetXTitle("\\Theta [\\circ]");
289 h->SetYTitle("\\sigma_{ped}");
290 h->Draw("box");
291 h->SetBit(kCanDelete);
292
293 //pad->cd(7);
294 //gPad->SetBorderMode(0);
295 //h = fSigmaTheta.ProjectionY("ProjY-sigma", -1, 9999, "E");
296 //h->SetDirectory(NULL);
297 //h->SetTitle("Distribution of \\bar{\\sigma}_{ped}");
298 //h->SetXTitle("\\bar{\\sigma}_{ped}");
299 //h->SetYTitle("No.of events");
300 //h->Draw(opt);
301 //h->SetBit(kCanDelete);
302
303 pad->cd(5);
304 gPad->SetBorderMode(0);
305 h = fDiffPixTheta.Project3D("zy");
306 h->SetDirectory(NULL);
307 h->SetTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2} vs. pixel Id (all \\Theta)");
308 h->SetXTitle("Pixel Id");
309 h->SetYTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2}");
310 h->Draw("box");
311 h->SetBit(kCanDelete);
312
313 pad->cd(6);
314 gPad->SetBorderMode(0);
315 h = fSigmaPixTheta.Project3D("zy");
316 h->SetDirectory(NULL);
317 h->SetTitle("\\sigma_{ped} vs. pixel Id (all \\Theta)");
318 h->SetXTitle("Pixel Id");
319 h->SetYTitle("\\sigma_{ped}");
320 h->Draw("box");
321 h->SetBit(kCanDelete);
322
323 pad->cd(4);
324 fSigmaTheta.Draw(opt);
325
326 //pad->cd(8);
327 //fDiffPixTheta.Draw(opt);
328
329 //pad->cd(9);
330 //fSigmaPixTheta.Draw(opt);
331}
332
333
334
335
336
337
338
339
340
341
342
343
344
345
Note: See TracBrowser for help on using the repository browser.