96 _stateNames(other._stateNames),
97 _insertionOrder(other._insertionOrder)
138 if (item.second ==
index)
139 return item.first.c_str();
181 if (!assumeSameType) {
195 if (item.second ==
index)
207 if (item.second ==
index)
247 coutE(InputArguments) <<
"RooAbsCategory::" << __func__ <<
"(" <<
GetName() <<
"): index "
248 <<
index <<
" already assigned" << std::endl;
253 coutE(InputArguments) <<
"RooAbsCategory::" << __func__ <<
"(" <<
GetName() <<
"): label "
254 << label <<
" already assigned or not allowed" << std::endl;
258 const auto result = theStateNames.emplace(label,
index);
261 if (theStateNames.size() == 1)
288 const auto item =
stateNames().find(stateName);
314 if (item.second ==
index) {
321 <<
index << std::endl;
336 if(
type.first == label)
343 if (endptr==label+strlen(label)) {
349 << label << std::endl;
415 os <<
indent <<
"--- RooAbsCategory ---" << std::endl;
417 os <<
indent <<
" ** No values defined **" << std::endl;
421 os <<
indent <<
" Possible states:" << std::endl;
450 TBranch* branch = tree.GetBranch(cleanName.c_str());
453 branch = tree.GetBranch(cleanName.c_str());
463 coutE(Eval) <<
"RooAbsCategory::attachToTree(" <<
GetName() <<
") ERROR: TTree branch " <<
GetName()
464 <<
" is an array and cannot be attached to a RooAbsCategory" << std::endl;
472 std::map<std::string, std::function<std::unique_ptr<TreeReadBuffer>()>> typeMap {
473 {
"Float_t", [&](){
return createTreeReadBuffer<Float_t >(cleanName, tree); }},
474 {
"Double_t", [&](){
return createTreeReadBuffer<Double_t >(cleanName, tree); }},
475 {
"UChar_t", [&](){
return createTreeReadBuffer<UChar_t >(cleanName, tree); }},
476 {
"Boolt_", [&](){
return createTreeReadBuffer<Bool_t >(cleanName, tree); }},
477 {
"Char_t", [&](){
return createTreeReadBuffer<Char_t >(cleanName, tree); }},
478 {
"UInt_t", [&](){
return createTreeReadBuffer<UInt_t >(cleanName, tree); }},
479 {
"Long64_t", [&](){
return createTreeReadBuffer<Long64_t >(cleanName, tree); }},
480 {
"ULong64_t", [&](){
return createTreeReadBuffer<ULong64_t>(cleanName, tree); }},
481 {
"Short_t", [&](){
return createTreeReadBuffer<Short_t >(cleanName, tree); }},
482 {
"UShort_t", [&](){
return createTreeReadBuffer<UShort_t >(cleanName, tree); }},
485 auto typeDetails = typeMap.find(typeName);
486 if (typeDetails != typeMap.end()) {
487 coutI(DataHandling) <<
"RooAbsCategory::attachToTree(" <<
GetName() <<
") TTree " << typeName <<
" branch \"" << cleanName
488 <<
"\" will be converted to int." << std::endl;
493 if (typeName ==
"Int_t") {
497 coutE(InputArguments) <<
"RooAbsCategory::attachToTree(" <<
GetName() <<
") data type " << typeName <<
" is not supported." << std::endl;
502 tree.Branch(cleanName.c_str(), ptr, (cleanName +
"/I").c_str(), bufSize);
516 coutF(DataHandling) <<
"RooAbsCategory::fillTreeBranch(" <<
GetName() <<
") ERROR: not attached to tree" << std::endl;
517 throw std::runtime_error(
"RooAbsCategory::fillTreeBranch(): Category is not attached to a tree.");
559 _currentIndex = other->_treeReadBuffer ? *other->_treeReadBuffer : other->_currentIndex;
596 if (
n >= theStateNames.size())
600 return *std::next(theStateNames.begin(),
n);
603 if (item != theStateNames.end())
619 for (
auto it = theStateNames.begin(); it != theStateNames.end(); ++it) {
620 if (it->second == currentIndex)
621 return std::distance(theStateNames.begin(), it);
639 auto fund = std::make_unique<RooCategory>(newname?newname:
GetName(),
GetTitle()) ;
643 fund->defineStateUnchecked(
type.first,
type.second);
646 return RooFit::makeOwningPtr<RooAbsArg>(std::move(fund));
658 if (theStateNames.size() > 3 || theStateNames.size() < 2)
return false;
659 if (mustHaveZero && theStateNames.size() != 3)
return false;
661 for (
const auto&
type : theStateNames) {
662 if (std::abs(
type.second)>1)
699 return result->second.get();
706 if (theStateNames.empty())
709 return 1 + std::max_element(theStateNames.begin(), theStateNames.end(),
710 [](
auto const& left,
auto const& right) { return left.second < right.second; })->second;
static void indent(ostringstream &buf, int indent_level)
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 result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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 Atom_t Time_t type
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Common abstract base class for objects that represent a value and a "shape" in RooFit.
void setShapeDirty()
Notify that a shape-like property (e.g. binning) has changed.
bool isShapeDirty() const
void clearValueDirty() const
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Implement multi-line detailed printing.
TString cleanBranchName() const
Construct a mangled name from the actual name that is free of any math symbols that might be interpre...
bool isValueDirty() const
A space to attach TBranches.
virtual value_type getCurrentIndex() const
Return index number of current state.
void setCachedValue(double value, bool notifyClients=true) final
Overwrite the value stored in this object's cache.
unsigned int getCurrentOrdinalNumber() const
Return ordinal number of the current state.
bool hasLabel(const std::string &label) const
Check if a state with name label exists.
virtual const char * getCurrentLabel() const
Return label string of current state.
const std::string & lookupName(value_type index) const
Get the name corresponding to the given index.
TIterator * typeIterator() const
bool operator==(value_type index) const
Equality operator with a integer (compares with state index number)
RooCatType * retrieveLegacyState(value_type index) const
Return the legacy RooCatType corresponding to index. If it doesn't exist, create one.
void copyCache(const RooAbsArg *source, bool valueOnly=false, bool setValueDirty=true) override
Copy the cached value from given source and raise dirty flag.
value_type _currentIndex
Current category state.
Roo1DTable * createTable(const char *label) const
Create a table matching the shape of this category.
void defineStateUnchecked(const std::string &label, value_type index)
Internal version of defineState() that does not check if type already exists.
const RooCatType * defineTypeUnchecked(const char *label, value_type index)
void setTreeBranchStatus(TTree &t, bool active) override
(De)activate associate tree branch
const RooCatType * lookupType(value_type index, bool printError=false) const
Find our type corresponding to the specified index, or return nullptr for no match.
void writeToStream(std::ostream &os, bool compact) const override
Write object contents to ostream.
value_type nextAvailableStateIndex() const
bool readFromStream(std::istream &is, bool compact, bool verbose=false) override
Read object contents from stream (dummy for now)
bool isSignType(bool mustHaveZero=false) const
Determine if category has 2 or 3 states with index values -1,0,1.
std::map< std::string, value_type >::const_iterator end() const
Iterator for category state names. Points to pairs of index and name.
virtual const std::map< std::string, RooAbsCategory::value_type >::value_type & defineState(const std::string &label)
Define a new state with given label.
virtual value_type evaluate() const =0
Evaluate the category state and return.
void syncCache(const RooArgSet *set=nullptr) override
Explicitly synchronize RooAbsCategory internal cache.
const std::map< std::string, value_type >::value_type & getOrdinal(unsigned int n) const
Return name and index of the nth defined state.
RooFit::OwningPtr< RooAbsArg > createFundamental(const char *newname=nullptr) const override
Create a RooCategory fundamental object with our properties.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Print info about this object to the specified stream.
std::map< value_type, std::unique_ptr< RooCatType, std::function< void(RooCatType *)> > > _legacyStates
! Map holding pointers to RooCatType instances. Only for legacy interface. Don't use if possible.
bool isIdentical(const RooAbsArg &other, bool assumeSameType=false) const override
~RooAbsCategory() override
Destructor.
std::vector< std::string > _insertionOrder
Keeps track in which order state numbers have been inserted. Make sure this is updated in recomputeSh...
std::map< std::string, value_type > _stateNames
Map state names to index numbers. Make sure state names are updated in recomputeShape().
bool isValid() const override
WVE (08/21/01) Probably obsolete now.
const RooCatType * defineType(const char *label)
const std::map< std::string, value_type > & stateNames() const
Access the map of state names to index numbers.
bool hasIndex(value_type index) const
Check if a state with index index exists.
void attachToVStore(RooVectorDataStore &vstore) override
Attach the category index and label to as branches to the given vector store.
static const decltype(_stateNames) ::value_type & invalidCategory()
A category state to signify an invalid category.
value_type lookupIndex(const std::string &stateName) const
Find the index number corresponding to the state name.
std::unique_ptr< TreeReadBuffer > _treeReadBuffer
void attachToTree(TTree &t, Int_t bufSize=32000) override
Attach the category index and label as branches to the given TTree.
void fillTreeBranch(TTree &t) override
Fill tree branches associated with current object with current value.
bool empty() const
If there are no states defined.
void clearTypes()
Delete all currently defined states.
void printValue(std::ostream &os) const override
Print value (label name)
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooCatType is an auxiliary class for RooAbsCategory and defines a a single category state.
void setBuffer(RooAbsCategory::value_type *newBuf)
Uses std::vector to store data columns.
CatVector * addCategory(RooAbsCategory *cat)
A TTree is a list of TBranches.
TObjArray * GetListOfLeaves()
Iterator abstract base class.
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
virtual const char * GetTypeName() const
virtual TLeaf * GetLeafCounter(Int_t &countval) const
Return a pointer to the counter of this leaf (if any) or store the number of elements that the leaf c...
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
TObject * At(Int_t idx) const override
virtual const char * ClassName() const
Returns name of class to which the object belongs.
const char * Data() const
A TTree represents a columnar dataset.
virtual void SetBranchStatus(const char *bname, bool status=true, UInt_t *found=nullptr)
Set branch status to Process or DoNotProcess.
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
T * OwningPtr
An alias for raw pointers for indicating that the return type of a RooFit function is an owning point...