#include "RooDataSet.h"
#include "RooRealVar.h"
#include "TString.h"
#include "RooFit.h"
#include "RooFitResult.h"
#include "RooDLLSignificanceMCSModule.h"
ClassImp(RooDLLSignificanceMCSModule)
  ;
RooDLLSignificanceMCSModule::RooDLLSignificanceMCSModule(const RooRealVar& param, Double_t nullHypoValue) : 
  RooAbsMCStudyModule(Form("RooDLLSignificanceMCSModule_%s",param.GetName()),Form("RooDLLSignificanceMCSModule_%s",param.GetName())),
  _parName(param.GetName()), 
  _data(0), _nll0h(0), _sig0h(0), _nullValue(nullHypoValue)
{
}
RooDLLSignificanceMCSModule::RooDLLSignificanceMCSModule(const char* parName, Double_t nullHypoValue) :
  RooAbsMCStudyModule(Form("RooDLLSignificanceMCSModule_%s",parName),Form("RooDLLSignificanceMCSModule_%s",parName)),
  _parName(parName), 
  _data(0), _nll0h(0), _sig0h(0), _nullValue(nullHypoValue)
{
}
RooDLLSignificanceMCSModule::RooDLLSignificanceMCSModule(const RooDLLSignificanceMCSModule& other) : 
  RooAbsMCStudyModule(other), 
  _parName(other._parName),
  _data(0), _nll0h(0), _sig0h(0), _nullValue(other._nullValue)
{
}
RooDLLSignificanceMCSModule:: ~RooDLLSignificanceMCSModule() 
{
  if (_nll0h) {
    delete _nll0h ;
  }    
  if (_sig0h) {
    delete _sig0h ;
  }
  if (_data) {
    delete _data ;
  }
}
Bool_t RooDLLSignificanceMCSModule::initializeInstance()
{
  
  
  if (!fitParams()->find(_parName.c_str())) {
    cout << "RooDLLSignificanceMCSModule::initializeInstance:: ERROR: No parameter named " << _parName << " in RooMCStudy!" << endl ;
    return kFALSE ;
  }
  
  TString nll0hName = Form("nll_nullhypo_%s",_parName.c_str()) ;
  TString nll0hTitle = Form("-log(L) with null hypothesis for parameter %s",_parName.c_str()) ;
  _nll0h = new RooRealVar(nll0hName.Data(),nll0hTitle.Data(),0) ;
  
  TString dll0hName = Form("dll_nullhypo_%s",_parName.c_str()) ;
  TString dll0hTitle = Form("-log(L) different w.r.t null hypothesis for parameter %s",_parName.c_str()) ;
  _dll0h = new RooRealVar(dll0hName.Data(),dll0hTitle.Data(),0) ;
  
  TString sig0hName = Form("significance_nullhypo_%s",_parName.c_str()) ;
  TString sig0hTitle = Form("Gaussian signficiance of Delta(-log(L)) w.r.t null hypothesis for parameter %s",_parName.c_str()) ;
  _sig0h = new RooRealVar(sig0hName.Data(),sig0hTitle.Data(),-10,100) ;
  
  _data = new RooDataSet("DeltaLLSigData","Additional data for Delta(-log(L)) study",RooArgSet(*_nll0h,*_dll0h,*_sig0h)) ;
  return kTRUE ;
}
Bool_t RooDLLSignificanceMCSModule::initializeRun(Int_t ) 
{
  
  _data->reset() ;
  return kTRUE ;
}
RooDataSet* RooDLLSignificanceMCSModule::finalizeRun() 
{
  
  return _data ;
}
Bool_t RooDLLSignificanceMCSModule::processAfterFit(Int_t )  
{
  
  
  RooRealVar* par = static_cast<RooRealVar*>(fitParams()->find(_parName.c_str())) ;
  par->setVal(_nullValue) ;
  par->setConstant(kTRUE) ;
  RooFitResult* frnull = refit() ;
  par->setConstant(kFALSE) ;
  
  _nll0h->setVal(frnull->minNll()) ;
  Double_t deltaLL = (frnull->minNll() - nllVar()->getVal()) ;
  Double_t signif = deltaLL>0 ? sqrt(2*deltaLL) : -sqrt(-2*deltaLL) ;
  _sig0h->setVal(signif) ;
  _dll0h->setVal(deltaLL) ;
  _data->add(RooArgSet(*_nll0h,*_dll0h,*_sig0h)) ;
  delete frnull ;
  return kTRUE ;
}
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.