10#include "ChiSqMap2D.h"
22#include <TMatrixDfwd.h>
27 ChiSqMap2D::ChiSqMap2D() :
37 ChiSqMap2D::ChiSqMap2D(TString name, Int_t xbins, Double_t xlow, Double_t xhigh, Int_t ybins, Double_t ylow, Double_t yhigh) :
39 fHist =
new TH2D(name,
"", xbins, xlow, xhigh, ybins, ylow, yhigh);
43 if (errHigh == -1) errHigh = errLow;
44 if (fLineX)
delete fLineX;
45 if (fLineXlow)
delete fLineXlow;
46 if (fLineXhigh)
delete fLineXhigh;
48 fLineX = MakeXLine(Value, 1);
49 fLineXlow = MakeXLine(Value - errLow, 10);
50 fLineXhigh = MakeXLine(Value + errHigh, 10);
54 if (errHigh == -1) errHigh = errLow;
55 if (fLineY)
delete fLineY;
56 if (fLineYlow)
delete fLineYlow;
57 if (fLineYhigh)
delete fLineYhigh;
59 fLineY = MakeYLine(Value, 1);
60 fLineYlow = MakeYLine(Value - errLow, 10);
61 fLineYhigh = MakeYLine(Value + errHigh, 10);
65 if (fHist == NULL)
return;
66 fHist->SetStats(kFALSE);
69 if (!option.Contains(
"nolin")) {
72 DrawLineX(fLineXhigh);
75 DrawLineY(fLineYhigh);
77 if (option.Contains(
"min")) {
79 Double_t min = DBL_MAX;
80 for (
int i = 1; i <= fHist->GetNbinsX(); i++) {
81 for (
int j = 1; j <= fHist->GetNbinsY(); j++) {
82 if (fHist->GetBinContent(i, j) < min) {
83 min = fHist->GetBinContent(i, j);
89 Double_t x1 = fHist->GetXaxis()->GetBinLowEdge(xb);
90 Double_t y1 = fHist->GetYaxis()->GetBinLowEdge(yb);
91 Double_t x2 = fHist->GetXaxis()->GetBinUpEdge(xb);
92 Double_t y2 = fHist->GetYaxis()->GetBinUpEdge(yb);
93 TLine** line =
new TLine*[6];
94 line[0] =
new TLine(x1, y1, x1, y2);
95 line[1] =
new TLine(x2, y1, x2, y2);
96 line[2] =
new TLine(x1, y1, x2, y1);
97 line[3] =
new TLine(x1, y2, x2, y2);
98 line[4] =
new TLine(x1, y1, x2, y2);
99 line[5] =
new TLine(x2, y1, x1, y2);
101 for (
int i = 0; i < 6; i++) {
102 line[i]->SetLineColor(kGray);
103 line[i]->Draw(
"SAME");
106 if (option.Contains(
"fit")) {
107 Double_t x1 = fHist->GetXaxis()->GetBinLowEdge(1);
108 Double_t y1 = fHist->GetYaxis()->GetBinLowEdge(1);
109 Double_t x2 = fHist->GetXaxis()->GetBinUpEdge(fHist->GetNbinsX());
110 Double_t y2 = fHist->GetYaxis()->GetBinUpEdge(fHist->GetNbinsY());
113 TLine** line =
new TLine*[2];
114 line[0] =
new TLine(x1, Y, x2, Y);
115 line[1] =
new TLine(X, y1, X, y2);
116 for (
int i = 0; i < 2; i++) {
117 line[i]->SetLineColor(kGray + 2);
118 line[i]->Draw(
"SAME");
124 if (fHist == NULL)
return;
125 fHist->GetXaxis()->SetTitle(xpar);
126 fHist->GetYaxis()->SetTitle(ypar);
129 Bool_t ChiSqMap2D::CheckX(Double_t x)
const {
130 Double_t x_low = fHist->GetXaxis()->GetBinLowEdge(1);
131 Double_t x_high = fHist->GetXaxis()->GetBinUpEdge(fHist->GetNbinsX());
132 if (x < x_low)
return kFALSE;
133 if (x > x_high)
return kFALSE;
137 Bool_t ChiSqMap2D::CheckY(Double_t y)
const {
138 Double_t y_low = fHist->GetYaxis()->GetBinLowEdge(1);
139 Double_t y_high = fHist->GetYaxis()->GetBinUpEdge(fHist->GetNbinsY());
140 if (y < y_low)
return kFALSE;
141 if (y > y_high)
return kFALSE;
145 TLine* ChiSqMap2D::MakeXLine(Double_t x, Style_t style)
const {
146 Double_t y_low = fHist->GetYaxis()->GetBinLowEdge(1);
147 Double_t y_high = fHist->GetYaxis()->GetBinUpEdge(fHist->GetNbinsY());
148 TLine* l =
new TLine(x, y_low, x, y_high);
149 l->SetLineStyle(style);
153 TLine* ChiSqMap2D::MakeYLine(Double_t y, Style_t style)
const {
154 Double_t x_low = fHist->GetXaxis()->GetBinLowEdge(1);
155 Double_t x_high = fHist->GetXaxis()->GetBinUpEdge(fHist->GetNbinsX());
156 TLine* l =
new TLine(x_low, y, x_high, y);
157 l->SetLineStyle(style);
162 if (fLineX == NULL)
return 0;
163 return fLineX->GetX1();
167 if (fLineY == NULL)
return 0;
168 return fLineY->GetY1();
172 if (fLineYhigh == NULL)
return 0;
173 return fLineYhigh->GetX1();
177 if (fLineXlow == NULL)
return 0;
178 return fLineXlow->GetX1();
182 if (fLineYhigh == NULL)
return 0;
183 return fLineYhigh->GetY1();
187 if (fLineYlow == NULL)
return 0;
188 return fLineYlow->GetY1();
191 void ChiSqMap2D::DrawLineX(TLine* l) {
192 if (l == NULL)
return;
193 if (CheckX(l->GetX1())) l->Draw(
"SAME");
196 void ChiSqMap2D::DrawLineY(TLine* l) {
197 if (l == NULL)
return;
198 if (CheckY(l->GetY1())) l->Draw(
"SAME");
202 Int_t xb = 0, yb = 0;
203 Double_t min = DBL_MAX;
204 for (
int i = 1; i <= fHist->GetNbinsX(); i++) {
205 for (
int j = 1; j <= fHist->GetNbinsY(); j++) {
206 if (fHist->GetBinContent(i, j) < min) {
207 min = fHist->GetBinContent(i, j);
213 x = fHist->GetXaxis()->GetBinCenter(xb);
214 y = fHist->GetYaxis()->GetBinCenter(yb);
217 ChiSqMap2D::~ChiSqMap2D() {
218 if (fHist)
delete fHist;
219 if (fLineX)
delete fLineX;
220 if (fLineY)
delete fLineY;
221 if (fLineXlow)
delete fLineXlow;
222 if (fLineXhigh)
delete fLineXhigh;
223 if (fLineYlow)
delete fLineYlow;
224 if (fLineYhigh)
delete fLineYhigh;
230 binX = fHist->GetXaxis()->FindBin(
GetFitX());
231 binY = fHist->GetYaxis()->FindBin(
GetFitY());
235 binX = fHist->GetXaxis()->FindBin(x);
236 binY = fHist->GetYaxis()->FindBin(y);
238 if (binX <= 1 || binX >= fHist->GetNbinsX())
return 0;
239 Double_t dX = fHist->GetXaxis()->GetBinWidth(binX);
240 Double_t X = fHist->GetXaxis()->GetBinCenter(binX);
241 Double_t y1 = fHist->GetBinContent(binX - 1, binY);
242 Double_t y2 = fHist->GetBinContent(binX, binY);
243 Double_t y3 = fHist->GetBinContent(binX + 1, binY);
244 Double_t x1 = X - dX;
246 Double_t x3 = X + dX;
248 Hal::Std::FitParabola(x1, x2, x3, y1, y2, y3, a, b, c);
250 if (thres <= 0)
return 1.0 / TMath::Sqrt(a);
251 Hal::Std::SolveParabola(a, b, c - y2 * (1.0 + thres), X1, X2);
252 return TMath::Max(TMath::Abs(X1 - X), TMath::Abs(X2 - X));
258 binX = fHist->GetXaxis()->FindBin(
GetFitX());
259 binY = fHist->GetYaxis()->FindBin(
GetFitY());
263 binX = fHist->GetXaxis()->FindBin(x);
264 binY = fHist->GetYaxis()->FindBin(y);
266 if (binY <= 1 || binY >= fHist->GetNbinsY())
return 0;
267 Double_t dX = fHist->GetYaxis()->GetBinWidth(binY);
268 Double_t X = fHist->GetYaxis()->GetBinCenter(binY);
269 Double_t y1 = fHist->GetBinContent(binX, binY - 1);
270 Double_t y2 = fHist->GetBinContent(binX, binY);
271 Double_t y3 = fHist->GetBinContent(binX, binY + 1);
272 Double_t x1 = X - dX;
274 Double_t x3 = X + dX;
276 Hal::Std::FitParabola(x1, x2, x3, y1, y2, y3, a, b, c);
278 if (thres <= 0)
return 1.0 / TMath::Sqrt(a);
279 Hal::Std::SolveParabola(a, b, c - y2 * (1.0 + thres), X1, X2);
280 return TMath::Max(TMath::Abs(X1 - X), TMath::Abs(X2 - X));
287 binX = fHist->GetXaxis()->FindBin(x);
288 binY = fHist->GetYaxis()->FindBin(y);
289 if (binY <= 1 || binY >= fHist->GetNbinsY())
return 0;
290 Double_t dX = fHist->GetXaxis()->GetBinWidth(binX);
291 Double_t X = fHist->GetXaxis()->GetBinCenter(binX);
292 Double_t y1 = fHist->GetBinContent(binX - 1, binY);
293 Double_t y2 = fHist->GetBinContent(binX, binY);
294 Double_t y3 = fHist->GetBinContent(binX + 1, binY);
295 Double_t x1 = X - dX;
297 Double_t x3 = X + dX;
299 Hal::Std::FitParabola(x1, x2, x3, y1, y2, y3, a, b, c);
300 return -b / (2.0 * a);
307 binX = fHist->GetXaxis()->FindBin(x);
308 binY = fHist->GetYaxis()->FindBin(y);
309 if (binY <= 1 || binY >= fHist->GetNbinsY())
return 0;
310 Double_t dX = fHist->GetYaxis()->GetBinWidth(binY);
311 Double_t X = fHist->GetYaxis()->GetBinCenter(binY);
312 Double_t y1 = fHist->GetBinContent(binX, binY - 1);
313 Double_t y2 = fHist->GetBinContent(binX, binY);
314 Double_t y3 = fHist->GetBinContent(binX, binY + 1);
315 Double_t x1 = X - dX;
317 Double_t x3 = X + dX;
319 Hal::Std::FitParabola(x1, x2, x3, y1, y2, y3, a, b, c);
320 return -b / (2.0 * a);
325 Int_t gBinX = fHist->GetXaxis()->FindBin(x);
326 Int_t gBinY = fHist->GetYaxis()->FindBin(y);
327 Double_t xlow = fHist->GetXaxis()->GetBinCenter(gBinX - 1);
328 Double_t xhig = fHist->GetXaxis()->GetBinCenter(gBinX + 1);
329 Double_t ylow = fHist->GetYaxis()->GetBinCenter(gBinY - 1);
330 Double_t yhig = fHist->GetYaxis()->GetBinCenter(gBinY + 1);
331 Double_t chi2ndf = fHist->GetBinContent(gBinX, gBinY);
332 TH2D* h =
new TH2D(
"tempHes",
"tempHes", 3, xlow, xhig, 3, ylow, yhig);
333 for (
int i = 1; i <= 3; i++) {
334 for (
int j = 1; j <= 3; j++) {
335 h->SetBinContent(i, j, fHist->GetBinContent(gBinX + i - 2, gBinY + j - 2));
351 Double_t fXY = a3 + 2. * a6 * x + 2.0 * a7 * y + 4.0 * a8 * x * y;
353 Double_t fXX = 2.0 * a4 + 2.0 * a6 * y + 2.0 * a8 * y * y;
354 Double_t fYY = 2.0 * a5 + 2.0 * a7 * x + 2.0 * a8 * x * x;
361 TMatrixD inv = m.Invert();
363 eX = TMath::Sqrt(inv[0][0]) * chi2ndf;
364 eY = TMath::Sqrt(inv[1][1]) * chi2ndf;
void GetMin(Double_t &x, Double_t &y) const
Double_t GetFitYErrorLow() const
void Draw(Option_t *opt="")
void SetParNames(TString xpar, TString ypar)
Double_t GetFitYErrorUp() const
Double_t GetFitXErrorLow() const
void GetXYE(Double_t &x, Double_t &eX, Double_t &y, Double_t &eY) const
void SetXFit(Double_t Value, Double_t errLow=0, Double_t errHigh=-1)
void SetYFit(Double_t Value, Double_t errLow=0, Double_t errHigh=-1)
Double_t GetFitXErrorUp() const
Double_t GetEstErrorY(Double_t thres=0.1, Bool_t around_fit=kTRUE) const
Double_t GetEstErrorX(Double_t thres=0.1, Bool_t around_fit=kTRUE) const
Double_t GetExtrapolationParam(Double_t x, Double_t y, Int_t param) const