RooDLLSignificanceMCSModule.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooDLLSignificanceMCSModule.cxx 26174 2008-11-13 08:25:25Z wouter $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 
00017 //////////////////////////////////////////////////////////////////////////////
00018 // 
00019 // BEGIN_HTML
00020 // RooDLLSignificanceMCSModule is an add-on modules to RooMCStudy that
00021 // calculates the significance of a signal by comparing the likelihood of
00022 // a fit fit with a given parameter floating with a fit with that given
00023 // parameter fixed to a nominal value (usually zero). The difference in
00024 // the -log(L) of those two fits can be interpreted as the probability
00025 // that a statistical background fluctation may result in a signal as large
00026 // or larger than the signal observed. This interpretation is contingent
00027 // on underlying normal sampling distributions and a MC study is a good way
00028 // to test that assumption.
00029 // END_HTML
00030 //
00031 //
00032 
00033 #include "Riostream.h"
00034 
00035 #include "RooDataSet.h"
00036 #include "RooRealVar.h"
00037 #include "TString.h"
00038 #include "RooFit.h"
00039 #include "RooFitResult.h"
00040 #include "RooDLLSignificanceMCSModule.h"
00041 #include "RooMsgService.h"
00042 
00043 
00044 
00045 ClassImp(RooDLLSignificanceMCSModule)
00046   ;
00047 
00048 
00049 
00050 //_____________________________________________________________________________
00051 RooDLLSignificanceMCSModule::RooDLLSignificanceMCSModule(const RooRealVar& param, Double_t nullHypoValue) : 
00052   RooAbsMCStudyModule(Form("RooDLLSignificanceMCSModule_%s",param.GetName()),Form("RooDLLSignificanceMCSModule_%s",param.GetName())),
00053   _parName(param.GetName()), 
00054   _data(0), _nll0h(0), _dll0h(0), _sig0h(0), _nullValue(nullHypoValue)
00055 {
00056   // Constructor of module with parameter to be interpreted as nSignal and the value of the
00057   // null hypothesis for nSignal (usually zero)
00058 }
00059 
00060 
00061 
00062 //_____________________________________________________________________________
00063 RooDLLSignificanceMCSModule::RooDLLSignificanceMCSModule(const char* parName, Double_t nullHypoValue) :
00064   RooAbsMCStudyModule(Form("RooDLLSignificanceMCSModule_%s",parName),Form("RooDLLSignificanceMCSModule_%s",parName)),
00065   _parName(parName), 
00066   _data(0), _nll0h(0), _dll0h(0), _sig0h(0), _nullValue(nullHypoValue)
00067 {
00068   // Constructor of module with parameter name to be interpreted as nSignal and the value of the
00069   // null hypothesis for nSignal (usually zero)
00070 }
00071 
00072 
00073 
00074 //_____________________________________________________________________________
00075 RooDLLSignificanceMCSModule::RooDLLSignificanceMCSModule(const RooDLLSignificanceMCSModule& other) : 
00076   RooAbsMCStudyModule(other), 
00077   _parName(other._parName),
00078   _data(0), _nll0h(0), _dll0h(0), _sig0h(0), _nullValue(other._nullValue)
00079 {
00080   // Copy constructor
00081 }
00082 
00083 
00084 
00085 //_____________________________________________________________________________
00086 RooDLLSignificanceMCSModule:: ~RooDLLSignificanceMCSModule() 
00087 {
00088   // Destructor
00089 
00090   if (_nll0h) {
00091     delete _nll0h ;
00092   }    
00093   if (_dll0h) {
00094     delete _dll0h ;
00095   }    
00096   if (_sig0h) {
00097     delete _sig0h ;
00098   }
00099   if (_data) {
00100     delete _data ;
00101   }
00102 }
00103 
00104 
00105 
00106 //_____________________________________________________________________________
00107 Bool_t RooDLLSignificanceMCSModule::initializeInstance()
00108 {
00109   // Initialize module after attachment to RooMCStudy object
00110 
00111   // Check that parameter is also present in fit parameter list of RooMCStudy object
00112   if (!fitParams()->find(_parName.c_str())) {
00113     coutE(InputArguments) << "RooDLLSignificanceMCSModule::initializeInstance:: ERROR: No parameter named " << _parName << " in RooMCStudy!" << endl ;
00114     return kFALSE ;
00115   }
00116 
00117   // Construct variable that holds -log(L) fit with null hypothesis for given parameter
00118   TString nll0hName = Form("nll_nullhypo_%s",_parName.c_str()) ;
00119   TString nll0hTitle = Form("-log(L) with null hypothesis for param %s",_parName.c_str()) ;
00120   _nll0h = new RooRealVar(nll0hName.Data(),nll0hTitle.Data(),0) ;
00121 
00122   // Construct variable that holds -log(L) fit with null hypothesis for given parameter
00123   TString dll0hName = Form("dll_nullhypo_%s",_parName.c_str()) ;
00124   TString dll0hTitle = Form("-log(L) difference w.r.t null hypo for param %s",_parName.c_str()) ;
00125   _dll0h = new RooRealVar(dll0hName.Data(),dll0hTitle.Data(),0) ;
00126 
00127   // Construct variable that holds significance corresponding to delta(-log(L)) w.r.t to null hypothesis for given parameter
00128   TString sig0hName = Form("significance_nullhypo_%s",_parName.c_str()) ;
00129   TString sig0hTitle = Form("Gaussian signficiance of Delta(-log(L)) w.r.t null hypo for param %s",_parName.c_str()) ;
00130   _sig0h = new RooRealVar(sig0hName.Data(),sig0hTitle.Data(),-10,100) ;
00131 
00132   // Create new dataset to be merged with RooMCStudy::fitParDataSet
00133   _data = new RooDataSet("DeltaLLSigData","Additional data for Delta(-log(L)) study",RooArgSet(*_nll0h,*_dll0h,*_sig0h)) ;
00134 
00135   return kTRUE ;
00136 }
00137 
00138 
00139 
00140 //_____________________________________________________________________________
00141 Bool_t RooDLLSignificanceMCSModule::initializeRun(Int_t /*numSamples*/) 
00142 {
00143   // Initialize module at beginning of RooCMStudy run
00144 
00145   _data->reset() ;
00146   return kTRUE ;
00147 }
00148 
00149 
00150 
00151 //_____________________________________________________________________________
00152 RooDataSet* RooDLLSignificanceMCSModule::finalizeRun() 
00153 {
00154   // Return auxiliary dataset with results of delta(-log(L))
00155   // calculations of this module so that it is merged with
00156   // RooMCStudy::fitParDataSet() by RooMCStudy
00157 
00158   return _data ;
00159 }
00160 
00161 
00162 
00163 //_____________________________________________________________________________
00164 Bool_t RooDLLSignificanceMCSModule::processAfterFit(Int_t /*sampleNum*/)  
00165 {
00166   // Save likelihood from nominal fit, fix chosen parameter to its
00167   // null hypothesis value and rerun fit Save difference in likelihood
00168   // and associated Gaussian significance in auxilary dataset
00169 
00170   RooRealVar* par = static_cast<RooRealVar*>(fitParams()->find(_parName.c_str())) ;
00171   par->setVal(_nullValue) ;
00172   par->setConstant(kTRUE) ;
00173   RooFitResult* frnull = refit() ;
00174   par->setConstant(kFALSE) ;
00175   
00176   _nll0h->setVal(frnull->minNll()) ;
00177 
00178   Double_t deltaLL = (frnull->minNll() - nllVar()->getVal()) ;
00179   Double_t signif = deltaLL>0 ? sqrt(2*deltaLL) : -sqrt(-2*deltaLL) ;
00180   _sig0h->setVal(signif) ;
00181   _dll0h->setVal(deltaLL) ;
00182 
00183 
00184   _data->add(RooArgSet(*_nll0h,*_dll0h,*_sig0h)) ;
00185 
00186   delete frnull ;
00187 
00188   return kTRUE ;
00189 }

Generated on Tue Jul 5 15:06:28 2011 for ROOT_528-00b_version by  doxygen 1.5.1