
#include "BackgroundType.hpp"
#include "GlobalFunctions.hh"
#include <boost/algorithm/string.hpp>

using namespace RooFit;

void BackgroundType::setBackgroundType(string bkgType, bool TM, bool FixParams, bool ConstrParams){//construct from a string

    SingleExponential = false;
    DoubleExponential = false;
    ExpGaus = false;
    NoBackground = false;
    bkgOneCB = false;

    FixBkgParameters = FixParams;
    ConstrBkgParameters = ConstrParams;

    boost::to_lower(bkgType); //so far it doesn't complain about non-existing library

    if (TM) NoBackground = true;
    else{
        if(bkgType.find("exponen") < 100 ){
            if(bkgType.find("double") < 100 ) DoubleExponential = true;
            else                              SingleExponential = true;

        }
        else if(bkgType.find("expgaus") < 100 ) {
            ExpGaus = true;
            SingleExponential = true;    //ExpGauss is implemented for now only with a singleExp
        }
        //Possibly add OneCB to the fit model
        if(bkgType.find("onecb") < 100 ){
            bkgOneCB = true;
        }

        if (bkgOneCB && DoubleExponential){
            coutWarning("Option of a CB with TWO exponentials is not implemented! Setting DoubleExp to SingleExp!");
            DoubleExponential = false;
            SingleExponential = true;
        }
        if (bkgOneCB && ExpGaus){
            coutWarning("Option of CB with ExpGauss AND OneCB is not implemented! Replacing ExpGauss by a single exponential!");
            ExpGaus = false;
        }
        if (!(SingleExponential || DoubleExponential || ExpGaus || bkgOneCB)) NoBackground = true;
    }

    coutDebug("Final background type(s):");
    coutDebug(SingleExponential ? "SingleExponential" : "");
    coutDebug(DoubleExponential ? "DoubleExponential" : "");
    coutDebug(ExpGaus           ? "ExpGaus" : "");
    coutDebug(NoBackground      ? "NoBackground"   : "");
    coutDebug(bkgOneCB          ? "OneCB"  : "");

}

vector<string> BackgroundType::getBkgListOfParams(){
    vector<string> tmp = {};
    for (auto var : BkgRooVars) tmp.push_back(var->GetName());
    return tmp;
}
