1 #include "DrawingUtils.hxx" 4 std::map<std::string, std::string> _options;
6 double drawUtils::legendEntryHeight=0.05;
20 if (tree->FindLeaf(var.c_str()))
32 TH1_h h0(
"v",
"v",1,0,1);
33 tree->Project(
"v",
"0.5",(
"(1==1)*"+var).c_str(),
"",1);
34 return (
int)(h0.GetBinContent(1));
64 std::map< std::string, SampleGroup >::iterator it;
66 const std::string& groupName2 = it->first;
67 if (groupName2 != groupName && groupName!=
"all")
continue;
71 std::map< std::string, DataSample*>& mcSamples = sampleGroup.
GetMCSamples();
72 std::map< std::string, DataSample*>::iterator it;
73 for (it = mcSamples.begin(); it != mcSamples.end(); it++) {
74 const std::string& mcSampleName2 = it->first;
75 if (mcSampleName2 != mcSampleName && mcSampleName!=
"all")
continue;
79 if (value!=-1 && value2!=value){
80 std::cout <<
"Experiment has different values for var " << var <<
"!!!!" << std::endl;
95 std::stringstream scode;
105 std::stringstream scode;
124 if (uopt.find(
"NOVARBIN")!=std::string::npos || mode==0){
125 for (
int i=0;i<h->GetNbinsX();i++)
126 h->SetBinError(i+1, h->GetBinError(i+1));
130 int entries = (int)h->GetEntries();
133 if (uopt.find(
"USEMINWIDTH")==std::string::npos){
135 for (
int i=0;i<h->GetNbinsX();i++){
136 Double_t w = h->GetXaxis()->GetBinWidth(i+1);
137 if (w<wmin && h->GetBinContent(i+1)>0) wmin=w;
143 if(h->GetNbinsY() > 1)
148 for (
int i=0;i<h->GetNbinsX();i++){
149 Double_t w = h->GetBinWidth(i+1);
150 Double_t y = h->GetBinContent(i+1);
153 Double_t yp = y*(wmin/w);
154 h->SetBinContent(i+1,yp);
160 Double_t e = h->GetBinError(i+1);
161 Double_t ep = e*(wmin/w);
162 h->SetBinError(i+1,ep);
170 for (
int i = 0; i < h->GetNbinsX(); i++){
171 for(
int j = 0; j < h2->GetNbinsY(); j++){
172 Double_t wx = h2->GetXaxis()->GetBinWidth(i+1);
173 Double_t wy = h2->GetYaxis()->GetBinWidth(j+1);
174 Double_t a = wx * wy;
175 if (a < amin && h2->GetBinContent(h2->GetBin(i+1,j+1)) != 0) amin=a;
178 for(
int i = 0; i < h2->GetNbinsX(); i++){
179 for(
int j = 0; j < h2->GetNbinsY(); j++){
180 Double_t wx = h2->GetXaxis()->GetBinWidth(i+1);
181 Double_t wy = h2->GetYaxis()->GetBinWidth(j+1);
182 Double_t y = h2->GetBinContent(h2->GetBin(i+1,j+1));
185 Double_t yp = y*(amin/(wx*wy));
186 h2->SetBinContent(h2->GetBin(i+1,j+1),yp);
188 if (y > ymax) ymax = y;
192 Double_t e = h2->GetBinError(i+1);
193 Double_t ep = e*(amin/(wx*wy));
194 h2->SetBinError(h2->GetBin(i+1,j+1),ep);
200 h->SetEntries(entries);
219 while(pos!=std::string::npos){
220 pos = uopt.find(c,pos_ini);
221 std::string single_opt = uopt.substr(pos_ini, pos-pos_ini);
236 if (uopt.find(this_opt)!= std::string::npos)
return true;
244 if (uopt.find(this_opt)!= std::string::npos)
return true;
252 if (uopt.find(
ConvertOption(this_opt))!= std::string::npos)
return true;
260 if (opt==kNOERROR)
return "NOERROR";
261 else if (opt==kAREA)
return "AREA";
279 sprintf(opt2,
"%-20s", (opt+
":").c_str());
280 std::cout << opt2 << _options[opt] << std::endl;
290 drawUtils::AddOption(
"SCALETODATA",
"Scale the MC covariance matrix to data POT when using Experiment");
292 drawUtils::AddOption(
"E0",
"Error style option for second sample. Does the same as the root option e0");
293 drawUtils::AddOption(
"E1",
"Error style option for second sample. Does the same as the root option e1");
294 drawUtils::AddOption(
"E2",
"Error style option for second sample. Does the same as the root option e2");
295 drawUtils::AddOption(
"E3",
"Error style option for second sample. Does the same as the root option e3");
296 drawUtils::AddOption(
"E4",
"Error style option for second sample. Does the same as the root option e4");
297 drawUtils::AddOption(
"E5",
"Error style option for second sample. Does the same as the root option e5");
298 drawUtils::AddOption(
"E6",
"Error style option for second sample. Does the same as the root option e6");
299 drawUtils::AddOption(
"ETOT",
"When drawing with color codes, draw also the total error for the stacked histogram");
300 drawUtils::AddOption(
"NOTOTERROR",
"Don't draw the total error (stat+syst) but only the statistical or systematic error");
301 drawUtils::AddOption(
"NOSTERROR",
"Don't draw the statistical error but only the total error, and also the systematic error when SYSTERROR options is also used");
302 drawUtils::AddOption(
"SYSTERROR",
"Don't draw the statistical error but only the systematic error, together with the total");
304 drawUtils::AddOption(
"NODRAW",
"Don't draw anything. You should use the option DUMP to see the results");
305 drawUtils::AddOption(
"ST",
"When using DrawErrors or DrawRelativeErrors only statistical errors are plotted. In combination with SYS, SSYS or WSYS adds statisticak and systematic errors in quadrature");
306 drawUtils::AddOption(
"SYS",
"draw all systematics. Error bars correspond to the RMS of all toy experiments");
307 drawUtils::AddOption(
"SSYS",
"Draw only standard systematics (reconstructed observable variations)");
309 drawUtils::AddOption(
"WSi",
"Draw only the specified (ith) weight systematic(s) (\" WS0 WS3 ... \")");
310 drawUtils::AddOption(
"NWSi",
"Exclude the specified (ith) weight systematic(s) (\"NWS0 NWS1 ... \")");
311 drawUtils::AddOption(
"WCi",
"Draw only the specified (ith) weight correction(s) (\" WC0 WC3 ... \")");
312 drawUtils::AddOption(
"NWCi",
"Exclude the specified (ith) weight correction(s) (\"NWC0 NWC1 ... \")");
314 drawUtils::AddOption(
"RELATIVE",
"When computing the covariance matrix divide by the average in each bin such that a relative covariance is computed");
317 drawUtils::AddOption(
"EFF",
"The efficiency-like ratio plot (out of two histograms, pass and total) is drawn, internal option");
321 drawUtils::AddOption(
"NOVARBIN",
"Plotting with variable binning, bin entries are normalized by bin width. This option disables this feature.");
322 drawUtils::AddOption(
"NOTOYW",
"No toy weight is applied for toy experiments. All toys will have the same weight 1.");
328 drawUtils::AddOption(
"NODEFAULT",
"By default the -999 default is plotted unless this option is used");
333 drawUtils::AddOption(
"AREA",
"For 1D histos normalization to 1 (if there is only one sample) or to the area of the first sample. In this normalization procedure the whole range of the variable allowed by 'cut' parameter is taken into account");
334 drawUtils::AddOption(
"AREA1",
"For 1D histos normalization to 1. In this normalization procedure the whole range of the variable allowed by 'cut' parameter is taken into account");
335 drawUtils::AddOption(
"AREA100",
"For 1D histos normalization to 100. In this normalization procedure the whole range of the variable allowed by 'cut' parameter is taken into account");
336 drawUtils::AddOption(
"POTNORM",
"Normalize the MC to the POT given as input normalization factor, regardless of the data POT (interprete valid norm factor as a POT value)");
339 drawUtils::AddOption(
"DRAWALLMC",
"Draw with black contour a histogram for all MC entries (works only while plotting histogram stack)");
340 drawUtils::AddOption(
"DRAWALLCUTS",
"Draw all cuts even if they are below the MinAccumLevelToSave when doing plots VSCuts");
341 drawUtils::AddOption(
"NOINFO",
"Dont dump on the screen histogram info when using the Draw methods");
359 if (_options.find(opt)==_options.end()){
362 if (opt.find(
"WS")==0 && opt.find_first_not_of(
"0123456789",2)==std::string::npos)
return true;
363 else if (opt.find(
"NWS")==0 && opt.find_first_not_of(
"0123456789",3)==std::string::npos)
return true;
364 else if (opt.find(
"WC")==0 && opt.find_first_not_of(
"0123456789",2)==std::string::npos)
return true;
365 else if (opt.find(
"NWC")==0 && opt.find_first_not_of(
"0123456789",3)==std::string::npos)
return true;
367 std::cout <<
"Invalid option '" << opt <<
"' !!!!" << std::endl;
378 for (std::map<std::string, std::string>::iterator it=_options.begin();it!=_options.end();it++){
387 leg->AddEntry(ht, type.c_str(), opt.c_str());
390 leg->ConvertNDCtoPad();
392 if (legendEntryHeight>0){
393 leg->SetY1NDC(leg->GetY1NDC()-legendEntryHeight);
void AddOption(const std::string &opt, const std::string &info)
Add option as valid, provided name and exlaination.
void AddLegendEntry(TLegend *leg, TObject *ht, const std::string &type, const std::string &opt)
Add an entry to the Legend and resize it.
TTree * GetTree(Int_t index)
Returns the a tree with a given index.
int GetNWeights(TTree *tree)
get the number of weights in the tree
void BuildOptions()
Build the map of valid options with AddOption.
void NormalizeVariableBinning(TH1 *h, int mode, const std::string &opt, Double_t &minwidth)
Normalize bin contents by bin width. return the with of the bin with minimum width.
bool TreeHasVar(TTree *tree, const std::string &var)
Check wether the tree has a given variable.
std::map< std::string, DataSample * > & GetMCSamples()
Get all MC samples in a group.
int GetVarFromTree(TTree *tree, const std::string &var)
Get the Value of an integer variable from the tree.
std::string GetString(int code)
convert integer to string
bool ContainValidOptions(const std::string &uopt)
Check if the input string contails only valid options.
bool IsValidOption(const std::string &opt)
Check if the option is in the list of available options (added with AddOption)
int GetVarFromExperiment(const std::string &var, Experiment &exp, const std::string &groupName="all", const std::string &mcSampleName="all")
Get the Value of an integer variable from the experiment.
void ExplainOption(OptionEnum opt)
Explain a given option given as enum.
void ListOptions()
List sll valid options and a description of each of them.
std::string ToUpper(const std::string &str)
bool CheckInternalOption(const std::string &uopt, const std::string &this_opt)
Check if specific option appears in option field (don't check if it exists: Added with AddOption) ...
int GetNToys(TTree *tree)
get the number of weights in the tree
int GetRefToy(TTree *tree)
get the reference toy in the tree
std::map< std::string, SampleGroup > & GetSampleGroups()
Returns all sample groups.
std::string ConvertOption(OptionEnum this_opt)
convert enum option to string
bool CheckOption(const std::string &uopt, const std::string &this_opt)
Check if specific option exists, and if so if it appears in option field.