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.

138 lines
6.1 KiB

  1. //Renata Kopecna
  2. #include <TFile.h>
  3. #include <TCanvas.h>
  4. #include <TChain.h>
  5. #include <TF1.h>
  6. #include <TH1D.h>
  7. #include "GetMeanError.hh"
  8. #include <design.hh>
  9. #include <helpers.hh>
  10. #include "ScriptHelpers.hh"
  11. std::vector<double> getSM(std::string observable){
  12. if (observable == "Fl") return {+0.248569008046490070, +0.2581971160208132000, +0.42526014659559220000, +0.49420669353506260000, +0.1850102996703149000}; //s1s
  13. else if (observable == "S3") return {+0.000732569649322501, -0.0324523859139632900, -0.08563864422457230000, -0.18934424485647136000, -0.0130310503598977030}; //s3
  14. else if (observable == "S4") return {-0.028317693174889150, -0.2425837027660650600, -0.28116530113868093000, -0.29668531019781386000, -0.1468982883895949300}; //s4
  15. else if (observable == "S5") return {+0.035479698896675250, -0.3745017565795041000, -0.40726931726860705000, -0.30161750053585110000, -0.1915219985323076700}; //s5
  16. else if (observable == "Afb")return {-0.122319885918514240, +0.2473816826915200600, +0.52432045165541470000, +0.52106439209368990000, +0.0147578966169414490}; //s6s
  17. else if (observable == "S7") return {-0.019468600975846337, -0.0105435770924197210, -0.00219285191192886900, -0.00119446595061885200, -0.0160492529928752330}; //s7
  18. else if (observable == "S8") return {-0.010192773160727949, -0.0043019891737210840, +0.00104987431866559550, +0.00027244645255727460, -0.0070279543261629670}; //s8
  19. else if (observable == "S9") return {-0.000756965302130655, -0.0006959911482550733, +0.00044741790607562027, +0.00026464193866571387, -0.0007199408885633002}; //s9
  20. else{
  21. spdlog::warn("Wrong observable, returning an empty vector");
  22. return {};
  23. }
  24. }
  25. std::vector<double> fixSM(std::string observable){
  26. std::vector<double> tmp = {};
  27. for (auto val : getSM(observable)){
  28. if (observable == "Fl") tmp.push_back(round((1-4.0*val/3.0)*100.0)/100.0);
  29. else if (observable=="Afb") tmp.push_back(round((3.0*val/4.0)*100.0)/100.0);
  30. else tmp.push_back(round(val*100.0)/100.0);
  31. }
  32. return tmp;
  33. }
  34. int loadAllFiles(std::string observable, basic_params params){
  35. //load chain with all results of bootstrapping
  36. TChain * ch = new TChain(observable.c_str());
  37. std::string files = final_result_name_toys(1111, params.reference, params.nBins, true, params, params.Run, false, false, false, false, false, true);
  38. replace(files, "1111", "*"); //integer replaced by a string *
  39. replace(files, "ToysFit/", "ToysFit/"+std::to_string(params.jobID)+"/");
  40. spdlog::debug("Loading files: " + files);
  41. ch->Add(files.c_str());
  42. int nEntries = ch->GetEntries();
  43. spdlog::debug("Loaded {0:d} entries", nEntries);
  44. if (nEntries == 0){
  45. spdlog::error("No files found!");
  46. return 404;
  47. }
  48. //link variables to branches
  49. double value = DEFAULT_TREE_VAL;
  50. double error = DEFAULT_TREE_ERR;
  51. double errorup = DEFAULT_TREE_ERR;
  52. double errordown = DEFAULT_TREE_ERR;
  53. int migrad = DEFAULT_TREE_INT;
  54. int cov = DEFAULT_TREE_INT;
  55. int bin = DEFAULT_TREE_INT;
  56. int pdf = DEFAULT_TREE_INT;
  57. ch->SetBranchStatus("*",1); //TODO optimize
  58. ch->SetBranchAddress("value", &value);
  59. ch->SetBranchAddress("error", &error);
  60. ch->SetBranchAddress("error_up", &errorup);
  61. ch->SetBranchAddress("error_down", &errordown);
  62. ch->SetBranchAddress("migrad", &migrad);
  63. ch->SetBranchAddress("status_cov", &cov);
  64. ch->SetBranchAddress("bin", &bin);
  65. ch->SetBranchAddress("pdf", &pdf);
  66. const int nBins = params.nBins;
  67. std::vector<double> errors[nBins]; //Don't fill a histogram just yet, just put the values in a vector first
  68. //Loop over the entries and fill the vector
  69. for (int iter = 0; iter < nEntries; iter++){
  70. ch->GetEntry(iter);
  71. //require converged migrad
  72. if (migrad!=0) continue;
  73. //require fitresult = 300 or 100 (or 200)
  74. if(!(cov == 1 || cov == 3 || cov == 2)) continue;
  75. if (pdf == 1) continue; //Just take one pdf, as the values are shared
  76. spdlog::trace("Parameter value at entry {0:d}: {1:f}", iter, value);
  77. spdlog::trace("Parameter error at entry {0:d}: {1:f}", iter, error);
  78. errors[bin].push_back(error);
  79. }
  80. //Debug print in case
  81. for (int b = 0; b < nBins; b++){
  82. spdlog::debug("Got {0:d} entries for bin {1:d}", errors[b].size(),b);
  83. }
  84. //Now init a histogram for each bin and fill it
  85. std::vector<double> means;
  86. for (int b = 0; b < nBins; b++){
  87. //Get the max and the min of the errors
  88. double max = *max_element(errors[b].begin(), errors[b].end());
  89. double min = *min_element(errors[b].begin(), errors[b].end());
  90. if (min == max) continue; //If errors are all the same, it was fixed, so don't plot
  91. //Easier than checking folding
  92. if (max>1.0) max = 0.5;
  93. if (min<0.01) min = 0.01;
  94. //Create the TH1D for the errors
  95. TH1D *h_errors = new TH1D(observable.c_str(),
  96. (observable+" in q^{2} bin #"+std::to_string(b)
  97. +";"+observable+";Entries").c_str(),
  98. errors[b].size()/10, min, max);
  99. //Fill the TH1D from the read vector
  100. for (auto err: errors[b]) h_errors->Fill(err);
  101. //Fit the distribution with a gaussia
  102. TF1 *fit_func = new TF1("fit_func","gaus",min,max);
  103. fit_func->SetParameters(h_errors->GetMaximum(), h_errors->GetMean(), h_errors->GetRMS() );
  104. h_errors->Fit("fit_func",spdlog_debug() ? "R" : "RQ");
  105. //Plot and save it
  106. plotAndSave(h_errors,observable,"./"+observable+"_"+std::to_string(params.jobID)+"_"+std::to_string(b),"eps");
  107. //Save the mean to a vector so you can print it later
  108. means.push_back(fit_func->GetParameter("Mean") );
  109. h_errors->Clear();
  110. }
  111. if (means.size()>0){
  112. std::vector<double>valSM = fixSM(observable);
  113. std::cout << "$" << observable << "$\t";
  114. for_indexed (auto val: means) std::cout << " & $" << valSM[i] << " \\pm " << val << "$";
  115. std::cout << "\\\\" << std::endl;
  116. }
  117. return 0;
  118. }