12 RooRealVar
x(
"InvMass",
"di-muon mass M(#mu^{+}#mu^{-}) [GeV]",
xMin,
xMax);
14 return std::make_unique<RooDataHist>(
"dh",
"dh",
x, RooFit::Import(*
histo));
19 TH1*
histo,
const TString signalType,
const TString backgroundType,
double xMin,
double xMax,
bool sumW2Error) {
23 RooRealVar
x(*static_cast<RooRealVar*>(
dh->get()->find(
"InvMass")));
26 RooPlot*
frame =
x.frame(RooFit::Title(
"di-muon mass M(#mu^{+}#mu^{-}) [GeV]"));
27 frame->SetName(TString(
histo->GetName()) +
"_frame");
31 std::unique_ptr<RooAbsPdf>
model =
buildModel(&
x, signalType, backgroundType);
33 std::unique_ptr<RooAbsReal>
chi2{
model->createChi2(*
dh, RooFit::DataError(RooAbsData::SumW2))};
40 model->fitTo(*
dh, RooFit::SumW2Error(sumW2Error), RooFit::PrintLevel(-1));
45 RooMinimizer
m(*
chi2);
58 RooFit::Layout(0.65, 0.90, 0.90),
59 RooFit::Format(
"NEU", RooFit::AutoPrecision(2)));
73 RooPlot* frame2 =
x.frame(RooFit::Title(
"di-muon mass M(#mu^{+}#mu^{-}) [GeV]"));
74 dh->plotOn(frame2, RooFit::DataError(RooAbsData::SumW2));
75 model->plotOn(frame2, RooFit::LineColor(kRed));
79 model->paramOn(frame2,
81 RooFit::Layout(0.65, 0.90, 0.90),
82 RooFit::Format(
"NEU", RooFit::AutoPrecision(2)));
220 auto initParam = [](std::unique_ptr<RooRealVar>&
var,
double val) {
252 if (signalType ==
"gaussian") {
256 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean and sigma";
259 return std::make_unique<RooGaussian>(
"gauss",
"gauss", *
x, *
mean_, *
sigma_);
260 }
else if (signalType ==
"doubleGaussian") {
264 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean, sigma and sigma2";
267 RooGaussModel* gaussModel =
new RooGaussModel(
"gaussModel",
"gaussModel", *
x, *
mean_, *
sigma_);
268 RooGaussModel* gaussModel2 =
new RooGaussModel(
"gaussModel2",
"gaussModel2", *
x, *
mean_, *
sigma2_);
269 RooArgList
components{*gaussModel, *gaussModel2};
273 }
else if (signalType ==
"tripleGaussian") {
278 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean, mean2, " 279 "mean3, sigma, sigma2, sigma3";
282 RooGaussModel* gaussModel =
new RooGaussModel(
"gaussModel",
"gaussModel", *
x, *
mean_, *
sigma_);
283 RooGaussModel* gaussModel2 =
new RooGaussModel(
"gaussModel2",
"gaussModel2", *
x, *
mean2_, *
sigma2_);
284 RooGaussModel* gaussModel3 =
new RooGaussModel(
"gaussModel3",
"gaussModel3", *
x, *
mean3_, *
sigma3_);
285 RooArgList
components{*gaussModel, *gaussModel2, *gaussModel3};
286 auto out = std::make_unique<RooAddModel>(
290 }
else if (signalType ==
"breitWigner") {
294 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean and gamma";
297 return std::make_unique<RooBreitWigner>(
"breiWign",
"breitWign", *
x, *
mean_, *
gamma_);
298 }
else if (signalType ==
"relBreitWigner") {
302 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean and gamma";
305 return std::make_unique<RooGenericPdf>(
"Relativistic Breit-Wigner",
307 "@0/(pow(@0*@0 - @1*@1,2) + @2*@2*@0*@0*@0*@0/(@1*@1))",
309 }
else if (signalType ==
"voigtian") {
313 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean, sigma and gamma";
317 }
else if (signalType ==
"crystalBall") {
321 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean, sigma, " 325 return std::make_unique<RooCBShape>(
"crystalBall",
"crystalBall", *
x, *
mean_, *
sigma_, *
alpha_, *
n_);
326 }
else if (signalType ==
"breitWignerTimesCB") {
329 (
alpha_ ==
nullptr) || (
n_ ==
nullptr)) {
331 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean, mean2, " 332 "sigma, gamma, alpha and n";
335 RooAbsPdf* bw =
new RooBreitWigner(
"breiWigner",
"breitWigner", *
x, *
mean_, *
gamma_);
337 auto out = std::make_unique<RooFFTConvPdf>(
"breitWignerTimesCB",
"breitWignerTimesCB", *
x, *bw, *cb);
338 out->addOwnedComponents({*bw, *cb});
340 }
else if (signalType ==
"relBreitWignerTimesCB") {
343 (
alpha_ ==
nullptr) || (
n_ ==
nullptr)) {
345 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean, mean2, " 346 "sigma, gamma, alpha and n";
349 RooGenericPdf* bw =
new RooGenericPdf(
"Relativistic Breit-Wigner",
351 "@0/(pow(@0*@0 - @1*@1,2) + @2*@2*@0*@0*@0*@0/(@1*@1))",
354 auto out = std::make_unique<RooFFTConvPdf>(
"relBreitWignerTimesCB",
"relBreitWignerTimesCB", *
x, *bw, *cb);
355 out->addOwnedComponents({*bw, *cb});
357 }
else if (signalType ==
"gaussianPlusCrystalBall") {
360 (
fGCB_ ==
nullptr)) {
362 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean, sigma, " 363 "sigma2, alpha, n and fGCB";
366 RooAbsPdf* tempCB =
new RooCBShape(
"crystalBall",
"crystalBall", *
x, *
mean_, *
sigma_, *
alpha_, *
n_);
367 RooAbsPdf* tempGaussian =
new RooGaussian(
"gauss",
"gauss", *
x, *
mean_, *
sigma2_);
368 RooArgList
components{*tempCB, *tempGaussian};
370 auto out = std::make_unique<RooAddPdf>(
"gaussianPlusCrystalBall",
"gaussianPlusCrystalBall",
components, *
fGCB_);
373 }
else if (signalType ==
"voigtianPlusCrystalBall") {
378 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean, gamma, " 379 "sigma, sigma2, alpha, n and fGCB";
382 RooAbsPdf* tempVoigt =
new RooVoigtian(
"voigt",
"voigt", *
x, *
mean_, *
gamma_, *
sigma_);
383 RooAbsPdf* tempCB =
new RooCBShape(
"crystalBall",
"crystalBall", *
x, *
mean_, *
sigma2_, *
alpha_, *
n_);
386 auto out = std::make_unique<RooAddPdf>(
"voigtianPlusCrystalBall",
"voigtianPlusCrystalBall",
components, *
fGCB_);
389 }
else if (signalType ==
"breitWignerPlusCrystalBall") {
392 (
fGCB_ ==
nullptr)) {
394 <<
"Error: one or more parameters are not initialized. Please be sure to initialize mean, gamma, " 395 "sigma, alpha, n and fGCB";
398 RooAbsPdf* tempBW =
new RooBreitWigner(
"breitWign",
"breitWign", *
x, *
mean_, *
gamma_);
399 RooAbsPdf* tempCB =
new RooCBShape(
"crystalBall",
"crystalBall", *
x, *
mean_, *
sigma2_, *
alpha_, *
n_);
403 std::make_unique<RooAddPdf>(
"breitWignerPlusCrystalBall",
"breitWignerPlusCrystalBall",
components, *
fGCB_);
408 else if (signalType !=
"") {
409 edm::LogError(
"FitWithRooFit") <<
"Unknown signal function: " << signalType <<
". Signal will not be in the model";
416 if (backgroundType ==
"exponential") {
420 <<
"Error: one or more parameters are not initialized. Please be sure to initialize expCoeffa1 and fsig";
423 return std::make_unique<RooExponential>(
"exponential",
"exponential", *
x, *
expCoeffa1_);
426 if (backgroundType ==
"exponentialpol") {
430 <<
"Error: one or more parameters are not initialized. Please be sure to initialize expCoeff and fsig";
433 return std::make_unique<RooGenericPdf>(
"exponential",
435 "TMath::Exp(@1+@2*@0+@3*@0*@0)",
439 else if (backgroundType ==
"chebychev0") {
441 if (
a0_ ==
nullptr) {
443 <<
"Error: one or more parameters are not initialized. Please be sure to initialize a0";
446 return std::make_unique<RooChebychev>(
"chebychev0",
"chebychev0", *
x, *
a0_);
447 }
else if (backgroundType ==
"chebychev1") {
449 if ((
a0_ ==
nullptr) || (
a1_ ==
nullptr)) {
451 <<
"Error: one or more parameters are not initialized. Please be sure to initialize a0 and a1";
454 return std::make_unique<RooChebychev>(
"chebychev1",
"chebychev1", *
x, RooArgList{*
a0_, *
a1_});
455 }
else if (backgroundType ==
"chebychev3") {
457 if ((
a0_ ==
nullptr) || (
a1_ ==
nullptr) || (
a2_ ==
nullptr) || (
a3_ ==
nullptr)) {
459 <<
"Error: one or more parameters are not initialized. Please be sure to initialize a0, a1, a2 and a3";
462 return std::make_unique<RooChebychev>(
"3rdOrderPol",
"3rdOrderPol", *
x, RooArgList{*
a0_, *
a1_, *
a2_, *
a3_});
465 else if (backgroundType ==
"chebychev6") {
467 if ((
a0_ ==
nullptr) || (
a1_ ==
nullptr) || (
a2_ ==
nullptr) || (
a3_ ==
nullptr) || (
a4_ ==
nullptr) ||
468 (
a5_ ==
nullptr) || (
a6_ ==
nullptr)) {
470 <<
"Error: one or more parameters are not initialized. Please be sure to initialize a0, a1, a2, a3, " 474 return std::make_unique<RooChebychev>(
482 const TString& signalType,
483 const TString& backgroundType) {
484 std::unique_ptr<RooAbsPdf>
model;
489 if ((signal !=
nullptr) && (background !=
nullptr)) {
491 edm::LogPrint(
"FitWithRooFit") <<
"Building model with signal and backgound";
492 RooArgList
components{*signal.release(), *background.release()};
495 }
else if (signal !=
nullptr) {
496 edm::LogPrint(
"FitWithRooFit") <<
"Building model with signal";
498 }
else if (background !=
nullptr) {
499 edm::LogPrint(
"FitWithRooFit") <<
"Building model with backgound";
void initA0(double value, double min, double max, const TString &name="a0", const TString &title="a0")
double initVal_expCoeffa0
void initGamma(double value, double min, double max, const TString &name="gamma", const TString &title="gamma")
std::unique_ptr< RooRealVar > fsig_
void initA5(double value, double min, double max, const TString &name="a5", const TString &title="a5")
void initSigma(double value, double min, double max, const TString &name="sigma", const TString &title="sigma")
std::unique_ptr< RooRealVar > sigma3_
void initSigma2(double value, double min, double max, const TString &name="sigma2", const TString &title="sigma2")
std::unique_ptr< RooRealVar > mean_
std::unique_ptr< RooRealVar > mean2_
void initMean3(double value, double min, double max, const TString &name="mean3", const TString &title="mean3")
void initGaussFrac2(double value, double min, double max, const TString &name="GaussFrac2", const TString &title="GaussFrac2")
void initA1(double value, double min, double max, const TString &name="a1", const TString &title="a1")
void initFGCB(double value, double min, double max, const TString &name="fGCB", const TString &title="fGCB")
void initA2(double value, double min, double max, const TString &name="a2", const TString &title="a2")
void initA6(double value, double min, double max, const TString &name="a6", const TString &title="a6")
Log< level::Error, false > LogError
std::unique_ptr< RooRealVar > a0_
void initMean2(double value, double min, double max, const TString &name="mean2", const TString &title="mean2")
std::unique_ptr< RooRealVar > a1_
std::unique_ptr< RooRealVar > mean3_
std::unique_ptr< RooRealVar > a5_
std::unique_ptr< RooRealVar > n_
std::unique_ptr< RooAbsPdf > buildSignalModel(RooRealVar *x, const TString &signalType)
Build the model for the specified signal type.
double initVal_expCoeffa1
double initVal_gaussFrac2
void reinitializeParameters()
std::unique_ptr< RooRealVar > a6_
void initN(double value, double min, double max, const TString &name="n", const TString &title="n")
std::unique_ptr< RooRealVar > sigma_
std::unique_ptr< RooAbsPdf > buildBackgroundModel(RooRealVar *x, const TString &backgroundType)
Build the model for the specified background type.
std::unique_ptr< RooRealVar > a4_
void initFsig(double value, double min, double max, const TString &name="fsig", const TString &title="signal fraction")
void initExpCoeffA1(double value, double min, double max, const TString &name="expCoeffa1", const TString &title="expCoeffa1")
Log< level::Warning, true > LogPrint
std::unique_ptr< RooRealVar > gaussFrac2_
std::unique_ptr< RooAbsPdf > buildModel(RooRealVar *x, const TString &signalType, const TString &backgroundType)
Build the model to fit.
double initVal_expCoeffa2
std::unique_ptr< RooRealVar > a2_
std::unique_ptr< RooRealVar > sigma2_
void initAlpha(double value, double min, double max, const TString &name="alpha", const TString &title="alpha")
void fit(TH1 *histo, const TString signalType, const TString backgroundType, double xMin=0., double xMax=0., bool sumW2Error=false)
std::unique_ptr< RooDataHist > importTH1(TH1 *histo, double xMin, double xMax)
std::unique_ptr< RooRealVar > gaussFrac_
std::unique_ptr< RooRealVar > gamma_
std::unique_ptr< RooRealVar > fGCB_
std::unique_ptr< RooRealVar > a3_
void initGaussFrac(double value, double min, double max, const TString &name="GaussFrac", const TString &title="GaussFrac")
std::unique_ptr< RooRealVar > expCoeffa0_
std::unique_ptr< RooRealVar > expCoeffa1_
void initExpCoeffA2(double value, double min, double max, const TString &name="expCoeffa2", const TString &title="expCoeffa2")
void initSigma3(double value, double min, double max, const TString &name="sigma3", const TString &title="sigma3")
void initA3(double value, double min, double max, const TString &name="a3", const TString &title="a3")
Log< level::Warning, false > LogWarning
void initExpCoeffA0(double value, double min, double max, const TString &name="expCoeffa0", const TString &title="expCoeffa0")
std::unique_ptr< RooRealVar > expCoeffa2_
std::unique_ptr< RooRealVar > alpha_
void initMean(double value, double min, double max, const TString &name="mean", const TString &title="mean")
void initA4(double value, double min, double max, const TString &name="a4", const TString &title="a4")