<commit_before>// @(#)root/roostats:$Id: LikelihoodIntervalPlot.h 26427 2009-05-20 15:45:36Z pellicci $

/*************************************************************************
 * Project: RooStats                                                     *
 * Package: RooFit/RooStats                                              *
 * Authors:                                                              *
 *   <NAME>, <NAME>, <NAME>, <NAME>       *
 *************************************************************************
 * Copyright (C) 1995-2008, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//____________________________________________________________________
/*
LikelihoodIntervalPlot : 

This class provides simple and straightforward utilities to plot a LikelihoodInterval
object.
*/

#include "RooStats/LikelihoodIntervalPlot.h"

#include <algorithm>
#include <iostream>

#include "TROOT.h"
#include "TMath.h"
#include "TLine.h"
#include "TObjArray.h"
#include "TList.h"
#include "TGraph.h"
#include "TPad.h"

#include "RooRealVar.h"
#include "RooPlot.h"

/// ClassImp for building the THtml documentation of the class 
ClassImp(RooStats::LikelihoodIntervalPlot);

using namespace RooStats;

//_______________________________________________________
LikelihoodIntervalPlot::LikelihoodIntervalPlot()
{
  // LikelihoodIntervalPlot default constructor
  fInterval = 0;
  fNdimPlot = 0;
  fParamsPlot = 0;
  fColor = 0;
  fFillStyle = 4050; // half transparent
  fLineColor = 0;
  fMaximum = 2.;
}

//_______________________________________________________
LikelihoodIntervalPlot::LikelihoodIntervalPlot(LikelihoodInterval* theInterval)
{
  // LikelihoodIntervalPlot constructor
  fInterval = theInterval;
  fParamsPlot = fInterval->GetParameters();
  fNdimPlot = fParamsPlot->getSize();
  fColor = kBlue;
  fLineColor = kGreen;
  fFillStyle = 4050; // half transparent
  fMaximum = 2.;
}

//_______________________________________________________
LikelihoodIntervalPlot::~LikelihoodIntervalPlot()
{
  // LikelihoodIntervalPlot destructor
}

//_____________________________________________________________________________
void LikelihoodIntervalPlot::SetLikelihoodInterval(LikelihoodInterval* theInterval)
{
  fInterval = theInterval;
  fParamsPlot = fInterval->GetParameters();
  fNdimPlot = fParamsPlot->getSize();

  return;
}

//_____________________________________________________________________________
void LikelihoodIntervalPlot::SetPlotParameters(const RooArgSet *params) 
{
  fNdimPlot = params->getSize();
  fParamsPlot = (RooArgSet*) params->clone((std::string(params->GetName())+"_clone").c_str());

  return;
}

//_____________________________________________________________________________
void LikelihoodIntervalPlot::Draw(const Option_t *options) 
{

  if(fNdimPlot > 2){
    std::cout << "LikelihoodIntervalPlot::Draw(" << GetName() 
	      << ") ERROR: contours for more than 2 dimensions not implemented!" << std::endl;
    return;
  }

  TIter it = fParamsPlot->createIterator();
  RooRealVar *myparam = (RooRealVar*)it.Next();


  //  RooAbsReal* newProfile = fInterval->GetLikelihoodRatio()->createProfile(*fParamsPlot);
  RooAbsReal* newProfile = fInterval->GetLikelihoodRatio(); 

  if(fNdimPlot == 1){

    const Double_t xcont_min = fInterval->LowerLimit(*myparam);
    const Double_t xcont_max = fInterval->UpperLimit(*myparam);

    RooRealVar* myarg = (RooRealVar *) newProfile->getVariables()->find(myparam->GetName());

    RooPlot *frame = myarg->frame();
    frame->SetTitle(GetTitle());
    frame->GetYaxis()->SetTitle("- log #lambda");
    //    frame->GetYaxis()->SetTitle("- log profile likelihood ratio");

    newProfile->plotOn(frame); 

    frame->SetMaximum(fMaximum);
    frame->SetMinimum(0.);

    // Double_t debug_var= newProfile->getVal();
    myarg->setVal(xcont_min);
    //const Double_t Yat_Xmin = newProfile->getVal();

    myarg->setVal(xcont_max);
    const Double_t Yat_Xmax = newProfile->getVal();

    TLine *Yline_cutoff = new TLine(myarg->getMin(),Yat_Xmax,myarg->getMax(),Yat_Xmax);
    TLine *Yline_min = new TLine(xcont_min,0.,xcont_min,Yat_Xmax);
    TLine *Yline_max = new TLine(xcont_max,0.,xcont_max,Yat_Xmax);

    //std::cout <<"debug " << xcont_min << "   " << xcont_max << "   "
    //<< Yat_Xmin << "   "  << Yat_Xmax << std::endl;

    Yline_cutoff->SetLineColor(fLineColor);
    Yline_min->SetLineColor(fLineColor);
    Yline_max->SetLineColor(fLineColor);

    frame->addObject(Yline_cutoff);
    frame->addObject(Yline_min);
    frame->addObject(Yline_max);

    frame->Draw(options);

    return;
  }
  else if(fNdimPlot == 2){<commit_msg>fix Profile likelihood plot by using a TF1 for drawing a profileLL<commit_after>// @(#)root/roostats:$Id: LikelihoodIntervalPlot.h 26427 2009-05-20 15:45:36Z pellicci $

/*************************************************************************
 * Project: RooStats                                                     *
 * Package: RooFit/RooStats                                              *
 * Authors:                                                              *
 *   <NAME>, <NAME>, <NAME>, <NAME>       *
 *************************************************************************
 * Copyright (C) 1995-2008, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//____________________________________________________________________
/*
LikelihoodIntervalPlot : 

This class provides simple and straightforward utilities to plot a LikelihoodInterval
object.
*/

#include "RooStats/LikelihoodIntervalPlot.h"

#include <algorithm>
#include <iostream>

#include "TROOT.h"
#include "TMath.h"
#include "TLine.h"
#include "TObjArray.h"
#include "TList.h"
#include "TGraph.h"
#include "TPad.h"

#include "RooRealVar.h"
#include "RooPlot.h"
//#include "RooProfileLL.h"
#include "TF1.h"

/// ClassImp for building the THtml documentation of the class 
ClassImp(RooStats::LikelihoodIntervalPlot);

using namespace RooStats;

//_______________________________________________________
LikelihoodIntervalPlot::LikelihoodIntervalPlot()
{
  // LikelihoodIntervalPlot default constructor
  fInterval = 0;
  fNdimPlot = 0;
  fParamsPlot = 0;
  fColor = 0;
  fFillStyle = 4050; // half transparent
  fLineColor = 0;
  fMaximum = 2.;
}

//_______________________________________________________
LikelihoodIntervalPlot::LikelihoodIntervalPlot(LikelihoodInterval* theInterval)
{
  // LikelihoodIntervalPlot constructor
  fInterval = theInterval;
  fParamsPlot = fInterval->GetParameters();
  fNdimPlot = fParamsPlot->getSize();
  fColor = kBlue;
  fLineColor = kGreen;
  fFillStyle = 4050; // half transparent
  fMaximum = 2.;
}

//_______________________________________________________
LikelihoodIntervalPlot::~LikelihoodIntervalPlot()
{
  // LikelihoodIntervalPlot destructor
}

//_____________________________________________________________________________
void LikelihoodIntervalPlot::SetLikelihoodInterval(LikelihoodInterval* theInterval)
{
  fInterval = theInterval;
  fParamsPlot = fInterval->GetParameters();
  fNdimPlot = fParamsPlot->getSize();

  return;
}

//_____________________________________________________________________________
void LikelihoodIntervalPlot::SetPlotParameters(const RooArgSet *params) 
{
  fNdimPlot = params->getSize();
  fParamsPlot = (RooArgSet*) params->clone((std::string(params->GetName())+"_clone").c_str());

  return;
}

//_____________________________________________________________________________
void LikelihoodIntervalPlot::Draw(const Option_t *options) 
{

  if(fNdimPlot > 2){
    std::cout << "LikelihoodIntervalPlot::Draw(" << GetName() 
	      << ") ERROR: contours for more than 2 dimensions not implemented!" << std::endl;
    return;
  }

  TIter it = fParamsPlot->createIterator();
  RooRealVar *myparam = (RooRealVar*)it.Next();


  //  RooAbsReal* newProfile = fInterval->GetLikelihoodRatio()->createProfile(*fParamsPlot);
  RooAbsReal* newProfile = fInterval->GetLikelihoodRatio(); 

  if(fNdimPlot == 1){


//      RooArgList fittedParams(((RooProfileLL*) newProfile)->bestFitParams());

     const Double_t xcont_min = fInterval->LowerLimit(*myparam);
     const Double_t xcont_max = fInterval->UpperLimit(*myparam);

//      std::cout << "BEST FIT PARAMETERS = " << std::endl;
//      for (int i = 0; i < fittedParams.getSize(); ++i) 
//         fittedParams[i].Print(); 

    RooRealVar* myarg = (RooRealVar *) newProfile->getVariables()->find(myparam->GetName());
    //myarg->Print(); 

//     myarg->setVal(xcont_min); 
//     std::cout << " Profile for x = " << xcont_min << " PLL = " << newProfile->getVal() << std::endl;
//     myarg->setVal(xcont_max); 
//     std::cout << " Profile for x = " << xcont_max << " PLL = " << newProfile->getVal() << std::endl;


//     RooPlot *frame = myarg->frame();
//     frame->SetTitle(GetTitle());
//     frame->GetYaxis()->SetTitle("- log #lambda");
//     //    frame->GetYaxis()->SetTitle("- log profile likelihood ratio");

//     newProfile->plotOn(frame); 


//     frame->SetMaximum(fMaximum);
//     frame->SetMinimum(0.);



     TF1 * f1 = newProfile->asTF(*myarg); 
     f1->SetTitle("- log profile likelihood ratio");
     TString name = TString(GetName()) + TString("_PLL_") + TString(myarg->GetName());
     f1->SetName(name);

     // set range for value of fMaximum
     // use a clone function which is sampled to avoid many profilell evaluations
     TF1 * tmp = (TF1*) f1->Clone(); 
     double x0 = tmp->GetX(0, myarg->getMin(), myarg->getMax()); 
     double x1 = tmp->GetX(fMaximum, myarg->getMin(), x0); 
     double x2 = tmp->GetX(fMaximum, x0, myarg->getMax()); 
     delete tmp;

     f1->SetMaximum(fMaximum);
     f1->SetRange(x1,x2);


     f1->SetLineColor(kBlue);
     f1->GetXaxis()->SetTitle(myarg->GetName());
     f1->GetYaxis()->SetTitle("- log #lambda");
     f1->Draw();
//     frame->addObject(f1);

    //f1->Draw("SAME");

    // Double_t debug_var= newProfile->getVal();
//     myarg->setVal(xcont_min);
//     const Double_t Yat_Xmin = newProfile->getVal();

    myarg->setVal(xcont_max);
    const Double_t Yat_Xmax = newProfile->getVal();

    TLine *Yline_cutoff = new TLine(x1,Yat_Xmax,x2,Yat_Xmax);
    TLine *Yline_min = new TLine(xcont_min,0.,xcont_min,Yat_Xmax);
    TLine *Yline_max = new TLine(xcont_max,0.,xcont_max,Yat_Xmax);

    //std::cout <<"debug " << xcont_min << "   " << xcont_max << "   "
    //<< Yat_Xmin << "   "  << Yat_Xmax << std::endl;

    Yline_cutoff->SetLineColor(fLineColor);
    Yline_min->SetLineColor(fLineColor);
    Yline_max->SetLineColor(fLineColor);

    Yline_cutoff->Draw();
    Yline_min->Draw();
    Yline_max->Draw();


//     frame->addObject(Yline_cutoff);
//     frame->addObject(Yline_min);
//     frame->addObject(Yline_max);


//     frame->Draw(options);

    return;
  }
  else if(fNdimPlot == 2){
{'fraction_non_alphanumeric': 0.16730169726359542, 'fraction_numerical': 0.01091098025632144, 'mean_word_length': 3.455632716049383, 'pattern_counts': {'":': 0, '<': 96, '<?xml version=': 0, '>': 129, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5317014', 'n_tokens_mistral': 3622, 'n_tokens_neox': 3344, 'n_words': 625}