55 RooStats::HistFactory::RooBarlowBeestonLL::RooBarlowBeestonLL() :
56 RooAbsReal("RooBarlowBeestonLL","RooBarlowBeestonLL"),
60 _pdf(
NULL), _data(NULL)
74 _nll(
"input",
"-log(L) function",this,nllIn),
106 _nll(
"nll",this,other._nll),
110 _paramFixed(other._paramFixed)
159 std::cout <<
"Error: Must initialize data before initializing cache" << std::endl;
160 throw std::runtime_error(
"Uninitialized Data");
163 std::cout <<
"Error: Must initialize model pdf before initializing cache" << std::endl;
164 throw std::runtime_error(
"Uninitialized model pdf");
168 std::map< std::string, std::vector<double> > ChannelBinDataMap;
174 RooArgSet* obsSet = _pdf->getObservables(*_data);
177 if( obsTerms.
getSize() == 0 ) {
178 std::cout <<
"Error: Found no observable terms with pdf: " << _pdf->GetName()
179 <<
" using dataset: " << _data->GetName() << std::endl;
182 if( constraints.
getSize() == 0 ) {
183 std::cout <<
"Error: Found no constraint terms with pdf: " << _pdf->GetName()
184 <<
" using dataset: " << _data->GetName() << std::endl;
216 std::string channel_name = channelPdf->
GetName();
222 if( ! hasStatUncert ) {
224 std::cout <<
"Channel: " << channel_name
225 <<
" doesn't have statistical uncertainties"
231 if(verbose) std::cout <<
"Found ParamHistFunc: " << param_func->
GetName() << std::endl;
238 int num_bins = param_func->
numBins();
243 std::vector<BarlowCache> temp_cache( num_bins );
244 bool channel_has_stat_uncertainty=
false;
246 for(
Int_t bin_index = 0; bin_index < num_bins; ++bin_index ) {
254 if(verbose) std::cout <<
"Ignoring constant gamma: " << gamma_stat->
GetName() << std::endl;
259 channel_has_stat_uncertainty=
true;
260 cache.
gamma = gamma_stat;
261 _statUncertParams.insert( gamma_stat->
GetName() );
278 if( !tau || !pois_mean ) {
279 std::cout <<
"Failed to find pois mean or tau parameter for " << gamma_stat->
GetName() << std::endl;
282 if(verbose) std::cout <<
"Found pois mean and tau for parameter: " << gamma_stat->
GetName()
284 <<
" pois_mean: " << pois_mean->
GetName() <<
" " << pois_mean->
getVal()
293 if( sum_pdf ==
NULL ) {
294 std::cout <<
"Failed to find RooRealSumPdf in channel " << channel_name
295 <<
", therefor skipping this channel for analytic uncertainty minimization"
297 channel_has_stat_uncertainty=
false;
303 if( ChannelBinDataMap.find(channel_name) == ChannelBinDataMap.end() ) {
304 std::cout <<
"Error: channel with name: " << channel_name
305 <<
" not found in BinDataMap" << std::endl;
306 throw runtime_error(
"BinDataMap");
308 double nData = ChannelBinDataMap[channel_name].at(bin_index);
311 temp_cache.at(bin_index) = cache;
316 if( channel_has_stat_uncertainty ) {
317 std::cout <<
"Adding channel: " << channel_name
318 <<
" to the barlow cache" << std::endl;
319 _barlowCache[channel_name] = temp_cache;
380 std::string arg_name = arg->
GetName();
385 if( _statUncertParams.find(arg_name.c_str()) != _statUncertParams.end() ) {
399 const RooArgSet& RooStats::HistFactory::RooBarlowBeestonLL::bestFitParams() const
402 return _paramAbsMin ;
408 const RooArgSet& RooStats::HistFactory::RooBarlowBeestonLL::bestFitObs() const
480 std::map< std::string, std::vector< BarlowCache > >::iterator iter_cache;
481 for( iter_cache = _barlowCache.begin(); iter_cache != _barlowCache.end(); ++iter_cache ) {
483 std::string channel_name = (*iter_cache).first;
484 std::vector< BarlowCache >& channel_cache = (*iter_cache).second;
499 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
505 std::vector< double > nu_b_vec( channel_cache.size() );
506 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
516 nu_b_vec.at(i) = nu_b;
521 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
527 std::vector< double > nu_b_stat_vec( channel_cache.size() );
528 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
537 double nu_b_stat = sum_pdf->
getVal(*obsSet)*sum_pdf->
expectedEvents(*obsSet)*binVolume - nu_b_vec.at(i);
538 nu_b_stat_vec.at(i) = nu_b_stat;
549 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
573 double nu_b = nu_b_vec.at(i);
574 double nu_b_stat = nu_b_stat_vec.at(i);
576 double tau_val = tau->
getVal();
577 double nData = bin_cache.
nData;
578 double m_val = pois_mean->
getVal();
581 double gamma_hat_hat = 1.0;
584 if(nu_b_stat > 0.00000001) {
586 double A = nu_b_stat*nu_b_stat + tau_val*nu_b_stat;
587 double B = nu_b*tau_val + nu_b*nu_b_stat - nData*nu_b_stat - m_val*nu_b_stat;
588 double C = -1*m_val*nu_b;
590 double discrim = B*B-4*A*
C;
593 std::cout <<
"Warning: Discriminant (B*B - 4AC) < 0" << std::endl;
594 std::cout <<
"Warning: Taking B*B - 4*A*C == 0" << std::endl;
599 std::cout <<
"Warning: A <= 0" << std::endl;
600 throw runtime_error(
"BarlowBeestonLL::evaluate() : A < 0");
603 gamma_hat_hat = ( -1*B +
TMath::Sqrt(discrim) ) / (2*A);
609 gamma_hat_hat = m_val/tau_val;
614 std::cout <<
"ERROR: gamma hat hat is NAN" << std::endl;
615 throw runtime_error(
"BarlowBeestonLL::evaluate() : gamma hat hat is NAN");
618 if( gamma_hat_hat <= 0 ) {
619 std::cout <<
"WARNING: gamma hat hat <= 0. Setting to 0" << std::endl;
636 gamma->
setVal( gamma_hat_hat );
666 void RooStats::HistFactory::RooBarlowBeestonLL::validateAbsMin() const
668 // Check if constant status of any of the parameters have changed
672 while((par=(RooAbsArg*)_piter->Next())) {
673 if (_paramFixed[par->GetName()] != par->isConstant()) {
674 cxcoutI(Minimization) << "RooStats::HistFactory::RooBarlowBeestonLL::evaluate(" << GetName() << ") constant status of parameter " << par->GetName() << " has changed from "
675 << (_paramFixed[par->GetName()]?"fixed":"floating") << " to " << (par->isConstant()?"fixed":"floating")
676 << ", recalculating absolute minimum" << endl ;
677 _absMinValid = kFALSE ;
684 // If we don't have the absolute minimum w.r.t all observables, calculate that first
687 cxcoutI(Minimization) << "RooStats::HistFactory::RooBarlowBeestonLL::evaluate(" << GetName() << ") determining minimum likelihood for current configurations w.r.t all observable" << endl ;
690 // Save current values of non-marginalized parameters
691 RooArgSet* obsStart = (RooArgSet*) _obs.snapshot(kFALSE) ;
693 // Start from previous global minimum
694 if (_paramAbsMin.getSize()>0) {
695 const_cast<RooSetProxy&>(_par).assignValueOnly(_paramAbsMin) ;
697 if (_obsAbsMin.getSize()>0) {
698 const_cast<RooSetProxy&>(_obs).assignValueOnly(_obsAbsMin) ;
701 // Find minimum with all observables floating
702 const_cast<RooSetProxy&>(_obs).setAttribAll("Constant",kFALSE) ;
705 // Save value and remember
707 _absMinValid = kTRUE ;
709 // Save parameter values at abs minimum as well
710 _paramAbsMin.removeAll() ;
712 // Only store non-constant parameters here!
713 RooArgSet* tmp = (RooArgSet*) _par.selectByAttrib("Constant",kFALSE) ;
714 _paramAbsMin.addClone(*tmp) ;
717 _obsAbsMin.addClone(_obs) ;
719 // Save constant status of all parameters
722 while((par=(RooAbsArg*)_piter->Next())) {
723 _paramFixed[par->GetName()] = par->isConstant() ;
726 if (dologI(Minimization)) {
727 cxcoutI(Minimization) << "RooStats::HistFactory::RooBarlowBeestonLL::evaluate(" << GetName() << ") minimum found at (" ;
732 while ((arg=(RooAbsReal*)_oiter->Next())) {
733 ccxcoutI(Minimization) << (first?"":", ") << arg->GetName() << "=" << arg->getVal() ;
736 ccxcoutI(Minimization) << ")" << endl ;
739 // Restore original parameter values
740 const_cast<RooSetProxy&>(_obs) = *obsStart ;
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
int getStatUncertaintyConstraintTerm(RooArgList *constraints, RooRealVar *gamma_stat, RooAbsReal *&pois_mean, RooRealVar *&tau)
void initializeBarlowCache()
bool getStatUncertaintyFromChannel(RooAbsPdf *channel, ParamHistFunc *¶mfunc, RooArgList *gammaList)
const RooAbsCategoryLValue & indexCat() const
RooAbsReal * nom_pois_mean
void SetBinCenter() const
RooAbsPdf * getPdf(const char *catName) const
Return the p.d.f associated with the given index category name.
virtual Double_t expectedEvents(const RooArgSet *nset) const
Return expected number of events from this p.d.f for use in extended likelihood calculations.
Iterator abstract base class.
std::map< std::string, std::string >::const_iterator iter
RooArgSet * getParameters(const RooArgSet *depList, Bool_t stripDisconnected=kTRUE) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
TIterator * createIterator(Bool_t dir=kIterForward) const
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state...
Double_t getVal(const RooArgSet *set=0) const
RooArgSet * getParameters(const RooAbsData *data, Bool_t stripDisconnected=kTRUE) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
RooRealVar represents a fundamental (non-derived) real valued object.
virtual void setVal(Double_t value)
Set value of variable to 'value'.
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
ClassImp(RooStats::HistFactory::RooBarlowBeestonLL) RooStats
void getDataValuesForObservables(std::map< std::string, std::vector< double > > &ChannelBinDataMap, RooAbsData *data, RooAbsPdf *simPdf)
virtual const char * GetName() const
Returns name of object.
RooCategory represents a fundamental (non-derived) discrete value object.
Bool_t isConstant() const
virtual ~RooBarlowBeestonLL()
Destructor.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects...
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
const RooArgSet * get(Int_t masterIdx) const
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
virtual TObject * Next()=0
Double_t Sqrt(Double_t x)
RooAbsPdf * getSumPdfFromChannel(RooAbsPdf *channel)
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset...
RooRealVar & getParameter() const
virtual const Text_t * GetName() const
Returns name of object.
void FactorizeHistFactoryPdf(const RooArgSet &, RooAbsPdf &, RooArgList &, RooArgList &)
TIterator * typeIterator() const
Return iterator over all defined states.
virtual Bool_t redirectServersHook(const RooAbsCollection &, Bool_t, Bool_t, Bool_t)
Double_t evaluate() const
Optimized implementation of createProfile for profile likelihoods.