Angular analysis of B+->K*+(K+pi0)mumu
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.

169 lines
6.2 KiB

  1. //Create tables of BDT significance for B+->Kst+mumu
  2. //david gerick
  3. #include "../../GlobalFunctions.hh"
  4. #include "../../HeidelbergFitter/LHCbStyle.h"
  5. //#include "MVA_b2kmm.cc"
  6. using namespace std;
  7. using namespace RooFit ;
  8. //////////////////////////////////////////////////////
  9. /// GetMVASignificance()
  10. ///
  11. void GetMVASignificance(std::vector<Int_t> Run, std::vector<std::string> DDLL, std::string BDTmethod) {
  12. bool debug = false;
  13. UInt_t NN = Run.size();
  14. assert(NN == DDLL.size());
  15. std::vector< std::vector<int> > rank;
  16. std::vector< std::vector< std::string> > latex_name;
  17. std::vector< std::vector<float> > value;
  18. for(UInt_t n = 0; n < NN; n++){
  19. std::cout << "[LOAD]\t\tRun" << Run.at(n) << " " << DDLL.at(n) << std::endl;
  20. //load MVAconfig
  21. MVA_variables vars(DDLL.at(n));
  22. rank.push_back(std::vector<int>());
  23. latex_name.push_back(std::vector<std::string>());
  24. value.push_back(std::vector<float>());
  25. //load results from .txt (This has to be saved manually from the MVA training output, before creating the LaTeX table)
  26. std::ifstream file;
  27. std::string line = "";
  28. std::string filename = path_to_data+"/"+BDTmethod+"results_Run"+std::to_string(Run.at(n))+DDLL.at(n)+".txt";
  29. file.open(filename);
  30. if (file.is_open()){
  31. std::cout << "[INFO]\t\tOpened the result file: " << filename << std::endl;
  32. std::cout << "[INFO]\t\tProceed with loading the results!" << std::endl;
  33. }
  34. else{
  35. std::cout << "[ERROR]\t\tCould not load the result file: " << filename << std::endl;
  36. std::cout << "[ERROR]\t\tMake sure, the result from the MVA training are copied (by hand) into the *.txt file" << std::endl;
  37. std::cout << "[ERROR]\t\tThe part that needs to be copied looks something like this:" << std::endl;
  38. std::cout << "[ERROR]\t\t" << std::endl;
  39. for(UInt_t i = 0; i < 8; i++)
  40. std::cout << "[ERROR]\t\t--- " << BDTmethod << " : " << i+1 << " : variable" << i+1 << " : value" << std::endl;
  41. return;
  42. }
  43. while(1){ //loop over lines until you find the end of the file
  44. getline(file, line);
  45. if(file.eof()) break;
  46. if(line.length() == 0)continue;
  47. size_t first_colon = line.find(":");
  48. if(first_colon == line.length())continue;
  49. size_t secon_colon = line.find(":", first_colon+1);
  50. if(secon_colon == line.length())continue;
  51. size_t third_colon = line.find(":", secon_colon+1);
  52. if(third_colon == line.length())continue;
  53. if(debug){
  54. std::cout << "Line: '" << line << "'\twith length=" << line.length() << std::endl;
  55. std::cout << "First ':' at pos=" << first_colon << "\tSecond ':' at pos=" << secon_colon << "\tThird ':' at pos=" << third_colon << std::endl;
  56. }
  57. //save the rank
  58. rank.at(n).push_back(atoi(line.substr(first_colon+1, secon_colon-first_colon-2).c_str()));
  59. std::string branch_name = line.substr(secon_colon+2, third_colon-secon_colon-2);
  60. while(replace(branch_name, " ", ""));
  61. while(replace(branch_name, "log_", ""));
  62. //convert and save the LaTeX name
  63. Int_t var = 0;
  64. while(var < vars.NumberOfVariables()){
  65. if(vars.AllVariables.at(var).ReaderName.find(branch_name.c_str()) < vars.AllVariables.at(var).ReaderName.length())
  66. break;
  67. var++;
  68. }
  69. if(var == vars.NumberOfVariables()){
  70. std::cout << "[ERROR]\t\tNo LaTeX name found for varialbe: '" << branch_name << "'" << std::endl;
  71. return;
  72. }
  73. latex_name.at(n).push_back(vars.AllVariables.at(var).LaTeXName);
  74. while(replace(latex_name.at(n).back(), "K_{s}^{0}", "\\KS "));
  75. while(replace(latex_name.at(n).back(), "K_{s}", "\\KS "));
  76. while(replace(latex_name.at(n).back(), "B^{+}", "\\Bu "));
  77. while(replace(latex_name.at(n).back(), "#chi^{2}", "\\chisq "));
  78. while(replace(latex_name.at(n).back(), "#mu^{+}", "\\mup "));
  79. while(replace(latex_name.at(n).back(), "#mu^{-}", "\\mun "));
  80. while(replace(latex_name.at(n).back(), "K^{*+}", "\\Kstarp "));
  81. while(replace(latex_name.at(n).back(), "#pi^{+}", "\\pip "));
  82. while(replace(latex_name.at(n).back(), "p_{T}", "\\pt "));
  83. while(replace(latex_name.at(n).back(), "#eta", "$\\eta$"));
  84. while(replace(latex_name.at(n).back(), "#", "\\"));
  85. // while(replace(latex_name.at(n).back(), "", ""));
  86. //save the MVA significance value (in %)
  87. value.at(n).push_back(atof(line.substr(third_colon+2).c_str())*100.);
  88. }
  89. assert(rank.at(n).size() == latex_name.at(n).size());
  90. assert(rank.at(n).size() == value.at(n).size());
  91. if(debug){
  92. for(UInt_t i = 0; i < rank.at(n).size(); i++){
  93. std::cout << "#" << rank.at(n).at(i) << ": " << latex_name.at(n).at(i) << " = " << Form("%.2f", value.at(n).at(i)) << std::endl;
  94. }
  95. }
  96. file.close();
  97. }
  98. //print LaTeX table:
  99. std::cout << std::endl << std::endl << std::endl;
  100. std::cout << "\\begin{center}\\begin{tabular}{";
  101. for(UInt_t n = 0; n < NN; n++)
  102. std::cout << "lr";
  103. std::cout << "} \\hline" << std::endl;
  104. for(UInt_t n = 0; n < NN; n++){
  105. if(n != 0)
  106. std::cout << "\t&";
  107. std::cout << "Run " << Run.at(n);
  108. if(DDLL.at(n) != "")
  109. std::cout << " \\" << DDLL.at(n);
  110. std::cout << "\t&[\\\%]";
  111. }
  112. std::cout << "\\\\" << std::endl;
  113. std::cout << "\\hline" << std::endl;
  114. for(UInt_t v = 0; v < rank.at(0).size(); v++){
  115. for(UInt_t n = 0; n < NN; n++){
  116. if(n != 0)
  117. std::cout << "\t&";
  118. if(latex_name.at(n).size() > v)
  119. std::cout << latex_name.at(n).at(v) << "\t&" << Form("%.2f", value.at(n).at(v));
  120. else
  121. std::cout << "\t &";
  122. }
  123. std::cout << "\\\\" << std::endl;
  124. }
  125. std::cout << "\\hline" << std::endl;
  126. std::cout << "\\end{tabular}\\end{center}" << std::endl;
  127. std::cout << std::endl << std::endl << std::endl;
  128. return;
  129. }
  130. void GetAllMVATables(){
  131. std::string method = std::string(TMVAmethod);
  132. if(Kst2Kspiplus){
  133. GetMVASignificance({1, 1}, {"DD", "LL"}, method);
  134. GetMVASignificance({2, 2}, {"DD", "LL"}, method);
  135. }
  136. else{
  137. GetMVASignificance({1, 2}, {"",""}, method);
  138. }
  139. }