31 namespace HistFactory {
36 : _minBinToPrint(-1), _maxBinToPrint(-1),
37 _label_print_width(20), _bin_print_width(12) {
40 std::cout <<
"Error: The supplied ModelConfig is NULL " << std::endl;
47 std::cout <<
"Error: The pdf found in the ModelConfig: " << mc->
GetName()
48 <<
" is NULL" << std::endl;
57 if( !observables_in_mc ) {
58 std::cout <<
"Error: Observable set in the ModelConfig: " << mc->
GetName()
59 <<
" is NULL" << std::endl;
62 if( observables_in_mc->
getSize() == 0 ) {
63 std::cout <<
"Error: Observable list: " << observables_in_mc->
GetName()
64 <<
" found in ModelConfig: " << mc->
GetName()
65 <<
" has no entries." << std::endl;
80 const std::string& WorkspaceName,
81 const std::string& ModelConfigName) :
82 _minBinToPrint(-1), _maxBinToPrint(-1),
83 _label_print_width(20), _bin_print_width(12) {
88 std::cout <<
"Error: Failed to open file: " << FileName << std::endl;
95 std::cout <<
"Error: Failed to get workspace: " << WorkspaceName
96 <<
" from file: " << FileName << std::endl;
103 std::cout <<
"Error: Failed to find ModelConfig: " << ModelConfigName
104 <<
" from workspace: " << WorkspaceName
105 <<
" in file: " << FileName << std::endl;
112 std::cout <<
"Error: The pdf found in the ModelConfig: " << ModelConfigName
113 <<
" is NULL" << std::endl;
122 if( !observables_in_mc ) {
123 std::cout <<
"Error: Observable set in the ModelConfig: " << ModelConfigName
124 <<
" is NULL" << std::endl;
127 if( observables_in_mc->
getSize() == 0 ) {
128 std::cout <<
"Error: Observable list: " << observables_in_mc->
GetName()
129 <<
" found in ModelConfig: " << ModelConfigName
130 <<
" in file: " << FileName
131 <<
" has no entries." << std::endl;
146 _minBinToPrint(-1), _maxBinToPrint(-1),
147 _label_print_width(20), _bin_print_width(12) {
151 std::cout <<
"Error: The supplied pdf is NULL" << std::endl;
161 std::cout <<
"Error: Supplied Observable set is NULL" << std::endl;
164 if( observables->
getSize() == 0 ) {
165 std::cout <<
"Error: Observable list: " << observables->
GetName()
166 <<
" has no entries." << std::endl;
181 for(
int i = 0; i < num_bins; ++i) {
191 std::cout << std::setw(bin_print_width) << hist->
GetBinContent(current_bin);
193 std::cout << std::endl;
201 std::map< std::string, RooAbsPdf* >::iterator itr;
205 std::cout <<
"Warning: Could not find channel: " << channel
212 std::cout <<
"Warning: Pdf associated with channel: " << channel
213 <<
" is NULL" << std::endl;
225 std::cout << std::endl << channel <<
":" << std::endl;
242 std::map< std::string, RooAbsReal*>::iterator itr = SampleFunctionMap.begin();
243 for( ; itr != SampleFunctionMap.end(); ++itr) {
245 std::string sample_name = itr->first;
246 std::string tmp_name = sample_name + channel +
"_pretty_tmp";
258 std::string line_break;
263 for(
int i = 0; i < break_length; ++i) {
266 std::cout << line_break << std::endl;
268 std::string tmp_name = channel +
"_pretty_tmp";
295 for( std::map< std::string, RooAbsReal*>::iterator itr = SampleFunctionMap.begin();
296 itr != SampleFunctionMap.end(); ++itr) {
297 std::string sample_name = itr->first;
306 const std::string& channel_to_print) {
326 for(
unsigned int i_chan=0; i_chan <
fChannelNameVec.size(); ++i_chan) {
331 if( channel_to_print !=
"" && channel_name != channel_to_print)
continue;
333 TH1* data_hist =
GetDataHist(data, channel_name, channel_name+
"_tmp");
355 std::cout << std::endl;
365 std::cout << std::endl;
368 std::cout << std::setw(30) <<
"Parameter";
369 std::cout << std::setw(15) <<
"Value"
370 << std::setw(15) <<
"Error Low"
371 << std::setw(15) <<
"Error High"
379 if( !IncludeConstantParams && param->
isConstant() )
continue;
381 std::cout << std::setw(30) << param->
GetName();
382 std::cout << std::setw(15) << param->
getVal();
386 std::cout<< std::endl;
389 std::cout << std::endl;
395 bool IncludeConstantParams) {
403 std::cout << std::endl;
406 std::cout << std::setw(30) <<
"Parameter";
407 std::cout << std::setw(15) <<
"Value"
408 << std::setw(15) <<
"Error Low"
409 << std::setw(15) <<
"Error High"
417 if( !IncludeConstantParams && param->
isConstant() )
continue;
421 std::cout << std::setw(30) << param->
GetName();
422 std::cout << std::setw(15) << param->
getVal();
426 std::cout<< std::endl;
429 std::cout << std::endl;
436 const std::string& sample,
437 bool IncludeConstantParams) {
445 std::cout << std::endl;
448 std::cout << std::setw(30) <<
"Parameter";
449 std::cout << std::setw(15) <<
"Value"
450 << std::setw(15) <<
"Error Low"
451 << std::setw(15) <<
"Error High"
459 if( !IncludeConstantParams && param->
isConstant() )
continue;
463 std::cout << std::setw(30) << param->
GetName();
464 std::cout << std::setw(15) << param->
getVal();
468 std::cout<< std::endl;
471 std::cout << std::endl;
486 delete channel_hist_tmp;
498 TH1* sample_hist_tmp =
GetSampleHist(channel, sample, (channel+
"_tmp").c_str());
500 delete sample_hist_tmp;
509 std::map< std::string, std::map< std::string, RooAbsReal*> >::iterator channel_itr;
512 std::cout <<
"Error: Channel: " << channel <<
" not found in Navigation" << std::endl;
516 return channel_itr->second;
524 std::map< std::string, std::map< std::string, RooAbsReal*> >::iterator channel_itr;
527 std::cout <<
"Error: Channel: " << channel <<
" not found in Navigation" << std::endl;
531 std::map< std::string, RooAbsReal*>& SampleMap = channel_itr->second;
532 std::map< std::string, RooAbsReal*>::iterator sample_itr;
533 sample_itr = SampleMap.find(sample);
534 if( sample_itr==SampleMap.end() ){
535 std::cout <<
"Error: Sample: " << sample <<
" not found in Navigation" << std::endl;
539 return sample_itr->second;
547 std::map< std::string, RooArgSet*>::iterator channel_itr;
550 std::cout <<
"Error: Channel: " << channel <<
" not found in Navigation" << std::endl;
554 return channel_itr->second;
560 const std::string& hist_name) {
567 std::string
name = hist_name;
568 if(hist_name==
"")
name = channel +
"_" + sample +
"_hist";
587 TH1* total_hist=NULL;
588 std::map< std::string, RooAbsReal*>::iterator itr = SampleFunctionMap.begin();
589 for( ; itr != SampleFunctionMap.end(); ++itr) {
590 std::string sample_name = itr->first;
591 std::string tmp_hist_name = sample_name +
"_hist_tmp";
595 total_hist = (
TH1*) sample_hist->
Clone(
"TotalHist");
603 itr = SampleFunctionMap.begin();
604 for( ; itr != SampleFunctionMap.end(); ++itr) {
605 std::string sample_name = itr->first;
606 std::string tmp_hist_name = sample_name +
"_hist_tmp";
610 total_hist->
Add(sample_hist);
614 if(hist_name==
"") total_hist->
SetName(hist_name.c_str());
615 else total_hist->
SetName( (channel +
"_hist").c_str() );
624 std::vector<std::string> sample_list;
627 std::map< std::string, RooAbsReal*>::iterator itr = sample_map.begin();;
628 for( ; itr != sample_map.end(); ++itr) {
629 sample_list.push_back( itr->first );
638 const std::string&
name) {
645 for(
unsigned int i=0; i < samples.size(); ++i) {
646 std::string sample_name = samples.at(i);
659 const std::string&
name) {
674 TList* dataset_list = data->
split(*channelCat);
705 std::cout <<
"Error: To Create Histogram from RooDataSet, Dimension must be 1, 2, or 3" << std::endl;
706 std::cout <<
"Observables: " << std::endl;
725 data_hist->
Draw(
"SAME");
782 if(strcmp(modelPdf->
ClassName(),
"RooSimultaneous")==0){
790 TIterator* iter = channelCat->typeIterator() ;
793 std::string ChannelName =
tt->GetName();
804 std::string ChannelName = modelPdf->
GetName();
805 ChannelName = ChannelName.replace(0, 6,
"");
856 std::map< std::string, RooAbsReal*> sampleFunctionMap;
869 std::string SampleName = sample->
GetName();
870 if( SampleName.find(
"L_x_") != std::string::npos ) {
871 size_t index = SampleName.find(
"L_x_");
872 SampleName.replace( index, 4,
"" );
874 if( SampleName.find(ChannelName.c_str()) != std::string::npos ) {
875 size_t index = SampleName.find(ChannelName.c_str());
876 SampleName = SampleName.substr(0, index-1);
880 sampleFunctionMap[SampleName] = func;
904 std::string ArgName = arg->
GetName();
905 if( ArgName ==
name ) {
913 if( term != NULL )
return term;
923 std::string ParamName = param->
GetName();
924 if( ParamName ==
name ) {
952 std::string ConstraintTermName = parameter +
"Constraint";
958 std::cout <<
"Error: Couldn't Find parameter: " << parameter <<
" in model."
964 if( parameter.find(
"gamma_stat_") != std::string::npos ) {
965 ConstraintTermName = parameter +
"_constraint";
972 std::cout <<
"Error: Couldn't Find constraint term for parameter: " << parameter
973 <<
" (Looked for '" << ConstraintTermName <<
"')" << std::endl;
985 if( constraintTerm==NULL ) {
986 std::cout <<
"Error: Cannot get uncertainty because parameter: " << parameter
987 <<
" has no constraint term" << std::endl;
992 std::string ConstraintType = constraintTerm->IsA()->
GetName();
997 if( ConstraintType ==
"" ) {
998 std::cout <<
"Error: Constraint type is an empty string."
999 <<
" This simply should not be." << std::endl;
1002 else if( ConstraintType ==
"RooGaussian" ){
1011 std::string sigmaName =
"";
1012 if( parameter.find(
"alpha_")!=std::string::npos ) {
1015 else if( parameter.find(
"gamma_stat_")!=std::string::npos ) {
1016 sigmaName = parameter +
"_sigma";
1021 if( sigmaVar==NULL ) {
1022 std::cout <<
"Error: Failed to find the 'sigma' node: " << sigmaName
1023 <<
" in the RooGaussian: " << constraintTerm->
GetName() << std::endl;
1029 else if( ConstraintType ==
"RooPoisson" ){
1031 std::string tauName =
"nom_" + parameter;
1033 if( tauVar==NULL ) {
1034 std::cout <<
"Error: Failed to find the nominal 'tau' node: " << tauName
1035 <<
" for the RooPoisson: " << constraintTerm->
GetName() << std::endl;
1038 double tau_val = tauVar->
getVal();
1042 std::cout <<
"Error: Encountered unknown constraint type for Stat Uncertainties: "
1043 << ConstraintType << std::endl;
1055 if( nodeToReplace==NULL ) {
1056 std::cout <<
"Error: Cannot replace node: " << ToReplace
1057 <<
" because this node wasn't found in: " <<
fModel->
GetName()
1067 for (
auto client : nodeToReplace->
clients()) {
1075 bool valueProp=
false;
1076 bool shapeProp=
false;
1077 client->replaceServer( *nodeToReplace, *ReplaceWith, valueProp, shapeProp );
1078 std::cout <<
"Replaced: " << ToReplace <<
" with: " << ReplaceWith->
GetName()
1079 <<
" in node: " << client->GetName() << std::endl;
1089 const std::string& sample) {
1098 std::string total_Name = sampleNode->
GetName();
1105 int label_print_width = 30;
1106 int bin_print_width = 12;
1107 if( strcmp(sampleNode->
ClassName(),
"RooProduct")==0){
1112 components.
add(*sampleNode);
1121 std::string NodeName = component->
GetName();
1122 label_print_width =
TMath::Max(label_print_width, (
int)NodeName.size()+2);
1127 std::cout << std::endl;
1128 std::cout <<
"Channel: " << channel <<
" Sample: " << sample << std::endl;
1129 std::cout << std::setw(label_print_width) <<
"Factor";
1131 for(
unsigned int i=0; i < num_bins; ++i) {
1134 std::stringstream sstr;
1136 std::cout << std::setw(bin_print_width) << sstr.str();
1138 std::cout << std::endl;
1144 std::string NodeName = component->
GetName();
1161 std::cout << std::setw(label_print_width) << NodeName;
1168 std::string line_break;
1171 int break_length = (high_bin - low_bin + 1) * bin_print_width;
1172 break_length += label_print_width;
1173 for(
int i = 0; i < break_length; ++i) {
1176 std::cout << line_break << std::endl;
1178 std::cout << std::setw(label_print_width) <<
"TOTAL:";
1196 std::string
name ) {
1234 std::cout <<
"Error: To Create Histogram from RooAbsReal function, Dimension must be 1, 2, or 3" << std::endl;
1253 TString RegexTString(regExpr);
1254 TRegexp theRegExpr(RegexTString);
1262 std::cout << std::endl;
1265 std::cout << std::setw(30) <<
"Parameter";
1266 std::cout << std::setw(15) <<
"Value"
1267 << std::setw(15) <<
"Error Low"
1268 << std::setw(15) <<
"Error High"
1276 std::string ParamName = param->
GetName();
1277 TString ParamNameTString(ParamName);
1282 if( theRegExpr.
Index(ParamNameTString, &
dummy) == -1 )
continue;
1285 std::cout <<
"Setting param: " << ParamName <<
" constant"
1286 <<
" (matches regex: " << regExpr <<
")" << std::endl;
1293 if( !arg )
return NULL;
static RooMathCoreReg dummy
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Return the observables of this pdf given a set of observables.
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...
const RefCountList_t & clients() const
List of all clients of this object.
RooArgSet * getComponents() const
Bool_t isConstant() const
RooAbsArg * findServer(const char *name) const
Return server of this with name name. Returns nullptr if not found.
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
const char * GetName() const
Returns name of object.
TIterator * createIterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
TIterator-style iteration over contained elements.
virtual TList * split(const RooAbsCategory &splitCat, Bool_t createEmptyDataSets=kFALSE) const
Split dataset into subsets based on states of given splitCat in this dataset.
void setConstant(Bool_t value=kTRUE)
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
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 w...
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state.
RooCategory represents a fundamental (non-derived) discrete value object.
RooDataSet is a container class to hold unbinned data.
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.
static RooMsgService & instance()
Return reference to singleton instance.
void setGlobalKillBelow(RooFit::MsgLevel level)
RooFit::MsgLevel globalKillBelow() const
A RooProduct represents the product of a given set of RooAbsReal objects.
The class RooRealSumPdf implements a PDF constructed from a sum of functions:
const RooArgList & funcList() const
RooRealVar represents a variable that can be changed from the outside.
Double_t getErrorHi() const
Double_t getErrorLo() const
const RooAbsBinning & getBinning(const char *name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const
Return binning definition with name.
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
const RooAbsCategoryLValue & indexCat() const
RooAbsPdf * getPdf(const char *catName) const
Return the p.d.f associated with the given index category name.
void PrintParameters(bool IncludeConstantParams=false)
Print the current values and errors of pdf parameters.
std::vector< std::string > fChannelNameVec
The list of channels.
RooArgSet * GetObservableSet(const std::string &channel)
Get the set of observables for a given channel.
TH1 * GetDataHist(RooDataSet *data, const std::string &channel, const std::string &name="")
Get a histogram from the dataset for this channel.
RooArgSet * fObservables
The observables.
void _GetNodes(ModelConfig *mc)
Fetch the node information for the pdf in question, and save it in the varous collections in this cla...
std::map< std::string, RooAbsPdf * > fChannelSumNodeMap
Map of channel names to pdf without constraint.
void ReplaceNode(const std::string &ToReplace, RooAbsArg *ReplaceWith)
Find a node in the pdf and replace it with a new node These nodes can be functions,...
void PrintState()
Should pretty print all channels and the current values

void PrintSampleComponents(const std::string &channel, const std::string &sample)
Print the different components that make up a sample (NormFactors, Statistical Uncertainties,...
void SetPrintWidths(const std::string &channel)
Set the title and bin widths.
RooAbsPdf * fModel
The HistFactory Pdf Pointer.
TH1 * GetChannelHist(const std::string &channel, const std::string &name="")
Get the total channel histogram for this channel.
TH1 * GetSampleHist(const std::string &channel, const std::string &sample, const std::string &name="")
The (current) histogram for that sample This includes all parameters and interpolation.
TH1 * MakeHistFromRooFunction(RooAbsReal *func, RooArgList vars, std::string name="Hist")
Make a histogram from a funciton Edit so it can take a RooArgSet of parameters.
void PrintMultiDimHist(TH1 *hist, int bin_print_width)
Print a histogram's contents to the screen void PrettyPrintHistogram(TH1* hist);.
void DrawChannel(const std::string &channel, RooDataSet *data=NULL)
Draw a stack of the channel, and include data if the pointer is supplied.
void PrintSampleParameters(const std::string &channel, const std::string &sample, bool IncludeConstantParams=false)
Print parameters that effect a particular sample.
std::map< std::string, RooAbsReal * > GetSampleFunctionMap(const std::string &channel)
Get a map of sample names to their functions for a particular channel.
RooAbsReal * SampleFunction(const std::string &channel, const std::string &sample)
Get the RooAbsReal function for a given sample in a given channel.
HistFactoryNavigation(ModelConfig *mc)
Initialze based on an already-created HistFactory Model.
double GetBinValue(int bin, const std::string &channel)
The value of the ith bin for the total in that channel.
RooAbsArg * findChild(const std::string &name, RooAbsReal *parent) const
Internal method implementation of finding a daughter node from a parent node (looping over all genera...
std::map< std::string, std::map< std::string, RooAbsReal * > > fChannelSampleFunctionMap
Map of Map of Channel, Sample names to Function Nodes Used by doing: fChannelSampleFunctionMap["MyCha...
std::map< std::string, RooAbsPdf * > fChannelPdfMap
Map of channel names to their full pdf's.
std::vector< std::string > GetChannelSampleList(const std::string &channel)
void PrintModelAndData(RooDataSet *data)
Print the model and the data, comparing channel by channel.
std::map< std::string, RooArgSet * > fChannelObservMap
Map of channel names to their set of ovservables.
RooAbsPdf * GetChannelPdf(const std::string &channel)
void PrintDataSet(RooDataSet *data, const std::string &channel="")
Print a "HistFactory style" RooDataSet in a readable way.
void PrintChannelParameters(const std::string &channel, bool IncludeConstantParams=false)
Print parameters that effect a particular channel.
void SetConstant(const std::string ®Expr=".*", bool constant=true)
RooArgSet _GetAllProducts(RooProduct *node)
Recursively get all products of products.
THStack * GetChannelStack(const std::string &channel, const std::string &name="")
Get a stack of all samples in a channel.
RooAbsReal * GetConstraintTerm(const std::string ¶meter)
Get the constraint term for a given systematic (alpha or gamma)
RooRealVar * var(const std::string &varName) const
double GetConstraintUncertainty(const std::string ¶meter)
Get the uncertainty based on the constraint term for a given systematic.
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
const RooArgSet * GetObservables() const
get RooArgSet for observables (return NULL if not existing)
RooAbsPdf * GetPdf() const
get model PDF (return NULL if pdf has not been specified or does not exist)
The RooWorkspace is a persistable container for RooFit projects.
TObject * obj(const char *name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name)
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
virtual Int_t GetNbinsY() const
virtual Int_t GetNbinsZ() const
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.
virtual Int_t GetNbinsX() const
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),...
Bool_t IsBinUnderflow(Int_t bin, Int_t axis=0) const
Return true if the bin is underflow.
Bool_t IsBinOverflow(Int_t bin, Int_t axis=0) const
Return true if the bin is overflow.
virtual void Draw(Option_t *option="")
Draw this histogram with options.
virtual void SetName(const char *name)
Change the name of this histogram.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
The Histogram stack class.
virtual void Draw(Option_t *chopt="")
Draw this multihist with its current attributes.
virtual void Add(TH1 *h, Option_t *option="")
add a new histogram to the list Only 1-d and 2-d histograms currently supported.
Iterator abstract base class.
virtual TObject * Next()=0
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
virtual const char * GetName() const
Returns name of object.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Regular expression class.
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 std::string ClassName(PyObject *pyobj)
Retrieve the class name from the given python object (which may be just an instance of the class).
RooCmdArg Scaling(Bool_t flag)
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
RooCmdArg Binning(const RooAbsBinning &binning)
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
Namespace for the RooStats classes.
Short_t Max(Short_t a, Short_t b)
Double_t Sqrt(Double_t x)
Short_t Min(Short_t a, Short_t b)