56 RooAbsReal(
"RooBarlowBeestonLL",
"RooBarlowBeestonLL"),
60 _pdf(NULL), _data(NULL)
74 _nll(
"input",
"-log(L) function",this,nllIn),
143 TIterator* iter = bin_center->createIterator() ;
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;
177 if( obsTerms.
getSize() == 0 ) {
178 std::cout <<
"Error: Found no observable terms with pdf: " <<
_pdf->
GetName()
182 if( constraints.
getSize() == 0 ) {
183 std::cout <<
"Error: Found no constraint terms with pdf: " <<
_pdf->
GetName()
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;
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;
380 std::string arg_name = arg->
GetName();
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;
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 ;
virtual const char * GetName() const
Returns name of object.
TIterator * createIterator(Bool_t dir=kIterForward) const
int getStatUncertaintyConstraintTerm(RooArgList *constraints, RooRealVar *gamma_stat, RooAbsReal *&pois_mean, RooRealVar *&tau)
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
void initializeBarlowCache()
Double_t getVal(const RooArgSet *set=0) const
bool getStatUncertaintyFromChannel(RooAbsPdf *channel, ParamHistFunc *¶mfunc, RooArgList *gammaList)
std::map< std::string, std::vector< BarlowCache > > _barlowCache
RooAbsReal * nom_pois_mean
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...
std::set< std::string > _statUncertParams
void SetBinCenter() const
Iterator abstract base class.
const RooArgSet * get(Int_t masterIdx) const
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t tau
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state...
virtual Double_t expectedEvents(const RooArgSet *nset) const
Return expected number of events from this p.d.f for use in extended likelihood calculations.
RooRealVar represents a fundamental (non-derived) real valued object.
virtual void setVal(Double_t value)
Set value of variable to 'value'.
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
TIterator * typeIterator() const
Return iterator over all defined states.
virtual const Text_t * GetName() const
Returns name of object.
const RooAbsCategoryLValue & indexCat() const
Double_t evaluate() const
Optimized implementation of createProfile for profile likelihoods.
void getDataValuesForObservables(std::map< std::string, std::vector< double > > &ChannelBinDataMap, RooAbsData *data, RooAbsPdf *simPdf)
RooCategory represents a fundamental (non-derived) discrete value object.
virtual ~RooBarlowBeestonLL()
Destructor.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
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...
std::map< std::string, bool > _paramFixed
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.
RooAbsPdf * getPdf(const char *catName) const
Return the p.d.f associated with the given index category name.
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
virtual TObject * Next()=0
RooRealVar & getParameter() const
Double_t Sqrt(Double_t x)
RooAbsPdf * getSumPdfFromChannel(RooAbsPdf *channel)
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset...
void FactorizeHistFactoryPdf(const RooArgSet &, RooAbsPdf &, RooArgList &, RooArgList &)
virtual Bool_t redirectServersHook(const RooAbsCollection &, Bool_t, Bool_t, Bool_t)
Bool_t isConstant() const