#include "RooFit.h"
#include "Riostream.h"
#include "Riostream.h"
#include <iomanip>
#include "TString.h"
#include "Roo1DTable.h"
ClassImp(Roo1DTable)
Roo1DTable::Roo1DTable(const char *name, const char *title, const RooAbsCategory& cat) :
RooTable(name,title), _total(0), _nOverflow(0)
{
Int_t nbin(0) ;
TIterator* tIter = cat.typeIterator() ;
RooCatType* type ;
while (((type = (RooCatType*)tIter->Next()))) {
_types.Add(new RooCatType(*type)) ;
nbin++ ;
}
delete tIter ;
_count = new Double_t[nbin] ;
for (int i=0 ; i<nbin ; i++) _count[i] = 0 ;
}
Roo1DTable::Roo1DTable(const Roo1DTable& other) :
RooTable(other), _total(other._total), _nOverflow(other._nOverflow)
{
Int_t nbin(0) ;
int i;
for (i=0 ; i<other._types.GetEntries() ; i++) {
_types.Add(new RooCatType(*(RooCatType*)other._types.At(i))) ;
nbin++ ;
}
_count = new Double_t[nbin] ;
for (i=0 ; i<nbin ; i++) _count[i] = other._count[i] ;
}
Roo1DTable::~Roo1DTable()
{
_types.Delete() ;
delete[] _count ;
}
void Roo1DTable::fill(RooAbsCategory& cat, Double_t weight)
{
if (weight==0) return ;
_total += weight ;
for (int i=0 ; i<_types.GetEntries() ; i++) {
RooCatType* entry = (RooCatType*) _types.At(i) ;
if (cat.getIndex()==entry->getVal()) {
_count[i] += weight ; ;
return;
}
}
_nOverflow += weight ;
}
void Roo1DTable::printToStream(ostream& os, PrintOption opt, TString indent) const
{
os << indent << endl ;
os << indent << " Table " << GetName() << " : " << GetTitle() << endl ;
Int_t labelWidth(0) ;
Double_t maxCount(1) ;
int i;
for (i=0 ; i<_types.GetEntries() ; i++) {
RooCatType* entry = (RooCatType*) _types.At(i) ;
Int_t lwidth = strlen(entry->GetName());
labelWidth = lwidth > labelWidth ? lwidth : labelWidth;
maxCount=_count[i]>maxCount?_count[i]:maxCount ;
}
if (_nOverflow>0) {
labelWidth=labelWidth>8?labelWidth:8 ;
maxCount=maxCount>_nOverflow?maxCount:_nOverflow ;
}
Int_t countWidth=((Int_t)log10(maxCount))+1 ;
os << indent << " +-" << setw(labelWidth) << setfill('-') << "-" << "-+-" << setw(countWidth) << "-" << "-+" << endl ;
os << setfill(' ') ;
for (i=0 ; i<_types.GetEntries() ; i++) {
RooCatType* entry = (RooCatType*) _types.At(i) ;
if (_count[i]>0 || opt>=Verbose) {
os << " | " << setw(labelWidth) << entry->GetName() << " | " << setw(countWidth) << _count[i] << " |" << endl ;
}
}
if (_nOverflow) {
os << indent << " +-" << setw(labelWidth) << setfill('-') << "-" << "-+-" << setw(countWidth) << "-" << "-+" << endl ;
os << indent << " | " << "Overflow" << " | " << setw(countWidth) << _nOverflow << " |" << endl ;
}
os << indent << " +-" << setw(labelWidth) << setfill('-') << "-" << "-+-" << setw(countWidth) << "-" << "-+" << endl ;
os << setfill(' ') ;
os << indent << endl ;
}
Double_t Roo1DTable::get(const char* label, Bool_t silent) const
{
TObject* cat = _types.FindObject(label) ;
if (!cat) {
if (!silent) {
cout << "Roo1DTable::get: ERROR: no such entry: " << label << endl ;
}
return 0 ;
}
return _count[_types.IndexOf(cat)] ;
}
Double_t Roo1DTable::getOverflow() const
{
return _nOverflow ;
}
Double_t Roo1DTable::getFrac(const char* label, Bool_t silent) const
{
if (_total) {
return get(label,silent) / _total ;
} else {
if (!silent) cout << "Roo1DTable::getFrac: WARNING table empty, returning 0" << endl ;
return 0. ;
}
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.