// Class RooThresholdCategory provides a real-to-category mapping defined
// by a series of thresholds.
// END_HTML
#include "RooFit.h"
#include "Riostream.h"
#include "Riostream.h"
#include <stdlib.h>
#include <stdio.h>
#include "TString.h"
#include "RooThresholdCategory.h"
#include "RooStreamParser.h"
#include "RooThreshEntry.h"
#include "RooMsgService.h"
ClassImp(RooThresholdCategory)
RooThresholdCategory::RooThresholdCategory(const char *name, const char *title, RooAbsReal& inputVar,
const char* defOut, Int_t defIdx) :
RooAbsCategory(name, title), _inputVar("inputVar","Input category",this,inputVar)
{
_defCat = (RooCatType*) defineType(defOut,defIdx) ;
_threshIter = _threshList.MakeIterator() ;
}
RooThresholdCategory::RooThresholdCategory(const RooThresholdCategory& other, const char *name) :
RooAbsCategory(other,name), _inputVar("inputVar",this,other._inputVar)
{
_defCat = (RooCatType*) lookupType(other._defCat->GetName()) ;
other._threshIter->Reset() ;
RooThreshEntry* te ;
while((te=(RooThreshEntry*)other._threshIter->Next())) {
_threshList.Add(new RooThreshEntry(*te)) ;
}
_threshIter = _threshList.MakeIterator() ;
}
RooThresholdCategory::~RooThresholdCategory()
{
_threshList.Delete() ;
delete _threshIter ;
}
Bool_t RooThresholdCategory::addThreshold(Double_t upperLimit, const char* catName, Int_t catIdx)
{
_threshIter->Reset() ;
RooThreshEntry* te ;
while ((te=(RooThreshEntry*)_threshIter->Next())) {
if (te->thresh() == upperLimit) {
coutW(InputArguments) << "RooThresholdCategory::addThreshold(" << GetName()
<< ") threshold at " << upperLimit << " already defined" << endl ;
return kTRUE ;
}
}
const RooCatType* type = lookupType(catName,kFALSE) ;
if (!type) {
if (catIdx==-99999) {
type=defineType(catName) ;
} else {
type=defineType(catName,catIdx) ;
}
}
te = new RooThreshEntry(upperLimit,*type) ;
_threshList.Add(te) ;
return kFALSE ;
}
RooCatType RooThresholdCategory::evaluate() const
{
_threshIter->Reset() ;
RooThreshEntry* te ;
while((te=(RooThreshEntry*)_threshIter->Next())) {
if (_inputVar<te->thresh()) return te->cat() ;
}
return *_defCat ;
}
void RooThresholdCategory::writeToStream(ostream& os, Bool_t compact) const
{
if (compact) {
os << getLabel() ;
} else {
_threshIter->Reset() ;
RooThreshEntry* te ;
while((te=(RooThreshEntry*)_threshIter->Next())) {
os << te->cat().GetName() << ":<" << te->thresh() << " " ;
}
os << _defCat->GetName() << ":*" ;
}
}
void RooThresholdCategory::printMultiline(ostream& os, Int_t content, Bool_t verbose, TString indent) const
{
RooAbsCategory::printMultiline(os,content,verbose,indent);
if (verbose) {
os << indent << "--- RooThresholdCategory ---" << endl
<< indent << " Maps from " ;
_inputVar.arg().printStream(os,0,kStandard);
os << indent << " Threshold list" << endl ;
_threshIter->Reset() ;
RooThreshEntry* te ;
while((te=(RooThreshEntry*)_threshIter->Next())) {
os << indent << " input < " << te->thresh() << " --> " ;
te->cat().printStream(os,kName|kValue,kSingleLine) ;
}
os << indent << " Default value is " ;
_defCat->printStream(os,kValue,kSingleLine);
}
}
Last change: Mon Aug 25 11:37:02 2008
Last generated: 2008-08-25 11:37
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.