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
00026 #include "RooFit.h"
00027
00028 #include "Riostream.h"
00029 #include "Riostream.h"
00030 #include <stdlib.h>
00031 #include <stdio.h>
00032 #include "TString.h"
00033 #include "RooThresholdCategory.h"
00034 #include "RooStreamParser.h"
00035 #include "RooThreshEntry.h"
00036 #include "RooMsgService.h"
00037
00038 ClassImp(RooThresholdCategory)
00039
00040
00041
00042
00043 RooThresholdCategory::RooThresholdCategory(const char *name, const char *title, RooAbsReal& inputVar,
00044 const char* defOut, Int_t defIdx) :
00045 RooAbsCategory(name, title), _inputVar("inputVar","Input category",this,inputVar)
00046 {
00047
00048
00049
00050 _defCat = (RooCatType*) defineType(defOut,defIdx) ;
00051 _threshIter = _threshList.MakeIterator() ;
00052 }
00053
00054
00055
00056
00057 RooThresholdCategory::RooThresholdCategory(const RooThresholdCategory& other, const char *name) :
00058 RooAbsCategory(other,name), _inputVar("inputVar",this,other._inputVar)
00059 {
00060
00061
00062 _defCat = (RooCatType*) lookupType(other._defCat->GetName()) ;
00063
00064 other._threshIter->Reset() ;
00065 RooThreshEntry* te ;
00066 while((te=(RooThreshEntry*)other._threshIter->Next())) {
00067 _threshList.Add(new RooThreshEntry(*te)) ;
00068 }
00069
00070 _threshIter = _threshList.MakeIterator() ;
00071 }
00072
00073
00074
00075
00076 RooThresholdCategory::~RooThresholdCategory()
00077 {
00078
00079
00080 _threshList.Delete() ;
00081 delete _threshIter ;
00082 }
00083
00084
00085
00086
00087 Bool_t RooThresholdCategory::addThreshold(Double_t upperLimit, const char* catName, Int_t catIdx)
00088 {
00089
00090
00091
00092
00093 _threshIter->Reset() ;
00094 RooThreshEntry* te ;
00095 while ((te=(RooThreshEntry*)_threshIter->Next())) {
00096 if (te->thresh() == upperLimit) {
00097 coutW(InputArguments) << "RooThresholdCategory::addThreshold(" << GetName()
00098 << ") threshold at " << upperLimit << " already defined" << endl ;
00099 return kTRUE ;
00100 }
00101 }
00102
00103
00104
00105 const RooCatType* type = lookupType(catName,kFALSE) ;
00106 if (!type) {
00107 if (catIdx==-99999) {
00108 type=defineType(catName) ;
00109 } else {
00110 type=defineType(catName,catIdx) ;
00111 }
00112 }
00113 te = new RooThreshEntry(upperLimit,*type) ;
00114 _threshList.Add(te) ;
00115
00116 return kFALSE ;
00117 }
00118
00119
00120
00121
00122 RooCatType RooThresholdCategory::evaluate() const
00123 {
00124
00125
00126
00127 _threshIter->Reset() ;
00128 RooThreshEntry* te ;
00129 while((te=(RooThreshEntry*)_threshIter->Next())) {
00130 if (_inputVar<te->thresh()) return te->cat() ;
00131 }
00132
00133
00134 return *_defCat ;
00135 }
00136
00137
00138
00139
00140 void RooThresholdCategory::writeToStream(ostream& os, Bool_t compact) const
00141 {
00142
00143
00144 if (compact) {
00145
00146 os << getLabel() ;
00147 } else {
00148
00149
00150
00151 _threshIter->Reset() ;
00152 RooThreshEntry* te ;
00153 while((te=(RooThreshEntry*)_threshIter->Next())) {
00154 os << te->cat().GetName() << ":<" << te->thresh() << " " ;
00155 }
00156 os << _defCat->GetName() << ":*" ;
00157 }
00158 }
00159
00160
00161
00162
00163 void RooThresholdCategory::printMultiline(ostream& os, Int_t content, Bool_t verbose, TString indent) const
00164 {
00165
00166
00167
00168
00169
00170
00171
00172 RooAbsCategory::printMultiline(os,content,verbose,indent);
00173
00174 if (verbose) {
00175 os << indent << "--- RooThresholdCategory ---" << endl
00176 << indent << " Maps from " ;
00177 _inputVar.arg().printStream(os,0,kStandard);
00178
00179 os << indent << " Threshold list" << endl ;
00180 _threshIter->Reset() ;
00181 RooThreshEntry* te ;
00182 while((te=(RooThreshEntry*)_threshIter->Next())) {
00183 os << indent << " input < " << te->thresh() << " --> " ;
00184 te->cat().printStream(os,kName|kValue,kSingleLine) ;
00185 }
00186 os << indent << " Default value is " ;
00187 _defCat->printStream(os,kValue,kSingleLine);
00188
00189
00190 }
00191 }
00192
00193