50 RooAbsReal(
"RooBarlowBeestonLL",
"RooBarlowBeestonLL"),
65 _nll(
"input",
"-log(L) function",this,nllIn)
90 _nll(
"nll",this,other._nll),
93 _paramFixed(other._paramFixed)
106 for (
auto const *var : static_range_cast<RooRealVar *>(*bin_center)) {
108 target->setVal(var->getVal()) ;
119 std::cout <<
"Error: Must initialize data before initializing cache" << std::endl;
120 throw std::runtime_error(
"Uninitialized Data");
123 std::cout <<
"Error: Must initialize model pdf before initializing cache" << std::endl;
124 throw std::runtime_error(
"Uninitialized model pdf");
128 std::map< std::string, std::vector<double> > ChannelBinDataMap;
134 RooArgSet* obsSet = std::unique_ptr<RooArgSet>{_pdf->getObservables(*_data)}.release();
137 if( obsTerms.
empty() ) {
138 std::cout <<
"Error: Found no observable terms with pdf: " << _pdf->GetName()
139 <<
" using dataset: " << _data->GetName() << std::endl;
142 if( constraints.
empty() ) {
143 std::cout <<
"Error: Found no constraint terms with pdf: " << _pdf->GetName()
144 <<
" using dataset: " << _data->GetName() << std::endl;
151 for (
const auto& nameIdx : *channelCat) {
156 std::string channel_name = channelPdf->
GetName();
162 if( ! hasStatUncert ) {
164 std::cout <<
"Channel: " << channel_name
165 <<
" doesn't have statistical uncertainties"
171 if(verbose) std::cout <<
"Found ParamHistFunc: " << param_func->
GetName() << std::endl;
178 int num_bins = param_func->
numBins();
183 std::vector<BarlowCache> temp_cache( num_bins );
184 bool channel_has_stat_uncertainty=
false;
186 for(
Int_t bin_index = 0; bin_index < num_bins; ++bin_index ) {
193 if(!gamma_stat)
throw std::runtime_error(
"ParamHistFunc contains non-RooRealVar, not supported in RooBarlowBeestonLL");
195 if(verbose) std::cout <<
"Ignoring constant gamma: " << gamma_stat->
GetName() << std::endl;
200 channel_has_stat_uncertainty=
true;
201 cache.
gamma = gamma_stat;
202 _statUncertParams.insert( gamma_stat->
GetName() );
219 if( !tau || !pois_mean ) {
220 std::cout <<
"Failed to find pois mean or tau parameter for " << gamma_stat->
GetName() << std::endl;
223 if(verbose) std::cout <<
"Found pois mean and tau for parameter: " << gamma_stat->
GetName()
225 <<
" pois_mean: " << pois_mean->
GetName() <<
" " << pois_mean->
getVal()
234 if( sum_pdf ==
nullptr ) {
235 std::cout <<
"Failed to find RooRealSumPdf in channel " << channel_name
236 <<
", therefor skipping this channel for analytic uncertainty minimization"
238 channel_has_stat_uncertainty=
false;
244 if( ChannelBinDataMap.find(channel_name) == ChannelBinDataMap.end() ) {
245 std::cout <<
"Error: channel with name: " << channel_name
246 <<
" not found in BinDataMap" << std::endl;
247 throw runtime_error(
"BinDataMap");
249 double nData = ChannelBinDataMap[channel_name].at(bin_index);
252 temp_cache.at(bin_index) = cache;
257 if( channel_has_stat_uncertainty ) {
258 std::cout <<
"Adding channel: " << channel_name
259 <<
" to the barlow cache" << std::endl;
260 _barlowCache[channel_name] = temp_cache;
317 bool stripDisconnected)
const {
321 toRemove.
reserve( _statUncertParams.size());
323 for (
auto const& arg : outputSet) {
328 if( _statUncertParams.find(arg->GetName()) != _statUncertParams.end() ) {
329 toRemove.
add( *arg );
333 for(
auto& arg : toRemove) outputSet.
remove( *arg,
true );
335 return errorInBaseCall ||
false;
343const RooArgSet& RooStats::HistFactory::RooBarlowBeestonLL::bestFitParams() const
346 return _paramAbsMin ;
352const RooArgSet& RooStats::HistFactory::RooBarlowBeestonLL::bestFitObs() const
410 std::map< std::string, std::vector< BarlowCache > >::iterator iter_cache;
411 for( iter_cache = _barlowCache.begin(); iter_cache != _barlowCache.end(); ++iter_cache ) {
413 std::string channel_name = (*iter_cache).first;
414 std::vector< BarlowCache >& channel_cache = (*iter_cache).second;
429 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
435 std::vector< double > nu_b_vec( channel_cache.size() );
436 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
446 nu_b_vec.at(i) = nu_b;
451 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
457 std::vector< double > nu_b_stat_vec( channel_cache.size() );
458 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
467 double nu_b_stat = sum_pdf->
getVal(*obsSet)*sum_pdf->
expectedEvents(*obsSet)*binVolume - nu_b_vec.at(i);
468 nu_b_stat_vec.at(i) = nu_b_stat;
479 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
503 double nu_b = nu_b_vec.at(i);
504 double nu_b_stat = nu_b_stat_vec.at(i);
506 double tau_val = tau->
getVal();
507 double nData = bin_cache.
nData;
508 double m_val = pois_mean->
getVal();
511 double gamma_hat_hat = 1.0;
514 if(nu_b_stat > 0.00000001) {
516 double A = nu_b_stat*nu_b_stat + tau_val*nu_b_stat;
517 double B = nu_b*tau_val + nu_b*nu_b_stat - nData*nu_b_stat - m_val*nu_b_stat;
518 double C = -1*m_val*nu_b;
520 double discrim = B*B-4*A*C;
523 std::cout <<
"Warning: Discriminant (B*B - 4AC) < 0" << std::endl;
524 std::cout <<
"Warning: Taking B*B - 4*A*C == 0" << std::endl;
529 std::cout <<
"Warning: A <= 0" << std::endl;
530 throw runtime_error(
"BarlowBeestonLL::evaluate() : A < 0");
533 gamma_hat_hat = ( -1*B +
TMath::Sqrt(discrim) ) / (2*A);
539 gamma_hat_hat = m_val/tau_val;
544 std::cout <<
"ERROR: gamma hat hat is NAN" << std::endl;
545 throw runtime_error(
"BarlowBeestonLL::evaluate() : gamma hat hat is NAN");
548 if( gamma_hat_hat <= 0 ) {
549 std::cout <<
"WARNING: gamma hat hat <= 0. Setting to 0" << std::endl;
566 gamma->setVal( gamma_hat_hat );
596void RooStats::HistFactory::RooBarlowBeestonLL::validateAbsMin() const
598 // Check if constant status of any of the parameters have changed
602 while((par=(RooAbsArg*)_piter->Next())) {
603 if (_paramFixed[par->GetName()] != par->isConstant()) {
604 cxcoutI(Minimization) << "RooStats::HistFactory::RooBarlowBeestonLL::evaluate(" << GetName() << ") constant status of parameter " << par->GetName() << " has changed from "
605 << (_paramFixed[par->GetName()]?"fixed":"floating") << " to " << (par->isConstant()?"fixed":"floating")
606 << ", recalculating absolute minimum" << endl ;
607 _absMinValid = false ;
614 // If we don't have the absolute minimum w.r.t all observables, calculate that first
617 cxcoutI(Minimization) << "RooStats::HistFactory::RooBarlowBeestonLL::evaluate(" << GetName() << ") determining minimum likelihood for current configurations w.r.t all observable" << endl ;
620 // Save current values of non-marginalized parameters
621 std::unique_ptr<RooArgSet> obsStart{(RooArgSet*) _obs.snapshot(false)};
623 // Start from previous global minimum
624 if (_paramAbsMin.getSize()>0) {
625 const_cast<RooSetProxy&>(_par).assignValueOnly(_paramAbsMin) ;
627 if (_obsAbsMin.getSize()>0) {
628 const_cast<RooSetProxy&>(_obs).assignValueOnly(_obsAbsMin) ;
631 // Find minimum with all observables floating
632 const_cast<RooSetProxy&>(_obs).setAttribAll("Constant",false) ;
635 // Save value and remember
637 _absMinValid = true ;
639 // Save parameter values at abs minimum as well
640 _paramAbsMin.removeAll() ;
642 // Only store non-constant parameters here!
643 std::unique_ptr<RooArgSet> tmp{(RooArgSet*) _par.selectByAttrib("Constant",false)};
644 _paramAbsMin.addClone(*tmp) ;
646 _obsAbsMin.addClone(_obs) ;
648 // Save constant status of all parameters
651 while((par=(RooAbsArg*)_piter->Next())) {
652 _paramFixed[par->GetName()] = par->isConstant() ;
655 if (dologI(Minimization)) {
656 cxcoutI(Minimization) << "RooStats::HistFactory::RooBarlowBeestonLL::evaluate(" << GetName() << ") minimum found at (" ;
661 while ((arg=(RooAbsReal*)_oiter->Next())) {
662 ccxcoutI(Minimization) << (first?"":", ") << arg->GetName() << "=" << arg->getVal() ;
665 ccxcoutI(Minimization) << ")" << endl ;
668 // Restore original parameter values
669 const_cast<RooSetProxy&>(_obs) = *obsStart ;
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
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
bool isConstant() const
Check if the "Constant" attribute is set.
RooFit::OwningPtr< 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...
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
void reserve(Storage_t::size_type count)
Abstract interface for all probability density functions.
virtual double expectedEvents(const RooArgSet *nset) const
Return expected number of events to be used in calculation of extended likelihood.
Abstract base class for objects that represent a real value and implements functionality common to al...
double 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.
Object to represent discrete states.
RooRealVar represents a variable that can be changed from the outside.
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
RooAbsPdf * getPdf(RooStringView catName) const
Return the p.d.f associated with the given index category name.
const RooAbsCategoryLValue & indexCat() const
RooAbsReal * nom_pois_mean
void SetBinCenter() const
Class RooBarlowBeestonLL implements the profile likelihood estimator for a given likelihood and set o...
double evaluate() const override
Optimized implementation of createProfile for profile likelihoods.
bool getParameters(const RooArgSet *depList, RooArgSet &outputSet, bool stripDisconnected=true) const override
Fills a list with leaf nodes in the arg tree starting with ourself as top node that don't match any o...
void initializeBarlowCache()
const char * GetName() const override
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)
Returns the square root of x.