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

Last change on this file since 4188 was 3339, checked in by wittek, 21 years ago
*** empty log message ***
File size: 10.1 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, -10, 20);
98 binsb.SetEdges(100, 0, 10);
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 fCam = (MGeomCam*)plist->FindObject("MGeomCam");
116 if (!fCam)
117 {
118 *fLog << err << "MGeomCam not found (no geometry information available)... aborting." << endl;
119 return kFALSE;
120 }
121
122 fMcEvt = (MMcEvt*)plist->FindObject("MMcEvt");
123 if (!fMcEvt)
124 *fLog << warn << "MMcEvt not found... aborting." << endl;
125
126
127 fPed = (MPedPhotCam*)plist->FindObject("MPedPhotCam");
128 if (!fPed)
129 {
130 *fLog << err << "MPedPhotCam not found... aborting." << endl;
131 return kFALSE;
132 }
133 fPed->InitSize(fCam->GetNumPixels());
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 *fLog << "npix1 = " << npix1 << endl;
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 ? fMcEvt->GetTelescopeTheta()*kRad2Deg : 0;
196 fSigmabar->Calc(*fCam, *fPed, *fEvt);
197 Double_t mysig = fSigmabar->GetSigmabarInner();
198
199 //*fLog << "theta, mysig = " << theta << ", " << mysig << endl;
200
201 fSigmaTheta.Fill(theta, mysig);
202
203 const UInt_t npix = fEvt->GetNumPixels();
204
205 for (UInt_t i=0; i<npix; i++)
206 {
207 MCerPhotPix cerpix = (*fEvt)[i];
208 if (!cerpix.IsPixelUsed())
209 continue;
210
211 const Int_t id = cerpix.GetPixId();
212 const MPedPhotPix &pix = (*fPed)[id];
213
214 // ratio is the area of pixel 0
215 // divided by the area of the current pixel
216 const Double_t ratio = fCam->GetPixRatio(id);
217 const Double_t sigma = pix.GetRms();
218
219 fSigmaPixTheta.Fill(theta, (Double_t)id, sigma*sqrt(ratio));
220
221 const Double_t diff = sigma*sigma*ratio - mysig*mysig;
222 fDiffPixTheta.Fill(theta, (Double_t)id, diff);
223 }
224
225 return kTRUE;
226}
227
228// --------------------------------------------------------------------------
229//
230// Update the projections and (if possible) set log scales before painting
231//
232void MHSigmaTheta::Paint(Option_t *opt)
233{
234 TVirtualPad *padsave = gPad;
235
236 TH1D* h;
237
238 padsave->cd(1);
239 if ((h = (TH1D*)gPad->FindObject("ProjX-Theta")))
240 {
241 ProjectionX(*h, fSigmaTheta);
242 if (h->GetEntries()!=0)
243 gPad->SetLogy();
244 }
245
246 padsave->cd(4);
247 if ((h = (TH1D*)gPad->FindObject("ProjY-sigma")))
248 ProjectionY(*h, fSigmaTheta);
249
250 gPad = padsave;
251}
252
253// --------------------------------------------------------------------------
254//
255// Draw the histogram
256//
257void MHSigmaTheta::Draw(Option_t *opt)
258{
259 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
260 pad->SetBorderMode(0);
261
262 AppendPad("");
263
264 pad->Divide(3, 2);
265
266 // draw the 2D histogram Sigmabar versus Theta
267 TH1 *h;
268
269 pad->cd(1);
270 gPad->SetBorderMode(0);
271 h = fSigmaTheta.ProjectionX("ProjX-Theta", -1, 9999, "E");
272 h->SetDirectory(NULL);
273 h->SetTitle("Distribution of \\Theta");
274 h->SetXTitle("\\Theta [\\circ]");
275 h->SetYTitle("No.of events");
276 h->Draw(opt);
277 h->SetBit(kCanDelete);
278
279 pad->cd(2);
280 gPad->SetBorderMode(0);
281 h = fDiffPixTheta.Project3D("zx");
282 h->SetDirectory(NULL);
283 h->SetTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2} vs. \\Theta (all pixels)");
284 h->SetXTitle("\\Theta [\\circ]");
285 h->SetYTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2}");
286 h->Draw("box");
287 h->SetBit(kCanDelete);
288
289 pad->cd(3);
290 gPad->SetBorderMode(0);
291 h = fSigmaPixTheta.Project3D("zx");
292 h->SetDirectory(NULL);
293 h->SetTitle("\\sigma_{ped} vs. \\Theta (all pixels)");
294 h->SetXTitle("\\Theta [\\circ]");
295 h->SetYTitle("\\sigma_{ped}");
296 h->Draw("box");
297 h->SetBit(kCanDelete);
298
299 //pad->cd(7);
300 //gPad->SetBorderMode(0);
301 //h = fSigmaTheta.ProjectionY("ProjY-sigma", -1, 9999, "E");
302 //h->SetDirectory(NULL);
303 //h->SetTitle("Distribution of \\bar{\\sigma}_{ped}");
304 //h->SetXTitle("\\bar{\\sigma}_{ped}");
305 //h->SetYTitle("No.of events");
306 //h->Draw(opt);
307 //h->SetBit(kCanDelete);
308
309 pad->cd(5);
310 gPad->SetBorderMode(0);
311 h = fDiffPixTheta.Project3D("zy");
312 h->SetDirectory(NULL);
313 h->SetTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2} vs. pixel Id (all \\Theta)");
314 h->SetXTitle("Pixel Id");
315 h->SetYTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2}");
316 h->Draw("box");
317 h->SetBit(kCanDelete);
318
319 pad->cd(6);
320 gPad->SetBorderMode(0);
321 h = fSigmaPixTheta.Project3D("zy");
322 h->SetDirectory(NULL);
323 h->SetTitle("\\sigma_{ped} vs. pixel Id (all \\Theta)");
324 h->SetXTitle("Pixel Id");
325 h->SetYTitle("\\sigma_{ped}");
326 h->Draw("box");
327 h->SetBit(kCanDelete);
328
329 pad->cd(4);
330 fSigmaTheta.Draw(opt);
331
332 //pad->cd(8);
333 //fDiffPixTheta.Draw(opt);
334
335 //pad->cd(9);
336 //fSigmaPixTheta.Draw(opt);
337}
338
339
340
341
342
343
344
345
346
347
348
349
350
351
Note: See TracBrowser for help on using the repository browser.