32 ClassImp(RooThresholdCategory);
35 bool threshListSorter(
const std::pair<double,RooCatType>& lhs,
const std::pair<double,RooCatType>& rhs) {
36 return lhs.first < rhs.first || (lhs.first == rhs.first && lhs.second.getVal() < rhs.second.getVal());
46 RooThresholdCategory::RooThresholdCategory(
const char *name,
const char *title, RooAbsReal& inputVar,
47 const char* defOut, Int_t defIdx) :
48 RooAbsCategory(name, title), _inputVar(
"inputVar",
"Input category",this,inputVar)
50 _defCat = defineType(defOut,defIdx);
58 RooThresholdCategory::RooThresholdCategory(
const RooThresholdCategory& other,
const char *name) :
59 RooAbsCategory(other,name), _inputVar(
"inputVar",this,other._inputVar)
61 _defCat = lookupType(other._defCat->GetName());
63 for (
const auto& cat : other._threshList){
64 _threshList.push_back(cat);
66 std::sort(_threshList.begin(), _threshList.end(), threshListSorter);
74 Bool_t RooThresholdCategory::addThreshold(Double_t upperLimit,
const char* catName, Int_t catIdx)
77 for (
const auto& thresh : _threshList) {
78 if (thresh.first == upperLimit) {
79 coutW(InputArguments) <<
"RooThresholdCategory::addThreshold(" << GetName()
80 <<
") threshold at " << upperLimit <<
" already defined" << endl ;
86 const RooCatType* type = lookupType(catName,kFALSE) ;
89 type=defineType(catName) ;
91 type=defineType(catName,catIdx) ;
95 _threshList.emplace_back(upperLimit, *type);
96 std::sort(_threshList.begin(), _threshList.end(), threshListSorter);
106 RooCatType RooThresholdCategory::evaluate()
const
109 for (
const auto& thresh : _threshList) {
110 if (_inputVar<thresh.first)
111 return thresh.second;
123 void RooThresholdCategory::writeToStream(ostream& os, Bool_t compact)
const
132 for (
const auto& thresh : _threshList) {
133 os << thresh.second.GetName() <<
":<" << thresh.first <<
" " ;
135 os << _defCat->GetName() <<
":*" ;
149 void RooThresholdCategory::printMultiline(ostream& os, Int_t content, Bool_t verbose, TString indent)
const
151 RooAbsCategory::printMultiline(os,content,verbose,indent);
154 os << indent <<
"--- RooThresholdCategory ---" << endl
155 << indent <<
" Maps from " ;
156 _inputVar.arg().printStream(os,0,kStandard);
158 os << indent <<
" Threshold list" << endl ;
159 for (
const auto& thresh : _threshList) {
160 os << indent <<
" input < " << thresh.first <<
" --> " ;
161 thresh.second.printStream(os,kName|kValue,kSingleLine) ;
163 os << indent <<
" Default value is " ;
164 _defCat->printStream(os,kValue,kSingleLine);