Example #1
0
RooStats::ModelConfig * Tprime::SetBModel( void ) {
    //
    // Define model config and parameter snapshot to describe the b model.
    // Import to workspace.
    //

    std::string legend = "[Tprime::SetBModel]: ";

    // full signal+background model
    //RooStats::ModelConfig * pSBModel = (RooStats::ModelConfig *)pWs->genobj("ModelConfig");

    // let's make the b model (bg-only) from the alt model (s+b) with xsec=0
    //RooStats::ModelConfig * pBModel =
    //  new RooStats::ModelConfig(*(RooStats::ModelConfig *)pWs->genobj("ModelConfig"));
    RooStats::ModelConfig * _sbModel = (RooStats::ModelConfig *)pWs->genobj("ModelConfig");
    RooStats::ModelConfig * pBModel = _sbModel->Clone("BModel");

    //pBModel->SetName("BModel");

    pBModel->SetWorkspace(*pWs);

    //pBModel->SetParametersOfInterest(RooArgSet());
    pWs->import(*pBModel);

    // set POI to the b model value and take snapshot
    RooRealVar * pPoi = (RooRealVar *)pBModel->GetParametersOfInterest()->first();
    pPoi->setVal(0.0);
    pBModel->SetSnapshot(*pPoi);

    pBModel->Print();

    return pBModel;
}
Example #2
0
RooAbsData * Tprime::GetPseudoData( void ) {
    //
    // Generate pseudo data, return a pointer.
    // Class member pointer data set to point to the dataset.
    // Caller does not take ownership.
    //

    static int n_toys = 0;

    // legend for printouts
    std::string legend = "[Tprime::GetPseudoData()]: ";

    delete data;

    // We will use ToyMCSampler to generate pseudo-data (and test statistic, eventually)
    // We are responsible for randomizing nuisances and global observables,
    // ToyMCSampler only generates observables (as of ROOT 5.30.00-rc1 and before)

    // MC sampler and test statistic
    if(n_toys == 0) { // on first entry
        // get B model config from workspace
        RooStats::ModelConfig * pBModel = (RooStats::ModelConfig *)pWs->obj("BModel");
        pBModel->SetWorkspace(*pWs);

        // get parameter of interest set
        //const RooArgSet * poi = pSbModel->GetParametersOfInterest();

        //RooStats::TestStatistic * pTestStatistic = new RooStats::ProfileLikelihoodTestStat(*pBModel->GetPdf());
        //RooStats::ToyMCSampler toymcs(*pTestStatistic, 1);
        pTestStatistic = new RooStats::ProfileLikelihoodTestStat(*pBModel->GetPdf());
        pToyMcSampler = new RooStats::ToyMCSampler(*pTestStatistic, 1);
        pToyMcSampler->SetPdf(*pBModel->GetPdf());
        pToyMcSampler->SetObservables(*pBModel->GetObservables());
        pToyMcSampler->SetParametersForTestStat(*pBModel->GetParametersOfInterest()); // just POI
        pToyMcSampler->SetGlobalObservables(*pBModel->GetGlobalObservables());
    }

    // load parameter point
    pWs->loadSnapshot("parametersToGenerateData");

    RooArgSet dummySet;
    data = pToyMcSampler->GenerateToyData(dummySet);
    std::cout << legend << "generated the following background-only pseudo-data:" << std::endl;
    data->Print();

    // count number of generated toys
    ++n_toys;

    return data;
}
Example #3
0
Int_t Tprime::RunMcmc( std::string channel, // ejets, mujets, combined
                       std::string mode,    // observed, expected
                       double peak,         // resonance mass
                       std::string suffix,  // suffix for output file names
                       Int_t ntoys,         // number of pseudoexperiments for expected limit
                       Int_t mcmc_iter,     // number of MCMC iterations
                       Int_t mcmc_burnin,   // number of MCMC burn in steps to be discarded
                       std::string inputdir // input dir name
                     ) {
    //
    // Bayesian MCMC calculation
    //

    std::string legend = "[tprime::RunMcmc()]: ";

    // print out inputs
    std::cout << legend << std::endl;
    std::cout << legend << "Input parameters specified. Some of them are not used and defaults are entered" << std::endl;
    std::cout << legend << "------------------------------" << std::endl;
    std::cout << legend << "channel: " << channel << std::endl;
    std::cout << legend << "mode: " << mode << std::endl;
    std::cout << legend << "input directory: " << inputdir << std::endl;
    std::cout << legend << "resonance peak mass: " << peak << std::endl;
    std::cout << legend << "suffix: ->" << suffix << "<-" << std::endl;
    std::cout << legend << "number of pseudo-experiments: "<< ntoys << std::endl;
    std::cout << legend << std::endl;
    std::cout << legend << "Bayesian MCMC parameters" << std::endl;
    std::cout << legend << "------------------------------" << std::endl;
    std::cout << legend << "number of iterations: " << mcmc_iter << std::endl;
    std::cout << legend << "number of burn-in steps to discard: " << mcmc_burnin << std::endl;
    std::cout << legend << std::endl;

    // compose the workspace file name
    char buf[1024];
    sprintf(buf, "%sresults_%04.0f/tprime_%s_tprimeCrossSection_model.root", inputdir.c_str(), peak, channel.c_str());
    std::string _file = buf;
    std::cout << legend << "guessed name of the file with the workspace: >" << _file << "<" << std::endl;

    //load workspace
    LoadWorkspace(_file, channel);

    // change POI range
    double poiUpper = GetPoiUpper(channel, peak);
    std::cout << legend << "setting POI range to [0; " << poiUpper << "]" << std::endl;
    pWs->var("xsec")->setRange(0.0, poiUpper);

    // timer
    TStopwatch t;
    t.Start();

    int pe_counter = 0;
    std::vector<Double_t> _limits;
    while (pe_counter < ntoys) {

        // for mass limit, add k-factor systematics to the nsig systematics
        // FIXME: this is a correlated part of the uncertainty!!!
        //  - different uncertainties for graviton and Z' models
        if ( mode.find("mass_") != std::string::npos ) {

            std::cout << legend << std::endl;
            std::cout << legend << "this a mass limit calculation," << std::endl;
            std::cout << legend << "I would add k-factor uncertainty to the nsig uncertainty" << std::endl;
            std::cout << legend << "I would do it " << ntoys << " times, so one can average. " << pe_counter+1 << " of " << ntoys << std::endl;
            std::cout << legend << "Not implemented yet " << std::endl;
            std::cout << legend << std::endl;

            //Double_t kfactor_err = GetKfactorUncertainty(peak, mode);

            //double nsig_kappa = ws->var("nsig_kappa_dimuon")->getVal();
            //nsig_kappa = sqrt(nsig_kappa*nsig_kappa + kfactor_err*kfactor_err);
            //ws->var("nsig_kappa_dimuon")->setVal(nsig_kappa);

            //ntoys = 1;

        }

        else if ( mode.find("expected") != std::string::npos ) {

            std::cout << legend << std::endl;
            std::cout << legend << "this is pseudoexperiment " << pe_counter+1 << " of " << ntoys << std::endl;
            std::cout << legend << "for the expected limit estimate" << std::endl;
            std::cout << legend << std::endl;

            // prepare PE data
            GetPseudoData();

        }

        else { //  "regular" observed limit

            std::cout << legend << std::endl;
            std::cout << legend << "calculating an observed limit..." << std::endl;
            std::cout << legend << "I will do it " << ntoys << " times, so one can average. " << pe_counter+1 << " of " << ntoys << std::endl;
            std::cout << legend << std::endl;

            GetWorkspaceData("obsData");

            //ntoys = 1;
        }

        mcInt = GetMcmcInterval(0.95,        // conf level
                                mcmc_iter,   // number of iterations
                                mcmc_burnin, // number of burn-in to discard
                                0.0,         // left side tail fraction, 0 for upper limit
                                100);        // number of bins in posterior, only for plotting

        ++pe_counter;

        if (!mcInt) {
            continue;
        }
        else {

            std::string _outfile = "tprime_"+channel+"_xsec_mcmc_limit_" + suffix + ".ascii";
            printMcmcUpperLimit( peak, _outfile );

            // limits for averaging/medianing
            RooStats::ModelConfig * pSbModel = GetModelConfig("ModelConfig");
            RooRealVar * firstPOI = (RooRealVar*) pSbModel->GetParametersOfInterest()->first();
            double _limit = mcInt->UpperLimit(*firstPOI);
            _limits.push_back(_limit);

        } // end of valid mcInt block

    } // end of while

    // write median limit to a file
    if (_limits.size() > 0) {
        Double_t _median_limit = TMath::Median(_limits.size(), &_limits[0]);
        std::vector<Double_t> _mass_limit;
        _mass_limit.push_back(peak);
        _mass_limit.push_back(_median_limit);
        std::string _outfile = "tprime_"+channel+"_xsec_mcmc_median_limit_" + suffix + ".ascii";
        PrintToFile(_outfile, _mass_limit, "#  mass         median_limit");
    }

    std::string _outfile = "tprime_"+channel+"_xsec_mcmc_posterior_" + suffix + ".pdf";
    makeMcmcPosteriorPlot( _outfile );

    // timer
    t.Print();

    return 0;
}
Example #4
0
Int_t Tprime::SetParameterPoints( std::string sbModelName,
                                  std::string bModelName ) {
    //
    // Fit the data with S+B model.
    // Make a snapshot of the S+B parameter point.
    // Profile with POI=0.
    // Make a snapshot of the B parameter point
    // (B model is the S+B model with POI=0
    //

    Double_t poi_value_for_b_model = 0.0;

    // get S+B model config from workspace
    RooStats::ModelConfig * pSbModel = (RooStats::ModelConfig *)pWs->obj(sbModelName.c_str());
    pSbModel->SetWorkspace(*pWs);

    // get parameter of interest set
    const RooArgSet * poi = pSbModel->GetParametersOfInterest();

    // get B model config from workspace
    RooStats::ModelConfig * pBModel = (RooStats::ModelConfig *)pWs->obj(bModelName.c_str());
    pBModel->SetWorkspace(*pWs);

    // make sure that data has been loaded
    if (!data) return -1;

    // find parameter point for global maximum with the S+B model,
    // with conditional MLEs for nuisance parameters
    // and save the parameter point snapshot in the Workspace
    RooAbsReal * nll = pSbModel->GetPdf()->createNLL(*data);
    RooAbsReal * profile = nll->createProfile(RooArgSet());
    profile->getVal(); // this will do fit and set POI and nuisance parameters to fitted values
    RooArgSet * poiAndNuisance = new RooArgSet();
    if(pSbModel->GetNuisanceParameters())
        poiAndNuisance->add(*pSbModel->GetNuisanceParameters());
    poiAndNuisance->add(*pSbModel->GetParametersOfInterest());
    pWs->defineSet("SPlusBModelParameters", *poiAndNuisance);
    pWs->saveSnapshot("SPlusBFitParameters",*poiAndNuisance);
    pSbModel->SetSnapshot(*poi);
    RooArgSet * sbModelFitParams = (RooArgSet *)poiAndNuisance->snapshot();
    cout << "\nWill save these parameter points that correspond to the fit to data" << endl;
    sbModelFitParams->Print("v");
    delete profile;
    delete nll;
    delete poiAndNuisance;
    delete sbModelFitParams;

    //

    // Find a parameter point for generating pseudo-data
    // with the background-only data.
    // Save the parameter point snapshot in the Workspace
    nll = pBModel->GetPdf()->createNLL(*data);
    profile = nll->createProfile(*poi);
    ((RooRealVar *)poi->first())->setVal(poi_value_for_b_model);
    profile->getVal(); // this will do fit and set nuisance parameters to profiled values
    poiAndNuisance = new RooArgSet();
    if(pBModel->GetNuisanceParameters())
        poiAndNuisance->add(*pBModel->GetNuisanceParameters());
    poiAndNuisance->add(*pBModel->GetParametersOfInterest());
    pWs->defineSet("parameterPointToGenerateData", *poiAndNuisance);
    pWs->saveSnapshot("parametersToGenerateData",*poiAndNuisance);
    pBModel->SetSnapshot(*poi);
    RooArgSet * paramsToGenerateData = (RooArgSet *)poiAndNuisance->snapshot();
    cout << "\nShould use these parameter points to generate pseudo data for bkg only" << endl;
    paramsToGenerateData->Print("v");
    delete profile;
    delete nll;
    delete poiAndNuisance;
    delete paramsToGenerateData;

    return 0;
}