31 : _minBinToPrint(-1), _maxBinToPrint(-1),
32 _label_print_width(20), _bin_print_width(12) {
35 std::cout <<
"Error: The supplied ModelConfig is NULL " << std::endl;
42 std::cout <<
"Error: The pdf found in the ModelConfig: " << mc->
GetName()
43 <<
" is NULL" << std::endl;
52 if( !observables_in_mc ) {
53 std::cout <<
"Error: Observable set in the ModelConfig: " << mc->
GetName()
54 <<
" is NULL" << std::endl;
57 if( observables_in_mc->
getSize() == 0 ) {
58 std::cout <<
"Error: Observable list: " << observables_in_mc->
GetName()
59 <<
" found in ModelConfig: " << mc->
GetName()
60 <<
" has no entries." << std::endl;
75 const std::string& WorkspaceName,
76 const std::string& ModelConfigName) :
77 _minBinToPrint(-1), _maxBinToPrint(-1),
78 _label_print_width(20), _bin_print_width(12) {
83 std::cout <<
"Error: Failed to open file: " << FileName << std::endl;
90 std::cout <<
"Error: Failed to get workspace: " << WorkspaceName
91 <<
" from file: " << FileName << std::endl;
98 std::cout <<
"Error: Failed to find ModelConfig: " << ModelConfigName
99 <<
" from workspace: " << WorkspaceName
100 <<
" in file: " << FileName << std::endl;
107 std::cout <<
"Error: The pdf found in the ModelConfig: " << ModelConfigName
108 <<
" is NULL" << std::endl;
117 if( !observables_in_mc ) {
118 std::cout <<
"Error: Observable set in the ModelConfig: " << ModelConfigName
119 <<
" is NULL" << std::endl;
122 if( observables_in_mc->
getSize() == 0 ) {
123 std::cout <<
"Error: Observable list: " << observables_in_mc->
GetName()
124 <<
" found in ModelConfig: " << ModelConfigName
125 <<
" in file: " << FileName
126 <<
" has no entries." << std::endl;
141 _minBinToPrint(-1), _maxBinToPrint(-1),
142 _label_print_width(20), _bin_print_width(12) {
146 std::cout <<
"Error: The supplied pdf is NULL" << std::endl;
156 std::cout <<
"Error: Supplied Observable set is NULL" << std::endl;
159 if( observables->
getSize() == 0 ) {
160 std::cout <<
"Error: Observable list: " << observables->
GetName()
161 <<
" has no entries." << std::endl;
176 for(
int i = 0; i < num_bins; ++i) {
186 std::cout << std::setw(bin_print_width) << hist->
GetBinContent(current_bin);
188 std::cout << std::endl;
196 std::map< std::string, RooAbsPdf* >::iterator itr;
200 std::cout <<
"Warning: Could not find channel: " << channel
207 std::cout <<
"Warning: Pdf associated with channel: " << channel
208 <<
" is NULL" << std::endl;
220 std::cout << std::endl << channel <<
":" << std::endl;
237 std::map< std::string, RooAbsReal*>::iterator itr = SampleFunctionMap.begin();
238 for( ; itr != SampleFunctionMap.end(); ++itr) {
240 std::string sample_name = itr->first;
241 std::string tmp_name = sample_name + channel +
"_pretty_tmp";
253 std::string line_break;
258 for(
int i = 0; i < break_length; ++i) {
261 std::cout << line_break << std::endl;
263 std::string tmp_name = channel +
"_pretty_tmp";
290 for( std::map< std::string, RooAbsReal*>::iterator itr = SampleFunctionMap.begin();
291 itr != SampleFunctionMap.end(); ++itr) {
292 std::string sample_name = itr->first;
301 const std::string& channel_to_print) {
321 for(
unsigned int i_chan=0; i_chan <
fChannelNameVec.size(); ++i_chan) {
326 if( channel_to_print !=
"" && channel_name != channel_to_print)
continue;
328 TH1* data_hist =
GetDataHist(data, channel_name, channel_name+
"_tmp");
350 std::cout << std::endl;
360 std::cout << std::endl;
363 std::cout << std::setw(30) <<
"Parameter";
364 std::cout << std::setw(15) <<
"Value"
365 << std::setw(15) <<
"Error Low"
366 << std::setw(15) <<
"Error High"
374 if( !IncludeConstantParams && param->
isConstant() )
continue;
376 std::cout << std::setw(30) << param->
GetName();
377 std::cout << std::setw(15) << param->
getVal();
381 std::cout<< std::endl;
384 std::cout << std::endl;
390 bool IncludeConstantParams) {
398 std::cout << std::endl;
401 std::cout << std::setw(30) <<
"Parameter";
402 std::cout << std::setw(15) <<
"Value"
403 << std::setw(15) <<
"Error Low"
404 << std::setw(15) <<
"Error High"
412 if( !IncludeConstantParams && param->
isConstant() )
continue;
416 std::cout << std::setw(30) << param->
GetName();
417 std::cout << std::setw(15) << param->
getVal();
421 std::cout<< std::endl;
424 std::cout << std::endl;
431 const std::string& sample,
432 bool IncludeConstantParams) {
440 std::cout << std::endl;
443 std::cout << std::setw(30) <<
"Parameter";
444 std::cout << std::setw(15) <<
"Value"
445 << std::setw(15) <<
"Error Low"
446 << std::setw(15) <<
"Error High"
454 if( !IncludeConstantParams && param->
isConstant() )
continue;
458 std::cout << std::setw(30) << param->
GetName();
459 std::cout << std::setw(15) << param->
getVal();
463 std::cout<< std::endl;
466 std::cout << std::endl;
481 delete channel_hist_tmp;
493 TH1* sample_hist_tmp =
GetSampleHist(channel, sample, (channel+
"_tmp").c_str());
495 delete sample_hist_tmp;
504 std::map< std::string, std::map< std::string, RooAbsReal*> >::iterator channel_itr;
507 std::cout <<
"Error: Channel: " << channel <<
" not found in Navigation" << std::endl;
511 return channel_itr->second;
519 std::map< std::string, std::map< std::string, RooAbsReal*> >::iterator channel_itr;
522 std::cout <<
"Error: Channel: " << channel <<
" not found in Navigation" << std::endl;
526 std::map< std::string, RooAbsReal*>& SampleMap = channel_itr->second;
527 std::map< std::string, RooAbsReal*>::iterator sample_itr;
528 sample_itr = SampleMap.find(sample);
529 if( sample_itr==SampleMap.end() ){
530 std::cout <<
"Error: Sample: " << sample <<
" not found in Navigation" << std::endl;
534 return sample_itr->second;
542 std::map< std::string, RooArgSet*>::iterator channel_itr;
545 std::cout <<
"Error: Channel: " << channel <<
" not found in Navigation" << std::endl;
549 return channel_itr->second;
555 const std::string& hist_name) {
562 std::string
name = hist_name;
563 if(hist_name==
"") name = channel +
"_" + sample +
"_hist";
583 std::map< std::string, RooAbsReal*>::iterator itr = SampleFunctionMap.begin();
584 for( ; itr != SampleFunctionMap.end(); ++itr) {
585 std::string sample_name = itr->first;
586 std::string tmp_hist_name = sample_name +
"_hist_tmp";
590 total_hist = (
TH1*) sample_hist->
Clone(
"TotalHist");
598 itr = SampleFunctionMap.begin();
599 for( ; itr != SampleFunctionMap.end(); ++itr) {
600 std::string sample_name = itr->first;
601 std::string tmp_hist_name = sample_name +
"_hist_tmp";
605 total_hist->
Add(sample_hist);
609 if(hist_name==
"") total_hist->
SetName(hist_name.c_str());
610 else total_hist->
SetName( (channel +
"_hist").c_str() );
619 std::vector<std::string> sample_list;
622 std::map< std::string, RooAbsReal*>::iterator itr = sample_map.begin();;
623 for( ; itr != sample_map.end(); ++itr) {
624 sample_list.push_back( itr->first );
633 const std::string&
name) {
640 for(
unsigned int i=0; i < samples.size(); ++i) {
641 std::string sample_name = samples.at(i);
654 const std::string&
name) {
669 TList* dataset_list = data->
split(*channelCat);
700 std::cout <<
"Error: To Create Histogram from RooDataSet, Dimension must be 1, 2, or 3" << std::endl;
701 std::cout <<
"Observables: " << std::endl;
720 data_hist->
Draw(
"SAME");
743 if( ClassName ==
"RooProduct" ) {
777 if(strcmp(modelPdf->
ClassName(),
"RooSimultaneous")==0){
788 std::string ChannelName = tt->
GetName();
799 std::string ChannelName = modelPdf->
GetName();
800 ChannelName = ChannelName.replace(0, 6,
"");
828 if( ClassName ==
"RooRealSumPdf" ) {
851 std::map< std::string, RooAbsReal*> sampleFunctionMap;
864 std::string SampleName = sample->
GetName();
865 if( SampleName.find(
"L_x_") != std::string::npos ) {
866 size_t index = SampleName.find(
"L_x_");
867 SampleName.replace( index, 4,
"" );
869 if( SampleName.find(ChannelName.c_str()) != std::string::npos ) {
870 size_t index = SampleName.find(ChannelName.c_str());
871 SampleName = SampleName.substr(0, index-1);
875 sampleFunctionMap[SampleName] =
func;
899 std::string ArgName = arg->
GetName();
900 if( ArgName == name ) {
908 if( term !=
NULL )
return term;
918 std::string ParamName = param->
GetName();
919 if( ParamName == name ) {
947 std::string ConstraintTermName = parameter +
"Constraint";
953 std::cout <<
"Error: Couldn't Find parameter: " << parameter <<
" in model."
959 if( parameter.find(
"gamma_stat_") != std::string::npos ) {
960 ConstraintTermName = parameter +
"_constraint";
967 std::cout <<
"Error: Couldn't Find constraint term for parameter: " << parameter
968 <<
" (Looked for '" << ConstraintTermName <<
"')" << std::endl;
980 if( constraintTerm==
NULL ) {
981 std::cout <<
"Error: Cannot get uncertainty because parameter: " << parameter
982 <<
" has no constraint term" << std::endl;
987 std::string ConstraintType = constraintTerm->IsA()->
GetName();
992 if( ConstraintType ==
"" ) {
993 std::cout <<
"Error: Constraint type is an empty string."
994 <<
" This simply should not be." << std::endl;
997 else if( ConstraintType ==
"RooGaussian" ){
1006 std::string sigmaName =
"";
1007 if( parameter.find(
"alpha_")!=std::string::npos ) {
1010 else if( parameter.find(
"gamma_stat_")!=std::string::npos ) {
1011 sigmaName = parameter +
"_sigma";
1016 if( sigmaVar==
NULL ) {
1017 std::cout <<
"Error: Failed to find the 'sigma' node: " << sigmaName
1018 <<
" in the RooGaussian: " << constraintTerm->
GetName() << std::endl;
1022 sigma = sigmaVar->
getVal();
1024 else if( ConstraintType ==
"RooPoisson" ){
1026 std::string tauName =
"nom_" + parameter;
1028 if( tauVar==
NULL ) {
1029 std::cout <<
"Error: Failed to find the nominal 'tau' node: " << tauName
1030 <<
" for the RooPoisson: " << constraintTerm->
GetName() << std::endl;
1033 double tau_val = tauVar->
getVal();
1037 std::cout <<
"Error: Encountered unknown constraint type for Stat Uncertainties: "
1038 << ConstraintType << std::endl;
1050 if( nodeToReplace==
NULL ) {
1051 std::cout <<
"Error: Cannot replace node: " << ToReplace
1052 <<
" because this node wasn't found in: " <<
fModel->
GetName()
1072 bool valueProp=
false;
1073 bool shapeProp=
false;
1074 client->
replaceServer( *nodeToReplace, *ReplaceWith, valueProp, shapeProp );
1075 std::cout <<
"Replaced: " << ToReplace <<
" with: " << ReplaceWith->
GetName()
1076 <<
" in node: " << client->
GetName() << std::endl;
1087 const std::string& sample) {
1096 std::string total_Name = sampleNode->
GetName();
1103 int label_print_width = 30;
1104 int bin_print_width = 12;
1105 if( strcmp(sampleNode->
ClassName(),
"RooProduct")==0){
1110 components.
add(*sampleNode);
1119 std::string NodeName = component->
GetName();
1120 label_print_width =
TMath::Max(label_print_width, (
int)NodeName.size()+2);
1125 std::cout << std::endl;
1126 std::cout <<
"Channel: " << channel <<
" Sample: " << sample << std::endl;
1127 std::cout << std::setw(label_print_width) <<
"Factor";
1129 for(
unsigned int i=0; i < num_bins; ++i) {
1132 std::stringstream sstr;
1134 std::cout << std::setw(bin_print_width) << sstr.str();
1136 std::cout << std::endl;
1142 std::string NodeName = component->
GetName();
1159 std::cout << std::setw(label_print_width) << NodeName;
1166 std::string line_break;
1169 int break_length = (high_bin - low_bin + 1) * bin_print_width;
1170 break_length += label_print_width;
1171 for(
int i = 0; i < break_length; ++i) {
1174 std::cout << line_break << std::endl;
1176 std::cout << std::setw(label_print_width) <<
"TOTAL:";
1194 std::string
name ) {
1232 std::cout <<
"Error: To Create Histogram from RooAbsReal function, Dimension must be 1, 2, or 3" << std::endl;
1251 TString RegexTString(regExpr);
1252 TRegexp theRegExpr(RegexTString);
1260 std::cout << std::endl;
1263 std::cout << std::setw(30) <<
"Parameter";
1264 std::cout << std::setw(15) <<
"Value"
1265 << std::setw(15) <<
"Error Low"
1266 << std::setw(15) <<
"Error High"
1274 std::string ParamName = param->
GetName();
1275 TString ParamNameTString(ParamName);
1280 if( theRegExpr.
Index(ParamNameTString, &dummy) == -1 )
continue;
1283 std::cout <<
"Setting param: " << ParamName <<
" constant"
1284 <<
" (matches regex: " << regExpr <<
")" << std::endl;
1291 if( !arg )
return NULL;
TH1 * MakeHistFromRooFunction(RooAbsReal *func, RooArgList vars, std::string name="Hist")
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
RooAbsPdf * GetPdf() const
get model PDF (return NULL if pdf has not been specified or does not exist)
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Bool_t IsBinOverflow(Int_t bin) const
The Histogram stack class.
RooRealVar * var(const std::string &varName) const
Bool_t IsBinUnderflow(Int_t bin) const
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Ssiz_t Index(const TString &str, Ssiz_t *len, Ssiz_t start=0) const
Find the first occurrence of the regexp in string and return the position, or -1 if there is no match...
const RooAbsCategoryLValue & indexCat() const
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
void PrintMultiDimHist(TH1 *hist, int bin_print_width)
Regular expression class.
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
RooAbsReal * GetConstraintTerm(const std::string ¶meter)
TH1 * GetSampleHist(const std::string &channel, const std::string &sample, const std::string &name="")
const RooAbsBinning & getBinning(const char *name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const
Return binning definition with name.
Short_t Min(Short_t a, Short_t b)
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
RooAbsArg * findChild(const std::string &name, RooAbsReal *parent) const
virtual Int_t GetNbinsX() const
void PrintChannelParameters(const std::string &channel, bool IncludeConstantParams=false)
static RooMsgService & instance()
Return reference to singleton instance.
RooAbsPdf * getPdf(const char *catName) const
Return the p.d.f associated with the given index category name.
void replaceServer(RooAbsArg &oldServer, RooAbsArg &newServer, Bool_t valueProp, Bool_t shapeProp)
Replace 'oldServer' with 'newServer'.
std::map< std::string, RooAbsPdf * > fChannelPdfMap
virtual void Draw(Option_t *chopt="")
Draw this multihist with its current attributes.
Iterator abstract base class.
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
void PrintSampleComponents(const std::string &channel, const std::string &sample)
RooArgSet _GetAllProducts(RooProduct *node)
std::map< std::string, std::string >::const_iterator iter
TIterator * createIterator(Bool_t dir=kIterForward) const
THStack * GetChannelStack(const std::string &channel, const std::string &name="")
const std::string ClassName(PyObject *pyobj)
Retrieve the class name from the given python object (which may be just an instance of the class)...
Double_t getVal(const RooArgSet *set=0) const
void ReplaceNode(const std::string &ToReplace, RooAbsArg *ReplaceWith)
RooAbsReal * SampleFunction(const std::string &channel, const std::string &sample)
TH1 * GetChannelHist(const std::string &channel, const std::string &name="")
void _GetNodes(ModelConfig *mc)
RooArgSet * getParameters(const RooAbsData *data, Bool_t stripDisconnected=kTRUE) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
RooFit::MsgLevel globalKillBelow() const
virtual void SetLineColor(Color_t lcolor)
TIterator * clientIterator() const
std::map< std::string, RooArgSet * > fChannelObservMap
virtual void Draw(Option_t *option="")
Draw this histogram with options.
virtual void SetFillColor(Color_t fcolor)
void setConstant(Bool_t value=kTRUE)
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
void SetPrintWidths(const std::string &channel)
std::map< std::string, std::map< std::string, RooAbsReal * > > fChannelSampleFunctionMap
virtual Int_t GetNbinsZ() const
void setGlobalKillBelow(RooFit::MsgLevel level)
virtual const char * GetName() const
Returns name of object.
Double_t getErrorHi() const
void PrintDataSet(RooDataSet *data, const std::string &channel="")
Bool_t isConstant() const
double GetBinValue(int bin, const std::string &channel)
const RooArgSet * GetObservables() const
get RooArgSet for observables (return NULL if not existing)
virtual void SetName(const char *name)
Change the name of this histogram.
Namespace for the RooStats classes.
RooAbsArg * at(Int_t idx) const
ClassImp(RooStats::HistFactory::HistFactoryNavigation)
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
void PrintSampleParameters(const std::string &channel, const std::string &sample, bool IncludeConstantParams=false)
TH1 * GetDataHist(RooDataSet *data, const std::string &channel, const std::string &name="")
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
static RooMathCoreReg dummy
virtual void Add(TH1 *h, Option_t *option="")
add a new histogram to the list Only 1-d and 2-d histograms currently supported.
double func(double *x, double *p)
TH1 * createHistogram(const char *varNameList, Int_t xbins=0, Int_t ybins=0, Int_t zbins=0) const
Create and fill a ROOT histogram TH1,TH2 or TH3 with the values of this function for the variables wi...
TObject * obj(const char *name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name) ...
RooArgSet * getComponents() const
virtual TList * split(const RooAbsCategory &splitCat, Bool_t createEmptyDataSets=kFALSE) const
Split dataset into subsets based on states of given splitCat in this dataset.
const RooArgList & funcList() const
std::vector< std::string > fChannelNameVec
TH2F * createHistogram(const RooAbsRealLValue &var1, const RooAbsRealLValue &var2, const char *cuts="", const char *name="hist") const
Create a TH2F histogram of the distribution of the specified variable using this dataset.
virtual Bool_t Add(TF1 *h1, Double_t c1=1, Option_t *option="")
Performs the operation: this = this + c1*f1 if errors are defined (see TH1::Sumw2), errors are also recalculated.
RooCmdArg Scaling(Bool_t flag)
std::map< std::string, RooAbsReal * > GetSampleFunctionMap(const std::string &channel)
virtual Int_t GetNbinsY() const
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Short_t Max(Short_t a, Short_t b)
virtual TObject * Next()=0
void PrintModelAndData(RooDataSet *data)
void PrintParameters(bool IncludeConstantParams=false)
Double_t Sqrt(Double_t x)
double GetConstraintUncertainty(const std::string ¶meter)
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
std::vector< std::string > GetChannelSampleList(const std::string &channel)
Double_t getErrorLo() const
HistFactoryNavigation(ModelConfig *mc)
RooAbsPdf * GetChannelPdf(const std::string &channel)
std::map< std::string, RooAbsPdf * > fChannelSumNodeMap
virtual const Text_t * GetName() const
Returns name of object.
RooArgSet * GetObservableSet(const std::string &channel)
TIterator * typeIterator() const
Return iterator over all defined states.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add element to non-owning set.
void SetConstant(const std::string ®Expr=".*", bool constant=true)
const char * GetName() const
Returns name of object.
RooCmdArg Binning(const RooAbsBinning &binning)
void DrawChannel(const std::string &channel, RooDataSet *data=NULL)
RooAbsArg * findServer(const char *name) const