6 double xMin = inputXmin;
7 double xMax = inputXmax;
13 RooRealVar
x(
"InvMass",
"di-muon mass M(#mu^{+}#mu^{-}) [GeV]",
xMin,
xMax);
15 return (std::make_pair(
x,
new RooDataHist(
"dh",
"dh",
x, RooFit::Import(*
histo))));
20 const TString signalType,
21 const TString backgroundType,
28 RooRealVar
x(imported.first);
29 RooDataHist*
dh = imported.second;
32 RooPlot*
frame =
x.frame(RooFit::Title(
"di-muon mass M(#mu^{+}#mu^{-}) [GeV]"));
33 frame->SetName(TString(
histo->GetName()) +
"_frame");
39 std::unique_ptr<RooAbsReal>
chi2{
model->createChi2(*
dh, RooFit::DataError(RooAbsData::SumW2))};
46 model->fitTo(*
dh, RooFit::Save(), RooFit::SumW2Error(kTRUE));
53 RooMinimizer
m(*
chi2);
59 model->plotOn(
frame, RooFit::Components(backgroundType), RooFit::LineStyle(kDashed));
62 RooFit::Layout(0.65, 0.90, 0.90),
63 RooFit::Format(
"NEU", RooFit::AutoPrecision(2)));
76 RooPlot* frame2 =
x.frame(RooFit::Title(
"di-muon mass M(#mu^{+}#mu^{-}) [GeV]"));
77 dh->plotOn(frame2, RooFit::DataError(RooAbsData::SumW2));
78 model->plotOn(frame2, RooFit::LineColor(kRed));
79 model->plotOn(frame2, RooFit::Components(backgroundType), RooFit::LineStyle(kDashed));
80 model->paramOn(frame2,
82 RooFit::Layout(0.65, 0.90, 0.90),
83 RooFit::Format(
"NEU", RooFit::AutoPrecision(2)));
106 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
107 if (
mean_ !=
nullptr)
114 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
122 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
130 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
138 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
146 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
154 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
162 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
170 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
178 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
186 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
194 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
202 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
203 if (
fsig_ !=
nullptr)
210 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
218 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
226 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
234 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
242 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
250 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
258 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
266 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
274 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
282 const double&
value,
const double&
min,
const double&
max,
const TString&
name,
const TString&
title) {
283 if (
fGCB_ !=
nullptr)
290 if (
mean_ !=
nullptr)
314 if (
fsig_ !=
nullptr)
334 if (
fGCB_ !=
nullptr)
340 RooAbsPdf* signal =
nullptr;
341 if (signalType ==
"gaussian") {
345 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean and sigma";
348 signal =
new RooGaussian(
"gauss",
"gauss", *
x, *
mean_, *
sigma_);
349 }
else if (signalType ==
"doubleGaussian") {
353 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean, sigma and sigma2";
356 RooGaussModel* gaussModel =
new RooGaussModel(
"gaussModel",
"gaussModel", *
x, *
mean_, *
sigma_);
357 RooGaussModel* gaussModel2 =
new RooGaussModel(
"gaussModel2",
"gaussModel2", *
x, *
mean_, *
sigma2_);
358 signal =
new RooAddModel(
"doubleGaussian",
"double gaussian", RooArgList(*gaussModel, *gaussModel2), *
gaussFrac_);
359 }
else if (signalType ==
"tripleGaussian") {
364 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean, mean2, " 365 "mean3, sigma, sigma2, sigma3";
368 RooGaussModel* gaussModel =
new RooGaussModel(
"gaussModel",
"gaussModel", *
x, *
mean_, *
sigma_);
369 RooGaussModel* gaussModel2 =
new RooGaussModel(
"gaussModel2",
"gaussModel2", *
x, *
mean2_, *
sigma2_);
370 RooGaussModel* gaussModel3 =
new RooGaussModel(
"gaussModel3",
"gaussModel3", *
x, *
mean3_, *
sigma3_);
371 signal =
new RooAddModel(
"tripleGaussian",
373 RooArgList(*gaussModel, *gaussModel2, *gaussModel3),
375 }
else if (signalType ==
"breitWigner") {
379 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean and gamma";
382 signal =
new RooBreitWigner(
"breiWign",
"breitWign", *
x, *
mean_, *
gamma_);
383 }
else if (signalType ==
"relBreitWigner") {
387 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean and gamma";
390 signal =
new RooGenericPdf(
"Relativistic Breit-Wigner",
392 "@0/(pow(@0*@0 - @1*@1,2) + @2*@2*@0*@0*@0*@0/(@1*@1))",
394 }
else if (signalType ==
"voigtian") {
398 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean, sigma and gamma";
402 }
else if (signalType ==
"crystalBall") {
406 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean, sigma, " 411 }
else if (signalType ==
"breitWignerTimesCB") {
414 (
alpha_ ==
nullptr) || (
n_ ==
nullptr)) {
416 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean, mean2, " 417 "sigma, gamma, alpha and n";
420 RooAbsPdf* bw =
new RooBreitWigner(
"breiWigner",
"breitWigner", *
x, *
mean_, *
gamma_);
422 signal =
new RooFFTConvPdf(
"breitWignerTimesCB",
"breitWignerTimesCB", *
x, *bw, *cb);
423 }
else if (signalType ==
"relBreitWignerTimesCB") {
426 (
alpha_ ==
nullptr) || (
n_ ==
nullptr)) {
428 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean, mean2, " 429 "sigma, gamma, alpha and n";
432 RooGenericPdf* bw =
new RooGenericPdf(
"Relativistic Breit-Wigner",
434 "@0/(pow(@0*@0 - @1*@1,2) + @2*@2*@0*@0*@0*@0/(@1*@1))",
437 signal =
new RooFFTConvPdf(
"relBreitWignerTimesCB",
"relBreitWignerTimesCB", *
x, *bw, *cb);
438 }
else if (signalType ==
"gaussianPlusCrystalBall") {
441 (
fGCB_ ==
nullptr)) {
443 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean, sigma, " 444 "sigma2, alpha, n and fGCB";
447 RooAbsPdf* tempCB =
new RooCBShape(
"crystalBall",
"crystalBall", *
x, *
mean_, *
sigma_, *
alpha_, *
n_);
448 RooAbsPdf* tempGaussian =
new RooGaussian(
"gauss",
"gauss", *
x, *
mean_, *
sigma2_);
451 new RooAddPdf(
"gaussianPlusCrystalBall",
"gaussianPlusCrystalBall", RooArgList(*tempCB, *tempGaussian), *
fGCB_);
452 }
else if (signalType ==
"voigtianPlusCrystalBall") {
457 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean, gamma, " 458 "sigma, sigma2, alpha, n and fGCB";
461 RooAbsPdf* tempVoigt =
new RooVoigtian(
"voigt",
"voigt", *
x, *
mean_, *
gamma_, *
sigma_);
462 RooAbsPdf* tempCB =
new RooCBShape(
"crystalBall",
"crystalBall", *
x, *
mean_, *
sigma2_, *
alpha_, *
n_);
465 new RooAddPdf(
"voigtianPlusCrystalBall",
"voigtianPlusCrystalBall", RooArgList(*tempCB, *tempVoigt), *
fGCB_);
466 }
else if (signalType ==
"breitWignerPlusCrystalBall") {
469 (
fGCB_ ==
nullptr)) {
471 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean, gamma, " 472 "sigma, alpha, n and fGCB";
475 RooAbsPdf* tempBW =
new RooBreitWigner(
"breitWign",
"breitWign", *
x, *
mean_, *
gamma_);
476 RooAbsPdf* tempCB =
new RooCBShape(
"crystalBall",
"crystalBall", *
x, *
mean_, *
sigma2_, *
alpha_, *
n_);
479 new RooAddPdf(
"breitWignerPlusCrystalBall",
"breitWignerPlusCrystalBall", RooArgList(*tempCB, *tempBW), *
fGCB_);
482 else if (signalType !=
"") {
483 edm::LogError(
"FitWithRooFit") <<
"Unknown signal function: " << signalType <<
". Signal will not be in the model";
490 RooAbsPdf* background =
nullptr;
491 if (backgroundType ==
"exponential") {
495 <<
"Error: one or more parameters are not initialized. Please be sure to initialize expCoeffa1 and fsig";
498 background =
new RooExponential(
"exponential",
"exponential", *
x, *
expCoeffa1_);
501 if (backgroundType ==
"exponentialpol") {
505 <<
"Error: one or more parameters are not initialized. Please be sure to initialize expCoeff and fsig";
508 background =
new RooGenericPdf(
"exponential",
510 "TMath::Exp(@1+@2*@0+@3*@0*@0)",
514 else if (backgroundType ==
"chebychev0") {
516 if (
a0_ ==
nullptr) {
518 <<
"Error: one or more parameters are not initialized. Please be sure to initialize a0";
521 background =
new RooChebychev(
"chebychev0",
"chebychev0", *
x, *
a0_);
522 }
else if (backgroundType ==
"chebychev1") {
524 if ((
a0_ ==
nullptr) || (
a1_ ==
nullptr)) {
526 <<
"Error: one or more parameters are not initialized. Please be sure to initialize a0 and a1";
529 background =
new RooChebychev(
"chebychev1",
"chebychev1", *
x, RooArgList(*
a0_, *
a1_));
530 }
else if (backgroundType ==
"chebychev3") {
532 if ((
a0_ ==
nullptr) || (
a1_ ==
nullptr) || (
a2_ ==
nullptr) || (
a3_ ==
nullptr)) {
534 <<
"Error: one or more parameters are not initialized. Please be sure to initialize a0, a1, a2 and a3";
537 background =
new RooChebychev(
"3rdOrderPol",
"3rdOrderPol", *
x, RooArgList(*
a0_, *
a1_, *
a2_, *
a3_));
540 else if (backgroundType ==
"chebychev6") {
542 if ((
a0_ ==
nullptr) || (
a1_ ==
nullptr) || (
a2_ ==
nullptr) || (
a3_ ==
nullptr) || (
a4_ ==
nullptr) ||
543 (
a5_ ==
nullptr) || (
a6_ ==
nullptr)) {
545 <<
"Error: one or more parameters are not initialized. Please be sure to initialize a0, a1, a2, a3, " 558 RooAbsPdf*
model =
nullptr;
563 if ((signal !=
nullptr) && (background !=
nullptr)) {
565 edm::LogPrint(
"FitWithRooFit") <<
"Building model with signal and backgound";
566 model =
new RooAddPdf(
"model",
"model", RooArgList(*signal, *background), *
fsig_);
567 }
else if (signal !=
nullptr) {
568 edm::LogPrint(
"FitWithRooFit") <<
"Building model with signal";
570 }
else if (background !=
nullptr) {
571 edm::LogPrint(
"FitWithRooFit") <<
"Building model with backgound";
void initGaussFrac2(const double &value, const double &min, const double &max, const TString &name="GaussFrac2", const TString &title="GaussFrac2")
void initGaussFrac(const double &value, const double &min, const double &max, const TString &name="GaussFrac", const TString &title="GaussFrac")
void initA6(const double &value, const double &min, const double &max, const TString &name="a6", const TString &title="a6")
double initVal_expCoeffa0
void initA1(const double &value, const double &min, const double &max, const TString &name="a1", const TString &title="a1")
void initFsig(const double &value, const double &min, const double &max, const TString &name="fsig", const TString &title="signal fraction")
void fit(TH1 *histo, const TString signalType, const TString backgroundType, const double &xMin=0., const double &xMax=0., bool sumW2Error=false)
RooAbsPdf * buildModel(RooRealVar *x, const TString &signalType, const TString &backgroundType)
Build the model to fit.
RooAbsPdf * buildSignalModel(RooRealVar *x, const TString &signalType)
Build the model for the specified signal type.
void initGamma(const double &value, const double &min, const double &max, const TString &name="gamma", const TString &title="gamma")
Log< level::Error, false > LogError
void initA3(const double &value, const double &min, const double &max, const TString &name="a3", const TString &title="a3")
double initVal_expCoeffa1
double initVal_gaussFrac2
void reinitializeParameters()
void initMean3(const double &value, const double &min, const double &max, const TString &name="mean3", const TString &title="mean3")
void initA4(const double &value, const double &min, const double &max, const TString &name="a4", const TString &title="a4")
Log< level::Warning, true > LogPrint
void initMean(const double &value, const double &min, const double &max, const TString &name="mean", const TString &title="mean")
RooAbsPdf * buildBackgroundModel(RooRealVar *x, const TString &backgroundType)
Build the model for the specified background type.
void initN(const double &value, const double &min, const double &max, const TString &name="n", const TString &title="n")
double initVal_expCoeffa2
rooPair importTH1(TH1 *histo, const double &inputXmin, const double &inputXmax)
void initA0(const double &value, const double &min, const double &max, const TString &name="a0", const TString &title="a0")
void initAlpha(const double &value, const double &min, const double &max, const TString &name="alpha", const TString &title="alpha")
void initSigma3(const double &value, const double &min, const double &max, const TString &name="sigma3", const TString &title="sigma3")
void initA5(const double &value, const double &min, const double &max, const TString &name="a5", const TString &title="a5")
void initExpCoeffA0(const double &value, const double &min, const double &max, const TString &name="expCoeffa0", const TString &title="expCoeffa0")
void initExpCoeffA1(const double &value, const double &min, const double &max, const TString &name="expCoeffa1", const TString &title="expCoeffa1")
void initA2(const double &value, const double &min, const double &max, const TString &name="a2", const TString &title="a2")
void initSigma2(const double &value, const double &min, const double &max, const TString &name="sigma2", const TString &title="sigma2")
void initFGCB(const double &value, const double &min, const double &max, const TString &name="fGCB", const TString &title="fGCB")
void initExpCoeffA2(const double &value, const double &min, const double &max, const TString &name="expCoeffa2", const TString &title="expCoeffa2")
Log< level::Warning, false > LogWarning
void initSigma(const double &value, const double &min, const double &max, const TString &name="sigma", const TString &title="sigma")
void initMean2(const double &value, const double &min, const double &max, const TString &name="mean2", const TString &title="mean2")