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): Thomas Bretz, 3/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MHFalseSource
|
---|
28 | //
|
---|
29 | // Create a false source plot. For the Binning in x,y the object MBinning
|
---|
30 | // "BinningFalseSource" is taken from the paremeter list.
|
---|
31 | //
|
---|
32 | // The binning in alpha is currently fixed as 18bins from 0 to 90deg.
|
---|
33 | //
|
---|
34 | // If MTime, MObservatory and MPointingPos is available in the paremeter
|
---|
35 | // list each image is derotated.
|
---|
36 | //
|
---|
37 | // MHFalseSource fills a 3D histogram with alpha distribution for
|
---|
38 | // each (derotated) x and y position.
|
---|
39 | //
|
---|
40 | // Only a radius of 1.2deg around the camera center is taken into account.
|
---|
41 | //
|
---|
42 | // The displayed histogram is the projection of alpha<fAlphaCut into
|
---|
43 | // the x,y plain and the projection of alpha>90-fAlphaCut
|
---|
44 | //
|
---|
45 | // By using the context menu (find it in a small region between the single
|
---|
46 | // pads) you can change the AlphaCut 'online'
|
---|
47 | //
|
---|
48 | // Here is a slightly simplified version of the algorithm:
|
---|
49 | // ------------------------------------------------------
|
---|
50 | // MHillas hil; // Taken as second argument in MFillH
|
---|
51 | //
|
---|
52 | // MSrcPosCam src;
|
---|
53 | // MHillasSrc hsrc;
|
---|
54 | // hsrc.SetSrcPos(&src);
|
---|
55 | //
|
---|
56 | // for (int ix=0; ix<nx; ix++)
|
---|
57 | // for (int iy=0; iy<ny; iy++)
|
---|
58 | // {
|
---|
59 | // TVector2 v(cx[ix], cy[iy]); //cx center of x-bin ix
|
---|
60 | // if (rho!=0) //cy center of y-bin iy
|
---|
61 | // v.Rotate(-rho); //image rotation angle
|
---|
62 | //
|
---|
63 | // src.SetXY(v); //source position in the camera
|
---|
64 | //
|
---|
65 | // if (!hsrc.Calc(hil)) //calc source dependant hillas
|
---|
66 | // return;
|
---|
67 | //
|
---|
68 | // //fill absolute alpha into histogram
|
---|
69 | // const Double_t alpha = hsrc.GetAlpha();
|
---|
70 | // fHist.Fill(cx[ix], cy[iy], TMath::Abs(alpha), w);
|
---|
71 | // }
|
---|
72 | // }
|
---|
73 | //
|
---|
74 | // Use MHFalse Source like this:
|
---|
75 | // -----------------------------
|
---|
76 | // MFillH fill("MHFalseSource", "MHillas");
|
---|
77 | // or
|
---|
78 | // MHFalseSource hist;
|
---|
79 | // hist.SetAlphaCut(12.5); // The default value
|
---|
80 | // hist.SetBgmean(55); // The default value
|
---|
81 | // MFillH fill(&hist, "MHillas");
|
---|
82 | //
|
---|
83 | // To be implemented:
|
---|
84 | // ------------------
|
---|
85 | // - a switch to use alpha or |alpha|
|
---|
86 | // - taking the binning for alpha from the parlist (binning is
|
---|
87 | // currently fixed)
|
---|
88 | // - a possibility to change the fit-function (eg using a different TF1)
|
---|
89 | // - a possibility to change the fit algorithm (eg which paremeters
|
---|
90 | // are fixed at which time)
|
---|
91 | // - use a different varaible than alpha
|
---|
92 | // - a possiblity to change the algorithm which is used to calculate
|
---|
93 | // alpha (or another parameter) is missing (this could be done using
|
---|
94 | // a tasklist somewhere...)
|
---|
95 | // - a more clever (and faster) algorithm to fill the histogram, eg by
|
---|
96 | // calculating alpha once and fill the two coils around the mean
|
---|
97 | //
|
---|
98 | //////////////////////////////////////////////////////////////////////////////
|
---|
99 | #include "MHFalseSource.h"
|
---|
100 |
|
---|
101 | #include <TF1.h>
|
---|
102 | #include <TH2.h>
|
---|
103 | #include <TStyle.h>
|
---|
104 | #include <TCanvas.h>
|
---|
105 |
|
---|
106 | #include "MGeomCam.h"
|
---|
107 | #include "MSrcPosCam.h"
|
---|
108 | #include "MHillasSrc.h"
|
---|
109 | #include "MTime.h"
|
---|
110 | #include "MObservatory.h"
|
---|
111 | #include "MPointingPos.h"
|
---|
112 | #include "MAstroSky2Local.h"
|
---|
113 | #include "MStatusDisplay.h"
|
---|
114 |
|
---|
115 | #include "MBinning.h"
|
---|
116 | #include "MParList.h"
|
---|
117 |
|
---|
118 | #include "MLog.h"
|
---|
119 | #include "MLogManip.h"
|
---|
120 |
|
---|
121 | ClassImp(MHFalseSource);
|
---|
122 |
|
---|
123 | using namespace std;
|
---|
124 |
|
---|
125 | // --------------------------------------------------------------------------
|
---|
126 | //
|
---|
127 | // Default Constructor
|
---|
128 | //
|
---|
129 | MHFalseSource::MHFalseSource(const char *name, const char *title)
|
---|
130 | : fMm2Deg(-1), fUseMmScale(kTRUE), fAlphaCut(12.5), fBgMean(55)
|
---|
131 | {
|
---|
132 | //
|
---|
133 | // set the name and title of this object
|
---|
134 | //
|
---|
135 | fName = name ? name : "MHFalseSource";
|
---|
136 | fTitle = title ? title : "3D-plot of Alpha vs x, y";
|
---|
137 |
|
---|
138 | fHist.SetDirectory(NULL);
|
---|
139 |
|
---|
140 | fHist.SetName("Alpha");
|
---|
141 | fHist.SetTitle("3D-plot of Alpha vs x, y");
|
---|
142 | fHist.SetXTitle("x [\\circ]");
|
---|
143 | fHist.SetYTitle("y [\\circ]");
|
---|
144 | fHist.SetZTitle("\\alpha [\\circ]");
|
---|
145 | }
|
---|
146 |
|
---|
147 | // --------------------------------------------------------------------------
|
---|
148 | //
|
---|
149 | // Set the alpha cut (|alpha|<fAlphaCut) which is use to estimate the
|
---|
150 | // number of excess events
|
---|
151 | //
|
---|
152 | void MHFalseSource::SetAlphaCut(Float_t alpha)
|
---|
153 | {
|
---|
154 | if (alpha<0)
|
---|
155 | *fLog << warn << "Alpha<0... taking absolute value." << endl;
|
---|
156 |
|
---|
157 | fAlphaCut = TMath::Abs(alpha);
|
---|
158 |
|
---|
159 | Modified();
|
---|
160 | }
|
---|
161 |
|
---|
162 | // --------------------------------------------------------------------------
|
---|
163 | //
|
---|
164 | // Set mean alpha around which the off sample is determined
|
---|
165 | // (fBgMean-fAlphaCut/2<|fAlpha|<fBgMean+fAlphaCut/2) which is use
|
---|
166 | // to estimate the number of off events
|
---|
167 | //
|
---|
168 | void MHFalseSource::SetBgMean(Float_t alpha)
|
---|
169 | {
|
---|
170 | if (alpha<0)
|
---|
171 | *fLog << warn << "Alpha<0... taking absolute value." << endl;
|
---|
172 |
|
---|
173 | fBgMean = TMath::Abs(alpha);
|
---|
174 |
|
---|
175 | Modified();
|
---|
176 | }
|
---|
177 |
|
---|
178 | // --------------------------------------------------------------------------
|
---|
179 | //
|
---|
180 | // Use this function to setup your own conversion factor between degrees
|
---|
181 | // and millimeters. The conversion factor should be the one calculated in
|
---|
182 | // MGeomCam. Use this function with Caution: You could create wrong values
|
---|
183 | // by setting up your own scale factor.
|
---|
184 | //
|
---|
185 | void MHFalseSource::SetMm2Deg(Float_t mmdeg)
|
---|
186 | {
|
---|
187 | if (mmdeg<0)
|
---|
188 | {
|
---|
189 | *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl;
|
---|
190 | return;
|
---|
191 | }
|
---|
192 |
|
---|
193 | if (fMm2Deg>=0)
|
---|
194 | *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl;
|
---|
195 |
|
---|
196 | fMm2Deg = mmdeg;
|
---|
197 | }
|
---|
198 |
|
---|
199 | // --------------------------------------------------------------------------
|
---|
200 | //
|
---|
201 | // With this function you can convert the histogram ('on the fly') between
|
---|
202 | // degrees and millimeters.
|
---|
203 | //
|
---|
204 | void MHFalseSource::SetMmScale(Bool_t mmscale)
|
---|
205 | {
|
---|
206 | if (fUseMmScale == mmscale)
|
---|
207 | return;
|
---|
208 |
|
---|
209 | if (fMm2Deg<0)
|
---|
210 | {
|
---|
211 | *fLog << warn << dbginf << "Warning - Sorry, no conversion factor for conversion available." << endl;
|
---|
212 | return;
|
---|
213 | }
|
---|
214 |
|
---|
215 | if (fUseMmScale)
|
---|
216 | {
|
---|
217 | fHist.SetXTitle("x [mm]");
|
---|
218 | fHist.SetYTitle("y [mm]");
|
---|
219 |
|
---|
220 | fHist.Scale(1./fMm2Deg);
|
---|
221 | }
|
---|
222 | else
|
---|
223 | {
|
---|
224 | fHist.SetXTitle("x [\\circ]");
|
---|
225 | fHist.SetYTitle("y [\\circ]");
|
---|
226 |
|
---|
227 | fHist.Scale(1./fMm2Deg);
|
---|
228 | }
|
---|
229 |
|
---|
230 | fUseMmScale = mmscale;
|
---|
231 | }
|
---|
232 |
|
---|
233 | // --------------------------------------------------------------------------
|
---|
234 | //
|
---|
235 | // Calculate Significance as
|
---|
236 | // significance = (s-b)/sqrt(s+k*k*b) mit k=s/b
|
---|
237 | //
|
---|
238 | Double_t MHFalseSource::Significance(Double_t s, Double_t b)
|
---|
239 | {
|
---|
240 | const Double_t k = b==0 ? 0 : s/b;
|
---|
241 | const Double_t f = s+k*k*b;
|
---|
242 |
|
---|
243 | return f==0 ? 0 : (s-b)/TMath::Sqrt(f);
|
---|
244 | }
|
---|
245 |
|
---|
246 | // --------------------------------------------------------------------------
|
---|
247 | //
|
---|
248 | // Set binnings (takes BinningFalseSource) and prepare filling of the
|
---|
249 | // histogram.
|
---|
250 | //
|
---|
251 | // Also search for MTime, MObservatory and MPointingPos
|
---|
252 | //
|
---|
253 | Bool_t MHFalseSource::SetupFill(const MParList *plist)
|
---|
254 | {
|
---|
255 | const MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
|
---|
256 | if (geom)
|
---|
257 | {
|
---|
258 | fMm2Deg = geom->GetConvMm2Deg();
|
---|
259 | fUseMmScale = kFALSE;
|
---|
260 |
|
---|
261 | fHist.SetXTitle("x [\\circ]");
|
---|
262 | fHist.SetYTitle("y [\\circ]");
|
---|
263 | }
|
---|
264 |
|
---|
265 | MBinning binsa;
|
---|
266 | binsa.SetEdges(18, 0, 90);
|
---|
267 |
|
---|
268 | const MBinning *bins = (MBinning*)plist->FindObject("BinningFalseSource");
|
---|
269 | if (!bins)
|
---|
270 | {
|
---|
271 | Float_t r = geom ? geom->GetMaxRadius() : 600;
|
---|
272 | r /= 3;
|
---|
273 | if (!fUseMmScale)
|
---|
274 | r *= fMm2Deg;
|
---|
275 |
|
---|
276 | MBinning b;
|
---|
277 | b.SetEdges(100, -r, r);
|
---|
278 | SetBinning(&fHist, &b, &b, &binsa);
|
---|
279 | }
|
---|
280 | else
|
---|
281 | SetBinning(&fHist, bins, bins, &binsa);
|
---|
282 |
|
---|
283 | fPointPos = (MPointingPos*)plist->FindObject(AddSerialNumber("MPointingPos"));
|
---|
284 | if (!fPointPos)
|
---|
285 | *fLog << warn << "MPointingPos not found... no derotation." << endl;
|
---|
286 |
|
---|
287 | fTime = (MTime*)plist->FindObject(AddSerialNumber("MTime"));
|
---|
288 | if (!fTime)
|
---|
289 | *fLog << warn << "MTime not found... no derotation." << endl;
|
---|
290 |
|
---|
291 | fObservatory = (MObservatory*)plist->FindObject(AddSerialNumber("MObservatory"));
|
---|
292 | if (!fObservatory)
|
---|
293 | *fLog << err << "MObservatory not found... no derotation." << endl;
|
---|
294 |
|
---|
295 |
|
---|
296 | return kTRUE;
|
---|
297 | }
|
---|
298 |
|
---|
299 | // --------------------------------------------------------------------------
|
---|
300 | //
|
---|
301 | // Fill the histogram. For details see the code or the class description
|
---|
302 | //
|
---|
303 | Bool_t MHFalseSource::Fill(const MParContainer *par, const Stat_t w)
|
---|
304 | {
|
---|
305 | MHillas *hil = (MHillas*)par;
|
---|
306 |
|
---|
307 | const Double_t maxr = 0.98*TMath::Abs(fHist.GetBinCenter(1));
|
---|
308 |
|
---|
309 | // Get camera rotation angle
|
---|
310 | Double_t rho = 0;
|
---|
311 | if (fTime && fObservatory && fPointPos)
|
---|
312 | {
|
---|
313 | const Double_t ra = fPointPos->GetRa();
|
---|
314 | const Double_t dec = fPointPos->GetDec();
|
---|
315 |
|
---|
316 | rho = MAstroSky2Local(*fTime, *fObservatory).RotationAngle(ra, dec);
|
---|
317 | }
|
---|
318 |
|
---|
319 | MSrcPosCam src;
|
---|
320 | MHillasSrc hsrc;
|
---|
321 | hsrc.SetSrcPos(&src);
|
---|
322 |
|
---|
323 | const Int_t nx = fHist.GetNbinsX();
|
---|
324 | const Int_t ny = fHist.GetNbinsY();
|
---|
325 |
|
---|
326 | Axis_t cx[nx];
|
---|
327 | Axis_t cy[ny];
|
---|
328 | fHist.GetXaxis()->GetCenter(cx);
|
---|
329 | fHist.GetYaxis()->GetCenter(cy);
|
---|
330 |
|
---|
331 | for (int ix=0; ix<nx; ix++)
|
---|
332 | {
|
---|
333 | for (int iy=0; iy<ny; iy++)
|
---|
334 | {
|
---|
335 | if (TMath::Hypot(cx[ix], cy[iy])>maxr)
|
---|
336 | continue;
|
---|
337 |
|
---|
338 | TVector2 v(cx[ix], cy[iy]);
|
---|
339 | if (rho!=0)
|
---|
340 | v.Rotate(-rho);
|
---|
341 |
|
---|
342 | if (!fUseMmScale)
|
---|
343 | v *= 1./fMm2Deg;
|
---|
344 |
|
---|
345 | src.SetXY(v);
|
---|
346 |
|
---|
347 | if (!hsrc.Calc(hil))
|
---|
348 | {
|
---|
349 | *fLog << warn << "Calculation of MHillasSrc failed for x=" << cx[ix] << " y=" << cy[iy] << endl;
|
---|
350 | return kFALSE;
|
---|
351 | }
|
---|
352 |
|
---|
353 | const Double_t alpha = hsrc.GetAlpha();
|
---|
354 | fHist.Fill(cx[ix], cy[iy], TMath::Abs(alpha), w);
|
---|
355 | }
|
---|
356 | }
|
---|
357 |
|
---|
358 | return kTRUE;
|
---|
359 | }
|
---|
360 |
|
---|
361 | // --------------------------------------------------------------------------
|
---|
362 | //
|
---|
363 | // Create projection for off data, taking sum of bin contents of
|
---|
364 | // range (fBgMean-fAlphaCut/2, fBgMean+fAlphaCut) Making sure to take
|
---|
365 | // the same number of bins than for on-data
|
---|
366 | //
|
---|
367 | void MHFalseSource::ProjectOff(TH2D *h2)
|
---|
368 | {
|
---|
369 | TAxis &axe = *fHist.GetZaxis();
|
---|
370 |
|
---|
371 | // Find range to cut (left edge and width)
|
---|
372 | const Int_t f = axe.FindBin(fBgMean-fAlphaCut/2);
|
---|
373 | const Int_t l = axe.FindBin(fAlphaCut)+f-1;
|
---|
374 |
|
---|
375 | axe.SetRange(f, l);
|
---|
376 | const Float_t cut1 = axe.GetBinLowEdge(f);
|
---|
377 | const Float_t cut2 = axe.GetBinUpEdge(l);
|
---|
378 | h2->SetTitle(Form("Distribution of %.1f\\circ<|\\alpha|<%.1f\\circ in x,y", cut1, cut2));
|
---|
379 |
|
---|
380 | // Get projection for range
|
---|
381 | TH2D *p = (TH2D*)fHist.Project3D("xy_off");
|
---|
382 |
|
---|
383 | // Reset range
|
---|
384 | axe.SetRange(0,9999);
|
---|
385 |
|
---|
386 | // Move contents from projection to h2
|
---|
387 | h2->Reset();
|
---|
388 | h2->Add(p);
|
---|
389 |
|
---|
390 | // Delete p
|
---|
391 | delete p;
|
---|
392 |
|
---|
393 | // Set Minimum as minimum value Greater Than 0
|
---|
394 | h2->SetMinimum(GetMinimumGT(*h2));
|
---|
395 | }
|
---|
396 |
|
---|
397 | // --------------------------------------------------------------------------
|
---|
398 | //
|
---|
399 | // Create projection for on data, taking sum of bin contents of
|
---|
400 | // range (0, fAlphaCut)
|
---|
401 | //
|
---|
402 | void MHFalseSource::ProjectOn(TH2D *h3)
|
---|
403 | {
|
---|
404 | TAxis &axe = *fHist.GetZaxis();
|
---|
405 |
|
---|
406 | // Find range to cut
|
---|
407 | axe.SetRangeUser(0, fAlphaCut);
|
---|
408 | const Float_t cut = axe.GetBinUpEdge(axe.GetLast());
|
---|
409 | h3->SetTitle(Form("Distribution of |\\alpha|<%.1f\\circ in x,y", cut));
|
---|
410 |
|
---|
411 | // Get projection for range
|
---|
412 | TH2D *p = (TH2D*)fHist.Project3D("xy_on");
|
---|
413 |
|
---|
414 | // Reset range
|
---|
415 | axe.SetRange(0,9999);
|
---|
416 |
|
---|
417 | // Move contents from projection to h3
|
---|
418 | h3->Reset();
|
---|
419 | h3->Add(p);
|
---|
420 | delete p;
|
---|
421 |
|
---|
422 | // Set Minimum as minimum value Greater Than 0
|
---|
423 | h3->SetMinimum(GetMinimumGT(*h3));
|
---|
424 | }
|
---|
425 |
|
---|
426 | // --------------------------------------------------------------------------
|
---|
427 | //
|
---|
428 | // Update the projections
|
---|
429 | //
|
---|
430 | void MHFalseSource::Paint(Option_t *opt)
|
---|
431 | {
|
---|
432 | // sigma = (s-b)/sqrt(s+k*k*b) mit k=s/b
|
---|
433 |
|
---|
434 | gStyle->SetPalette(1, 0);
|
---|
435 |
|
---|
436 | TVirtualPad *padsave = gPad;
|
---|
437 |
|
---|
438 | TH1D* h1;
|
---|
439 | TH2D* h2;
|
---|
440 | TH2D* h3;
|
---|
441 | TH2D* h4;
|
---|
442 |
|
---|
443 | padsave->cd(3);
|
---|
444 | if ((h3 = (TH2D*)gPad->FindObject("Alpha_xy_on")))
|
---|
445 | ProjectOn(h3);
|
---|
446 |
|
---|
447 | padsave->cd(4);
|
---|
448 | if ((h2 = (TH2D*)gPad->FindObject("Alpha_xy_off")))
|
---|
449 | ProjectOff(h2);
|
---|
450 |
|
---|
451 | padsave->cd(2);
|
---|
452 | if (h2 && h3 && (h4 = (TH2D*)gPad->FindObject("Alpha_xy_sig")))
|
---|
453 | {
|
---|
454 | const Int_t nx = h4->GetXaxis()->GetNbins();
|
---|
455 | const Int_t ny = h4->GetYaxis()->GetNbins();
|
---|
456 |
|
---|
457 | Int_t maxx=nx/2;
|
---|
458 | Int_t maxy=ny/2;
|
---|
459 |
|
---|
460 | Int_t max = h4->GetBin(maxx, maxy);
|
---|
461 |
|
---|
462 | for (int ix=0; ix<nx; ix++)
|
---|
463 | for (int iy=0; iy<ny; iy++)
|
---|
464 | {
|
---|
465 | const Int_t n = h4->GetBin(ix+1, iy+1);
|
---|
466 |
|
---|
467 | const Double_t s = h3->GetBinContent(n);
|
---|
468 | const Double_t b = h2->GetBinContent(n);
|
---|
469 |
|
---|
470 | const Double_t sig = Significance(s, b);
|
---|
471 |
|
---|
472 | h4->SetBinContent(n, sig);
|
---|
473 |
|
---|
474 | if (sig>h4->GetBinContent(max) && sig!=0)
|
---|
475 | {
|
---|
476 | max = n;
|
---|
477 | maxx=ix;
|
---|
478 | maxy=iy;
|
---|
479 | }
|
---|
480 | }
|
---|
481 |
|
---|
482 | padsave->cd(1);
|
---|
483 | if ((h1 = (TH1D*)gPad->FindObject("Alpha")))
|
---|
484 | {
|
---|
485 | //h1->Reset();
|
---|
486 |
|
---|
487 | const Double_t x = fHist.GetXaxis()->GetBinCenter(maxx);
|
---|
488 | const Double_t y = fHist.GetYaxis()->GetBinCenter(maxy);
|
---|
489 | const Double_t s = h4->GetBinContent(max);
|
---|
490 |
|
---|
491 | TH1 *h = fHist.ProjectionZ("Alpha", maxx, maxx, maxy, maxy);
|
---|
492 | h->SetTitle(Form("Distribution of \\alpha for x=%.2f y=%.2f (\\sigma=%.1f)", x, y, s));
|
---|
493 | }
|
---|
494 | }
|
---|
495 |
|
---|
496 | gPad = padsave;
|
---|
497 | }
|
---|
498 |
|
---|
499 | // --------------------------------------------------------------------------
|
---|
500 | //
|
---|
501 | // Draw the histogram
|
---|
502 | //
|
---|
503 | void MHFalseSource::Draw(Option_t *opt)
|
---|
504 | {
|
---|
505 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
|
---|
506 | pad->SetBorderMode(0);
|
---|
507 |
|
---|
508 | AppendPad("");
|
---|
509 |
|
---|
510 | pad->Divide(2, 2);
|
---|
511 |
|
---|
512 | // draw the 2D histogram Sigmabar versus Theta
|
---|
513 | pad->cd(1);
|
---|
514 | gPad->SetBorderMode(0);
|
---|
515 | TH1 *h1 = fHist.ProjectionZ("Alpha");
|
---|
516 | h1->SetDirectory(NULL);
|
---|
517 | h1->SetTitle("Distribution of \\alpha");
|
---|
518 | h1->SetXTitle(fHist.GetZaxis()->GetTitle());
|
---|
519 | h1->SetYTitle("Counts");
|
---|
520 | h1->Draw(opt);
|
---|
521 | h1->SetBit(kCanDelete);
|
---|
522 |
|
---|
523 | pad->cd(4);
|
---|
524 | gPad->SetBorderMode(0);
|
---|
525 | fHist.GetZaxis()->SetRangeUser(fBgMean-fAlphaCut/2, fBgMean+fAlphaCut/2);
|
---|
526 | TH1 *h2 = fHist.Project3D("xy_off");
|
---|
527 | h2->SetDirectory(NULL);
|
---|
528 | h2->SetXTitle(fHist.GetXaxis()->GetTitle());
|
---|
529 | h2->SetYTitle(fHist.GetYaxis()->GetTitle());
|
---|
530 | h2->Draw("colz");
|
---|
531 | h2->SetBit(kCanDelete);
|
---|
532 |
|
---|
533 | pad->cd(3);
|
---|
534 | gPad->SetBorderMode(0);
|
---|
535 | fHist.GetZaxis()->SetRangeUser(0,fAlphaCut);
|
---|
536 | TH1 *h3 = fHist.Project3D("xy_on");
|
---|
537 | fHist.GetZaxis()->SetRange(0,9999);
|
---|
538 | h3->SetDirectory(NULL);
|
---|
539 | h3->SetXTitle(fHist.GetXaxis()->GetTitle());
|
---|
540 | h3->SetYTitle(fHist.GetYaxis()->GetTitle());
|
---|
541 | h3->Draw("colz");
|
---|
542 | h3->SetBit(kCanDelete);
|
---|
543 |
|
---|
544 | pad->cd(2);
|
---|
545 | gPad->SetBorderMode(0);
|
---|
546 | fHist.GetZaxis()->SetRange(0,0);
|
---|
547 | TH1 *h4 = fHist.Project3D("xy_sig"); // Do this to get the correct binning....
|
---|
548 | fHist.GetZaxis()->SetRange(0,9999);
|
---|
549 | h4->SetTitle("Significance");
|
---|
550 | h4->SetDirectory(NULL);
|
---|
551 | h4->SetXTitle(fHist.GetXaxis()->GetTitle());
|
---|
552 | h4->SetYTitle(fHist.GetYaxis()->GetTitle());
|
---|
553 | h4->Draw("colz");
|
---|
554 | h4->SetBit(kCanDelete);
|
---|
555 |
|
---|
556 | }
|
---|
557 |
|
---|
558 | // --------------------------------------------------------------------------
|
---|
559 | //
|
---|
560 | // Everything which is in the main pad belongs to this class!
|
---|
561 | //
|
---|
562 | Int_t MHFalseSource::DistancetoPrimitive(Int_t px, Int_t py)
|
---|
563 | {
|
---|
564 | return 0;
|
---|
565 | }
|
---|
566 |
|
---|
567 | // --------------------------------------------------------------------------
|
---|
568 | //
|
---|
569 | // Set all sub-pads to Modified()
|
---|
570 | //
|
---|
571 | void MHFalseSource::Modified()
|
---|
572 | {
|
---|
573 | if (!gPad)
|
---|
574 | return;
|
---|
575 |
|
---|
576 | TVirtualPad *padsave = gPad;
|
---|
577 | padsave->Modified();
|
---|
578 | padsave->cd(1);
|
---|
579 | gPad->Modified();
|
---|
580 | padsave->cd(2);
|
---|
581 | gPad->Modified();
|
---|
582 | padsave->cd(3);
|
---|
583 | gPad->Modified();
|
---|
584 | padsave->cd(4);
|
---|
585 | gPad->Modified();
|
---|
586 | gPad->cd();
|
---|
587 | }
|
---|
588 |
|
---|
589 | Double_t fcn(Double_t *arg, Double_t *p)
|
---|
590 | {
|
---|
591 | const Double_t x = arg[0];
|
---|
592 |
|
---|
593 | const Double_t dx = (x-p[1])/p[2];
|
---|
594 |
|
---|
595 | const Double_t f1 = p[0]*TMath::Exp(-0.5*dx*dx);
|
---|
596 | const Double_t f2 = p[3]*x*x + p[4];
|
---|
597 |
|
---|
598 | return f1 + f2;
|
---|
599 | }
|
---|
600 |
|
---|
601 | Double_t FcnI1(Double_t x, Double_t *p)
|
---|
602 | {
|
---|
603 | return (p[3]*x*x/3+p[4])*x;
|
---|
604 | }
|
---|
605 | Double_t FcnI2(Double_t x, Double_t *p)
|
---|
606 | {
|
---|
607 | static const Double_t sqrt2 = TMath::Sqrt(2.);
|
---|
608 | static const Double_t sqrt2pi = TMath::Sqrt(TMath::TwoPi());
|
---|
609 |
|
---|
610 | const Double_t dx = (x-p[1])/p[2];
|
---|
611 |
|
---|
612 | const Double_t f2 = p[0]*p[2]*sqrt2pi*TMath::Erf(dx/sqrt2)/2;
|
---|
613 |
|
---|
614 | return f2;
|
---|
615 | }
|
---|
616 |
|
---|
617 |
|
---|
618 | void MHFalseSource::FitSignificance()
|
---|
619 | {
|
---|
620 | TH1D h0a("A", "Parameter A", 50, 0, 4000);
|
---|
621 | TH1D h0b("a", "Parameter a", 50, 0, 4000);
|
---|
622 | TH1D h1("mu", "Parameter mu", 50, -1, 1);
|
---|
623 | TH1D h2("sigma", "Parameter sigma", 50, 0, 90);
|
---|
624 | TH1D h3("b", "Parameter b", 50, -0.1, 0.1);
|
---|
625 | TH1D h4a("chisq1", "\\chi^{2}", 50, 0, 35);
|
---|
626 | TH1D h5a("prob1", "Fit probability", 50, 0, 1.1);
|
---|
627 | TH1D h4b("chisq2", "\\chi^{2}", 50, 0, 35);
|
---|
628 | TH1D h5b("prob2", "Fit probability", 50, 0, 1.1);
|
---|
629 | TH1D h6("Signif", "Significance", 50, -20, 20);
|
---|
630 | h0a.SetDirectory(NULL);
|
---|
631 | h0b.SetDirectory(NULL);
|
---|
632 | h1.SetDirectory(NULL);
|
---|
633 | h2.SetDirectory(NULL);
|
---|
634 | h3.SetDirectory(NULL);
|
---|
635 | h4a.SetDirectory(NULL);
|
---|
636 | h5b.SetDirectory(NULL);
|
---|
637 | h4a.SetDirectory(NULL);
|
---|
638 | h5b.SetDirectory(NULL);
|
---|
639 | h6.SetDirectory(NULL);
|
---|
640 |
|
---|
641 | h0a.SetLineColor(kBlue);
|
---|
642 | h4a.SetLineColor(kBlue);
|
---|
643 | h5a.SetLineColor(kBlue);
|
---|
644 | h0b.SetLineColor(kRed);
|
---|
645 | h4b.SetLineColor(kRed);
|
---|
646 | h5b.SetLineColor(kRed);
|
---|
647 |
|
---|
648 | TH1 *hist = fHist.Project3D("xy_fit");
|
---|
649 |
|
---|
650 | // xmin, xmax, npar
|
---|
651 | TF1 func("MyFunc", fcn, 0, 90, 5);
|
---|
652 |
|
---|
653 | TArrayD samx(50);
|
---|
654 | TArrayD samw(50);
|
---|
655 |
|
---|
656 | // func.CalcGaussLegendreSamplingPoints(50, samx.GetArray(), samw.GetArray());
|
---|
657 | // func.IntegralFast(50, samx.GetArray(), samw.GetArray(), 0, 15);
|
---|
658 |
|
---|
659 | func.SetParName(0, "A");
|
---|
660 | func.SetParName(1, "mu");
|
---|
661 | func.SetParName(2, "sigma");
|
---|
662 | func.SetParName(3, "a");
|
---|
663 | func.SetParName(4, "b");
|
---|
664 |
|
---|
665 | func.SetParLimits(3, -1, 1);
|
---|
666 |
|
---|
667 | const Int_t nx = fHist.GetXaxis()->GetNbins();
|
---|
668 | const Int_t ny = fHist.GetYaxis()->GetNbins();
|
---|
669 |
|
---|
670 | Double_t maxs=3;
|
---|
671 | TH1 *result=0;
|
---|
672 | TF1 *fres=0;
|
---|
673 |
|
---|
674 |
|
---|
675 | TH1 *h=0;
|
---|
676 | for (int ix=0; ix<nx; ix++)
|
---|
677 | for (int iy=0; iy<ny; iy++)
|
---|
678 | {
|
---|
679 | h = fHist.ProjectionZ("AlphaFit", ix+1, ix+1, iy+1, iy+1);
|
---|
680 |
|
---|
681 | // Check for the regios which is not filled...
|
---|
682 | if (h->GetBinContent(1)==0)
|
---|
683 | continue;
|
---|
684 |
|
---|
685 | // First fit a polynom in the off region
|
---|
686 | func.FixParameter(0, 0);
|
---|
687 | func.FixParameter(1, 0);
|
---|
688 | func.FixParameter(2, 1);
|
---|
689 | func.ReleaseParameter(3);
|
---|
690 | func.ReleaseParameter(4);
|
---|
691 |
|
---|
692 | h->Fit(&func, "N0Q", "", 35, 75);
|
---|
693 | //*fLog << dbg << ix << "/" << iy << ": " << func.GetParameter(3) << " " << func.GetParameter(4) << endl;
|
---|
694 |
|
---|
695 | h4a.Fill(func.GetChisquare());
|
---|
696 | h5a.Fill(func.GetProb());
|
---|
697 |
|
---|
698 | // Now fit a gaus in the on region on top of the polynom
|
---|
699 | func.SetParameter(0, h->GetBinContent(1)-func.GetParameter(4));
|
---|
700 | func.SetParameter(2, 80);
|
---|
701 |
|
---|
702 | //func.SetParLimits(0, 0.5*h->GetBinContent(1), 1.5*h->GetBinContent(1));
|
---|
703 | //func.SetParLimits(2, 5, 90);
|
---|
704 |
|
---|
705 | func.ReleaseParameter(0);
|
---|
706 | //func.ReleaseParameter(1);
|
---|
707 | func.ReleaseParameter(2);
|
---|
708 | func.FixParameter(3, func.GetParameter(3));
|
---|
709 | func.FixParameter(4, func.GetParameter(4));
|
---|
710 |
|
---|
711 | func.SetParLimits(2, 0, 80);
|
---|
712 | h->Fit(&func, "N0Q", "", 0, 35);
|
---|
713 | //*fLog << dbg << " " << func.GetParameter(0) << " " << func.GetParameter(1) << " " << func.GetParameter(2) << endl;
|
---|
714 |
|
---|
715 | // Fill results into some histograms
|
---|
716 | h0a.Fill(func.GetParameter(0));
|
---|
717 | h0b.Fill(func.GetParameter(4));
|
---|
718 | h1.Fill(func.GetParameter(1));
|
---|
719 | h2.Fill(func.GetParameter(2));
|
---|
720 | h3.Fill(func.GetParameter(3));
|
---|
721 | h4b.Fill(func.GetChisquare());
|
---|
722 | h5b.Fill(func.GetProb());
|
---|
723 |
|
---|
724 | const Int_t n = hist->GetBin(ix+1, iy+1);
|
---|
725 | if (func.GetParameter(0)>h->GetBinContent(1)*2 ||
|
---|
726 | func.GetParameter(2)<2.5 || func.GetParameter(2)>70
|
---|
727 | /*func.GetProb()<0.005 ||*/)
|
---|
728 | {
|
---|
729 | hist->SetBinContent(n, 0);
|
---|
730 | continue;
|
---|
731 | }
|
---|
732 |
|
---|
733 | //*fLog << dbg << " Chisq=" << func.GetChisquare() << " NDF=" << func.GetNDF()
|
---|
734 | // << " Prob=" << func.GetProb() << " FitP=" << func.GetNumberFitPoints() << endl;
|
---|
735 |
|
---|
736 | Double_t b = FcnI1(15, func.GetParameters());
|
---|
737 | Double_t s = FcnI2(15, func.GetParameters());
|
---|
738 |
|
---|
739 | //*fLog << dbg << func.GetParameter(3) << ": " << b << " ";
|
---|
740 | //*fLog << dbg << func.GetParameter(0) << ": " << s;
|
---|
741 | //*fLog << endl;
|
---|
742 |
|
---|
743 | if (b<0)
|
---|
744 | continue;
|
---|
745 |
|
---|
746 | const Double_t sig = Significance(s+b, b);
|
---|
747 |
|
---|
748 | hist->SetBinContent(n, sig);
|
---|
749 | h6.Fill(sig);
|
---|
750 |
|
---|
751 | if (sig>maxs)
|
---|
752 | {
|
---|
753 | maxs = sig;
|
---|
754 | if (result)
|
---|
755 | {
|
---|
756 | delete result;
|
---|
757 | delete fres;
|
---|
758 | }
|
---|
759 | result=(TH1*)h->Clone("Result \\alpha");
|
---|
760 | fres =(TF1*)func.Clone("Result Func");
|
---|
761 | }
|
---|
762 | }
|
---|
763 |
|
---|
764 | hist->SetMinimum(-10);
|
---|
765 | hist->SetMaximum(maxs);
|
---|
766 |
|
---|
767 | TCanvas *c=new TCanvas;
|
---|
768 |
|
---|
769 | c->Divide(3,2);
|
---|
770 | c->cd(1);
|
---|
771 | h0b.DrawCopy();
|
---|
772 | h0a.DrawCopy("same");
|
---|
773 | c->cd(2);
|
---|
774 | hist->Draw("colz");
|
---|
775 | hist->SetDirectory(NULL);
|
---|
776 | hist->SetBit(kCanDelete);
|
---|
777 | c->cd(3);
|
---|
778 | h2.DrawCopy();
|
---|
779 | c->cd(4);
|
---|
780 | h3.DrawCopy();
|
---|
781 | c->cd(5);
|
---|
782 | h4a.DrawCopy();
|
---|
783 | h4b.DrawCopy("same");
|
---|
784 | h6.DrawCopy("same");
|
---|
785 | c->cd(6);
|
---|
786 | h5a.DrawCopy();
|
---|
787 | h5b.DrawCopy("same");
|
---|
788 |
|
---|
789 | if (result)
|
---|
790 | {
|
---|
791 | c=new TCanvas;
|
---|
792 | result->SetBit(kCanDelete);
|
---|
793 | result->Draw();
|
---|
794 |
|
---|
795 | TF1 f1("MyFunc1", fcn, 0, 90, 5);
|
---|
796 | TF1 f2("MyFunc2", fcn, 0, 90, 5);
|
---|
797 | f1.SetParameters(fres->GetParameters());
|
---|
798 | f2.SetParameters(fres->GetParameters());
|
---|
799 | f2.FixParameter(0, 0);
|
---|
800 | f2.FixParameter(1, 0);
|
---|
801 | f2.FixParameter(2, 1);
|
---|
802 | f1.SetLineColor(kGreen);
|
---|
803 | f2.SetLineColor(kRed);
|
---|
804 |
|
---|
805 | f2.DrawCopy("same");
|
---|
806 | f1.DrawCopy("same");
|
---|
807 |
|
---|
808 | delete fres;
|
---|
809 | }
|
---|
810 | }
|
---|
811 |
|
---|