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

Last change on this file since 2173 was 2173, 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 {
118 *fLog << err << "MMcEvt not found... aborting." << endl;
119 return kFALSE;
120 }
121
122 fPed = (MPedestalCam*)plist->FindObject("MPedestalCam");
123 if (!fPed)
124 {
125 *fLog << err << "MPedestalCam not found... aborting." << endl;
126 return kFALSE;
127 }
128
129 fCam = (MGeomCam*)plist->FindObject("MGeomCam");
130 if (!fCam)
131 {
132 *fLog << err << "MGeomCam not found (no geometry information available)... aborting." << endl;
133 return kFALSE;
134 }
135
136 fEvt = (MCerPhotEvt*)plist->FindObject("MCerPhotEvt");
137 if (!fEvt)
138 {
139 *fLog << err << "MCerPhotEvt not found... aborting." << endl;
140 return kFALSE;
141 }
142
143 fSigmabar = (MSigmabar*)plist->FindObject("MSigmabar");
144 if (!fSigmabar)
145 {
146 *fLog << err << "MSigmabar not found... aborting." << endl;
147 return kFALSE;
148 }
149
150 // Get Theta Binning
151 MBinning* binstheta = (MBinning*)plist->FindObject("BinningTheta", "MBinning");
152 if (!binstheta)
153 {
154 *fLog << warn << "Object 'BinningTheta' [MBinning] not found... no binning applied." << endl;
155 return kTRUE;
156 }
157
158 // Get Sigmabar binning
159 MBinning* binssigma = (MBinning*)plist->FindObject("BinningSigmabar", "MBinning");
160 if (!binssigma)
161 *fLog << warn << "Object 'BinningSigmabar' [MBinning] not found... no binning applied." << endl;
162
163 // Get binning for (sigma^2-sigmabar^2)
164 MBinning* binsdiff = (MBinning*)plist->FindObject("BinningDiffsigma2", "MBinning");
165 if (!binsdiff)
166 *fLog << warn << "Object 'BinningDiffsigma2' [MBinning] not found... no binning applied." << endl;
167
168 //FIXME: Missing: Apply new binning to only one axis!
169
170 // Get binning for pixel number
171 const UInt_t npix1 = fPed->GetSize()+1;
172
173 MBinning binspix("BinningPixel");
174 binspix.SetEdges(npix1, -0.5, npix1-0.5);
175
176 // Set binnings in histograms
177 if (binssigma)
178 {
179 SetBinning(&fSigmaTheta, binstheta, binssigma);
180 SetBinning(&fSigmaPixTheta, binstheta, &binspix, binssigma);
181 }
182
183 if (binsdiff)
184 SetBinning(&fDiffPixTheta, binstheta, &binspix, binsdiff);
185
186 return kTRUE;
187}
188
189// --------------------------------------------------------------------------
190//
191// Fill the histograms
192//
193Bool_t MHSigmaTheta::Fill(const MParContainer *par, const Stat_t w)
194{
195 Double_t theta = fMcEvt->GetTelescopeTheta()*kRad2Deg;
196 Double_t mysig = fSigmabar->Calc(*fCam, *fPed, *fEvt);
197
198 fSigmaTheta.Fill(theta, mysig);
199
200 const UInt_t npix = fEvt->GetNumPixels();
201
202 for (UInt_t i=0; i<npix; i++)
203 {
204 MCerPhotPix cerpix = (*fEvt)[i];
205 if (!cerpix.IsPixelUsed())
206 continue;
207
208 const Int_t id = cerpix.GetPixId();
209 const MPedestalPix &pix = (*fPed)[id];
210
211 const Double_t sigma = pix.GetMeanRms();
212 const Double_t area = fCam->GetPixRatio(id);
213
214 fSigmaPixTheta.Fill(theta, (Double_t)id, sigma);
215
216 const Double_t diff = sigma*sigma/area - mysig*mysig;
217 fDiffPixTheta.Fill(theta, (Double_t)id, diff);
218 }
219
220 return kTRUE;
221}
222
223// --------------------------------------------------------------------------
224//
225// Update the projections and (if possible) set log scales before painting
226//
227void MHSigmaTheta::Paint(Option_t *opt)
228{
229 TVirtualPad *padsave = gPad;
230
231 TH1D* h;
232
233 padsave->cd(1);
234 if ((h = (TH1D*)gPad->FindObject("ProjX-Theta")))
235 {
236 ProjectionX(*h, fSigmaTheta);
237 if (h->GetEntries()!=0)
238 gPad->SetLogy();
239 }
240
241 padsave->cd(4);
242 if ((h = (TH1D*)gPad->FindObject("ProjY-sigma")))
243 ProjectionY(*h, fSigmaTheta);
244
245 gPad = padsave;
246}
247
248// --------------------------------------------------------------------------
249//
250// Draw the histogram
251//
252void MHSigmaTheta::Draw(Option_t *opt)
253{
254 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
255 pad->SetBorderMode(0);
256
257 AppendPad("");
258
259 pad->Divide(3, 2);
260
261 // draw the 2D histogram Sigmabar versus Theta
262 TH1 *h;
263
264 pad->cd(1);
265 gPad->SetBorderMode(0);
266 h = fSigmaTheta.ProjectionX("ProjX-Theta", -1, 9999, "E");
267 h->SetDirectory(NULL);
268 h->SetTitle("Distribution of \\Theta");
269 h->SetXTitle("\\Theta [\\circ]");
270 h->SetYTitle("No.of events");
271 h->Draw(opt);
272 h->SetBit(kCanDelete);
273
274 pad->cd(2);
275 gPad->SetBorderMode(0);
276 h = fDiffPixTheta.Project3D("zx");
277 h->SetDirectory(NULL);
278 h->SetTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2} vs. \\Theta (all pixels)");
279 h->SetXTitle("\\Theta [\\circ]");
280 h->SetYTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2}");
281 h->Draw("box");
282 h->SetBit(kCanDelete);
283
284 pad->cd(3);
285 gPad->SetBorderMode(0);
286 h = fSigmaPixTheta.Project3D("zx");
287 h->SetDirectory(NULL);
288 h->SetTitle("\\sigma_{ped} vs. \\Theta (all pixels)");
289 h->SetXTitle("\\Theta [\\circ]");
290 h->SetYTitle("\\sigma_{ped}");
291 h->Draw("box");
292 h->SetBit(kCanDelete);
293
294 //pad->cd(7);
295 //gPad->SetBorderMode(0);
296 //h = fSigmaTheta.ProjectionY("ProjY-sigma", -1, 9999, "E");
297 //h->SetDirectory(NULL);
298 //h->SetTitle("Distribution of \\bar{\\sigma}_{ped}");
299 //h->SetXTitle("\\bar{\\sigma}_{ped}");
300 //h->SetYTitle("No.of events");
301 //h->Draw(opt);
302 //h->SetBit(kCanDelete);
303
304 pad->cd(5);
305 gPad->SetBorderMode(0);
306 h = fDiffPixTheta.Project3D("zy");
307 h->SetDirectory(NULL);
308 h->SetTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2} vs. pixel Id (all \\Theta)");
309 h->SetXTitle("Pixel Id");
310 h->SetYTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2}");
311 h->Draw("box");
312 h->SetBit(kCanDelete);
313
314 pad->cd(6);
315 gPad->SetBorderMode(0);
316 h = fSigmaPixTheta.Project3D("zy");
317 h->SetDirectory(NULL);
318 h->SetTitle("\\sigma_{ped} vs. pixel Id (all \\Theta)");
319 h->SetXTitle("Pixel Id");
320 h->SetYTitle("\\sigma_{ped}");
321 h->Draw("box");
322 h->SetBit(kCanDelete);
323
324 pad->cd(4);
325 fSigmaTheta.Draw(opt);
326
327 //pad->cd(8);
328 //fDiffPixTheta.Draw(opt);
329
330 //pad->cd(9);
331 //fSigmaPixTheta.Draw(opt);
332}
333
334
335
336
337
Note: See TracBrowser for help on using the repository browser.