1 #include "RooGaussian.h" 2 #include "RooChebychev.h" 3 #include "RooVoigtian.h" 4 #include "RooExponential.h" 5 #include "RooRealVar.h" 6 #include "RooFormulaVar.h" 7 #include "RooDataHist.h" 9 #include "RooGlobalFunc.h" 10 #include "RooCategory.h" 11 #include "RooSimultaneous.h" 16 #include "TProfile2D.h" 43 :
mass(
"mass",
"mass", 0., 100.,
"GeV"),
44 mean(
"mean",
"mean", 0., 100.,
"GeV"),
45 sigma(
"sigma",
"sigma", 0., 100.,
"GeV"),
46 efficiency(
"efficiency",
"efficiency", 0.5, 0.0, 1.0),
47 nSignalAll(
"nSignalAll",
"nSignalAll", 0., 1e10),
66 void setup(
double expectedMean_,
double massLow,
double massHigh,
double expectedSigma_) {
72 virtual void fit(TH1*
num, TH1* den) = 0;
78 RooPlot*
frame =
mass.frame(
Name(
name), Title(
"Failing and Passing Probe Distributions"));
79 data->plotOn(
frame, Cut(
"category==category::pass"), LineColor(kGreen), MarkerColor(kGreen));
80 data->plotOn(
frame, Cut(
"category==category::fail"), LineColor(kRed), MarkerColor(kRed));
84 data->statOn(
frame, Layout(0.70, 0.99, 0.5));
90 TH3* pass, TH3*
all,
int massDimension, TProfile2D*& eff, TProfile2D*& effChi2,
const TString&
plotName =
"") {
92 TAxis *par1Axis, *par2Axis, *massAxis;
93 int par1C, par2C, massC;
94 if (massDimension == 1) {
95 massAxis =
all->GetXaxis();
97 par1Axis =
all->GetYaxis();
98 par1C =
all->GetXaxis()->GetNbins() + 2;
99 par2Axis =
all->GetZaxis();
100 par2C = (
all->GetXaxis()->GetNbins() + 2) * (
all->GetYaxis()->GetNbins() + 2);
101 }
else if (massDimension == 2) {
102 par1Axis =
all->GetXaxis();
104 massAxis =
all->GetYaxis();
105 massC =
all->GetXaxis()->GetNbins() + 2;
106 par2Axis =
all->GetZaxis();
107 par2C = (
all->GetXaxis()->GetNbins() + 2) * (
all->GetYaxis()->GetNbins() + 2);
108 }
else if (massDimension == 3) {
109 par1Axis =
all->GetXaxis();
111 par2Axis =
all->GetYaxis();
112 par2C =
all->GetXaxis()->GetNbins() + 2;
113 massAxis =
all->GetZaxis();
114 massC = (
all->GetXaxis()->GetNbins() + 2) * (
all->GetYaxis()->GetNbins() + 2);
116 return "massDimension > 3 !, skipping...";
120 if (!par1Axis || !par2Axis)
121 return "No par1Axis or par2Axis!";
122 if (par1Axis->GetXbins()->GetSize() == 0 && par2Axis->GetXbins()->GetSize() == 0) {
123 eff =
new TProfile2D(
"efficiency",
125 par1Axis->GetNbins(),
128 par2Axis->GetNbins(),
130 par2Axis->GetXmax());
131 }
else if (par1Axis->GetXbins()->GetSize() == 0) {
132 eff =
new TProfile2D(
"efficiency",
134 par1Axis->GetNbins(),
137 par2Axis->GetNbins(),
138 par2Axis->GetXbins()->GetArray());
139 }
else if (par2Axis->GetXbins()->GetSize() == 0) {
140 eff =
new TProfile2D(
"efficiency",
142 par1Axis->GetNbins(),
143 par1Axis->GetXbins()->GetArray(),
144 par2Axis->GetNbins(),
146 par2Axis->GetXmax());
148 eff =
new TProfile2D(
"efficiency",
150 par1Axis->GetNbins(),
151 par1Axis->GetXbins()->GetArray(),
152 par2Axis->GetNbins(),
153 par2Axis->GetXbins()->GetArray());
156 eff->SetXTitle(par1Axis->GetTitle());
157 eff->SetYTitle(par2Axis->GetTitle());
158 eff->SetStats(kFALSE);
159 effChi2 = (TProfile2D*)eff->Clone(
"efficiencyChi2");
160 eff->SetZTitle(
"Efficiency");
161 eff->SetOption(
"colztexte");
162 eff->GetZaxis()->SetRangeUser(-0.001, 1.001);
163 effChi2->SetZTitle(
"Chi^2/NDF");
164 effChi2->SetOption(
"colztext");
167 TH1D* all1D = (massAxis->GetXbins()->GetSize() == 0)
168 ?
new TH1D(
"all1D",
"all1D", massAxis->GetNbins(), massAxis->GetXmin(), massAxis->GetXmax())
169 :
new TH1D(
"all1D",
"all1D", massAxis->GetNbins(), massAxis->GetXbins()->GetArray());
170 auto* pass1D = (TH1D*)all1D->Clone(
"pass1D");
173 for (
int par1 = 1;
par1 <= par1Axis->GetNbins();
par1++) {
174 for (
int par2 = 1;
par2 <= par2Axis->GetNbins();
par2++) {
175 for (
int mass = 1;
mass <= massAxis->GetNbins();
mass++) {
178 pass1D->SetBinContent(
mass, pass->GetBinContent(
index));
183 eff->SetBinEntries(
index, 1);
184 eff->SetBinError(
index,
187 effChi2->SetBinEntries(
index, 1);
199 TH2* pass, TH2*
all,
int massDimension, TProfile*& eff, TProfile*& effChi2,
const TString&
plotName =
"") {
201 TAxis *par1Axis, *massAxis;
203 if (massDimension == 1) {
204 massAxis =
all->GetXaxis();
206 par1Axis =
all->GetYaxis();
207 par1C =
all->GetXaxis()->GetNbins() + 2;
208 }
else if (massDimension == 2) {
209 par1Axis =
all->GetXaxis();
211 massAxis =
all->GetYaxis();
212 massC =
all->GetXaxis()->GetNbins() + 2;
214 return "massDimension > 2 !, skipping...";
219 return "No par1Axis!";
221 (par1Axis->GetXbins()->GetSize() == 0)
222 ?
new TProfile(
"efficiency",
"efficiency", par1Axis->GetNbins(), par1Axis->GetXmin(), par1Axis->GetXmax())
223 :
new TProfile(
"efficiency",
"efficiency", par1Axis->GetNbins(), par1Axis->GetXbins()->GetArray());
225 eff->SetXTitle(par1Axis->GetTitle());
226 eff->SetLineColor(2);
227 eff->SetLineWidth(2);
228 eff->SetMarkerStyle(20);
229 eff->SetMarkerSize(0.8);
230 eff->SetStats(kFALSE);
231 effChi2 = (TProfile*)eff->Clone(
"efficiencyChi2");
232 eff->SetYTitle(
"Efficiency");
233 eff->SetOption(
"PE");
234 eff->GetYaxis()->SetRangeUser(-0.001, 1.001);
235 effChi2->SetYTitle(
"Chi^2/NDF");
236 effChi2->SetOption(
"HIST");
239 TH1D* all1D = (massAxis->GetXbins()->GetSize() == 0)
240 ?
new TH1D(
"all1D",
"all1D", massAxis->GetNbins(), massAxis->GetXmin(), massAxis->GetXmax())
241 :
new TH1D(
"all1D",
"all1D", massAxis->GetNbins(), massAxis->GetXbins()->GetArray());
242 auto* pass1D = (TH1D*)all1D->Clone(
"pass1D");
245 for (
int par1 = 1;
par1 <= par1Axis->GetNbins();
par1++) {
246 for (
int mass = 1;
mass <= massAxis->GetNbins();
mass++) {
249 pass1D->SetBinContent(
mass, pass->GetBinContent(
index));
254 eff->SetBinEntries(
index, 1);
257 effChi2->SetBinEntries(
index, 1);
283 slopeFail(
"slopeFail",
"slopeFail", 0., -1., 1.),
284 linearFail(
"linearFail",
"linearFail",
mass, slopeFail),
285 slopePass(
"slopePass",
"slopePass", 0., -1., 1.),
286 linearPass(
"linearPass",
"linearPass",
mass, slopePass),
289 simPdf.addPdf(pdfFail,
"fail");
290 simPdf.addPdf(pdfPass,
"pass");
300 data =
new RooDataHist(
"data",
"data",
mass, Index(
category), Import(
"fail", *fail), Import(
"pass", *pass));
301 if (pass->Integral() + fail->Integral() < 5) {
309 efficiency.setVal(pass->Integral() / (pass->Integral() + fail->Integral()));
310 nSignalAll.setVal(0.5 * (fail->Integral() + pass->Integral()));
313 slopeFail.setVal(0.);
314 slopePass.setVal(0.);
318 simPdf.fitTo(*
data,
Verbose(kFALSE), PrintLevel(-1), Warnings(kFALSE), PrintEvalErrors(-1));
320 RooDataHist dataFail(
"fail",
"fail",
mass, fail);
321 RooDataHist dataPass(
"pass",
"pass",
mass, pass);
322 using AbsRealPtr = std::unique_ptr<RooAbsReal>;
323 const double chi2Fail = AbsRealPtr(pdfFail.createChi2(dataFail, DataError(RooAbsData::Poisson)))->getVal();
324 const double chi2Pass = AbsRealPtr(pdfPass.createChi2(dataPass, DataError(RooAbsData::Poisson)))->getVal();
325 chi2 = (chi2Fail + chi2Pass) / (2 * pass->GetNbinsX() - 8);
348 width(
"width",
"width", 2.5,
"GeV"),
350 slopeFail(
"slopeFail",
"slopeFail", 0., -1., 0.),
351 exponentialFail(
"linearFail",
"linearFail",
mass, slopeFail),
352 slopePass(
"slopePass",
"slopePass", 0., -1., 0.),
353 exponentialPass(
"linearPass",
"linearPass",
mass, slopePass),
358 width.setConstant(kTRUE);
359 simPdf.addPdf(pdfFail,
"fail");
360 simPdf.addPdf(pdfPass,
"pass");
364 void setup(
double expectedMean_,
double massLow,
double massHigh,
double expectedSigma_,
double width_) {
369 width.setVal(width_);
377 data =
new RooDataHist(
"data",
"data",
mass, Index(
category), Import(
"fail", *fail), Import(
"pass", *pass));
378 if (pass->Integral() + fail->Integral() < 5) {
386 efficiency.setVal(pass->Integral() / (pass->Integral() + fail->Integral()));
387 nSignalAll.setVal(0.5 * (fail->Integral() + pass->Integral()));
390 slopeFail.setVal(0.);
391 slopePass.setVal(0.);
395 simPdf.fitTo(*
data,
Verbose(kFALSE), PrintLevel(-1), Warnings(kFALSE), PrintEvalErrors(-1));
397 RooDataHist dataFail(
"fail",
"fail",
mass, fail);
398 RooDataHist dataPass(
"pass",
"pass",
mass, pass);
399 using AbsRealPtr = std::unique_ptr<RooAbsReal>;
400 const double chi2Fail = AbsRealPtr(pdfFail.createChi2(dataFail, DataError(RooAbsData::Poisson)))->getVal();
401 const double chi2Pass = AbsRealPtr(pdfPass.createChi2(dataPass, DataError(RooAbsData::Poisson)))->getVal();
402 chi2 = (chi2Fail + chi2Pass) / (2 *
all->GetNbinsX() - 8);
RooRealVar nBackgroundFail
static PFTauRenderPlugin instance
void setup(double expectedMean_, double massLow, double massHigh, double expectedSigma_)
void savePlot(const TString &name)
void setup(double expectedMean_, double massLow, double massHigh, double expectedSigma_, double width_)
RooFormulaVar nSignalFail
RooExponential exponentialFail
virtual ~AbstractFitter()=default
TString calculateEfficiency(TH3 *pass, TH3 *all, int massDimension, TProfile2D *&eff, TProfile2D *&effChi2, const TString &plotName="")
GaussianPlusLinearFitter(bool verbose=false)
void fit(TH1 *pass, TH1 *all) override
VoigtianPlusExponentialFitter(bool verbose=false)
double getEfficiencyError()
void fit(TH1 *pass, TH1 *all) override
AbstractFitter(bool verbose_=false)
TString calculateEfficiency(TH2 *pass, TH2 *all, int massDimension, TProfile *&eff, TProfile *&effChi2, const TString &plotName="")
RooExponential exponentialPass
RooFormulaVar nSignalPass
virtual void fit(TH1 *num, TH1 *den)=0
RooRealVar nBackgroundPass