54 RooAbsReal(
"RooBarlowBeestonLL",
"RooBarlowBeestonLL"),
58 _pdf(NULL), _data(NULL)
72 _nll(
"input",
"-log(L) function",this,nllIn),
75 _pdf(NULL), _data(NULL)
104 _nll(
"nll",this,other._nll),
107 _pdf(NULL), _data(NULL),
108 _paramFixed(other._paramFixed)
141 TIterator* iter = bin_center->createIterator() ;
157 std::cout <<
"Error: Must initialize data before initializing cache" << std::endl;
158 throw std::runtime_error(
"Uninitialized Data");
161 std::cout <<
"Error: Must initialize model pdf before initializing cache" << std::endl;
162 throw std::runtime_error(
"Uninitialized model pdf");
166 std::map< std::string, std::vector<double> > ChannelBinDataMap;
172 RooArgSet* obsSet = _pdf->getObservables(*_data);
175 if( obsTerms.
getSize() == 0 ) {
176 std::cout <<
"Error: Found no observable terms with pdf: " << _pdf->GetName()
177 <<
" using dataset: " << _data->GetName() << std::endl;
180 if( constraints.
getSize() == 0 ) {
181 std::cout <<
"Error: Found no constraint terms with pdf: " << _pdf->GetName()
182 <<
" using dataset: " << _data->GetName() << std::endl;
196 for (
const auto& nameIdx : *channelCat) {
201 std::string channel_name = channelPdf->
GetName();
207 if( ! hasStatUncert ) {
209 std::cout <<
"Channel: " << channel_name
210 <<
" doesn't have statistical uncertainties"
216 if(verbose) std::cout <<
"Found ParamHistFunc: " << param_func->
GetName() << std::endl;
223 int num_bins = param_func->
numBins();
228 std::vector<BarlowCache> temp_cache( num_bins );
229 bool channel_has_stat_uncertainty=
false;
231 for(
Int_t bin_index = 0; bin_index < num_bins; ++bin_index ) {
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 {
364 for (
auto const& arg : outputSet) {
369 if( _statUncertParams.find(arg->GetName()) != _statUncertParams.end() ) {
370 outputSet.
remove( *arg,
true );
375 return errorInBaseCall ||
false;
383const RooArgSet& RooStats::HistFactory::RooBarlowBeestonLL::bestFitParams() const
386 return _paramAbsMin ;
392const RooArgSet& RooStats::HistFactory::RooBarlowBeestonLL::bestFitObs() const
464 std::map< std::string, std::vector< BarlowCache > >::iterator iter_cache;
465 for( iter_cache = _barlowCache.begin(); iter_cache != _barlowCache.end(); ++iter_cache ) {
467 std::string channel_name = (*iter_cache).first;
468 std::vector< BarlowCache >& channel_cache = (*iter_cache).second;
483 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
489 std::vector< double > nu_b_vec( channel_cache.size() );
490 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
500 nu_b_vec.at(i) = nu_b;
505 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
511 std::vector< double > nu_b_stat_vec( channel_cache.size() );
512 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
521 double nu_b_stat = sum_pdf->
getVal(*obsSet)*sum_pdf->
expectedEvents(*obsSet)*binVolume - nu_b_vec.at(i);
522 nu_b_stat_vec.at(i) = nu_b_stat;
533 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
557 double nu_b = nu_b_vec.at(i);
558 double nu_b_stat = nu_b_stat_vec.at(i);
560 double tau_val = tau->
getVal();
561 double nData = bin_cache.
nData;
562 double m_val = pois_mean->
getVal();
565 double gamma_hat_hat = 1.0;
568 if(nu_b_stat > 0.00000001) {
570 double A = nu_b_stat*nu_b_stat + tau_val*nu_b_stat;
571 double B = nu_b*tau_val + nu_b*nu_b_stat - nData*nu_b_stat - m_val*nu_b_stat;
572 double C = -1*m_val*nu_b;
574 double discrim = B*B-4*A*C;
577 std::cout <<
"Warning: Discriminant (B*B - 4AC) < 0" << std::endl;
578 std::cout <<
"Warning: Taking B*B - 4*A*C == 0" << std::endl;
583 std::cout <<
"Warning: A <= 0" << std::endl;
584 throw runtime_error(
"BarlowBeestonLL::evaluate() : A < 0");
587 gamma_hat_hat = ( -1*B +
TMath::Sqrt(discrim) ) / (2*A);
593 gamma_hat_hat = m_val/tau_val;
598 std::cout <<
"ERROR: gamma hat hat is NAN" << std::endl;
599 throw runtime_error(
"BarlowBeestonLL::evaluate() : gamma hat hat is NAN");
602 if( gamma_hat_hat <= 0 ) {
603 std::cout <<
"WARNING: gamma hat hat <= 0. Setting to 0" << std::endl;
620 gamma->setVal( gamma_hat_hat );
650void RooStats::HistFactory::RooBarlowBeestonLL::validateAbsMin() const
652 // Check if constant status of any of the parameters have changed
656 while((par=(RooAbsArg*)_piter->Next())) {
657 if (_paramFixed[par->GetName()] != par->isConstant()) {
658 cxcoutI(Minimization) << "RooStats::HistFactory::RooBarlowBeestonLL::evaluate(" << GetName() << ") constant status of parameter " << par->GetName() << " has changed from "
659 << (_paramFixed[par->GetName()]?"fixed":"floating") << " to " << (par->isConstant()?"fixed":"floating")
660 << ", recalculating absolute minimum" << endl ;
661 _absMinValid = kFALSE ;
668 // If we don't have the absolute minimum w.r.t all observables, calculate that first
671 cxcoutI(Minimization) << "RooStats::HistFactory::RooBarlowBeestonLL::evaluate(" << GetName() << ") determining minimum likelihood for current configurations w.r.t all observable" << endl ;
674 // Save current values of non-marginalized parameters
675 RooArgSet* obsStart = (RooArgSet*) _obs.snapshot(kFALSE) ;
677 // Start from previous global minimum
678 if (_paramAbsMin.getSize()>0) {
679 const_cast<RooSetProxy&>(_par).assignValueOnly(_paramAbsMin) ;
681 if (_obsAbsMin.getSize()>0) {
682 const_cast<RooSetProxy&>(_obs).assignValueOnly(_obsAbsMin) ;
685 // Find minimum with all observables floating
686 const_cast<RooSetProxy&>(_obs).setAttribAll("Constant",kFALSE) ;
689 // Save value and remember
691 _absMinValid = kTRUE ;
693 // Save parameter values at abs minimum as well
694 _paramAbsMin.removeAll() ;
696 // Only store non-constant parameters here!
697 RooArgSet* tmp = (RooArgSet*) _par.selectByAttrib("Constant",kFALSE) ;
698 _paramAbsMin.addClone(*tmp) ;
701 _obsAbsMin.addClone(_obs) ;
703 // Save constant status of all parameters
706 while((par=(RooAbsArg*)_piter->Next())) {
707 _paramFixed[par->GetName()] = par->isConstant() ;
710 if (dologI(Minimization)) {
711 cxcoutI(Minimization) << "RooStats::HistFactory::RooBarlowBeestonLL::evaluate(" << GetName() << ") minimum found at (" ;
716 while ((arg=(RooAbsReal*)_oiter->Next())) {
717 ccxcoutI(Minimization) << (first?"":", ") << arg->GetName() << "=" << arg->getVal() ;
720 ccxcoutI(Minimization) << ")" << endl ;
723 // Restore original parameter values
724 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
RooRealVar & 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 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 from this p.d.f for use in extended likelihood calculations.
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...
virtual Bool_t redirectServersHook(const RooAbsCollection &, Bool_t, Bool_t, Bool_t)
Function that is called at the end of redirectServers().
Double_t evaluate() const
Optimized implementation of createProfile for profile likelihoods.
void initializeBarlowCache()
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)