1 #include "DrawingTools.hxx" 2 #include "SystematicTools.hxx" 8 DrawingTools::DrawingTools(
const std::string& file, Int_t T2KstyleIndex):
DrawingToolsBase(file,T2KstyleIndex){
11 _treeForSystErrors = NULL;
18 _treeForSystErrors = NULL;
78 std::string DrawingTools::GetCombinedCut(
DataSample& sample,
const std::string& cut){
81 std::string cut1 = cut;
82 if (sample.GetCut() !=
"") cut1 = cut+
" && ("+sample.GetCut()+
")";
87 void DrawingTools::Project(
HistoStack* hs,
const std::string& sample_name,
DataSample& sample,
const std::string& var,
int nx,
double* xbins,
int ny,
double* ybins,
const std::string& categ,
88 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors){
91 std::string opt2 = opt +
" EXP";
92 DrawingToolsBase::Project(hs, sample_name, sample.
GetTree(),var,nx,xbins,ny,ybins,categ,GetCombinedCut(sample,cut),root_opt,opt2,norm,scale_errors);
97 const std::string& var,
int nx,
double* xbins,
int ny,
double* ybins,
const std::string& categ,
98 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
bool scale_errors,
double norm,
bool pot_norm){
101 if (!sample1 || !sample2)
return;
104 norm = GetNormalisationFactor(sample1, sample2, norm, pot_norm, opt);
107 std::string opt2 = opt +
" EXP";
108 DrawingToolsBase::Project(hs1,hs2,sample1->
GetTree(), sample2->
GetTree(), var,nx,xbins,ny,ybins,categ,cut,root_opt,opt2,norm,scale_errors);
113 const std::string& var,
int nx,
double* xbins,
int ny,
double* ybins,
const std::string& categ,
114 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors){
117 if (mcSampleName!=
"all"){
118 if (!sampleGroup.
HasMCSample(mcSampleName))
return;
129 Project(hs1,
"sample1", *sample1,var,nx,xbins,ny,ybins,
"all",cut,root_opt,opt,1 ,scale_errors);
133 std::map< std::string, DataSample*>& mcSamples = sampleGroup.
GetMCSamples();
134 std::map< std::string, DataSample*>::iterator it;
135 for (it = mcSamples.begin(); it != mcSamples.end(); it++) {
136 const std::string& mcSampleName2 = it->first;
137 if (mcSampleName2 != mcSampleName && mcSampleName!=
"all")
continue;
142 double norm2 = GetNormalisationFactor(sample1, sample2, norm,
true, opt);
146 std::string syst_opt = sample2->GetSystOption();
147 Project(hs2,
"sample2_"+mcSampleName2, *sample2,var,nx,xbins,ny,ybins,categ,cut,root_opt,opt+
" "+syst_opt,norm2,scale_errors);
155 const std::string& var,
int nx,
double* xbins,
int ny,
double* ybins,
const std::string& categ,
156 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors){
162 std::map< std::string, SampleGroup >::iterator it;
164 const std::string& groupName2 = it->first;
165 if (groupName2 != groupName && groupName!=
"all")
continue;
168 Project(hs1, hs2, sampleGroup, mcSampleName, var,nx,xbins,ny,ybins,categ,cut,root_opt,uopt+
" NOAREA",norm,scale_errors);
196 ReadCategories(_config_file);
198 if (!cat().HasCategory(categ) || categ ==
"all" ) {
199 std::cout <<
" ------------------------------------------ " << std::endl;
200 std::cout <<
" Invalid category " << categ << std::endl;
201 std::cout <<
" ------------------------------------------ " << std::endl;
209 std::vector<TrackTypeDefinition>::iterator it;
211 double dummy1, dummy2, nev1, nev2;
213 dummy1 = GetEff(exp,
false, dummy1, dummy2, nev1, nev2, cut, cut,
"",uopt+
" PUR");
215 std::cout <<
" --------------------------------------------------------" << std::endl;
216 std::cout <<
" Experiment Purities (not POT normalized): " << std::endl;
217 std::cout <<
" Category: " << categ << std::endl;
218 std::cout <<
" Cut: " << cut << std::endl;
219 std::cout <<
" Events: " << nev1 << std::endl;
220 std::cout <<
" --------------------------------------------------------" << std::endl;
223 std::ostringstream percstr, str_tmp;
224 const int ntypes = (
const int)cat().GetCategoryTypes(categ).size();
225 std::string* cattypes =
new std::string[ntypes];
226 int* catcodes =
new int[ntypes];
227 int* catcolors =
new int[ntypes];
230 for (it=cat().GetCategoryTypes(categ).begin();it!=cat().GetCategoryTypes(categ).end();it++, i++){
231 std::string type = it->_name;
234 std::string cut2 = categ+
"=="+code;
236 double frac = GetEff(exp,
false, dummy1, dummy2, nev1, nev2, cut2, cut,
"",uopt+
" PUR");
238 std::cout << std::setprecision(8) << std::setw(25) << type << std::setw(12) << frac*100. <<
" % (" << nev1 <<
" events)" << std::endl;
241 percstr.str(std::string());
242 percstr << std::setprecision(2) << std::fixed << frac*100.;
243 str_tmp.str(std::string());
244 str_tmp << it->_name << std::setw(8) << percstr.str() <<
" %";
245 cattypes[itype] = str_tmp.str();
246 catcodes[itype] = it->_code;
247 catcolors[itype] = it->_color;
252 bool multi = cat().GetCategory(categ).IsMultiType();
253 bool noWarning =
true, addNOTRUTH =
false, addSAND =
false;
254 cat().AddCategory(categ+
"_withPurities",itype,cattypes,catcodes,catcolors,multi,noWarning,addNOTRUTH,addSAND);
256 std::cout <<
" --------------------------------------------------------" << std::endl;
257 std::cout << std::endl;
263 void DrawingTools::Draw(
DataSample& sample,
const std::string& var,
int nx,
double xmin,
double xmax,
264 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors){
267 norm = GetNormalisationFactor(NULL, &sample, norm,
true, opt);
268 DrawingToolsBase::Draw(sample.
GetTree(), var,nx,xmin,xmax,categ,GetCombinedCut(sample,cut),root_opt,opt,norm,scale_errors);
272 void DrawingTools::Draw(
DataSample& sample,
const std::string& var,
int nbins,
double* xbins,
273 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors){
276 norm = GetNormalisationFactor(NULL, &sample, norm,
true, opt);
277 DrawingToolsBase::Draw(sample.
GetTree(), var,nbins,xbins,categ,GetCombinedCut(sample,cut),root_opt,opt,norm,scale_errors);
281 void DrawingTools::Draw(
DataSample& sample,
const std::string& var,
int nx,
double xmin,
double xmax,
int ny,
double ymin,
double ymax,
282 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm){
285 norm = GetNormalisationFactor(NULL, &sample, norm,
true, opt);
286 DrawingToolsBase::Draw(sample.
GetTree(), var,nx,xmin,xmax,ny,ymin,ymax,categ,GetCombinedCut(sample,cut),root_opt,opt,norm);
290 void DrawingTools::Draw(
DataSample& sample,
const std::string& var,
int nx,
double* xbins,
int ny,
double* ybins,
291 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm){
294 norm = GetNormalisationFactor(NULL, &sample, norm,
true, opt);
295 DrawingToolsBase::Draw(sample.
GetTree(), var,nx,xbins,ny,ybins,categ,GetCombinedCut(sample,cut),root_opt,opt,norm);
299 void DrawingTools::DrawEff(
DataSample& sample,
const std::string& var,
int nx,
double xmin,
double xmax,
300 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt,
const std::string& leg_name){
303 DrawingToolsBase::DrawEff(sample.
GetTree(), var,nx,xmin,xmax,cut1,cut2,root_opt,opt,leg_name);
307 void DrawingTools::DrawEff(
DataSample& sample,
const std::string& var,
int nx,
double* xbins,
308 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt,
const std::string& leg_name){
311 DrawingToolsBase::DrawEff(sample.
GetTree(), var,nx,xbins,cut1,cut2,root_opt,opt,leg_name);
315 void DrawingTools::DrawDoubleEff(
DataSample& sample1,
DataSample& sample2,
const std::string& var,
int nx,
double xmin,
double xmax,
316 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt,
const std::string& leg_name){
319 DrawingToolsBase::DrawDoubleEff(sample1.
GetTree(), sample2.
GetTree(), var,nx,xmin,xmax,cut1,cut2,root_opt,opt,leg_name);
323 void DrawingTools::DrawDoubleEff(
DataSample& sample1,
DataSample& sample2,
const std::string& var,
int nx,
double* xbins,
324 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt,
const std::string& leg_name){
331 void DrawingTools::DrawEff(
Experiment& exp,
bool usedata,
const std::string& var,
int nx,
double xmin,
double xmax,
332 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt,
const std::string& leg_name) {
334 double xbins[NMAXBINS];
335 DrawEff(exp, usedata, var, nx, GetVariableBins(nx, xmin, xmax, xbins), cut1, cut2, root_opt, opt, leg_name);
339 void DrawingTools::DrawEff(
Experiment& exp,
bool usedata,
const std::string& var,
int nx,
double* xbins,
340 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt,
const std::string& leg) {
342 double dummy1, dummy2;
349 TGraphAsymmErrors* eff = GetEff(exp, usedata, var, nx, xbins, dummy1, dummy2, cut1, cut2, uroot_opt, uopt);
358 void DrawingTools::DrawEffNew(
Experiment& exp,
bool usedata,
const std::string& var,
int nx,
double xmin,
double xmax,
359 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt1,
const std::string& opt2,
360 const std::string& leg_name) {
362 double xbins[NMAXBINS];
363 DrawEffNew(exp, usedata, var, nx, GetVariableBins(nx, xmin, xmax, xbins), cut1, cut2, root_opt, opt1, opt2, leg_name);
367 void DrawingTools::DrawEffNew(
Experiment& exp,
bool usedata,
const std::string& var,
int nx,
double* xbins,
368 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt1,
369 const std::string& opt2,
const std::string& leg) {
371 double dummy1, dummy2;
382 TGraphAsymmErrors* eff = GetEffNew(exp, usedata, var, nx, xbins, dummy1, dummy2, cut1, cut2, uroot_opt, uopt1, uopt2);
391 void DrawingTools::DrawPur(
Experiment& exp,
const std::string& var,
int nx,
double xmin,
double xmax,
392 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt,
const std::string& leg_name) {
394 double xbins[NMAXBINS];
395 DrawPur(exp, var, nx, GetVariableBins(nx, xmin, xmax, xbins), cut1, cut2, root_opt, opt, leg_name);
399 void DrawingTools::DrawPur(
Experiment& exp,
const std::string& var,
int nx,
double* xbins,
400 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt,
const std::string& leg) {
403 double dummy1, dummy2;
413 TGraphAsymmErrors* eff = GetEff(exp,
false, var, nx, xbins, dummy1, dummy2, cut1, cut2, uroot_opt, uopt+
" PUR");
421 void DrawingTools::DrawSignificance(
DataSample& sample,
const std::string& var,
int nx,
double xmin,
double xmax,
422 const std::string& cut1,
const std::string& cut2,
double norm,
double rel_syst,
const std::string& root_opt,
const std::string& opt,
const std::string& leg_name){
425 DrawingToolsBase::DrawSignificance(sample.
GetTree(), var,nx,xmin,xmax,cut1,cut2,norm,rel_syst,root_opt,opt,leg_name);
429 void DrawingTools::DrawSignificance(
DataSample& sample,
const std::string& var,
int nx,
double* xbins,
const std::string& cut1,
const std::string& cut2,
430 double norm,
double rel_syst,
const std::string& root_opt,
const std::string& opt,
const std::string& leg_name){
433 DrawingToolsBase::DrawSignificance(sample.
GetTree(), var,nx,xbins,cut1,cut2,norm,rel_syst,root_opt,opt,leg_name);
437 void DrawingTools::DrawRatio(
DataSample& sample,
const std::string& var,
int nx,
double xmin,
double xmax,
438 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt,
const std::string& leg_name){
445 void DrawingTools::PrintEventNumbers(
DataSample& sample,
const std::string& cut,
const std::string& file,
int toy_ref){
452 void DrawingTools::DrawRatio(
DataSample& sample,
const std::string& var,
int nx,
double* xbins,
453 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt,
const std::string& leg_name){
460 void DrawingTools::Draw(
DataSample& sample1,
DataSample& sample2,
const std::string& var,
int nx,
double xmin,
double xmax,
461 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors,
bool pot_norm){
465 double xbins[NMAXBINS];
466 Draw(sample1,sample2,var,nx,GetVariableBins(nx,xmin,xmax,xbins),categ,cut,root_opt, opt,norm,scale_errors,pot_norm);
470 void DrawingTools::Draw(
DataSample& sample1,
DataSample& sample2,
const std::string& var,
int nx,
double* xbins,
471 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors,
bool pot_norm){
477 Draw(sample1,sample2,var,nx,xbins,ny,ybins,categ,cut,root_opt, opt,norm,scale_errors,pot_norm);
481 void DrawingTools::Draw(
DataSample& sample1,
DataSample& sample2,
const std::string& var,
int nx,
double xmin,
double xmax,
int ny,
double ymin,
double ymax,
482 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors,
bool pot_norm){
486 double xbins[NMAXBINS];
487 double ybins[NMAXBINS];
488 Draw(sample1,sample2,var,nx,GetVariableBins(nx,xmin,xmax,xbins),ny,GetVariableBins(ny,ymin,ymax,ybins),categ,cut,root_opt, opt,norm,scale_errors,pot_norm);
492 void DrawingTools::Draw(
DataSample& sample1,
DataSample& sample2,
const std::string& var,
int nx,
double* xbins,
int ny,
double* ybins,
493 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors,
bool pot_norm){
504 _saved_histoStacks.push_back(hs1);
505 _saved_histoStacks.push_back(hs2);
507 std::string slevel = GetSameLevel(root_opt);
510 Project(hs1, hs2, &sample1, &sample2, var,nx,xbins,ny,ybins,categ,cut,root_opt,opt,scale_errors,norm,pot_norm);
513 DrawingToolsBase::DrawHistoStacks(hs1,hs2,categ,root_opt,opt,1);
517 void DrawingTools::DrawRatio(
DataSample& sample1,
DataSample& sample2,
const std::string& var,
int nx,
double xmin,
double xmax,
518 const std::string& cut1,
const std::string& cut2,
double norm,
const std::string& root_opt,
const std::string& opt,
const std::string& leg_name,
bool pot_norm){
521 norm = GetNormalisationFactor(&sample1, &sample2, norm, pot_norm, opt);
522 DrawingToolsBase::DrawRatioTwoCuts(sample1.
GetTree(),sample2.
GetTree(),var,nx,xmin,xmax,cut1,cut2,root_opt,opt,leg_name,norm);
526 void DrawingTools::DrawRatio(
DataSample& sample1,
DataSample& sample2,
const std::string& var,
int nx,
double* xbins,
527 const std::string& cut1,
const std::string& cut2,
double norm,
const std::string& root_opt,
const std::string& opt,
const std::string& leg_name,
bool pot_norm){
530 norm = GetNormalisationFactor(&sample1, &sample2, norm, pot_norm, opt);
531 DrawingToolsBase::DrawRatioTwoCuts(sample1.
GetTree(),sample2.
GetTree(),var,nx,xbins,cut1,cut2,root_opt,opt,leg_name,norm);
535 void DrawingTools::DrawRatio(
DataSample& sample1,
DataSample& sample2,
const std::string& var,
int nx,
double xmin,
double xmax,
536 const std::string& cut,
double norm,
const std::string& root_opt,
const std::string& opt,
const std::string& leg_name,
bool pot_norm){
539 norm = GetNormalisationFactor(&sample1, &sample2, norm, pot_norm, opt);
540 DrawingToolsBase::DrawRatio(sample1.
GetTree(),sample2.
GetTree(),var,nx,xmin,xmax,cut,root_opt,opt,leg_name,norm);
544 void DrawingTools::DrawRatio(
DataSample& sample1,
DataSample& sample2,
const std::string& var,
int nx,
double* xbins,
545 const std::string& cut,
double norm,
const std::string& root_opt,
const std::string& opt,
const std::string& leg_name,
bool pot_norm){
548 norm = GetNormalisationFactor(&sample1, &sample2, norm, pot_norm, opt);
553 void DrawingTools::DrawToys(
DataSample& sample,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg_name){
560 void DrawingTools::DrawToysRatio(
DataSample& sample1,
DataSample& sample2,
const std::string& cut,
561 const std::string& root_opt,
const std::string& opt,
const std::string& leg_name,
double norm,
bool pot_norm){
564 norm = GetNormalisationFactor(&sample1, &sample2, norm, pot_norm, opt);
569 void DrawingTools::DrawToysRatioTwoCuts(
DataSample& sample1,
DataSample& sample2,
const std::string& cut1,
const std::string& cut2,
570 const std::string& root_opt,
const std::string& opt,
const std::string& leg_name,
double norm,
bool pot_norm){
573 norm = GetNormalisationFactor(&sample1, &sample2, norm, pot_norm);
580 const std::string& root_opt,
const std::string& opt,
const std::string& leg,
double norm,
bool pot_norm){
583 DrawRatioVSCut(sample1,sample2,0,precut,first_cut,last_cut,root_opt,opt,leg,norm,pot_norm);
588 const std::string& root_opt,
const std::string& opt,
const std::string& leg,
double norm,
bool pot_norm){
592 if (sel().GetSelection(ibranch,
true)) {
594 std::cout <<
"Drawing for selection " << isel <<
", branch 0" << std::endl;
595 return DrawRatioVSCut(sample1,sample2,isel,0,precut,first_cut,last_cut,root_opt,opt,leg,norm,pot_norm);
598 DrawRatioVSCut(sample1,sample2,0,ibranch,precut,first_cut,last_cut,root_opt,opt,leg,norm,pot_norm);
603 const std::string& root_opt,
const std::string& opt,
const std::string& leg,
double norm,
bool pot_norm){
606 ReadOther(sample1.
GetTree(
"config"));
607 norm = GetNormalisationFactor(&sample1, &sample2, norm, pot_norm, opt);
608 DrawingToolsBase::DrawRatioVSCut(sample1.
GetTree(),sample2.
GetTree(),isel, ibranch,precut,first_cut,last_cut,root_opt,opt,leg,norm);
612 void DrawingTools::DrawEffPurVSCut(
DataSample& sample,
const std::string& signal,
const std::string& precut,
int first_cut,
int last_cut,
613 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
616 DrawEffPurVSCut(sample,0,signal,precut,first_cut,last_cut, root_opt, opt, leg);
620 void DrawingTools::DrawEffPurVSCut(
DataSample& sample,
int branch,
const std::string& signal,
const std::string& precut,
int first_cut,
int last_cut,
621 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
624 DrawEffPurVSCut(sample,0,branch,signal,precut,first_cut,last_cut, root_opt, opt, leg);
628 void DrawingTools::DrawEffPurVSCut(
DataSample& sample,
int isel,
int branch,
const std::string& signal,
const std::string& precut,
int first_cut,
int last_cut,
629 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
632 DrawEffPurVSCut(sample,isel,branch,signal,precut,first_cut,last_cut, first_cut,last_cut, root_opt, opt, leg);
636 void DrawingTools::DrawEffPurVSCut(
DataSample& sample,
int isel,
int branch,
const std::string& signal,
const std::string& precut,
637 int first_cut_pur,
int last_cut_pur,
int first_cut_eff,
int last_cut_eff,
638 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
642 if (!sel().GetSelection(isel,
true))
return;
651 std::cout <<
"truth tree does not exists. Efficiency cannot be computed !!!" << std::endl;
656 ReadOther(sample.
GetTree(
"config"));
659 double sizex = _legendSize[0];
660 double sizey = _legendSize[1];
663 SetLegendSize(0.1,0.1);
672 SetLegendSize(sizex,sizey);
676 TH1_h* DrawingTools::GetHisto(
DataSample& sample,
const std::string& name,
const std::string& var,
int nx,
double* xbins,
677 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double scale,
bool scale_errors){
680 return GetHisto(sample.
GetTree(), name,var,nx,xbins,cut,root_opt,opt,scale,scale_errors);
684 TH1_h* DrawingTools::GetHisto(
HistoStack* hs, TTree* tree,
const std::string& name,
const std::string& var,
int nx,
double* xbins,
685 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double scale,
bool scale_errors,
int toy_ref){
696 return DrawingToolsBase::GetHisto(hs, tree, name,var,nx,xbins,cut,root_opt,opt,scale,scale_errors,toy_ref);
701 TH1_h* DrawingTools::GetRatioHisto(TTree* tree1,TTree* tree2,
const std::string& name,
const std::string& var,
int nx,
double* xbins,
702 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt,
double norm,
double scale,
bool scale_errors,
int toy_ref){
714 return DrawingToolsBase::GetRatioHisto(tree1, tree2, name,var,nx,xbins,cut1,cut2,root_opt,opt,norm,scale,scale_errors,toy_ref);
718 void DrawingTools::FillGraphErrors(
HistoStack* hs1,
HistoStack* hs2, TGraphAsymmErrors* graph,
const std::string uopt){
727 const TMatrixD& cov = syst_tools().GetRatioSystematicCov(hs1,hs2, uopt+
" RELATIVE");
729 for (
int i=0;i<nx;i++){
730 double err_low = cov(i,i);
731 double err_high = err_low;
733 err_low += graph->GetErrorYlow(i)*graph->GetErrorYlow(i);
734 err_high += graph->GetErrorYhigh(i)*graph->GetErrorYhigh(i);
736 graph->SetPointEYlow(i,sqrt(err_low));
737 graph->SetPointEYhigh(i,sqrt(err_high));
741 const TMatrixD& cov = syst_tools().GetSystematicCov(hs2, uopt);
743 for (
int i=0;i<nx;i++){
744 Double_t err_low = cov(i,i);
745 Double_t err_high = err_low;
746 err_low += graph->GetErrorXlow(i+1)*graph->GetErrorXlow(i+1);
747 err_high += graph->GetErrorXhigh(i+1)*graph->GetErrorXhigh(i+1);
748 graph->SetPointEXlow(i+1,sqrt(err_low));
749 graph->SetPointEXhigh(i+1,sqrt(err_high));
755 void DrawingTools::FillHistoErrors(
HistoStack* hs1,
HistoStack* hs2, TH1_h* histo,
const std::string uopt){
764 const TMatrixD& cov = syst_tools().GetRatioSystematicCov(hs1,hs2, uopt+
" RELATIVE");
766 for (
int i=0;i<nx;i++){
767 double err = cov(i,i);
769 err+= histo->GetBinError(i+1)*histo->GetBinError(i+1);
771 histo->SetBinError(i+1,sqrt(err));
775 const TMatrixD& cov = syst_tools().GetSystematicCov(hs2, uopt);
777 for (
int i=0;i<nx;i++)
778 histo->SetBinError(i+1,sqrt(cov(i,i)));
784 void DrawingTools::FillHistoErrors(
HistoStack* hs1,
HistoStack* hs2, TTree* tree1, TTree* tree2,
const std::string& name,
const std::string& var,
int nx,
double* xbins,
785 const std::string& cut1,
const std::string& cut2,
const std::string& opt,
double norm, TH1_h* hstat, TH1_h*& hsyst){
797 if(syst_tools().errdebug) std::cout<<
"FillHistoErrors \n=============== "<<std::endl;
803 if(syst_tools().errdebug) std::cout<<
" compute systematic errors cut1 "<<cut1<<
" cut2 "<<cut2<<
" name : "<<name<<std::endl;
804 hsyst = GetHistoWithSystErrors(hs1, hs2, tree1, tree2, name, var, nx, xbins, cut1, cut2, uopt+
" RELATIVE", norm);
809 TH1_h* DrawingTools::GetHistoWithSystErrors(
HistoStack* hs1,
HistoStack* hs2, TTree* tree1, TTree* tree2,
const std::string& name,
const std::string& var,
int nx,
double* xbins,
810 const std::string& cut1,
const std::string& cut2,
const std::string& opt,
double norm){
812 if(syst_tools().errdebug) std::cout<<
"GetHistoWithSystErrors \n======================== "<<std::endl;
830 TH1_h *hsyst =
new TH1_h(GetUniqueName(
"hsyst_"+name).c_str(),
"hsyst",nx,xbins);
831 _saved_histos.push_back(hsyst);
833 TTree* tree_syst=NULL;
834 if (_treeForSystErrors)
835 tree_syst = _treeForSystErrors;
842 syst_tools().UpdateSystematicCov(hs2, tree_syst, var, nx, xbins, cut2,
drawUtils::GetNToys(tree_syst), uopt);
844 syst_tools().UpdateSystematicCov(hs1, tree1, var, nx, xbins, cut1,
drawUtils::GetNToys(tree1), uopt);
845 const TMatrixD& cov = syst_tools().GetRatioSystematicCov(hs1,hs2, uopt);
847 for (
int i=0;i<nx;i++)
848 hsyst->SetBinError(i+1,sqrt(cov(i,i)));
851 const TMatrixD& cov = syst_tools().GetSystematicCov(hs2, uopt);
853 for (
int i=0;i<nx;i++)
854 hsyst->SetBinError(i+1,sqrt(cov(i,i)));
856 if(syst_tools().errdebug) std::cout<<
" =>set to hall, the systematic error bars "<<std::endl;
862 const std::string& cut1,
const std::string& cut2,
const std::string& opt,
double norm){
865 if(syst_tools().errdebug) std::cout<<
"UpdateSystInfo \n======================== "<<std::endl;
882 TTree* tree_syst=NULL;
883 if (_treeForSystErrors)
884 tree_syst = _treeForSystErrors;
891 syst_tools().UpdateSystematicCov(hs2, tree_syst, var, nx, xbins, cut2,
drawUtils::GetNToys(tree_syst), uopt);
893 if(syst_tools().errdebug) std::cout<<
" updated information for stack 2 "<<std::endl;
896 syst_tools().UpdateSystematicCov(hs1, tree1, var, nx, xbins, cut1,
drawUtils::GetNToys(tree1), uopt);
897 if(syst_tools().errdebug) std::cout<<
" updated information for stack 1 "<<std::endl;
945 double POTsample1 = POTsample1_byhand;
947 POTsample1 = sample1.GetNorm();
949 POTsample1 = sample1.
GetPOT();
953 double POTsample2 = sample2.GetNorm();
954 if (POTsample2==0 || POTsample2==1){
957 double sandFactor = 1;
958 #if !VERSION_HAS_OFFICIAL_POT 963 POTsample2 = sandFactor*sample2.
GetPOT();
968 if (POTsample2 == 0) {
969 std::cout <<
"Warning: denominator in POT ratio is zero! Setting ratio to 1." << std::endl;
971 }
else if (POTsample1 == 0) {
972 std::cout <<
"Warning: numerator in POT ratio is zero! Setting ratio to 1." << std::endl;
975 ratio = POTsample1 / POTsample2;
1000 else if (norm<=0 && sample1 && sample2){
1001 norm = GetPOTRatio(*sample1, *sample2);
1005 norm = GetPOTRatio(*sample2, *sample2, norm);
1018 void DrawingTools::DrawToys(
Experiment& exp,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1031 if (ntoys<=0)
return;
1037 double xbins[NMAXBINS];
1041 Project(NULL, hs2, exp,
"all",
"all",
"toy_index",ntoys,GetVariableBins(ntoys,0,ntoys,xbins),0,NULL,
"all",cut,root_opt,uopt+
" NOTOYW",0.,
true);
1047 std::string cut2=cut;
1048 if (cut2==
"") cut2=
"1==1";
1052 Project(NULL, hsw2, exp,
"all",
"all",
"toy_index",ntoys,GetVariableBins(ntoys,0,ntoys,xbins),0,NULL,
"all",cut,root_opt,uopt,0.,
true);
1062 DrawToysBase(*h1,hwa,root_opt,uopt,leg);
1070 void DrawingTools::Draw(
Experiment& exp,
const std::string& var,
int nx,
double xmin,
double xmax,
1071 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors){
1074 double xbins[NMAXBINS];
1075 Draw(exp,var,nx,GetVariableBins(nx,xmin,xmax,xbins),categ,cut,root_opt,opt,norm,scale_errors);
1079 void DrawingTools::Draw(
Experiment& exp,
const std::string& var,
int nx,
double xmin,
double xmax,
int ny,
double ymin,
double ymax,
1080 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors){
1083 double xbins[NMAXBINS];
1084 double ybins[NMAXBINS];
1085 Draw(exp,var,nx,GetVariableBins(nx,xmin,xmax,xbins),ny,GetVariableBins(ny,ymin,ymax,ybins),categ,cut,root_opt,opt,norm,scale_errors);
1089 void DrawingTools::Draw(
Experiment& exp,
const std::string& var,
int nx,
double* xbins,
1090 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors){
1093 double ybins[NMAXBINS];
1094 Draw(exp,var,nx,xbins,0,ybins,categ,cut,root_opt,opt,norm,scale_errors);
1098 void DrawingTools::Draw(
Experiment& exp,
const std::string& var,
int nx,
double* xbins,
int ny,
double* ybins,
1099 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors){
1102 Draw(exp,
"all",
"all",var,nx,xbins,ny,ybins,categ,cut,root_opt,opt,norm,scale_errors);
1106 void DrawingTools::Draw(
Experiment& exp,
const std::string& groupName,
const std::string& var,
int nx,
double xmin,
double xmax,
1107 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors){
1110 double xbins[NMAXBINS];
1111 Draw(exp,groupName,var,nx,GetVariableBins(nx,xmin,xmax,xbins),categ,cut,root_opt,opt,norm,scale_errors);
1115 void DrawingTools::Draw(
Experiment& exp,
const std::string& groupName,
const std::string& var,
int nx,
double xmin,
double xmax,
int ny,
double ymin,
double ymax,
1116 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors){
1119 double xbins[NMAXBINS];
1120 double ybins[NMAXBINS];
1121 Draw(exp,groupName,var,nx,GetVariableBins(nx,xmin,xmax,xbins),ny,GetVariableBins(ny,ymin,ymax,ybins),categ,cut,root_opt,opt,norm,scale_errors);
1125 void DrawingTools::Draw(
Experiment& exp,
const std::string& groupName,
const std::string& var,
int nx,
double* xbins,
1126 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors){
1129 double ybins[NMAXBINS];
1130 Draw(exp,groupName,var,nx,xbins,0,ybins,categ,cut,root_opt,opt,norm,scale_errors);
1134 void DrawingTools::Draw(
Experiment& exp,
const std::string& groupName,
const std::string& var,
int nx,
double* xbins,
int ny,
double* ybins,
1135 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors){
1138 Draw(exp,groupName,
"all",var,nx,xbins,ny,ybins,categ,cut,root_opt,opt,norm,scale_errors);
1142 void DrawingTools::Draw(
Experiment& exp,
const std::string& groupName,
const std::string& mcSampleName,
const std::string& var,
int nx,
double xmin,
double xmax,
1143 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors){
1146 double xbins[NMAXBINS];
1147 Draw(exp,groupName,mcSampleName,var,nx,GetVariableBins(nx,xmin,xmax,xbins),categ,cut,root_opt,opt,norm,scale_errors);
1151 void DrawingTools::Draw(
Experiment& exp,
const std::string& groupName,
const std::string& mcSampleName,
const std::string& var,
int nx,
double xmin,
double xmax,
int ny,
double ymin,
double ymax,
1152 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors){
1155 double xbins[NMAXBINS];
1156 double ybins[NMAXBINS];
1157 Draw(exp,groupName,mcSampleName,var,nx,GetVariableBins(nx,xmin,xmax,xbins),ny,GetVariableBins(ny,ymin,ymax,ybins),categ,cut,root_opt,opt,norm,scale_errors);
1161 void DrawingTools::Draw(
Experiment& exp,
const std::string& groupName,
const std::string& mcSampleName,
const std::string& var,
int nx,
double* xbins,
1162 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors){
1165 double ybins[NMAXBINS];
1166 Draw(exp,groupName,mcSampleName,var,nx,xbins,0,ybins,categ,cut,root_opt,opt,norm,scale_errors);
1170 void DrawingTools::Draw(
Experiment& exp,
const std::string& groupName,
const std::string& mcSampleName,
const std::string& var,
int nx,
double* xbins,
int ny,
double* ybins,
1171 const std::string& categ,
const std::string& cut,
const std::string& root_opt,
const std::string& opt,
double norm,
bool scale_errors){
1180 if (groupName!=
"all"){
1185 std::string categ2 = categ;
1187 std::string cut_range = AddRangeCut(var,nx,xbins,ny,ybins,cut,uopt);
1189 PrintPurities(exp, categ, cut_range,opt);
1190 categ2 +=
"_withPurities";
1196 hs1 =
new HistoStack(_title,_titleX,_titleY);
1197 hs2 =
new HistoStack(_title,_titleX,_titleY);
1198 _saved_histoStacks.push_back(hs1);
1199 _saved_histoStacks.push_back(hs2);
1201 std::string slevel = GetSameLevel(root_opt);
1204 Project(hs1, hs2, exp, groupName, mcSampleName, var,nx,xbins,ny,ybins,categ2,cut,root_opt,uopt,norm,scale_errors);
1207 DrawingToolsBase::DrawHistoStacks(hs1,hs2,categ2,root_opt,opt,1);
1213 void DrawingTools::DrawRatio(
Experiment& exp,
const std::string& groupName,
const std::string& mcSampleName,
const std::string& var,
int nx,
double* xbins,
1214 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1217 double ybins[NMAXBINS];
1218 DrawRatio(exp,groupName,mcSampleName,var,nx,xbins,0,ybins,cut,root_opt,opt,leg);
1222 void DrawingTools::DrawRatio(
Experiment& exp,
const std::string& groupName,
const std::string& mcSampleName,
const std::string& var,
int nx,
double xmin,
double xmax,
1223 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1226 double xbins[NMAXBINS];
1227 double ybins[NMAXBINS];
1228 DrawRatio(exp,groupName,mcSampleName,var,nx,GetVariableBins(nx,xmin,xmax,xbins),0,ybins,cut,root_opt,opt,leg);
1232 void DrawingTools::DrawRatio(
Experiment& exp,
const std::string& var,
int nx,
double* xbins,
1233 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1236 DrawRatio(exp,
"all",
"all",var,nx,xbins,cut,root_opt,opt,leg);
1240 void DrawingTools::DrawRatio(
Experiment& exp,
const std::string& var,
int nx,
double xmin,
double xmax,
1241 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1244 DrawRatio(exp,
"all",
"all",var,nx,xmin,xmax,cut,root_opt,opt,leg);
1248 void DrawingTools::DrawRatio(
Experiment& exp,
const std::string& groupName,
const std::string& mcSampleName,
const std::string& var,
int nx,
double* xbins,
int ny,
double* ybins,
1249 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1252 if (groupName!=
"all"){
1264 _saved_histoStacks.push_back(hs1);
1265 _saved_histoStacks.push_back(hs2);
1268 Project(hs1, hs2, exp, groupName, mcSampleName, var,nx,xbins,ny,ybins,
"all",cut,root_opt,uopt,0.,
true);
1271 DrawRatioHistoStacks(hs1,hs2,root_opt,uopt,0.,leg);
1282 void DrawingTools::AnalysisResults(
Experiment& exp,
const std::string& cut,
const std::string& opt,
const std::string& categ){
1285 AnalysisResults(exp,
"all",
"all",cut,opt,categ);
1289 void DrawingTools::AnalysisResults(
Experiment& exp,
const std::string& groupName,
const std::string& mcSampleName,
const std::string& cut,
const std::string& opt,
const std::string& categ){
1303 hs1 =
new HistoStack(_title,_titleX,_titleY);
1304 _saved_histoStacks.push_back(hs1);
1307 hs2 =
new HistoStack(_title,_titleX,_titleY);
1308 _saved_histoStacks.push_back(hs2);
1311 double xbins[2]={0.,1.};
1312 double *ybins = NULL;
1315 Project(hs1, hs2, exp, groupName, mcSampleName,
"0.5",1,xbins,0,ybins,
"all",cut,
"",opt,0.,
true);
1317 double N1 = hs1->
GetTotal1D()->GetBinContent(1);
1318 double N2 = hs2->
GetTotal1D()->GetBinContent(1);
1319 double est1 = hs1->
GetTotal1D()->GetBinError(1);
1320 double est2 = hs2->
GetTotal1D()->GetBinError(1);
1329 Double_t ratio = N1/N2;
1330 Double_t ratio_stat = sqrt(pow(est1/N2,2)+ pow(N1/(N2*N2)*est2,2));
1331 Double_t ratio_syst = N1/(N2*N2)*esys2;
1333 std::cout <<
" --------------------------------------------------------" << std::endl;
1334 std::cout <<
" Analysis results for " << cut << std::endl;
1335 std::cout <<
" --------------------------------------------------------" << std::endl;
1340 sprintf(out1,
"%-10s: %-12s %-12s %-12s",
"sample",
"events",
"stat error",
"syst error");
1341 sprintf(out2,
"%-10s: %-12.2f %-12.2f %-12.2f",
"data", N1, est1, 0.);
1342 sprintf(out3,
"%-10s: %-12.2f %-12.2f %-12.2f",
"mc", N2, est2, esys2);
1343 sprintf(out4,
"%-10s: %-12.3f %-12.3f %-12.4f",
"ratio",ratio, ratio_stat, ratio_syst);
1344 std::cout << out1 << std::endl;
1345 std::cout <<
" --------------------------------------------------------" << std::endl;
1346 std::cout << out2 << std::endl;
1347 std::cout << out3 << std::endl;
1348 std::cout << out4 << std::endl;
1352 PrintPurities(exp,categ,cut,uopt);
1356 void DrawingTools::DrawEventsVSCut(
Experiment& exp,
const std::string& cut_norm,
int first_cut,
int last_cut,
1357 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1360 DrawEventsVSCut(exp,0,cut_norm,first_cut,last_cut,root_opt,opt,leg);
1364 void DrawingTools::DrawEventsVSCut(
Experiment& exp,
int branch,
const std::string& cut_norm,
int first_cut,
int last_cut,
1365 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1368 DrawEventsVSCut(exp,0,branch,cut_norm,first_cut,last_cut,root_opt,opt,leg);
1372 void DrawingTools::DrawEventsVSCut(
Experiment& exp,
int isel,
int branch,
const std::string& cut_norm,
int first_cut,
int last_cut,
1373 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1380 if (!sel().GetSelection(isel,
true))
return;
1382 std::string slevel = GetSameLevel(root_opt);
1392 GetEventsVSCut(exp,
"events",cut_norm,isel,branch,first_cut, last_cut,root_opt,uopt,hdata,hmc);
1396 if (slevel==
"0" && (leg!=
"" || (hdata && hmc))){
1398 double sizex = _legendSize[0];
1399 double sizey = _legendSize[1];
1402 SetLegendSize(0.2,0.2);
1407 SetLegendSize(sizex,sizey);
1412 if (hdata) hall = hdata;
1415 Int_t cut_offset = 0;
1417 if (first_cut ==-1){
1418 hall->GetXaxis()->SetBinLabel(1,
"NO CUT");
1422 std::vector<StepBase*> cuts = sel().GetSelection(isel)->GetCutsInBranch(branch);
1424 for (
int i=cut_offset;i<hall->GetNbinsX();i++ ){
1425 int icut = first_cut+i;
1426 hall->GetXaxis()->SetBinLabel(i+1, cuts[icut]->Title().c_str());
1430 gStyle->SetErrorX(0.0001);
1432 hall->SetMarkerStyle(21);
1436 DrawHisto(hdata, _auto_colors[_same_level], _line_width, _auto_colors[_same_level], _fill_style,
"pl e"+root_opt, uopt+
" NOSTAT NOLEG");
1440 slevel = GetSameLevel(
"same");
1441 DrawHisto(hmc, _auto_colors[_same_level], _line_width, _auto_colors[_same_level], _fill_style,
"pl e same "+root_opt, uopt+
" NOSTAT NOLEG");
1444 DrawHisto(hmc, _auto_colors[_same_level], _line_width, _auto_colors[_same_level], _fill_style,
"pl e "+root_opt, uopt+
" NOSTAT NOLEG");
1447 hall->GetXaxis()->SetTitle(
"");
1448 hall->GetYaxis()->SetTitle(
"# events");
1452 if (leg!=
"" || (hdata && hmc)){
1453 if (hdata && !hmc) _legends.back()->AddEntry( hdata, leg.c_str(),
"LE1P");
1454 if (!hdata && hmc) _legends.back()->AddEntry( hmc, leg.c_str(),
"LE1P");
1456 _legends.back()->AddEntry( hdata, (
"data "+leg).c_str(),
"LE1P");
1457 _legends.back()->AddEntry( hmc, (
"MC "+leg).c_str(),
"LE1P");
1459 _legends.back()->Draw();
1466 gStyle->SetErrorX();
1475 std::cout <<
" ------------- Events vs cut ---------------------------------- " << std::endl;
1476 for (
int i=0;i<hall->GetNbinsX();i++ ){
1477 int icut = first_cut+i;
1478 std::string cut_name=
"";
1480 cut_name =
"NO CUT";
1482 cut_name = cuts[icut]->Title();
1485 sprintf(out1,
"%3s: %-25s %-10s %-10s",
"#",
"cut",
"data",
"MC");
1486 sprintf(out2,
"%3d: %-25s %-10.2f %-10.2f", icut, cut_name.c_str(), hdata->GetBinContent(i+1), hmc->GetBinContent(i+1));
1489 sprintf(out1,
"%3s: %-25s %-10s",
"#",
"cut",
"data");
1490 sprintf(out2,
"%3d: %-25s %-10.2f", icut, cut_name.c_str(), hdata->GetBinContent(i+1));
1493 sprintf(out1,
"%3s: %-25s %-10s",
"#",
"cut",
"MC");
1494 sprintf(out2,
"%3d: %-25s %-10.2f", icut, cut_name.c_str(), hmc->GetBinContent(i+1));
1497 if (i==0) std::cout << out1 << std::endl;
1498 std::cout << out2 << std::endl;
1504 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1507 DrawRatioVSCut(exp,0,precut,first_cut,last_cut,root_opt,opt,leg);
1512 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1515 DrawRatioVSCut(exp,0,branch,precut,first_cut,last_cut,root_opt,opt,leg);
1520 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1524 if (!sel().GetSelection(isel,
true))
return;
1531 std::string slevel = GetSameLevel(root_opt);
1532 if (slevel==
"0" && leg!=
"")
1537 Int_t first_cut2=-1;
1538 GetEventsVSCut(exp,
"ratio",precut,isel,branch,first_cut2, last_cut,root_opt,uopt,hdata,hmc);
1540 if (!hdata || !hmc){
1541 std::cout <<
"Cannot compute ratio because either data or MC histos are empty" << std::endl;
1545 std::cout <<
"----- Data/MC ratio values -----------" << std::endl;
1550 void DrawingTools::DrawPurVSCut(
Experiment& exp,
const std::string& signal,
const std::string& precut,
int first_cut,
int last_cut,
1551 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1554 DrawPurVSCut(exp,0,signal,precut,first_cut,last_cut,root_opt, opt, leg);
1558 void DrawingTools::DrawPurVSCut(
Experiment& exp,
int branch,
const std::string& signal,
const std::string& precut,
int first_cut,
int last_cut,
1559 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1562 DrawPurVSCut(exp,0,branch,signal,precut,first_cut,last_cut,root_opt, opt, leg);
1566 void DrawingTools::DrawPurVSCut(
Experiment& exp,
int isel,
int branch,
const std::string& signal,
const std::string& precut,
int first_cut,
int last_cut,
1567 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1571 if (!sel().GetSelection(isel,
true))
return;
1578 std::string slevel = GetSameLevel(root_opt);
1579 if (slevel==
"0" && leg!=
"")
1582 std::string numer =
"";
1585 }
else if (precut ==
"") {
1588 numer = signal+
"&&"+precut;
1593 TH1_h* hmc1, *hmc2 ;
1594 Int_t first_cut2=-1;
1595 GetEventsVSCut(exp,
"pur1",numer,isel,branch,first_cut2, last_cut,root_opt,uopt,hdata,hmc1);
1598 GetEventsVSCut(exp,
"pur2",precut,isel,branch,first_cut2, last_cut,root_opt,uopt,hdata,hmc2);
1600 if (!hmc1 || !hmc2){
1601 std::cout <<
"Cannot compute purity because the experiment does not have any MC sample" << std::endl;
1605 std::cout <<
"----- Purity values -----------" << std::endl;
1610 void DrawingTools::DrawEffVSCut(
Experiment& exp,
const std::string& signal,
const std::string& precut,
int first_cut,
int last_cut,
1611 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1614 DrawEffVSCut(exp,0,signal,precut,first_cut,last_cut,root_opt, opt, leg);
1618 void DrawingTools::DrawEffVSCut(
Experiment& exp,
int branch,
const std::string& signal,
const std::string& precut,
int first_cut,
int last_cut,
1619 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1622 DrawEffVSCut(exp,0,branch,signal,precut,first_cut,last_cut,root_opt, opt, leg);
1626 void DrawingTools::DrawEffVSCut(
Experiment& exp,
int isel,
int branch,
const std::string& signal,
const std::string& precut,
int first_cut,
int last_cut,
1627 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1631 if (!sel().GetSelection(isel,
true))
return;
1638 std::string slevel = GetSameLevel(root_opt);
1639 if (slevel==
"0" && leg!=
"")
1642 std::string numer =
"";
1645 }
else if (precut ==
"") {
1648 numer = signal+
"&&"+precut;
1660 Int_t first_cut2=-1;
1661 GetEventsVSCut(exp,
"eff1",numer,isel,branch,first_cut2, last_cut,root_opt,uopt,hdata,hmc1);
1664 std::cout <<
"Cannot compute efficiency because the experiment does not have any MC sample" << std::endl;
1672 int nx = hmc1->GetNbinsX();
1673 double xmin = hmc1->GetXaxis()->GetXmin();
1674 double xmax = hmc1->GetXaxis()->GetXmax();
1675 double xbins[NMAXBINS];
1676 TH1_h* hmc2 =
new TH1_h(GetUniqueName(
"eff2").c_str(),
"eff2",nx,GetVariableBins(nx,xmin,xmax,xbins));
1677 _saved_histos.push_back(hmc2);
1679 for (
int i=0; i<hmc2->GetNbinsX();i++){
1680 hmc2->SetBinContent(i+1,hmc1->GetBinContent(1));
1681 hmc2->SetBinError( i+1,hmc1->GetBinError(1));
1684 std::cout <<
"----- Efficiency values -----------" << std::endl;
1689 void DrawingTools::DrawEffPurVSCut(
Experiment& exp,
const std::string& signal,
const std::string& precut,
int first_cut,
int last_cut,
1690 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1693 DrawEffPurVSCut(exp,0,signal,precut,first_cut,last_cut, root_opt, opt, leg);
1698 void DrawingTools::DrawEffPurVSCut(
Experiment& exp,
int branch,
const std::string& signal,
const std::string& precut,
int first_cut,
int last_cut,
1699 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1702 DrawEffPurVSCut(exp,0,branch,signal,precut,first_cut,last_cut, root_opt, opt, leg);
1706 void DrawingTools::DrawEffPurVSCut(
Experiment& exp,
int isel,
int branch,
const std::string& signal,
const std::string& precut,
int first_cut,
int last_cut,
1707 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1710 DrawEffPurVSCut(exp,isel,branch,signal,precut,first_cut,last_cut, first_cut,last_cut, root_opt, opt, leg);
1714 void DrawingTools::DrawEffPurVSCut(
Experiment& exp,
int isel,
int branch,
const std::string& signal,
const std::string& precut,
1715 int first_cut_pur,
int last_cut_pur,
int first_cut_eff,
int last_cut_eff,
1716 const std::string& root_opt,
const std::string& opt,
const std::string& leg){
1720 if (!sel().GetSelection(isel,
true))
return;
1728 double sizex = _legendSize[0];
1729 double sizey = _legendSize[1];
1732 SetLegendSize(0.1,0.1);
1735 DrawEffVSCut(exp,isel,branch,signal,precut,first_cut_eff,last_cut_eff,root_opt, opt,
"eff "+leg);
1738 DrawPurVSCut(exp,isel,branch,signal,precut,first_cut_pur,last_cut_pur,(root_opt+
" same").c_str(),opt,
"pur "+leg);
1741 SetLegendSize(sizex,sizey);
1745 double DrawingTools::GetEff(
Experiment& exp,
bool usedata,
1746 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt) {
1748 double errhigh = 0.;
1752 return GetEff(exp, usedata, errlow, errhigh, nev1, nev2, cut1, cut2, root_opt, opt);
1756 double DrawingTools::GetEff(
Experiment& exp,
bool usedata,
double& errlow,
double& errhigh,
double& nev1,
double& nev2,
1757 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt) {
1764 std::string slevel = GetSameLevel(root_opt);
1773 std::string var =
"NWEIGHTS";
1775 double xbins[2] = {-1e6, 1e6};
1777 bool scale_errors =
true;
1779 TGraphAsymmErrors* eff = GetEff(exp, usedata, var, nx, xbins, nev1, nev2, cut1, cut2, root_opt, opt, scale_errors);
1782 if (eff->GetN() != 1) {
1783 std::cout <<
"Error computing efficiency" << std::endl;
1787 errlow = eff->GetEYlow()[0];
1788 errhigh = eff->GetEYhigh()[0];
1790 return eff->GetY()[0];
1794 TGraphAsymmErrors* DrawingTools::GetEff(
Experiment& exp,
bool usedata,
const std::string& var,
int nx,
double* xbins,
double& nev1,
double& nev2,
1795 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt,
bool scale_errors) {
1804 hs1d =
new HistoStack(_title,_titleX,_titleY);
1805 hs2d =
new HistoStack(_title,_titleX,_titleY);
1808 hs1m =
new HistoStack(_title,_titleX,_titleY);
1809 hs2m =
new HistoStack(_title,_titleX,_titleY);
1812 std::string groupName =
"all";
1813 std::string mcSampleName =
"all";
1814 std::string categ =
"all";
1815 std::string newopt = opt +
" NOVARBIN";
1821 if (newopt.find(
"PUR")==std::string::npos && newopt.find(
"NOTRUTH")==std::string::npos)
1825 double ybins[1] = {0};
1828 Project(hs1d, hs1m, exp, groupName, mcSampleName, var,nx,xbins,ny,ybins,categ,(cut1+
" && "+cut2),root_opt,newopt,0.,scale_errors);
1829 Project(hs2d, hs2m, exp, groupName, mcSampleName, var,nx,xbins,ny,ybins,categ, cut2, root_opt,newopt,0.,scale_errors);
1832 if (newopt.find(
"PUR")==std::string::npos && newopt.find(
"NOTRUTH")==std::string::npos)
1848 std::cout <<
"ERROR. numerator does not exist !!!" << std::endl;
1852 std::cout <<
"ERROR. denominator does not exist !!!" << std::endl;
1857 nev1 = h1->Integral(0, h1->GetNbinsX() + 1);
1858 nev2 = h2->Integral(0, h2->GetNbinsX() + 1);
1860 if (h1->GetSumw2N()==0) h1->Sumw2();
1861 if (h2->GetSumw2N()==0) h2->Sumw2();
1864 TGraphAsymmErrors* eff =
new TGraphAsymmErrors(h1);
1865 _saved_graphs.push_back(eff);
1866 eff->Divide(h1, h2, _eff_params.c_str());
1870 FillGraphErrors(hs1d, hs2d, eff, opt);
1872 FillGraphErrors(hs1m, hs2m, eff, opt);
1875 if (hs1d)
delete hs1d;
1876 if (hs2d)
delete hs2d;
1877 if (hs1m)
delete hs1m;
1878 if (hs2m)
delete hs2m;
1885 TGraphAsymmErrors* DrawingTools::GetEffNew(
Experiment& exp,
bool usedata,
const std::string& var,
int nx,
double* xbins,
double& nev1,
double& nev2,
1886 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt1,
1887 const std::string& opt2,
bool scale_errors) {
1898 hs1d =
new HistoStack(_title,_titleX,_titleY);
1899 hs2d =
new HistoStack(_title,_titleX,_titleY);
1902 hs1m =
new HistoStack(_title,_titleX,_titleY);
1903 hs2m =
new HistoStack(_title,_titleX,_titleY);
1906 std::string groupName =
"all";
1907 std::string mcSampleName =
"all";
1908 std::string categ =
"all";
1909 std::string newopt1 = opt1 +
" NOVARBIN";
1910 std::string newopt2 = opt2 +
" NOVARBIN";
1916 double ybins[1] = {0};
1919 Project(hs1d, hs1m, exp, groupName, mcSampleName, var,nx,xbins,ny,ybins,categ,cut1,root_opt,newopt1,0.,scale_errors);
1920 Project(hs2d, hs2m, exp, groupName, mcSampleName, var,nx,xbins,ny,ybins,categ,cut2,root_opt,newopt2,0.,scale_errors);
1937 nev1 = h1->Integral(0, h1->GetNbinsX() + 1);
1938 nev2 = h2->Integral(0, h2->GetNbinsX() + 1);
1941 TGraphAsymmErrors* eff =
new TGraphAsymmErrors(h1);
1942 _saved_graphs.push_back(eff);
1943 eff->Divide(h1, h2, _eff_params.c_str());
1947 FillGraphErrors(hs1d, hs2d, eff, opt1);
1949 FillGraphErrors(hs1m, hs2m, eff, opt1);
1952 if (hs1d)
delete hs1d;
1953 if (hs2d)
delete hs2d;
1954 if (hs1m)
delete hs1m;
1955 if (hs2m)
delete hs2m;
1962 void DrawingTools::DrawRatioNew(
Experiment& exp,
bool usedata,
const std::string& var,
int nx,
double xmin,
double xmax,
1963 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt1,
const std::string& opt2) {
1965 double xbins[NMAXBINS];
1966 DrawRatioNew(exp, usedata, var, nx, GetVariableBins(nx, xmin, xmax, xbins), cut1, cut2, root_opt, opt1, opt2);
1970 void DrawingTools::DrawRatioNew(
Experiment& exp,
bool usedata,
const std::string& var,
int nx,
double* xbins,
1971 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt1,
1972 const std::string& opt2) {
1974 double dummy1, dummy2;
1979 DrawRatioNew(exp, usedata, var, nx, xbins, dummy1, dummy2, cut1, cut2, uroot_opt, uopt1, uopt2);
1983 void DrawingTools::DrawRatioNew(
Experiment& exp,
bool usedata,
const std::string& var,
int nx,
double* xbins,
double& nev1,
double& nev2,
1984 const std::string& cut1,
const std::string& cut2,
const std::string& root_opt,
const std::string& opt1,
1985 const std::string& opt2,
bool scale_errors) {
2007 hs1d =
new HistoStack(_title,_titleX,_titleY);
2008 hs2d =
new HistoStack(_title,_titleX,_titleY);
2011 hs1m =
new HistoStack(_title,_titleX,_titleY);
2012 hs2m =
new HistoStack(_title,_titleX,_titleY);
2015 std::string groupName =
"all";
2016 std::string mcSampleName =
"all";
2017 std::string categ =
"all";
2018 std::string newopt1 = uopt1 +
" NOVARBIN";
2019 std::string newopt2 = uopt2 +
" NOVARBIN";
2025 double ybins[1] = {0};
2028 Project(hs1d, hs1m, exp, groupName, mcSampleName, var,nx,xbins,ny,ybins,categ,cut1,root_opt,newopt1,0.,scale_errors);
2029 Project(hs2d, hs2m, exp, groupName, mcSampleName, var,nx,xbins,ny,ybins,categ,cut2,root_opt,newopt2,0.,scale_errors);
2046 nev1 = h1->Integral(0, h1->GetNbinsX() + 1);
2047 nev2 = h2->Integral(0, h2->GetNbinsX() + 1);
2051 DrawRatioHistoStacks(hs1d,hs2d,root_opt,newopt1,0.);
2053 DrawRatioHistoStacks(hs1m,hs2m,root_opt,newopt1,0.);
2055 if (hs1d)
delete hs1d;
2056 if (hs2d)
delete hs2d;
2057 if (hs1m)
delete hs1m;
2058 if (hs2m)
delete hs2m;
2065 const std::string& root_opt,
const std::string& opt, TH1_h*& data, TH1_h*& mc){
2069 if (!sel().GetSelection(isel,
true))
return;
2079 if (last_cut>(
int)(sel().GetSelection(isel)->GetNCuts(ibranch)-1) || last_cut == -1) last_cut=sel().GetSelection(isel)->GetNCuts(ibranch)-1;
2080 if (first_cut<-1 || first_cut>last_cut ) first_cut=-1;
2083 double xmin=first_cut-0.5;
2084 double xmax=last_cut+0.5;
2085 int nx = (int)(xmax-xmin);
2087 std::vector<double> balldata;
2088 balldata.resize(nx);
2089 std::vector<double> ballmc;
2093 bool found_data=
false;
2094 bool found_mc=
false;
2098 std::string cut0 = cut_norm;
2099 if (cut0 ==
"") cut0 =
"1==1";
2101 for (
int i=0;i<nx;i++ ){
2102 int icut = first_cut+i;
2105 std::stringstream scut;
2107 std::stringstream sbranch;
2109 std::stringstream ssel;
2114 if (sel().GetNEnabledSelections()>1)
2115 cut= cut0 +
" && accum_level["+ssel.str()+
"]["+sbranch.str()+
"]>"+scut.str();
2117 cut= cut0 +
" && accum_level["+sbranch.str()+
"]>"+scut.str();
2120 if (sel().GetNEnabledSelections()>1)
2121 cut= cut0 +
" && accum_level[]["+ssel.str()+
"]["+sbranch.str()+
"]>"+scut.str();
2123 cut= cut0 +
" && accum_level[]["+sbranch.str()+
"]>"+scut.str();
2130 double xbins_dummy[2]={0,1};
2131 double ybins_dummy[1];
2134 Project(hs1, hs2, exp,
"all",
"all",
"0.5",1,xbins_dummy,0,ybins_dummy,
"all",cut,root_opt,opt,0.,
false);
2136 if (hs2->GetTotal1D()){
2137 ballmc[i] = (double)hs2->GetTotal1D()->Integral();
2142 balldata[i] = (double)hs1->
GetTotal1D()->Integral();
2153 double xbins[NMAXBINS];
2155 data =
new TH1_h(GetUniqueName(name+
"_data").c_str(),
"",nx,GetVariableBins(nx,xmin,xmax,xbins));
2156 _saved_histos.push_back(data);
2157 for (
int i=0;i<nx;i++ )
2158 data->SetBinContent(i+1,balldata[i]);
2161 mc =
new TH1_h(GetUniqueName(name+
"_mc").c_str(),
"",nx,GetVariableBins(nx,xmin,xmax,xbins));
2162 _saved_histos.push_back(mc);
2163 for (
int i=0;i<nx;i++ )
2164 mc->SetBinContent(i+1,ballmc[i]);
2171 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
bool scale_errors,
const std::string& normtype){
2174 double xbins[NMAXBINS];
2175 CompareSampleGroups(exp,mcSampleName,var,nx,GetVariableBins(nx,xmin,xmax,xbins),cut,root_opt,opt,scale_errors,normtype);
2180 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
bool scale_errors,
const std::string& normtype){
2183 std::vector<HistoStack*> hs;
2185 double ybins[NMAXBINS];
2204 std::map< std::string, SampleGroup >::iterator it;
2209 std::map< std::string, DataSample*>& mcSamples = sampleGroup.
GetMCSamples();
2212 bool thisfirst =
false;
2214 _saved_histoStacks.push_back(hs);
2216 if (unormtype ==
"POT") {
2221 norm = GetNormalisationFactor(firstSample, data, 1.0,
true, opt);
2233 Project(hs,
"sample1", *data, var, nx, xbins, ny, ybins,
"all", cut, uroot_opt, uopt, norm, scale_errors);
2235 if (unormtype ==
"ONE") {
2236 double integral = hs->
GetTotal1D()->Integral();
2241 std::string leg = it->first +
" Data";
2243 lc = _auto_colors[count];
2248 SetStatPos((1-0.4*count-gStyle->GetPadRightMargin()),(1.04-gStyle->GetPadTopMargin()));
2249 DrawHisto(hs->
GetTotal1D(),lc,1,lc,0, uroot_opt +
" E", uopt,
"lpe");
2254 uroot_opt +=
" SAMES";
2258 if (mcSamples.size() > 0) {
2259 bool thisfirst =
false;
2261 _saved_histoStacks.push_back(hs);
2263 std::map<std::string, DataSample*>::iterator it2;
2264 for (it2 = mcSamples.begin(); it2 != mcSamples.end(); it2++) {
2265 const std::string& mcSampleName2 = it2->first;
2266 if (mcSampleName2 != mcSampleName && mcSampleName !=
"all")
continue;
2270 if (unormtype ==
"POT") {
2272 firstSample = sample2;
2275 norm = GetNormalisationFactor(firstSample, sample2, 1.0,
true, opt);
2287 Project(hs,
"sample2", *sample2, var, nx, xbins, ny, ybins,
"all", cut, uroot_opt, uopt, norm, scale_errors);
2291 if (unormtype ==
"ONE") {
2292 double integral = hs->
GetTotal1D()->Integral();
2297 std::string leg = it->first;
2298 if (mcSampleName ==
"all") {
2301 leg +=
" " + mcSampleName;
2304 lc = _auto_colors[count];
2310 SetStatPos((0.8-0.4*count-gStyle->GetPadRightMargin()),(1.04-gStyle->GetPadTopMargin()));
2311 DrawHisto(hs->
GetTotal1D(),lc,2,lc,3004+count, uroot_opt +
" HIST", uopt,
"f");
2316 uroot_opt +=
" SAMES";
2325 _legends.back()->Draw();
2333 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg,
double norm,
bool scale_errors){
2337 double xbins[NMAXBINS];
2338 return DrawErrors(tree, var, nx, GetVariableBins(nx,xmin,xmax,xbins), cut, root_opt, opt, leg, norm, scale_errors);
2342 Double_t DrawingTools::DrawRelativeErrors(TTree* tree,
const std::string& var,
int nx,
double xmin,
double xmax,
2343 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg,
double norm,
bool scale_errors){
2347 double xbins[NMAXBINS];
2348 return DrawRelativeErrors(tree, var, nx, GetVariableBins(nx,xmin,xmax,xbins), cut, root_opt, opt, leg, norm, scale_errors);
2353 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg,
double norm,
bool scale_errors){
2357 bool relative=
false;
2358 return DrawErrorsBase(tree, var, nx, xbins, cut, relative, root_opt, opt, leg, norm, scale_errors);
2362 Double_t DrawingTools::DrawRelativeErrors(TTree* tree,
const std::string& var,
int nx,
double* xbins,
2363 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg,
double norm,
bool scale_errors){
2368 return DrawErrorsBase(tree, var, nx, xbins, cut, relative, root_opt, opt, leg, norm, scale_errors);
2372 Double_t DrawingTools::DrawRelativeErrors(TTree* tree1, TTree* tree2,
const std::string& var,
int nx,
double xmin,
double xmax,
2373 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg,
double norm,
bool scale_errors){
2377 double xbins[NMAXBINS];
2378 return DrawRelativeErrors(tree1, tree2, var, nx, GetVariableBins(nx,xmin,xmax,xbins), cut, root_opt, opt, leg, norm, scale_errors);
2382 Double_t DrawingTools::DrawRelativeErrors(TTree* tree1, TTree* tree2,
const std::string& var,
int nx,
double* xbins,
2383 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg,
double norm,
bool scale_errors){
2388 DrawErrorsBase(tree1, var, nx, xbins, cut, relative, root_opt, opt, leg, norm, scale_errors);
2389 return DrawErrorsBase(tree2, var, nx, xbins, cut, relative, root_opt+
" same", opt, leg, norm, scale_errors);
2393 Double_t DrawingTools::DrawErrorsBase(TTree* tree,
const std::string& var,
int nx,
double* xbins,
2394 const std::string& cut,
bool relative,
const std::string& root_opt,
const std::string& opt,
const std::string& leg,
double norm,
bool scale_errors){
2396 if(syst_tools().errdebug) std::cout<<
"DrawErrorBase \n=============== "<<std::endl;
2407 _saved_histoStacks.push_back(hs);
2412 DrawingToolsBase::Project(hs,
"", tree,var,nx,xbins,0,ybins,
"all",cut,root_opt,uopt,norm,scale_errors);
2414 return DrawErrorsBase(hs,relative,root_opt,opt,leg);
2419 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg,
bool scale_errors){
2423 double xbins[NMAXBINS];
2424 return DrawErrors(exp, var, nx, GetVariableBins(nx,xmin,xmax,xbins), cut, root_opt, opt, leg, scale_errors);
2428 Double_t DrawingTools::DrawRelativeErrors(
Experiment& exp,
const std::string& var,
int nx,
double xmin,
double xmax,
2429 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg,
bool scale_errors){
2433 double xbins[NMAXBINS];
2434 return DrawRelativeErrors(exp, var, nx, GetVariableBins(nx,xmin,xmax,xbins), cut, root_opt, opt, leg, scale_errors);
2439 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg,
bool scale_errors){
2443 bool relative=
false;
2444 return DrawErrorsBase(exp,
"all",
"all", var, nx, xbins, cut, relative, root_opt, opt, leg, scale_errors);
2448 Double_t DrawingTools::DrawRelativeErrors(
Experiment& exp,
const std::string& var,
int nx,
double* xbins,
2449 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg,
bool scale_errors){
2454 return DrawErrorsBase(exp,
"all",
"all", var, nx, xbins, cut, relative, root_opt, opt, leg, scale_errors);
2458 Double_t
DrawingTools::DrawErrors(
Experiment& exp,
const std::string& groupName,
const std::string& mcSampleName,
const std::string& var,
int nx,
double xmin,
double xmax,
2459 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg,
bool scale_errors){
2463 double xbins[NMAXBINS];
2464 return DrawErrors(exp, groupName, mcSampleName, var, nx, GetVariableBins(nx,xmin,xmax,xbins), cut, root_opt, opt, leg, scale_errors);
2468 Double_t DrawingTools::DrawRelativeErrors(
Experiment& exp,
const std::string& groupName,
const std::string& mcSampleName,
const std::string& var,
int nx,
double xmin,
double xmax,
2469 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg,
bool scale_errors){
2473 double xbins[NMAXBINS];
2474 return DrawRelativeErrors(exp, groupName, mcSampleName, var, nx, GetVariableBins(nx,xmin,xmax,xbins), cut, root_opt, opt, leg, scale_errors);
2479 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg,
bool scale_errors){
2483 bool relative=
false;
2484 return DrawErrorsBase(exp, groupName, mcSampleName, var, nx, xbins, cut, relative, root_opt, opt, leg, scale_errors);
2488 Double_t DrawingTools::DrawRelativeErrors(
Experiment& exp,
const std::string& groupName,
const std::string& mcSampleName,
const std::string& var,
int nx,
double* xbins,
2489 const std::string& cut,
const std::string& root_opt,
const std::string& opt,
const std::string& leg,
bool scale_errors){
2494 return DrawErrorsBase(exp, groupName, mcSampleName, var, nx, xbins, cut, relative, root_opt, opt, leg, scale_errors);
2498 Double_t DrawingTools::DrawErrorsBase(
Experiment& exp,
const std::string& groupName,
const std::string& mcSampleName,
const std::string& var,
int nx,
double* xbins,
2499 const std::string& cut,
bool relative,
const std::string& root_opt,
const std::string& opt,
const std::string& leg,
bool scale_errors){
2508 if (groupName!=
"all"){
2516 hs1 =
new HistoStack(_title,_titleX,_titleY);
2517 _saved_histoStacks.push_back(hs1);
2520 hs2 =
new HistoStack(_title,_titleX,_titleY);
2521 _saved_histoStacks.push_back(hs2);
2526 Project(hs1, hs2, exp, groupName, mcSampleName, var,nx,xbins,0,ybins,
"all",cut,root_opt,opt,0.,scale_errors);
2529 return DrawErrorsBase(hs2,relative,root_opt,opt,leg);
2531 return DrawErrorsBase(hs1,relative,root_opt,opt,leg);
2536 Double_t DrawingTools::DrawErrorsBase(
HistoStack* hs,
bool relative,
const std::string& root_opt,
const std::string& opt,
const std::string& leg){
2544 std::string slevel = GetSameLevel(root_opt);
2545 std::string name3 = GetUniqueName(
"alle");
2547 if (slevel==
"0" && leg!=
"")
2552 if (opt.find(
"ST")==std::string::npos && (opt.find(
"SYS")!=std::string::npos || opt.find(
"DIS")!=std::string::npos))
2554 else if (opt.find(
"ST")!=std::string::npos && (opt.find(
"SYS")==std::string::npos && opt.find(
"DIS")==std::string::npos))
2557 TH1_h* herrors =
new TH1_h(*hall);
2558 herrors->SetName(name3.c_str());
2559 _saved_histos.push_back(herrors);
2562 Double_t avg_error =0;
2563 for (
int i=0;i<hall->GetNbinsX();i++){
2565 if (hall->GetBinContent(i+1)!=0){
2566 herrors->SetBinContent(i+1, hall->GetBinError(i+1)/hall->GetBinContent(i+1));
2567 avg_error += hall->GetBinError(i+1);
2570 herrors->SetBinContent(i+1, 0.);
2572 avg_error += hall->GetBinError(i+1)*hall->GetBinContent(i+1);
2573 herrors->SetBinContent(i+1, hall->GetBinError(i+1));
2576 ntotal += hall->GetBinContent(i+1);
2577 herrors->SetBinError(i+1, 0);
2581 std::cout <<
"average differential error = " << avg_error << std::endl;
2583 std::string title_temp = _title;
2587 SetTitleY(
"relative error");
2589 SetTitleY(
"absolute error");
2591 herrors->SetTitle(leg.c_str());
2593 std::string varbin =
"";
2594 if (relative) varbin=
" NOVARBIN";
2597 DrawHisto(herrors, _line_width, _line_color, _fill_style, root_opt, uopt+
" NOSTAT"+varbin,
"LE1P");
2600 SetTitleY(title_temp);
2604 _legends.back()->Draw();
2614 const std::string& cut,
const std::string& root_opt,
const std::string& uopt){
2617 const TMatrixD& mcov = GetCovMatrix(tree, var, nx, xbins, cut, uopt);
2620 DrawMatrix(mcov, _auto_colors[_same_level], _line_width, _line_color, _fill_style, root_opt, uopt);
2626 const std::string& cut,
const std::string& root_opt,
const std::string& uopt){
2628 double xbins[NMAXBINS];
2630 DrawCovMatrix(tree, var, nx, GetVariableBins(nx, xmin, xmax, xbins), cut, root_opt, uopt);
2636 const std::string& cut,
const std::string& root_opt,
const std::string& uopt){
2638 const TMatrixD& mcov = GetCovMatrix(exp, groupName, mcSampleName, var, nx, xbins, cut, root_opt, uopt);
2641 DrawMatrix(mcov, _auto_colors[_same_level], _line_width, _line_color, _fill_style, root_opt, uopt);
2646 const std::string& cut,
const std::string& root_opt,
const std::string& uopt){
2648 const TMatrixD& mcov = GetCovMatrix(exp, groupName, mcSampleName, var, nx, xmin, xmax, cut, root_opt, uopt);
2651 DrawMatrix(mcov, _auto_colors[_same_level], _line_width, _line_color, _fill_style, root_opt, uopt);
2656 const std::string& cut,
const std::string& root_opt,
const std::string& uopt){
2658 const TMatrixD& mcov = GetCovMatrix(exp, var, nx, xbins, cut, root_opt, uopt);
2661 DrawMatrix(mcov, _auto_colors[_same_level], _line_width, _line_color, _fill_style, root_opt, uopt);
2667 const std::string& cut,
const std::string& root_opt,
const std::string& uopt){
2669 const TMatrixD& mcov = GetCovMatrix(exp, var, nx, xmin, xmax, cut, root_opt, uopt);
2672 DrawMatrix(mcov, _auto_colors[_same_level], _line_width, _line_color, _fill_style, root_opt, uopt);
2677 const std::string& cut,
const std::string& root_opt,
const std::string& opt){
2685 if (groupName!=
"all"){
2686 if (!exp.
HasSampleGroup(groupName))
return syst_tools().GetSystematicCov(NULL,
"DUMMY");
2692 hs1 =
new HistoStack(_title,_titleX,_titleY);
2693 _saved_histoStacks.push_back(hs1);
2698 _saved_histoStacks.push_back(hs2);
2701 std::string opt_tmp = uopt;
2705 opt_tmp +=
"MATRIX";
2709 Project(hs1, hs2, exp, groupName, mcSampleName, var,nx,xbins,0,ybins,
"all",cut,root_opt,opt_tmp, 0.,
false);
2713 const TMatrixD& mcov = syst_tools().GetSystematicCov(hs2, uopt);
2720 const std::string& cut,
const std::string& root_opt,
const std::string& uopt){
2722 double xbins[NMAXBINS];
2724 return GetCovMatrix(exp, groupName, mcSampleName, var, nx, GetVariableBins(nx, xmin, xmax, xbins), cut, root_opt, uopt);
2729 const std::string& cut,
const std::string& root_opt,
const std::string& uopt){
2732 return GetCovMatrix(exp,
"all",
"all", var, nx, xbins, cut, root_opt, uopt);
2737 const std::string& cut,
const std::string& root_opt,
const std::string& uopt){
2739 double xbins[NMAXBINS];
2741 return GetCovMatrix(exp,
"all",
"all", var, nx, GetVariableBins(nx, xmin, xmax, xbins), cut, root_opt, uopt);
2746 const std::string& cut,
const std::string& uopt){
2748 double xbins[NMAXBINS];
2751 return GetCovMatrix(tree, var, nx, GetVariableBins(nx, xmin, xmax, xbins), cut, uopt);
2756 const std::string& cut,
const std::string& uopt){
2764 const TMatrixD& mcov = syst_tools().GetSystematicCov(tree, var, nx, xbins, cut, NTOYS, uopt);
2771 const std::string& root_opt,
const std::string& uopt){
2775 TH2D* h =
new TH2D(m);
2778 std::string name = h->GetName();
2779 h->SetName(GetUniqueName(name).c_str());
2781 _saved_histos.push_back(h);
2784 DrawHisto(h, lc, lw, fc, fs, root_opt, uopt+
" NOSTAT NOMIN",
"");
2787 if (ropt.find(
"COLZ"))
2788 gPad->SetRightMargin(0.15);
2790 h->GetXaxis()->SetTitle(
"Bins");
2791 h->GetYaxis()->SetTitle(
"Bins");
bool HasMCSample(const std::string &name)
Check whether the group has a given MC sample.
TTree * GetTree(Int_t index)
Returns the a tree with a given index.
TH1_h * GetTotalStat1D()
Return the total 1D histo with only stat errors.
TH1_h * GetTotalSyst1D()
Return the total 1D histo with only systematic errors.
void SetCurrentSystGroup(const std::string &group)
Set the current Systematics group.
void NormalizeByArea(const std::string &uopt, double area=1)
normalize all histos in the stack by area
std::map< std::string, DataSample * > & GetMCSamples()
Get all MC samples in a group.
std::string GetString(int code)
convert integer to string
void DumpPOT(const std::string &name)
Dump detailed POT information for a given sample pair.
bool ContainValidOptions(const std::string &uopt)
Check if the input string contails only valid options.
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 SetCurrentTree(const std::string &name)
Set the current configuration to all samples in all SampleGroups.
bool HasSampleGroup(const std::string &name)
Checks if the Experiment has a SampleGroup with a given name.
DataSample * GetDataSample()
Get the data sample in a group.
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
TH1_h * GetTotal1D()
Return the total 1D histo.
const std::string & GetCurrentTree() const
Get the current configuration.
std::map< std::string, SampleGroup > & GetSampleGroups()
Returns all sample groups.
Float_t GetOverallPOTRatio()
Get the overall POT ratio.
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.