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

Last change on this file since 1809 was 1809, checked in by wittek, 22 years ago
*** empty log message ***
File size: 10.4 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!
20! Copyright: MAGIC Software Development, 2000-2002
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26// //
27// MHSigmaTheta (extension of Robert's MHSigmabarTheta) //
28// //
29// calculates - the 2D-histogram sigmabar vs. Theta, and //
30// - the 3D-histogram sigma, pixel no., Theta //
31// - the 3D-histogram (sigma^2-sigmabar^2), pixel no., Theta //
32// //
33//////////////////////////////////////////////////////////////////////////////
34
35#include "MHSigmaTheta.h"
36
37#include <TCanvas.h>
38
39#include "MTime.h"
40#include "MMcEvt.hxx"
41
42#include "MBinning.h"
43#include "MParList.h"
44#include "MPedestalCam.h"
45#include "MPedestalPix.h"
46#include "MCerPhotEvt.h"
47#include "MCerPhotPix.h"
48
49#include "MLog.h"
50#include "MLogManip.h"
51
52#include "MSigmabar.h"
53
54ClassImp(MHSigmaTheta);
55
56
57// --------------------------------------------------------------------------
58//
59// Default Constructor. It sets name and title of the histogram.
60//
61MHSigmaTheta::MHSigmaTheta(const char *name, const char *title)
62 : fSigmaTheta(), fSigmaPixTheta()
63{
64 fName = name ? name : "MHSigmaTheta";
65 fTitle = title ? title : "2D histogram sigmabar vs. Theta";
66
67 fSigmaTheta.SetDirectory(NULL);
68 fSigmaTheta.SetName("2D-ThetaSigmabar");
69 fSigmaTheta.SetTitle("2D : Sigmabar, \\Theta");
70 fSigmaTheta.SetXTitle("\\Theta [\\circ]");
71 fSigmaTheta.SetYTitle("Sigmabar");
72
73 fSigmaPixTheta.SetDirectory(NULL);
74 fSigmaPixTheta.SetName("3D-ThetaPixSigma");
75 fSigmaPixTheta.SetTitle("3D : \\Theta, pixel no., Sigma");
76 fSigmaPixTheta.SetXTitle("\\Theta [\\circ]");
77 fSigmaPixTheta.SetYTitle("pixel number");
78 fSigmaPixTheta.SetZTitle("Sigma");
79
80 fDiffPixTheta.SetDirectory(NULL);
81 fDiffPixTheta.SetName("3D-ThetaPixDiff");
82 fDiffPixTheta.SetTitle("3D : \\Theta, pixel, Sigma^2-Sigmabar^2");
83 fDiffPixTheta.SetXTitle("\\Theta [\\circ]");
84 fDiffPixTheta.SetYTitle("pixel number");
85 fDiffPixTheta.SetZTitle("Sigma^2-sigmabar^2");
86}
87
88// --------------------------------------------------------------------------
89//
90// Set the binnings and prepare the filling of the histogram
91//
92Bool_t MHSigmaTheta::SetupFill(const MParList *plist)
93{
94
95 fMcEvt = (MMcEvt*)plist->FindObject("MMcEvt");
96 if (!fMcEvt)
97 {
98 *fLog << err << dbginf << "MHSigmaTheta::SetupFill : MMcEvt not found... aborting." << endl;
99 return kFALSE;
100 }
101
102 fPed = (MPedestalCam*)plist->FindObject("MPedestalCam");
103 if (!fPed)
104 {
105 *fLog << dbginf << "MHSigmaTheta::SetupFill : MPedestalCam not found... aborting." << endl;
106 return kFALSE;
107 }
108
109 fCam = (MGeomCam*)plist->FindObject("MGeomCam");
110 if (!fCam)
111 {
112 *fLog << dbginf << "MHSigmaTheta::SetupFill : MGeomCam not found (no geometry information available)... aborting." << endl;
113 return kFALSE;
114 }
115
116 fEvt = (MCerPhotEvt*)plist->FindObject("MCerPhotEvt");
117 if (!fEvt)
118 {
119 *fLog << dbginf << "MHSigmaTheta::SetupFill : MCerPhotEvt not found... aborting." << endl;
120 return kFALSE;
121 }
122
123 fSigmabar = (MSigmabar*)plist->FindObject("MSigmabar");
124 if (!fSigmabar)
125 {
126 *fLog << dbginf << "MHSigmaTheta::SetupFill : MSigmabar not found... aborting." << endl;
127 return kFALSE;
128 }
129
130 // Get Theta Binning
131 MBinning* binstheta = (MBinning*)plist->FindObject("BinningTheta");
132 if (!binstheta)
133 {
134 *fLog << err << dbginf << "MHSigmaTheta::SetupFill : BinningTheta not found... aborting." << endl;
135 return kFALSE;
136 }
137
138 // Get Sigmabar binning
139 MBinning* binssigma = (MBinning*)plist->FindObject("BinningSigmabar");
140 if (!binssigma)
141 {
142 *fLog << err << dbginf << "MHSigmaTheta::SetupFill : BinningSigmabar not found... aborting." << endl;
143 return kFALSE;
144 }
145
146 // Get binning for (sigma^2-sigmabar^2)
147 MBinning* binsdiff = (MBinning*)plist->FindObject("BinningDiffsigma2");
148 if (!binsdiff)
149 {
150 *fLog << err << dbginf << "MHSigmaTheta::SetupFill : BinningDiffsigma2 not found... aborting." << endl;
151 return kFALSE;
152 }
153
154
155 // Set binnings in histograms
156 SetBinning(&fSigmaTheta, binstheta, binssigma);
157
158 // Get binning for pixel number
159 UInt_t npix = fPed->GetSize();
160 MBinning binspix("BinningPixel");
161 MBinning* binspixel = &binspix;
162 binspixel->SetEdges(npix, -0.5, ((float)npix)-0.5 );
163
164 SetBinning(&fSigmaPixTheta, binstheta, binspixel, binssigma);
165 SetBinning(&fDiffPixTheta, binstheta, binspixel, binsdiff);
166
167 return kTRUE;
168}
169
170// --------------------------------------------------------------------------
171//
172// Fill the histograms
173//
174Bool_t MHSigmaTheta::Fill(const MParContainer *par)
175{
176 //*fLog << "entry Fill" << endl;
177
178 Double_t Theta = fMcEvt->GetTelescopeTheta()*kRad2Deg;
179 Double_t mySig = fSigmabar->Calc(*fCam, *fPed, *fEvt);
180 fSigmaTheta.Fill(Theta, mySig);
181
182 //*fLog << "Theta, mySig = " << Theta << ", " << mySig << endl;
183
184 const UInt_t npix = fEvt->GetNumPixels();
185 for (UInt_t i=0; i<npix; i++)
186 {
187 MCerPhotPix cerpix = fEvt->operator[](i);
188 if (!cerpix.IsPixelUsed())
189 continue;
190
191 if (cerpix.GetNumPhotons() == 0)
192 continue;
193
194 Int_t j = cerpix.GetPixId();
195 const MPedestalPix pix = fPed->operator[](j);
196
197 Double_t Sigma = pix.GetMeanRms();
198 Double_t Area = fCam->GetPixRatio(j);
199
200 fSigmaPixTheta.Fill(Theta, (Double_t)j, Sigma);
201
202 Double_t Diff = Sigma*Sigma/Area - mySig*mySig;
203 fDiffPixTheta.Fill (Theta, (Double_t)j, Diff);
204 }
205
206 return kTRUE;
207}
208
209// --------------------------------------------------------------------------
210//
211// Plot the results
212//
213Bool_t MHSigmaTheta::Finalize()
214{
215 DrawClone();
216
217 return kTRUE;
218}
219
220// --------------------------------------------------------------------------
221//
222// Draw a copy of the histogram
223//
224TObject *MHSigmaTheta::DrawClone(Option_t *opt)
225{
226 TCanvas &c = *MakeDefCanvas("SigmaThetaPlot", "Sigmabar vs. Theta",
227 900, 900);
228 c.Divide(3, 3);
229
230 gROOT->SetSelectedPad(NULL);
231
232 //--------------------------------------------------------------------
233 // draw the 2D histogram Sigmabar versus Theta
234 TH1D *h;
235
236 c.cd(1);
237 h = ((TH2*)&fSigmaTheta)->ProjectionX("ProjX-Theta", -1, 9999, "E");
238 h->SetDirectory(NULL);
239 h->SetTitle("Distribution of \\Theta");
240 h->SetXTitle("\\Theta [\\circ]");
241 h->SetYTitle("No.of events");
242
243 h->DrawCopy(opt);
244 h->SetBit(kCanDelete);;
245 gPad->SetLogy();
246
247 c.cd(4);
248 h = ((TH2*)&fSigmaTheta)->ProjectionY("ProjY-sigma", -1, 9999, "E");
249 h->SetDirectory(NULL);
250 h->SetTitle("Distribution of Sigmabar");
251 h->SetXTitle("Sigmabar");
252 h->SetYTitle("No.of events");
253
254 h->DrawCopy(opt);
255 h->SetBit(kCanDelete);;
256
257 c.cd(7);
258 ((TH2*)&fSigmaTheta)->DrawCopy(opt);
259
260 //--------------------------------------------------------------------
261 // draw the 3D histogram : Theta, pixel, Sigma^2-Sigmabar^2
262
263 TH2D *l;
264
265 c.cd(2);
266 l = (TH2D*) ((TH3*)&fDiffPixTheta)->Project3D("zx");
267 l->SetDirectory(NULL);
268 l->SetTitle("Sigma^2-Sigmabar^2 vs. \\Theta (all pixels)");
269 l->SetXTitle("\\Theta [\\circ]");
270 l->SetYTitle("Sigma^2-Sigmabar^2");
271
272 l->DrawCopy("box");
273 l->SetBit(kCanDelete);;
274
275 c.cd(5);
276 l = (TH2D*) ((TH3*)&fDiffPixTheta)->Project3D("zy");
277 l->SetDirectory(NULL);
278 l->SetTitle("Sigma^2-Sigmabar^2 vs. pixel number (all \\Theta)");
279 l->SetXTitle("pixel");
280 l->SetYTitle("Sigma^2-Sigmabar^2");
281
282 l->DrawCopy("box");
283 l->SetBit(kCanDelete);;
284
285 c.cd(8);
286 ((TH2*)&fDiffPixTheta)->DrawCopy(opt);
287
288
289 //--------------------------------------------------------------------
290 // draw the 3D histogram : Theta, pixel, Sigma
291
292 TH2D *k;
293
294 c.cd(3);
295 k = (TH2D*) ((TH3*)&fSigmaPixTheta)->Project3D("zx");
296 k->SetDirectory(NULL);
297 k->SetTitle("Sigma vs. \\Theta (all pixels)");
298 k->SetXTitle("\\Theta [\\circ]");
299 k->SetYTitle("Sigma");
300
301 k->DrawCopy("box");
302 k->SetBit(kCanDelete);;
303
304 c.cd(6);
305 k = (TH2D*) ((TH3*)&fSigmaPixTheta)->Project3D("zy");
306 k->SetDirectory(NULL);
307 k->SetTitle("Sigma vs. pixel number (all \\Theta)");
308 k->SetXTitle("pixel");
309 k->SetYTitle("Sigma");
310
311 k->DrawCopy("box");
312 k->SetBit(kCanDelete);;
313
314 c.cd(9);
315 ((TH2*)&fSigmaPixTheta)->DrawCopy(opt);
316
317 //--------------------------------------------------------------------
318 c.Modified();
319 c.Update();
320
321 return &c;
322}
323
324// --------------------------------------------------------------------------
325//
326// Draw the histogram
327//
328void MHSigmaTheta::Draw(Option_t *opt)
329{
330 if (!gPad)
331 MakeDefCanvas("SigmaTheta", "Sigmabar vs. Theta",
332 600, 600);
333
334 TH1D *h;
335
336 gPad->Divide(2,2);
337
338 gPad->cd(1);
339 h = ((TH2*)&fSigmaTheta)->ProjectionX("ProjX-Theta", -1, 9999, "E");
340 h->SetTitle("Distribution of \\Theta");
341 h->SetXTitle("\\Theta [\\circ]");
342 h->SetYTitle("No.of events");
343
344 h->Draw(opt);
345 h->SetBit(kCanDelete);;
346 gPad->SetLogy();
347
348 gPad->cd(2);
349 h = ((TH2*)&fSigmaTheta)->ProjectionY("ProjY-sigma", -1, 9999, "E");
350 h->SetTitle("Distribution of Sigmabar");
351 h->SetXTitle("Sigmabar");
352 h->SetYTitle("No.of events");
353
354 h->Draw(opt);
355 h->SetBit(kCanDelete);;
356
357 gPad->cd(3);
358 fSigmaTheta.DrawCopy(opt);
359
360
361
362 gPad->Modified();
363 gPad->Update();
364}
365// --------------------------------------------------------------------------
366
367
368
369
Note: See TracBrowser for help on using the repository browser.