42using std::runtime_error;
60 _nll(
"input",
"-log(L) function",this,nllIn)
103 target->setVal(var->getVal()) ;
114 std::cout <<
"Error: Must initialize data before initializing cache" << std::endl;
115 throw std::runtime_error(
"Uninitialized Data");
118 std::cout <<
"Error: Must initialize model pdf before initializing cache" << std::endl;
119 throw std::runtime_error(
"Uninitialized model pdf");
123 std::map< std::string, std::vector<double> > ChannelBinDataMap;
129 RooArgSet* obsSet = std::unique_ptr<RooArgSet>{
_pdf->getObservables(*
_data)}.release();
132 if( obsTerms.
empty() ) {
133 std::cout <<
"Error: Found no observable terms with pdf: " <<
_pdf->GetName()
134 <<
" using dataset: " <<
_data->GetName() << std::endl;
137 if( constraints.
empty() ) {
138 std::cout <<
"Error: Found no constraint terms with pdf: " <<
_pdf->GetName()
139 <<
" using dataset: " <<
_data->GetName() << std::endl;
145 auto channelCat =
static_cast<RooCategory const*
>(&simPdf->indexCat());
146 for (
const auto& nameIdx : *channelCat) {
150 RooAbsPdf* channelPdf = simPdf->getPdf(nameIdx.first.c_str());
151 std::string channel_name = channelPdf->
GetName();
157 if( ! hasStatUncert ) {
159 std::cout <<
"Channel: " << channel_name
160 <<
" doesn't have statistical uncertainties"
166 if(verbose) std::cout <<
"Found ParamHistFunc: " << param_func->
GetName() << std::endl;
173 int num_bins = param_func->
numBins();
178 std::vector<BarlowCache> temp_cache( num_bins );
179 bool channel_has_stat_uncertainty=
false;
181 for(
Int_t bin_index = 0; bin_index < num_bins; ++bin_index ) {
188 if(!gamma_stat)
throw std::runtime_error(
"ParamHistFunc contains non-RooRealVar, not supported in RooBarlowBeestonLL");
190 if(verbose) std::cout <<
"Ignoring constant gamma: " << gamma_stat->
GetName() << std::endl;
195 channel_has_stat_uncertainty=
true;
196 cache.
gamma = gamma_stat;
214 if( !tau || !pois_mean ) {
215 std::cout <<
"Failed to find pois mean or tau parameter for " << gamma_stat->
GetName() << std::endl;
219 std::cout <<
"Found pois mean and tau for parameter: " << gamma_stat->
GetName() <<
" tau: " << tau->
GetName()
220 <<
" " << tau->
getVal() <<
" pois_mean: " << pois_mean->
GetName() <<
" " << pois_mean->
getVal()
230 if( sum_pdf ==
nullptr ) {
231 std::cout <<
"Failed to find RooRealSumPdf in channel " << channel_name
232 <<
", therefor skipping this channel for analytic uncertainty minimization"
234 channel_has_stat_uncertainty=
false;
240 if( ChannelBinDataMap.find(channel_name) == ChannelBinDataMap.end() ) {
241 std::cout <<
"Error: channel with name: " << channel_name
242 <<
" not found in BinDataMap" << std::endl;
243 throw runtime_error(
"BinDataMap");
245 double nData = ChannelBinDataMap[channel_name].at(bin_index);
248 temp_cache.at(bin_index) = cache;
253 if( channel_has_stat_uncertainty ) {
254 std::cout <<
"Adding channel: " << channel_name
255 <<
" to the barlow cache" << std::endl;
313 bool stripDisconnected)
const {
319 for (
auto const& arg : outputSet) {
325 toRemove.
add( *arg );
329 for(
auto& arg : toRemove) outputSet.
remove( *arg,
true );
331 return errorInBaseCall ||
false;
339const RooArgSet& RooStats::HistFactory::RooBarlowBeestonLL::bestFitParams() const
342 return _paramAbsMin ;
348const RooArgSet& RooStats::HistFactory::RooBarlowBeestonLL::bestFitObs() const
406 std::map< std::string, std::vector< BarlowCache > >::iterator iter_cache;
409 std::string channel_name = (*iter_cache).first;
410 std::vector< BarlowCache >& channel_cache = (*iter_cache).second;
425 for(
unsigned int i = 0;
i < channel_cache.size(); ++
i ) {
431 std::vector< double > nu_b_vec( channel_cache.size() );
432 for(
unsigned int i = 0;
i < channel_cache.size(); ++
i ) {
442 nu_b_vec.at(
i) = nu_b;
447 for(
unsigned int i = 0;
i < channel_cache.size(); ++
i ) {
453 std::vector< double > nu_b_stat_vec( channel_cache.size() );
454 for(
unsigned int i = 0;
i < channel_cache.size(); ++
i ) {
463 double nu_b_stat = sum_pdf->
getVal(*obsSet)*sum_pdf->
expectedEvents(*obsSet)*binVolume - nu_b_vec.at(
i);
464 nu_b_stat_vec.at(
i) = nu_b_stat;
475 for(
unsigned int i = 0;
i < channel_cache.size(); ++
i ) {
499 double nu_b = nu_b_vec.at(
i);
500 double nu_b_stat = nu_b_stat_vec.at(
i);
502 double tau_val = tau->
getVal();
503 double nData = bin_cache.
nData;
504 double m_val = pois_mean->
getVal();
507 double gamma_hat_hat = 1.0;
510 if(nu_b_stat > 0.00000001) {
512 double A = nu_b_stat*nu_b_stat + tau_val*nu_b_stat;
513 double B = nu_b*tau_val + nu_b*nu_b_stat - nData*nu_b_stat - m_val*nu_b_stat;
514 double C = -1*m_val*nu_b;
516 double discrim = B*B-4*A*C;
519 std::cout <<
"Warning: Discriminant (B*B - 4AC) < 0" << std::endl;
520 std::cout <<
"Warning: Taking B*B - 4*A*C == 0" << std::endl;
525 std::cout <<
"Warning: A <= 0" << std::endl;
526 throw runtime_error(
"BarlowBeestonLL::evaluate() : A < 0");
529 gamma_hat_hat = ( -1*B + std::sqrt(discrim) ) / (2*A);
535 gamma_hat_hat = m_val/tau_val;
540 std::cout <<
"ERROR: gamma hat hat is NAN" << std::endl;
541 throw runtime_error(
"BarlowBeestonLL::evaluate() : gamma hat hat is NAN");
544 if( gamma_hat_hat <= 0 ) {
545 std::cout <<
"WARNING: gamma hat hat <= 0. Setting to 0" << std::endl;
562 gamma->setVal( gamma_hat_hat );
592void RooStats::HistFactory::RooBarlowBeestonLL::validateAbsMin() const
594 // Check if constant status of any of the parameters have changed
598 while((par=(RooAbsArg*)_piter->Next())) {
599 if (_paramFixed[par->GetName()] != par->isConstant()) {
600 cxcoutI(Minimization) << "RooStats::HistFactory::RooBarlowBeestonLL::evaluate(" << GetName() << ") constant status of parameter " << par->GetName() << " has changed from "
601 << (_paramFixed[par->GetName()]?"fixed":"floating") << " to " << (par->isConstant()?"fixed":"floating")
602 << ", recalculating absolute minimum" << endl ;
603 _absMinValid = false ;
610 // If we don't have the absolute minimum w.r.t all observables, calculate that first
613 cxcoutI(Minimization) << "RooStats::HistFactory::RooBarlowBeestonLL::evaluate(" << GetName() << ") determining minimum likelihood for current configurations w.r.t all observable" << endl ;
616 // Save current values of non-marginalized parameters
617 std::unique_ptr<RooArgSet> obsStart{(RooArgSet*) _obs.snapshot(false)};
619 // Start from previous global minimum
620 if (_paramAbsMin.size()>0) {
621 const_cast<RooSetProxy&>(_par).assignValueOnly(_paramAbsMin) ;
623 if (_obsAbsMin.size()>0) {
624 const_cast<RooSetProxy&>(_obs).assignValueOnly(_obsAbsMin) ;
627 // Find minimum with all observables floating
628 const_cast<RooSetProxy&>(_obs).setAttribAll("Constant",false) ;
631 // Save value and remember
633 _absMinValid = true ;
635 // Save parameter values at abs minimum as well
636 _paramAbsMin.removeAll() ;
638 // Only store non-constant parameters here!
639 std::unique_ptr<RooArgSet> tmp{(RooArgSet*) _par.selectByAttrib("Constant",false)};
640 _paramAbsMin.addClone(*tmp) ;
642 _obsAbsMin.addClone(_obs) ;
644 // Save constant status of all parameters
647 while((par=(RooAbsArg*)_piter->Next())) {
648 _paramFixed[par->GetName()] = par->isConstant() ;
651 if (dologI(Minimization)) {
652 cxcoutI(Minimization) << "RooStats::HistFactory::RooBarlowBeestonLL::evaluate(" << GetName() << ") minimum found at (" ;
657 while ((arg=(RooAbsReal*)_oiter->Next())) {
658 ccxcoutI(Minimization) << (first?"":", ") << arg->GetName() << "=" << arg->getVal() ;
661 ccxcoutI(Minimization) << ")" << endl ;
664 // Restore original parameter values
665 const_cast<RooSetProxy&>(_obs) = *obsStart ;
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
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.
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooAbsReal()
coverity[UNINIT_CTOR] Default constructor
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...
RooBarlowBeestonLL()
Default constructor. Should only be used by proof.
std::set< std::string > _statUncertParams
std::map< std::string, bool > _paramFixed
Parameter constant status at last time of use.
std::map< std::string, std::vector< BarlowCache > > _barlowCache
void initializeBarlowCache()
RooRealProxy _nll
Input -log(L) function.
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)