27 namespace HistFactory {
32 : _minBinToPrint(-1), _maxBinToPrint(-1),
33 _label_print_width(20), _bin_print_width(12) {
36 std::cout <<
"Error: The supplied ModelConfig is NULL " << std::endl;
43 std::cout <<
"Error: The pdf found in the ModelConfig: " << mc->
GetName()
44 <<
" is NULL" << std::endl;
53 if( !observables_in_mc ) {
54 std::cout <<
"Error: Observable set in the ModelConfig: " << mc->
GetName()
55 <<
" is NULL" << std::endl;
58 if( observables_in_mc->
getSize() == 0 ) {
59 std::cout <<
"Error: Observable list: " << observables_in_mc->
GetName()
60 <<
" found in ModelConfig: " << mc->
GetName()
61 <<
" has no entries." << std::endl;
76 const std::string& WorkspaceName,
77 const std::string& ModelConfigName) :
84 std::cout <<
"Error: Failed to open file: " << FileName << std::endl;
91 std::cout <<
"Error: Failed to get workspace: " << WorkspaceName
92 <<
" from file: " << FileName << std::endl;
99 std::cout <<
"Error: Failed to find ModelConfig: " << ModelConfigName
100 <<
" from workspace: " << WorkspaceName
101 <<
" in file: " << FileName << std::endl;
108 std::cout <<
"Error: The pdf found in the ModelConfig: " << ModelConfigName
109 <<
" is NULL" << std::endl;
118 if( !observables_in_mc ) {
119 std::cout <<
"Error: Observable set in the ModelConfig: " << ModelConfigName
120 <<
" is NULL" << std::endl;
123 if( observables_in_mc->
getSize() == 0 ) {
124 std::cout <<
"Error: Observable list: " << observables_in_mc->
GetName()
125 <<
" found in ModelConfig: " << ModelConfigName
126 <<
" in file: " << FileName
127 <<
" has no entries." << std::endl;
147 std::cout <<
"Error: The supplied pdf is NULL" << std::endl;
157 std::cout <<
"Error: Supplied Observable set is NULL" << std::endl;
160 if( observables->
getSize() == 0 ) {
161 std::cout <<
"Error: Observable list: " << observables->
GetName()
162 <<
" has no entries." << std::endl;
177 for(
int i = 0; i < num_bins; ++i) {
187 std::cout << std::setw(bin_print_width) << hist->
GetBinContent(current_bin);
189 std::cout << std::endl;
197 std::map< std::string, RooAbsPdf* >::iterator itr;
201 std::cout <<
"Warning: Could not find channel: " << channel
208 std::cout <<
"Warning: Pdf associated with channel: " << channel
209 <<
" is NULL" << std::endl;
221 std::cout << std::endl << channel <<
":" << std::endl;
238 std::map< std::string, RooAbsReal*>::iterator itr = SampleFunctionMap.begin();
239 for( ; itr != SampleFunctionMap.end(); ++itr) {
241 std::string sample_name = itr->first;
242 std::string tmp_name = sample_name + channel +
"_pretty_tmp";
254 std::string line_break;
259 for(
int i = 0; i < break_length; ++i) {
262 std::cout << line_break << std::endl;
264 std::string tmp_name = channel +
"_pretty_tmp";
291 for( std::map< std::string, RooAbsReal*>::iterator itr = SampleFunctionMap.begin();
292 itr != SampleFunctionMap.end(); ++itr) {
293 std::string sample_name = itr->first;
302 const std::string& channel_to_print) {
322 for(
unsigned int i_chan=0; i_chan <
fChannelNameVec.size(); ++i_chan) {
327 if( channel_to_print !=
"" && channel_name != channel_to_print)
continue;
329 TH1* data_hist =
GetDataHist(data, channel_name, channel_name+
"_tmp");
351 std::cout << std::endl;
361 std::cout << std::endl;
364 std::cout << std::setw(30) <<
"Parameter";
365 std::cout << std::setw(15) <<
"Value" 366 << std::setw(15) <<
"Error Low" 367 << std::setw(15) <<
"Error High" 375 if( !IncludeConstantParams && param->
isConstant() )
continue;
377 std::cout << std::setw(30) << param->
GetName();
378 std::cout << std::setw(15) << param->
getVal();
382 std::cout<< std::endl;
385 std::cout << std::endl;
391 bool IncludeConstantParams) {
399 std::cout << std::endl;
402 std::cout << std::setw(30) <<
"Parameter";
403 std::cout << std::setw(15) <<
"Value" 404 << std::setw(15) <<
"Error Low" 405 << std::setw(15) <<
"Error High" 413 if( !IncludeConstantParams && param->
isConstant() )
continue;
417 std::cout << std::setw(30) << param->
GetName();
418 std::cout << std::setw(15) << param->
getVal();
422 std::cout<< std::endl;
425 std::cout << std::endl;
432 const std::string& sample,
433 bool IncludeConstantParams) {
441 std::cout << std::endl;
444 std::cout << std::setw(30) <<
"Parameter";
445 std::cout << std::setw(15) <<
"Value" 446 << std::setw(15) <<
"Error Low" 447 << std::setw(15) <<
"Error High" 455 if( !IncludeConstantParams && param->
isConstant() )
continue;
459 std::cout << std::setw(30) << param->
GetName();
460 std::cout << std::setw(15) << param->
getVal();
464 std::cout<< std::endl;
467 std::cout << std::endl;
482 delete channel_hist_tmp;
494 TH1* sample_hist_tmp =
GetSampleHist(channel, sample, (channel+
"_tmp").c_str());
496 delete sample_hist_tmp;
505 std::map< std::string, std::map< std::string, RooAbsReal*> >::iterator channel_itr;
508 std::cout <<
"Error: Channel: " << channel <<
" not found in Navigation" << std::endl;
512 return channel_itr->second;
520 std::map< std::string, std::map< std::string, RooAbsReal*> >::iterator channel_itr;
523 std::cout <<
"Error: Channel: " << channel <<
" not found in Navigation" << std::endl;
527 std::map< std::string, RooAbsReal*>& SampleMap = channel_itr->second;
528 std::map< std::string, RooAbsReal*>::iterator sample_itr;
529 sample_itr = SampleMap.find(sample);
530 if( sample_itr==SampleMap.end() ){
531 std::cout <<
"Error: Sample: " << sample <<
" not found in Navigation" << std::endl;
535 return sample_itr->second;
543 std::map< std::string, RooArgSet*>::iterator channel_itr;
546 std::cout <<
"Error: Channel: " << channel <<
" not found in Navigation" << std::endl;
550 return channel_itr->second;
556 const std::string& hist_name) {
563 std::string
name = hist_name;
564 if(hist_name==
"") name = channel +
"_" + sample +
"_hist";
584 std::map< std::string, RooAbsReal*>::iterator itr = SampleFunctionMap.begin();
585 for( ; itr != SampleFunctionMap.end(); ++itr) {
586 std::string sample_name = itr->first;
587 std::string tmp_hist_name = sample_name +
"_hist_tmp";
591 total_hist = (
TH1*) sample_hist->
Clone(
"TotalHist");
599 itr = SampleFunctionMap.begin();
600 for( ; itr != SampleFunctionMap.end(); ++itr) {
601 std::string sample_name = itr->first;
602 std::string tmp_hist_name = sample_name +
"_hist_tmp";
606 total_hist->
Add(sample_hist);
610 if(hist_name==
"") total_hist->
SetName(hist_name.c_str());
611 else total_hist->
SetName( (channel +
"_hist").c_str() );
620 std::vector<std::string> sample_list;
623 std::map< std::string, RooAbsReal*>::iterator itr = sample_map.begin();;
624 for( ; itr != sample_map.end(); ++itr) {
625 sample_list.push_back( itr->first );
634 const std::string&
name) {
641 for(
unsigned int i=0; i < samples.size(); ++i) {
642 std::string sample_name = samples.at(i);
655 const std::string&
name) {
670 TList* dataset_list = data->
split(*channelCat);
701 std::cout <<
"Error: To Create Histogram from RooDataSet, Dimension must be 1, 2, or 3" << std::endl;
702 std::cout <<
"Observables: " << std::endl;
721 data_hist->
Draw(
"SAME");
744 if( ClassName ==
"RooProduct" ) {
778 if(strcmp(modelPdf->
ClassName(),
"RooSimultaneous")==0){
789 std::string ChannelName = tt->
GetName();
800 std::string ChannelName = modelPdf->
GetName();
801 ChannelName = ChannelName.replace(0, 6,
"");
829 if( ClassName ==
"RooRealSumPdf" ) {
852 std::map< std::string, RooAbsReal*> sampleFunctionMap;
865 std::string SampleName = sample->
GetName();
866 if( SampleName.find(
"L_x_") != std::string::npos ) {
867 size_t index = SampleName.find(
"L_x_");
868 SampleName.replace( index, 4,
"" );
870 if( SampleName.find(ChannelName.c_str()) != std::string::npos ) {
871 size_t index = SampleName.find(ChannelName.c_str());
872 SampleName = SampleName.substr(0, index-1);
876 sampleFunctionMap[SampleName] =
func;
900 std::string ArgName = arg->
GetName();
901 if( ArgName == name ) {
909 if( term !=
NULL )
return term;
919 std::string ParamName = param->
GetName();
920 if( ParamName == name ) {
948 std::string ConstraintTermName = parameter +
"Constraint";
954 std::cout <<
"Error: Couldn't Find parameter: " << parameter <<
" in model." 960 if( parameter.find(
"gamma_stat_") != std::string::npos ) {
961 ConstraintTermName = parameter +
"_constraint";
968 std::cout <<
"Error: Couldn't Find constraint term for parameter: " << parameter
969 <<
" (Looked for '" << ConstraintTermName <<
"')" << std::endl;
981 if( constraintTerm==
NULL ) {
982 std::cout <<
"Error: Cannot get uncertainty because parameter: " << parameter
983 <<
" has no constraint term" << std::endl;
988 std::string ConstraintType = constraintTerm->IsA()->
GetName();
993 if( ConstraintType ==
"" ) {
994 std::cout <<
"Error: Constraint type is an empty string." 995 <<
" This simply should not be." << std::endl;
998 else if( ConstraintType ==
"RooGaussian" ){
1007 std::string sigmaName =
"";
1008 if( parameter.find(
"alpha_")!=std::string::npos ) {
1011 else if( parameter.find(
"gamma_stat_")!=std::string::npos ) {
1012 sigmaName = parameter +
"_sigma";
1017 if( sigmaVar==
NULL ) {
1018 std::cout <<
"Error: Failed to find the 'sigma' node: " << sigmaName
1019 <<
" in the RooGaussian: " << constraintTerm->
GetName() << std::endl;
1023 sigma = sigmaVar->
getVal();
1025 else if( ConstraintType ==
"RooPoisson" ){
1027 std::string tauName =
"nom_" + parameter;
1029 if( tauVar==
NULL ) {
1030 std::cout <<
"Error: Failed to find the nominal 'tau' node: " << tauName
1031 <<
" for the RooPoisson: " << constraintTerm->
GetName() << std::endl;
1034 double tau_val = tauVar->
getVal();
1038 std::cout <<
"Error: Encountered unknown constraint type for Stat Uncertainties: " 1039 << ConstraintType << std::endl;
1051 if( nodeToReplace==
NULL ) {
1052 std::cout <<
"Error: Cannot replace node: " << ToReplace
1053 <<
" because this node wasn't found in: " <<
fModel->
GetName()
1073 bool valueProp=
false;
1074 bool shapeProp=
false;
1075 client->
replaceServer( *nodeToReplace, *ReplaceWith, valueProp, shapeProp );
1076 std::cout <<
"Replaced: " << ToReplace <<
" with: " << ReplaceWith->
GetName()
1077 <<
" in node: " << client->
GetName() << std::endl;
1088 const std::string& sample) {
1097 std::string total_Name = sampleNode->
GetName();
1104 int label_print_width = 30;
1105 int bin_print_width = 12;
1106 if( strcmp(sampleNode->
ClassName(),
"RooProduct")==0){
1111 components.
add(*sampleNode);
1120 std::string NodeName = component->
GetName();
1121 label_print_width =
TMath::Max(label_print_width, (
int)NodeName.size()+2);
1126 std::cout << std::endl;
1127 std::cout <<
"Channel: " << channel <<
" Sample: " << sample << std::endl;
1128 std::cout << std::setw(label_print_width) <<
"Factor";
1130 for(
unsigned int i=0; i < num_bins; ++i) {
1133 std::stringstream sstr;
1135 std::cout << std::setw(bin_print_width) << sstr.str();
1137 std::cout << std::endl;
1143 std::string NodeName = component->
GetName();
1160 std::cout << std::setw(label_print_width) << NodeName;
1167 std::string line_break;
1170 int break_length = (high_bin - low_bin + 1) * bin_print_width;
1171 break_length += label_print_width;
1172 for(
int i = 0; i < break_length; ++i) {
1175 std::cout << line_break << std::endl;
1177 std::cout << std::setw(label_print_width) <<
"TOTAL:";
1195 std::string
name ) {
1233 std::cout <<
"Error: To Create Histogram from RooAbsReal function, Dimension must be 1, 2, or 3" << std::endl;
1252 TString RegexTString(regExpr);
1253 TRegexp theRegExpr(RegexTString);
1261 std::cout << std::endl;
1264 std::cout << std::setw(30) <<
"Parameter";
1265 std::cout << std::setw(15) <<
"Value" 1266 << std::setw(15) <<
"Error Low" 1267 << std::setw(15) <<
"Error High" 1275 std::string ParamName = param->
GetName();
1276 TString ParamNameTString(ParamName);
1281 if( theRegExpr.
Index(ParamNameTString, &dummy) == -1 )
continue;
1284 std::cout <<
"Setting param: " << ParamName <<
" constant" 1285 <<
" (matches regex: " << regExpr <<
")" << std::endl;
1292 if( !arg )
return NULL;
virtual const char * GetName() const
Returns name of object.
TIterator * createIterator(Bool_t dir=kIterForward) const
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...
Bool_t IsBinUnderflow(Int_t bin, Int_t axis=0) const
Return true if the bin is underflow.
const RooArgSet * GetObservables() const
get RooArgSet for observables (return NULL if not existing)
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...
The Histogram stack class.
Bool_t IsBinOverflow(Int_t bin, Int_t axis=0) const
Return true if the bin is overflow.
RooAbsArg * findChild(const std::string &name, RooAbsReal *parent) const
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Double_t getVal(const RooArgSet *set=0) const
const RooAbsBinning & getBinning(const char *name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const
Return binning definition with name.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
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.
RooFit::MsgLevel globalKillBelow() const
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
virtual Int_t GetNbinsZ() const
RooAbsReal * GetConstraintTerm(const std::string ¶meter)
TH1 * GetSampleHist(const std::string &channel, const std::string &sample, const std::string &name="")
Short_t Min(Short_t a, Short_t b)
void PrintChannelParameters(const std::string &channel, bool IncludeConstantParams=false)
const RooArgList & funcList() const
static RooMsgService & instance()
Return reference to singleton instance.
Class RooRealSumPdf implements a PDF constructed from a sum of functions:
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.
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
RooAbsArg * findServer(const char *name) const
Double_t getErrorLo() const
virtual const char * ClassName() const
Returns name of class to which the object belongs.
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...
void PrintSampleComponents(const std::string &channel, const std::string &sample)
RooArgSet _GetAllProducts(RooProduct *node)
THStack * GetChannelStack(const std::string &channel, const std::string &name="")
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state...
const std::string ClassName(PyObject *pyobj)
Retrieve the class name from the given python object (which may be just an instance of the class)...
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
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)
RooRealVar represents a fundamental (non-derived) real valued object.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
std::map< std::string, RooArgSet * > fChannelObservMap
virtual void Draw(Option_t *option="")
Draw this histogram with options.
TIterator * typeIterator() const
Return iterator over all defined states.
RooAbsArg * at(Int_t idx) const
virtual const Text_t * GetName() const
Returns name of object.
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
const RooAbsCategoryLValue & indexCat() const
void setConstant(Bool_t value=kTRUE)
RooArgSet * getComponents() const
RooRealVar * var(const std::string &varName) const
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.
void SetPrintWidths(const std::string &channel)
std::map< std::string, std::map< std::string, RooAbsReal * > > fChannelSampleFunctionMap
void setGlobalKillBelow(RooFit::MsgLevel level)
RooDataSet is a container class to hold unbinned data.
RooCategory represents a fundamental (non-derived) discrete value object.
RooProduct a RooAbsReal implementation that represent the product of a given set of other RooAbsReal ...
TObject * obj(const char *name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name) ...
void PrintDataSet(RooDataSet *data, const std::string &channel="")
double GetBinValue(int bin, const std::string &channel)
virtual void SetName(const char *name)
Change the name of this histogram.
Namespace for the RooStats classes.
RooAbsPdf * GetPdf() const
get model PDF (return NULL if pdf has not been specified or does not exist)
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
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...
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...
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)
std::vector< std::string > fChannelNameVec
const char * GetName() const
Returns name of object.
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)
RooAbsPdf * getPdf(const char *catName) const
Return the p.d.f associated with the given index category name.
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
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
void PrintModelAndData(RooDataSet *data)
void PrintParameters(bool IncludeConstantParams=false)
virtual TList * split(const RooAbsCategory &splitCat, Bool_t createEmptyDataSets=kFALSE) const
Split dataset into subsets based on states of given splitCat in this dataset.
virtual Int_t GetNbinsX() const
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)
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset...
HistFactoryNavigation(ModelConfig *mc)
RooAbsPdf * GetChannelPdf(const std::string &channel)
Double_t getErrorHi() const
std::map< std::string, RooAbsPdf *> fChannelSumNodeMap
RooArgSet * GetObservableSet(const std::string &channel)
Bool_t isConstant() const
void SetConstant(const std::string ®Expr=".*", bool constant=true)
The RooWorkspace is a persistable container for RooFit projects.
virtual Int_t GetNbinsY() const
RooCmdArg Binning(const RooAbsBinning &binning)
void DrawChannel(const std::string &channel, RooDataSet *data=NULL)
TIterator * clientIterator() const