00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "RooFit.h"
00026
00027 #include "Riostream.h"
00028 #include <iomanip>
00029 #include "TString.h"
00030 #include "TMath.h"
00031 #include "Roo1DTable.h"
00032 #include "RooMsgService.h"
00033 #include "TClass.h"
00034
00035 using namespace std ;
00036
00037 ClassImp(Roo1DTable)
00038
00039
00040
00041 Roo1DTable::Roo1DTable(const char *name, const char *title, const RooAbsCategory& cat) :
00042 RooTable(name,title), _total(0), _nOverflow(0)
00043 {
00044
00045
00046
00047
00048
00049
00050 Int_t nbin=0 ;
00051 TIterator* tIter = cat.typeIterator() ;
00052 RooCatType* type ;
00053 while (((type = (RooCatType*)tIter->Next()))) {
00054 _types.Add(new RooCatType(*type)) ;
00055 nbin++ ;
00056 }
00057 delete tIter ;
00058
00059
00060 _count.resize(nbin) ;
00061 for (int i=0 ; i<nbin ; i++) _count[i] = 0 ;
00062 }
00063
00064
00065
00066
00067 Roo1DTable::Roo1DTable(const Roo1DTable& other) :
00068 RooTable(other), _count(other._count), _total(other._total), _nOverflow(other._nOverflow)
00069 {
00070
00071
00072
00073
00074 int i;
00075 for (i=0 ; i<other._types.GetEntries() ; i++) {
00076 _types.Add(new RooCatType(*(RooCatType*)other._types.At(i))) ;
00077 }
00078
00079 }
00080
00081
00082
00083
00084 Roo1DTable::~Roo1DTable()
00085 {
00086
00087
00088
00089 _types.Delete() ;
00090 }
00091
00092
00093
00094
00095 void Roo1DTable::fill(RooAbsCategory& cat, Double_t weight)
00096 {
00097
00098
00099
00100
00101
00102 if (weight==0) return ;
00103
00104 _total += weight ;
00105
00106
00107 for (int i=0 ; i<_types.GetEntries() ; i++) {
00108 RooCatType* entry = (RooCatType*) _types.At(i) ;
00109 if (cat.getIndex()==entry->getVal()) {
00110 _count[i] += weight ; ;
00111
00112 return;
00113 }
00114 }
00115
00116
00117 _nOverflow += weight ;
00118
00119 }
00120
00121
00122
00123
00124 void Roo1DTable::printName(ostream& os) const
00125 {
00126
00127 os << GetName() ;
00128 }
00129
00130
00131
00132
00133 void Roo1DTable::printTitle(ostream& os) const
00134 {
00135
00136 os << GetTitle() ;
00137 }
00138
00139
00140
00141
00142 void Roo1DTable::printClassName(ostream& os) const
00143 {
00144
00145 os << IsA()->GetName() ;
00146 }
00147
00148
00149
00150
00151 void Roo1DTable::printValue(ostream& os) const
00152 {
00153
00154 os << "(" ;
00155 for (Int_t i=0 ; i<_types.GetEntries() ; i++) {
00156 RooCatType* entry = (RooCatType*) _types.At(i) ;
00157 if (_count[i]>0) {
00158 if (i>0) {
00159 os << "," ;
00160 }
00161 os << entry->GetName() << "=" << _count[i] ;
00162 }
00163 }
00164 os << ")" ;
00165 }
00166
00167
00168
00169
00170
00171 Int_t Roo1DTable::defaultPrintContents(Option_t* ) const
00172 {
00173
00174 return kName|kClassName|kValue|kArgs ;
00175 }
00176
00177
00178
00179
00180 void Roo1DTable::printMultiline(ostream& os, Int_t , Bool_t verbose, TString indent) const
00181 {
00182
00183
00184 os << indent << endl ;
00185 os << indent << " Table " << GetName() << " : " << GetTitle() << endl ;
00186
00187
00188 Int_t labelWidth(0) ;
00189 Double_t maxCount(1) ;
00190
00191 int i;
00192 for (i=0 ; i<_types.GetEntries() ; i++) {
00193 RooCatType* entry = (RooCatType*) _types.At(i) ;
00194
00195
00196
00197 Int_t lwidth = strlen(entry->GetName());
00198 labelWidth = lwidth > labelWidth ? lwidth : labelWidth;
00199 maxCount=_count[i]>maxCount?_count[i]:maxCount ;
00200 }
00201
00202 if (_nOverflow>0) {
00203 labelWidth=labelWidth>8?labelWidth:8 ;
00204 maxCount=maxCount>_nOverflow?maxCount:_nOverflow ;
00205 }
00206
00207
00208 Int_t countWidth=((Int_t)log10(maxCount))+1 ;
00209 os << indent << " +-" << setw(labelWidth) << setfill('-') << "-" << "-+-" << setw(countWidth) << "-" << "-+" << endl ;
00210 os << setfill(' ') ;
00211
00212
00213 for (i=0 ; i<_types.GetEntries() ; i++) {
00214 RooCatType* entry = (RooCatType*) _types.At(i) ;
00215 if (_count[i]>0 || verbose) {
00216 os << " | " << setw(labelWidth) << entry->GetName() << " | " << setw(countWidth) << _count[i] << " |" << endl ;
00217 }
00218 }
00219
00220
00221 if (_nOverflow) {
00222 os << indent << " +-" << setw(labelWidth) << setfill('-') << "-" << "-+-" << setw(countWidth) << "-" << "-+" << endl ;
00223 os << indent << " | " << "Overflow" << " | " << setw(countWidth) << _nOverflow << " |" << endl ;
00224 }
00225
00226
00227 os << indent << " +-" << setw(labelWidth) << setfill('-') << "-" << "-+-" << setw(countWidth) << "-" << "-+" << endl ;
00228 os << setfill(' ') ;
00229 os << indent << endl ;
00230 }
00231
00232
00233
00234
00235 Double_t Roo1DTable::get(const char* label, Bool_t silent) const
00236 {
00237
00238
00239
00240
00241 TObject* cat = _types.FindObject(label) ;
00242 if (!cat) {
00243 if (!silent) {
00244 coutE(InputArguments) << "Roo1DTable::get: ERROR: no such entry: " << label << endl ;
00245 }
00246 return 0 ;
00247 }
00248 return _count[_types.IndexOf(cat)] ;
00249 }
00250
00251
00252
00253
00254 Double_t Roo1DTable::getOverflow() const
00255 {
00256
00257
00258 return _nOverflow ;
00259 }
00260
00261
00262
00263
00264 Double_t Roo1DTable::getFrac(const char* label, Bool_t silent) const
00265 {
00266
00267
00268
00269
00270 if (_total) {
00271 return get(label,silent) / _total ;
00272 } else {
00273 if (!silent) coutW(Contents) << "Roo1DTable::getFrac: WARNING table empty, returning 0" << endl ;
00274 return 0. ;
00275 }
00276 }
00277
00278
00279
00280
00281 Bool_t Roo1DTable::isIdentical(const RooTable& other)
00282 {
00283
00284
00285 const Roo1DTable* other1d = &dynamic_cast<const Roo1DTable&>(other) ;
00286
00287 if (!other1d) {
00288 return kFALSE ;
00289 }
00290
00291 int i;
00292 for (i=0 ; i<_types.GetEntries() ; i++) {
00293
00294 if (_count[i] != other1d->_count[i]) {
00295 return kFALSE ;
00296 }
00297 }
00298 return kTRUE ;
00299 }