50 _nll(
"input",
"-log(L) function",this,nllIn)
75 _nll(
"nll",this,other._nll),
78 _paramFixed(other._paramFixed)
91 for (
auto const *var : static_range_cast<RooRealVar *>(*bin_center)) {
93 target->setVal(var->getVal()) ;
104 std::cout <<
"Error: Must initialize data before initializing cache" << std::endl;
105 throw std::runtime_error(
"Uninitialized Data");
108 std::cout <<
"Error: Must initialize model pdf before initializing cache" << std::endl;
109 throw std::runtime_error(
"Uninitialized model pdf");
113 std::map< std::string, std::vector<double> > ChannelBinDataMap;
119 RooArgSet* obsSet = std::unique_ptr<RooArgSet>{_pdf->getObservables(*_data)}.release();
122 if( obsTerms.
empty() ) {
123 std::cout <<
"Error: Found no observable terms with pdf: " << _pdf->GetName()
124 <<
" using dataset: " << _data->GetName() << std::endl;
127 if( constraints.
empty() ) {
128 std::cout <<
"Error: Found no constraint terms with pdf: " << _pdf->GetName()
129 <<
" using dataset: " << _data->GetName() << std::endl;
135 auto channelCat =
static_cast<RooCategory const*
>(&simPdf->indexCat());
136 for (
const auto& nameIdx : *channelCat) {
140 RooAbsPdf* channelPdf = simPdf->getPdf(nameIdx.first.c_str());
141 std::string channel_name = channelPdf->
GetName();
147 if( ! hasStatUncert ) {
149 std::cout <<
"Channel: " << channel_name
150 <<
" doesn't have statistical uncertainties"
156 if(verbose) std::cout <<
"Found ParamHistFunc: " << param_func->
GetName() << std::endl;
163 int num_bins = param_func->
numBins();
168 std::vector<BarlowCache> temp_cache( num_bins );
169 bool channel_has_stat_uncertainty=
false;
171 for(
Int_t bin_index = 0; bin_index < num_bins; ++bin_index ) {
178 if(!gamma_stat)
throw std::runtime_error(
"ParamHistFunc contains non-RooRealVar, not supported in RooBarlowBeestonLL");
180 if(verbose) std::cout <<
"Ignoring constant gamma: " << gamma_stat->
GetName() << std::endl;
185 channel_has_stat_uncertainty=
true;
186 cache.
gamma = gamma_stat;
187 _statUncertParams.insert( gamma_stat->
GetName() );
201 if( !tau || !pois_mean ) {
202 std::cout <<
"Failed to find pois mean or tau parameter for " << gamma_stat->
GetName() << std::endl;
206 std::cout <<
"Found pois mean and tau for parameter: " << gamma_stat->
GetName() <<
" tau: " << tau->
GetName()
207 <<
" " << tau->
getVal() <<
" pois_mean: " << pois_mean->
GetName() <<
" " << pois_mean->
getVal()
217 if( sum_pdf ==
nullptr ) {
218 std::cout <<
"Failed to find RooRealSumPdf in channel " << channel_name
219 <<
", therefor skipping this channel for analytic uncertainty minimization"
221 channel_has_stat_uncertainty=
false;
227 if( ChannelBinDataMap.find(channel_name) == ChannelBinDataMap.end() ) {
228 std::cout <<
"Error: channel with name: " << channel_name
229 <<
" not found in BinDataMap" << std::endl;
230 throw std::runtime_error(
"BinDataMap");
232 double nData = ChannelBinDataMap[channel_name].at(bin_index);
235 temp_cache.at(bin_index) = cache;
240 if( channel_has_stat_uncertainty ) {
241 std::cout <<
"Adding channel: " << channel_name
242 <<
" to the barlow cache" << std::endl;
243 _barlowCache[channel_name] = temp_cache;
300 bool stripDisconnected)
const {
304 toRemove.
reserve( _statUncertParams.size());
306 for (
auto const& arg : outputSet) {
311 if( _statUncertParams.find(arg->GetName()) != _statUncertParams.end() ) {
312 toRemove.
add( *arg );
316 for(
auto& arg : toRemove) outputSet.
remove( *arg,
true );
318 return errorInBaseCall ||
false;
326const RooArgSet& RooStats::HistFactory::RooBarlowBeestonLL::bestFitParams() const
329 return _paramAbsMin ;
335const RooArgSet& RooStats::HistFactory::RooBarlowBeestonLL::bestFitObs() const
393 std::map< std::string, std::vector< BarlowCache > >::iterator iter_cache;
394 for( iter_cache = _barlowCache.begin(); iter_cache != _barlowCache.end(); ++iter_cache ) {
396 std::vector< BarlowCache >& channel_cache = (*iter_cache).second;
411 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
417 std::vector< double > nu_b_vec( channel_cache.size() );
418 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
428 nu_b_vec.at(i) = nu_b;
433 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
439 std::vector< double > nu_b_stat_vec( channel_cache.size() );
440 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
449 double nu_b_stat = sum_pdf->
getVal(*obsSet)*sum_pdf->
expectedEvents(*obsSet)*binVolume - nu_b_vec.at(i);
450 nu_b_stat_vec.at(i) = nu_b_stat;
461 for(
unsigned int i = 0; i < channel_cache.size(); ++i ) {
485 double nu_b = nu_b_vec.at(i);
486 double nu_b_stat = nu_b_stat_vec.at(i);
488 double tau_val = tau->
getVal();
489 double nData = bin_cache.
nData;
490 double m_val = pois_mean->
getVal();
493 double gamma_hat_hat = 1.0;
496 if(nu_b_stat > 0.00000001) {
498 double A = nu_b_stat*nu_b_stat + tau_val*nu_b_stat;
499 double B = nu_b*tau_val + nu_b*nu_b_stat - nData*nu_b_stat - m_val*nu_b_stat;
500 double C = -1*m_val*nu_b;
502 double discrim = B*B-4*A*C;
505 std::cout <<
"Warning: Discriminant (B*B - 4AC) < 0" << std::endl;
506 std::cout <<
"Warning: Taking B*B - 4*A*C == 0" << std::endl;
511 std::cout <<
"Warning: A <= 0" << std::endl;
512 throw std::runtime_error(
"BarlowBeestonLL::evaluate() : A < 0");
515 gamma_hat_hat = ( -1*B + std::sqrt(discrim) ) / (2*A);
521 gamma_hat_hat = m_val/tau_val;
526 std::cout <<
"ERROR: gamma hat hat is NAN" << std::endl;
527 throw std::runtime_error(
"BarlowBeestonLL::evaluate() : gamma hat hat is NAN");
530 if( gamma_hat_hat <= 0 ) {
531 std::cout <<
"WARNING: gamma hat hat <= 0. Setting to 0" << std::endl;
548 gamma->setVal( gamma_hat_hat );
578void RooStats::HistFactory::RooBarlowBeestonLL::validateAbsMin() const
580 // Check if constant status of any of the parameters have changed
584 while((par=(RooAbsArg*)_piter->Next())) {
585 if (_paramFixed[par->GetName()] != par->isConstant()) {
586 cxcoutI(Minimization) << "RooStats::HistFactory::RooBarlowBeestonLL::evaluate(" << GetName() << ") constant status of parameter " << par->GetName() << " has changed from "
587 << (_paramFixed[par->GetName()]?"fixed":"floating") << " to " << (par->isConstant()?"fixed":"floating")
588 << ", recalculating absolute minimum" << std::endl ;
589 _absMinValid = false ;
596 // If we don't have the absolute minimum w.r.t all observables, calculate that first
599 cxcoutI(Minimization) << "RooStats::HistFactory::RooBarlowBeestonLL::evaluate(" << GetName() << ") determining minimum likelihood for current configurations w.r.t all observable" << std::endl ;
602 // Save current values of non-marginalized parameters
603 std::unique_ptr<RooArgSet> obsStart{(RooArgSet*) _obs.snapshot(false)};
605 // Start from previous global minimum
606 if (_paramAbsMin.size()>0) {
607 const_cast<RooSetProxy&>(_par).assignValueOnly(_paramAbsMin) ;
609 if (_obsAbsMin.size()>0) {
610 const_cast<RooSetProxy&>(_obs).assignValueOnly(_obsAbsMin) ;
613 // Find minimum with all observables floating
614 const_cast<RooSetProxy&>(_obs).setAttribAll("Constant",false) ;
617 // Save value and remember
619 _absMinValid = true ;
621 // Save parameter values at abs minimum as well
622 _paramAbsMin.removeAll() ;
624 // Only store non-constant parameters here!
625 std::unique_ptr<RooArgSet> tmp{_par.selectByAttrib("Constant",false)};
626 _paramAbsMin.addClone(*tmp) ;
628 _obsAbsMin.addClone(_obs) ;
630 // Save constant status of all parameters
633 while((par=(RooAbsArg*)_piter->Next())) {
634 _paramFixed[par->GetName()] = par->isConstant() ;
637 if (dologI(Minimization)) {
638 cxcoutI(Minimization) << "RooStats::HistFactory::RooBarlowBeestonLL::evaluate(" << GetName() << ") minimum found at (" ;
643 while ((arg=(RooAbsReal*)_oiter->Next())) {
644 ccxcoutI(Minimization) << (first?"":", ") << arg->GetName() << "=" << arg->getVal() ;
647 ccxcoutI(Minimization) << ")" << std::endl ;
650 // Restore original parameter values
651 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
double binVolume(std::size_t i) 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.
Variable that can be changed from the outside.
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
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()
RooBarlowBeestonLL(const char *name, const char *title, RooAbsReal &nll)
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)
int getStatUncertaintyConstraintTerm(RooArgList *constraints, RooRealVar *gamma_stat, RooAbsReal *&pois_nom, RooRealVar *&tau)
RooAbsPdf * getSumPdfFromChannel(RooAbsPdf *channel)