Exemple #1
0
double compNumEvents_profileLikelihoodUpperLimit(RooDataHist* data, RooAddPdf* pdf_BSM, RooAddPdf* pdf_SM, RooRealVar* norm_AH120)
{
//--- initialize normalization factors for "background" processes
//    with values best matching observed distribution of fit variables
    pdf_SM->fitTo(*data, RooFit::SumW2Error(false));

//--- initialize RooStats objects
//    for performing fit/computing limits via "profile-likelihood" method
    RooStats::ProfileLikelihoodCalculator* significanceCalculator = new RooStats::ProfileLikelihoodCalculator(*data, *pdf_BSM, *norm_AH120);

    RooStats::LikelihoodInterval* numEvents_AH120interval = significanceCalculator->GetInterval();
    double numEvents_AH120_upperLimit = numEvents_AH120interval->UpperLimit(*norm_AH120);

    TCanvas* canvas = new TCanvas("canvas", "canvas", 800, 600);
    canvas->SetFillColor(10);
    canvas->SetLogy();

    RooStats::LikelihoodIntervalPlot* likelihood_AH120plot = new RooStats::LikelihoodIntervalPlot(numEvents_AH120interval);
    likelihood_AH120plot->Draw();
    TF1* likelihood_AH120function = (TF1*)numEvents_AH120interval->GetLikelihoodRatio()->asTF(*norm_AH120)->Clone();
    likelihood_AH120function->Draw("same");

    canvas->Update();
    TString fileName = TString("mssmHiggsLimit").Append("_").Append("profileLikelihood");
    canvas->SaveAs(fileName.Append(".png"));

    delete canvas;

    return numEvents_AH120_upperLimit;
}
void ComputeUpperLimit(RooAbsData *data, RooStats::ModelConfig *model, float &UpperLimit, float &signif, RooRealVar *mu, RooArgSet *nullParams,RooWorkspace *ws,REGION region,const char* tag) {

  bool StoreEverything=false; // activate if you want to store frames and all
  
  RooStats::ProfileLikelihoodCalculator *plc = new RooStats::ProfileLikelihoodCalculator(*data, *model);
  plc->SetParameters(*mu);
  plc->SetNullParameters(*nullParams);
  plc->SetTestSize(0.05);
  RooStats::LikelihoodInterval *interval = plc->GetInterval();

  bool ComputationSuccessful=false;
  UpperLimit = interval->UpperLimit(*mu,ComputationSuccessful);
  signif = 0.0; // plc->GetHypoTest()->Significance();   // deactivated significance (to make algorithm faster)

  if(!ComputationSuccessful) {
    cout << "There seems to have been a problem. Returned upper limit is " << UpperLimit << " but it will be set to -999" << endl;
    UpperLimit=-999;
    signif=-999;
  }

  if(StoreEverything) {
    // Store it all
    RooRealVar* minv = (RooRealVar*)model->GetObservables()->first();
    minv->setBins(static_cast<int>((minv->getMax()-minv->getMin())/5.));

    RooPlot* frameEE = minv->frame(RooFit::Title("ee sample"));
    frameEE->GetXaxis()->CenterTitle(1);
    frameEE->GetYaxis()->CenterTitle(1);
    
    RooPlot* frameMM = minv->frame(RooFit::Title("mm sample"));
    frameMM->GetXaxis()->CenterTitle(1);
    frameMM->GetYaxis()->CenterTitle(1);
    
    RooPlot* frameOF = minv->frame(RooFit::Title("OF sample"));
    frameOF->GetXaxis()->CenterTitle(1);
    frameOF->GetYaxis()->CenterTitle(1);
    
    data->plotOn(frameMM,RooFit::Cut("catCentral==catCentral::MMCentral"));
    model->GetPdf()->plotOn(frameMM,RooFit::Slice(*ws->cat("catCentral"), "MMCentral"),RooFit::ProjWData(*data));
    
    data->plotOn(frameEE,RooFit::Cut("catCentral==catCentral::EECentral"));
    model->GetPdf()->plotOn(frameEE,RooFit::Slice(*ws->cat("catCentral"), "EECentral"),RooFit::ProjWData(*data));
    
    data->plotOn(frameOF,RooFit::Cut("catCentral==catCentral::OFOSCentral"));
    model->GetPdf()->plotOn(frameOF,RooFit::Slice(*ws->cat("catCentral"), "OFOSCentral"),RooFit::ProjWData(*data));
    
    TFile *fout = new TFile("fout.root","UPDATE");
    frameMM->Write(Concatenate(Concatenate(data->GetName(),"_MM"),tag),TObject::kOverwrite);
    frameEE->Write(Concatenate(Concatenate(data->GetName(),"_EE"),tag),TObject::kOverwrite);
    frameOF->Write(Concatenate(Concatenate(data->GetName(),"_OF"),tag),TObject::kOverwrite);
    fout->Close();
  }

  delete plc;
  plc=0;
}