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

Last change on this file since 3273 was 3140, checked in by wittek, 21 years ago
*** empty log message ***
File size: 10.2 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 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 //*fLog << "npix1 = " << npix1 << endl;
170 //MBinning binspix("BinningPixel");
171 //binspix.SetEdges(npix1, -0.5, npix1-0.5);
172 // the above gives npix1 = 1; therefore :
173 MBinning binspix("BinningPixel");
174 binspix.SetEdges(578, -0.5, 577.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.