53 RooAbsReal(
"RooBarlowBeestonLL",
"RooBarlowBeestonLL"),
57 _pdf(NULL), _data(NULL)
71 _nll(
"input",
"-log(L) function",this,nllIn),
74 _pdf(NULL), _data(NULL)
103 _nll(
"nll",this,other._nll),
106 _pdf(NULL), _data(NULL),
107 _paramFixed(other._paramFixed)
140 TIterator* iter = bin_center->createIterator() ;
156 std::cout <<
"Error: Must initialize data before initializing cache" << std::endl;
157 throw std::runtime_error(
"Uninitialized Data");
160 std::cout <<
"Error: Must initialize model pdf before initializing cache" << std::endl;
161 throw std::runtime_error(
"Uninitialized model pdf");
165 std::map< std::string, std::vector<double> > ChannelBinDataMap;
171 RooArgSet* obsSet = _pdf->getObservables(*_data);
174 if( obsTerms.
getSize() == 0 ) {
175 std::cout <<
"Error: Found no observable terms with pdf: " << _pdf->GetName()
176 <<
" using dataset: " << _data->GetName() << std::endl;
179 if( constraints.
getSize() == 0 ) {
180 std::cout <<
"Error: Found no constraint terms with pdf: " << _pdf->GetName()
181 <<
" using dataset: " << _data->GetName() << std::endl;
195 for (
const auto& nameIdx : *channelCat) {
200 std::string channel_name = channelPdf->
GetName();
206 if( ! hasStatUncert ) {
208 std::cout <<
"Channel: " << channel_name
209 <<
" doesn't have statistical uncertainties"
215 if(verbose) std::cout <<
"Found ParamHistFunc: " << param_func->
GetName() << std::endl;
222 int num_bins = param_func->
numBins();
227 std::vector<BarlowCache> temp_cache( num_bins );
228 bool channel_has_stat_uncertainty=
false;
230 for(
Int_t bin_index = 0; bin_index < num_bins; ++bin_index ) {
237 if(!gamma_stat)
throw std::runtime_error(
"ParamHistFunc contains non-RooRealVar, not supported in RooBarlowBeestonLL");
239 if(verbose) std::cout <<
"Ignoring constant gamma: " << gamma_stat->
GetName() << std::endl;
244 channel_has_stat_uncertainty=
true;
245 cache.
gamma = gamma_stat;
246 _statUncertParams.insert( gamma_stat->
GetName() );
263 if( !tau || !pois_mean ) {
264 std::cout <<
"Failed to find pois mean or tau parameter for " << gamma_stat->
GetName() << std::endl;
267 if(verbose) std::cout <<
"Found pois mean and tau for parameter: " << gamma_stat->
GetName()
269 <<
" pois_mean: " << pois_mean->
GetName() <<
" " << pois_mean->
getVal()
278 if( sum_pdf == NULL ) {
279 std::cout <<
"Failed to find RooRealSumPdf in channel " << channel_name
280 <<
", therefor skipping this channel for analytic uncertainty minimization"
282 channel_has_stat_uncertainty=
false;
288 if( ChannelBinDataMap.find(channel_name) == ChannelBinDataMap.end() ) {
289 std::cout <<
"Error: channel with name: " << channel_name
290 <<
" not found in BinDataMap" << std::endl;
291 throw runtime_error(
"BinDataMap");
293 double nData = ChannelBinDataMap[channel_name].at(bin_index);
296 temp_cache.at(bin_index) = cache;
301 if( channel_has_stat_uncertainty ) {
302 std::cout <<
"Adding channel: " << channel_name
303 <<
" to the barlow cache" << std::endl;
304 _barlowCache[channel_name] = temp_cache;
361 bool stripDisconnected)
const {
365 toRemove.
reserve( _statUncertParams.size());
367 for (
auto const& arg : outputSet) {
372 if( _statUncertParams.find(arg->GetName()) != _statUncertParams.end() ) {
373 toRemove.
add( *arg );
377 for(
auto& arg : toRemove) outputSet.
remove( *arg,
true );
379 return errorInBaseCall ||
false;
387const RooArgSet& RooStats::HistFactory::RooBarlowBeestonLL::bestFitParams() const
390 return _paramAbsMin ;
396const RooArgSet& RooStats::HistFactory::RooBarlowBeestonLL::bestFitObs() const
468 std::map< std::string, std::vector< BarlowCache > >::iterator iter_cache;
469 for( iter_cache = _barlowCache.begin(); iter_cache != _barlowCache.end(); ++iter_cache ) {
471 std::string channel_name = (*iter_cache).first;
472 std::vector< BarlowCache >& channel_cache = (*iter_cache).second;
487 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
493 std::vector< double > nu_b_vec( channel_cache.size() );
494 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
504 nu_b_vec.at(i) = nu_b;
509 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
515 std::vector< double > nu_b_stat_vec( channel_cache.size() );
516 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
525 double nu_b_stat = sum_pdf->
getVal(*obsSet)*sum_pdf->
expectedEvents(*obsSet)*binVolume - nu_b_vec.at(i);
526 nu_b_stat_vec.at(i) = nu_b_stat;
537 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
561 double nu_b = nu_b_vec.at(i);
562 double nu_b_stat = nu_b_stat_vec.at(i);
564 double tau_val = tau->
getVal();
565 double nData = bin_cache.
nData;
566 double m_val = pois_mean->
getVal();
569 double gamma_hat_hat = 1.0;
572 if(nu_b_stat > 0.00000001) {
574 double A = nu_b_stat*nu_b_stat + tau_val*nu_b_stat;
575 double B = nu_b*tau_val + nu_b*nu_b_stat - nData*nu_b_stat - m_val*nu_b_stat;
576 double C = -1*m_val*nu_b;
578 double discrim = B*B-4*A*C;
581 std::cout <<
"Warning: Discriminant (B*B - 4AC) < 0" << std::endl;
582 std::cout <<
"Warning: Taking B*B - 4*A*C == 0" << std::endl;
587 std::cout <<
"Warning: A <= 0" << std::endl;
588 throw runtime_error(
"BarlowBeestonLL::evaluate() : A < 0");
591 gamma_hat_hat = ( -1*B +
TMath::Sqrt(discrim) ) / (2*A);
597 gamma_hat_hat = m_val/tau_val;
602 std::cout <<
"ERROR: gamma hat hat is NAN" << std::endl;
603 throw runtime_error(
"BarlowBeestonLL::evaluate() : gamma hat hat is NAN");
606 if( gamma_hat_hat <= 0 ) {
607 std::cout <<
"WARNING: gamma hat hat <= 0. Setting to 0" << std::endl;
624 gamma->setVal( gamma_hat_hat );
654void RooStats::HistFactory::RooBarlowBeestonLL::validateAbsMin() const
656 // Check if constant status of any of the parameters have changed
660 while((par=(RooAbsArg*)_piter->Next())) {
661 if (_paramFixed[par->GetName()] != par->isConstant()) {
662 cxcoutI(Minimization) << "RooStats::HistFactory::RooBarlowBeestonLL::evaluate(" << GetName() << ") constant status of parameter " << par->GetName() << " has changed from "
663 << (_paramFixed[par->GetName()]?"fixed":"floating") << " to " << (par->isConstant()?"fixed":"floating")
664 << ", recalculating absolute minimum" << endl ;
665 _absMinValid = kFALSE ;
672 // If we don't have the absolute minimum w.r.t all observables, calculate that first
675 cxcoutI(Minimization) << "RooStats::HistFactory::RooBarlowBeestonLL::evaluate(" << GetName() << ") determining minimum likelihood for current configurations w.r.t all observable" << endl ;
678 // Save current values of non-marginalized parameters
679 RooArgSet* obsStart = (RooArgSet*) _obs.snapshot(kFALSE) ;
681 // Start from previous global minimum
682 if (_paramAbsMin.getSize()>0) {
683 const_cast<RooSetProxy&>(_par).assignValueOnly(_paramAbsMin) ;
685 if (_obsAbsMin.getSize()>0) {
686 const_cast<RooSetProxy&>(_obs).assignValueOnly(_obsAbsMin) ;
689 // Find minimum with all observables floating
690 const_cast<RooSetProxy&>(_obs).setAttribAll("Constant",kFALSE) ;
693 // Save value and remember
695 _absMinValid = kTRUE ;
697 // Save parameter values at abs minimum as well
698 _paramAbsMin.removeAll() ;
700 // Only store non-constant parameters here!
701 RooArgSet* tmp = (RooArgSet*) _par.selectByAttrib("Constant",kFALSE) ;
702 _paramAbsMin.addClone(*tmp) ;
705 _obsAbsMin.addClone(_obs) ;
707 // Save constant status of all parameters
710 while((par=(RooAbsArg*)_piter->Next())) {
711 _paramFixed[par->GetName()] = par->isConstant() ;
714 if (dologI(Minimization)) {
715 cxcoutI(Minimization) << "RooStats::HistFactory::RooBarlowBeestonLL::evaluate(" << GetName() << ") minimum found at (" ;
720 while ((arg=(RooAbsReal*)_oiter->Next())) {
721 ccxcoutI(Minimization) << (first?"":", ") << arg->GetName() << "=" << arg->getVal() ;
724 ccxcoutI(Minimization) << ")" << endl ;
727 // Restore original parameter values
728 const_cast<RooSetProxy&>(_obs) = *obsStart ;
A class which maps the current values of a RooRealVar (or a set of RooRealVars) to one of a number of...
const RooArgSet * get(Int_t masterIdx) const
RooAbsReal & getParameter() const
RooArgSet * getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
Bool_t isConstant() const
Check if the "Constant" attribute is set.
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
void reserve(Storage_t::size_type count)
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
virtual Double_t expectedEvents(const RooArgSet *nset) const
Return expected number of events to be used in calculation of extended likelihood.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
RooCategory is an object to represent discrete states.
RooRealVar represents a variable that can be changed from the outside.
virtual void setVal(Double_t value)
Set value of variable to 'value'.
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
const RooAbsCategoryLValue & indexCat() const
RooAbsPdf * getPdf(const char *catName) const
Return the p.d.f associated with the given index category name.
RooAbsReal * nom_pois_mean
void SetBinCenter() const
Class RooBarlowBeestonLL implements the profile likelihood estimator for a given likelihood and set o...
bool getParameters(const RooArgSet *depList, RooArgSet &outputSet, bool stripDisconnected=true) const
Fills a list with leaf nodes in the arg tree starting with ourself as top node that don't match any o...
Double_t evaluate() const
Optimized implementation of createProfile for profile likelihoods.
void initializeBarlowCache()
virtual bool redirectServersHook(const RooAbsCollection &, bool, bool, bool)
Function that is called at the end of redirectServers().
virtual ~RooBarlowBeestonLL()
Destructor.
Iterator abstract base class.
virtual TObject * Next()=0
virtual const char * GetName() const
Returns name of object.
bool getStatUncertaintyFromChannel(RooAbsPdf *channel, ParamHistFunc *¶mfunc, RooArgList *gammaList)
void FactorizeHistFactoryPdf(const RooArgSet &, RooAbsPdf &, RooArgList &, RooArgList &)
void getDataValuesForObservables(std::map< std::string, std::vector< double > > &ChannelBinDataMap, RooAbsData *data, RooAbsPdf *simPdf)
RooAbsPdf * getSumPdfFromChannel(RooAbsPdf *channel)
int getStatUncertaintyConstraintTerm(RooArgList *constraints, RooRealVar *gamma_stat, RooAbsReal *&pois_mean, RooRealVar *&tau)
Double_t Sqrt(Double_t x)