ROOT Analysis for the Inclusive Detachted Dilepton Trigger Lines
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
4.0 KiB

6 months ago
  1. #include <filesystem>
  2. #include "TMVA/efficiencies.h"
  3. #include "TH2F.h"
  4. #include "TFile.h"
  5. #include "TIterator.h"
  6. #include "TKey.h"
  7. void set_tmva_style()
  8. {
  9. TStyle *TMVAStyle = gROOT->GetStyle("TMVA");
  10. if (TMVAStyle != 0)
  11. {
  12. gROOT->SetStyle("TMVA");
  13. return;
  14. }
  15. TMVAStyle = new TStyle(*gROOT->GetStyle("Plain")); // our style is based on Plain
  16. TMVAStyle->SetName("TMVA");
  17. TMVAStyle->SetTitle("TMVA style based on \"Plain\" with modifications defined in tmvaglob.C");
  18. gROOT->GetListOfStyles()->Add(TMVAStyle);
  19. gROOT->SetStyle("TMVA");
  20. TMVAStyle->SetLineStyleString(5, "[52 12]");
  21. TMVAStyle->SetLineStyleString(6, "[22 12]");
  22. TMVAStyle->SetLineStyleString(7, "[22 10 7 10]");
  23. // the pretty color palette of old
  24. TMVAStyle->SetPalette((TMVA::gConfig().fVariablePlotting.fUsePaperStyle ? 18 : 1), 0);
  25. TMVAStyle->SetOptFile(0);
  26. // use plain black on white colors
  27. TMVAStyle->SetFrameBorderMode(0);
  28. TMVAStyle->SetCanvasBorderMode(0);
  29. TMVAStyle->SetPadBorderMode(0);
  30. TMVAStyle->SetPadColor(0);
  31. TMVAStyle->SetFillStyle(0);
  32. TMVAStyle->SetLegendBorderSize(0);
  33. // title properties
  34. // TMVAStyle->SetTitleW(.4);
  35. // TMVAStyle->SetTitleH(.10);
  36. // MVAStyle->SetTitleX(.5);
  37. // TMVAStyle->SetTitleY(.9);
  38. TMVAStyle->SetTitleFillColor(TColor::GetColor("#ffffff"));
  39. TMVAStyle->SetTitleTextColor(TColor::GetColor("#000000"));
  40. TMVAStyle->SetTitleBorderSize(0);
  41. TMVAStyle->SetLineColor(TMVA::TMVAGlob::getTitleBorder());
  42. if (!TMVA::gConfig().fVariablePlotting.fUsePaperStyle)
  43. {
  44. TMVAStyle->SetFrameFillColor(TColor::GetColor("#ffffff"));
  45. TMVAStyle->SetCanvasColor(TColor::GetColor("#ffffff"));
  46. }
  47. // set the paper & margin sizes
  48. TMVAStyle->SetPaperSize(20, 26);
  49. TMVAStyle->SetPadTopMargin(0.08);
  50. TMVAStyle->SetPadRightMargin(0.01);
  51. TMVAStyle->SetPadBottomMargin(0.01);
  52. TMVAStyle->SetPadLeftMargin(0.12);
  53. // use bold lines and markers
  54. TMVAStyle->SetMarkerStyle(21);
  55. TMVAStyle->SetMarkerSize(0.3);
  56. TMVAStyle->SetHistLineWidth(2);
  57. TMVAStyle->SetLineStyleString(2, "[12 12]"); // postscript dashes
  58. // do not display any of the standard histogram decorations
  59. TMVAStyle->SetOptTitle(1);
  60. TMVAStyle->SetTitleH(0.052);
  61. TMVAStyle->SetOptStat(0);
  62. TMVAStyle->SetOptFit(0);
  63. // put tick marks on top and RHS of plots
  64. TMVAStyle->SetPadTickX(1);
  65. TMVAStyle->SetPadTickY(1);
  66. }
  67. void set_title_vis(bool vis)
  68. {
  69. TStyle *TMVAStyle = gROOT->GetStyle("TMVA");
  70. TMVAStyle->SetTitleTextColor(TColor::GetColor(vis ? "#000000" : "#ffffff"));
  71. }
  72. void find_and_resize_canvas(const char *name, const char *save_folder_name, const char *save_file_name)
  73. {
  74. auto canvs = (TCanvas *)gROOT->FindObject(name);
  75. if (canvs != 0)
  76. {
  77. std::cout << "#### Resizing Canvas: " << canvs->GetTitle() << std::endl;
  78. canvs->SetCanvasSize(canvs->GetWindowWidth() * 1.5, canvs->GetWindowHeight() * 1.5);
  79. canvs->Update();
  80. canvs->SaveAs(TString::Format("output_files/tmva/%s/%s.pdf", save_folder_name, save_file_name));
  81. }
  82. }
  83. void run(const char *trigger) {
  84. std::filesystem::create_directory(TString::Format("output_files/tmva/%s", trigger).Data());
  85. TString input_file = TString::Format("%s_tmva_out.root", trigger);
  86. TString directory = TString::Format("%s_dataloader", trigger);
  87. set_title_vis(true);
  88. TMVA::efficiencies(directory, input_file, 2, true);
  89. find_and_resize_canvas("c", trigger, "efficiencies");
  90. TMVA::mvas(directory, input_file, TMVA::kMVAType, true);
  91. find_and_resize_canvas("canvas1", trigger, "class_output_testsamp");
  92. TMVA::mvas(directory, input_file, TMVA::kCompareType, true);
  93. find_and_resize_canvas("canvas1", trigger, "class_output_overtrain");
  94. set_title_vis(false);
  95. TMVA::variables(directory, input_file, "InputVariables_Id", "Input variables Id-transformed (training sample)", false, true);
  96. for (int i = 0; i < 3; i++)
  97. {
  98. find_and_resize_canvas(TString::Format("canvas%d", i + 1), trigger, TString::Format("variables%d", i + 1));
  99. }
  100. }
  101. int tmva_plotting()
  102. {
  103. set_tmva_style();
  104. run("BuToHpMuMu");
  105. run("B0ToHpHmMuMu");
  106. return 0;
  107. }
  108. /*
  109. //title properties
  110. */