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.

215 lines
8.1 KiB

  1. //Renata Kopecna
  2. #include "ScriptHelpers.hh"
  3. #include <paths.hh>
  4. #include <TFile.h>
  5. #include <TTree.h>
  6. #include <helpers.hh>
  7. #include <design.hh>
  8. #include <constants.hh>
  9. #include <spdlog.h>
  10. //Takes two valErr and returns the difference in sigmas
  11. double sigmaAway(valErr a, valErr b){
  12. double diff = a.val - b.val;
  13. double effErr = sqrt(pow(a.err,2)+pow(b.err,2));
  14. return effErr == 0 ? 0 : diff/effErr;
  15. }
  16. //Returns true if the observable is measured in certain folding
  17. bool plotObsv(int folding, std::string obs){
  18. if (obs == "Fl" || obs == "S3") return true; //FL and S3 always there
  19. switch(folding){
  20. case -1: return true;
  21. case 0:
  22. if (obs == "Afb") return true;
  23. else if (obs == "S9") return true;
  24. else return false;
  25. case 1:
  26. if (obs == "S4") return true;
  27. else return false;
  28. case 2:
  29. if (obs == "S5") return true;
  30. else return false;
  31. case 3:
  32. if (obs == "S7") return true;
  33. else return false;
  34. case 4:
  35. if (obs == "S8") return true;
  36. else return false;
  37. }
  38. return false;
  39. }
  40. std::vector<double> obsv_range(std::string parName){
  41. if (parName == "S1s") return {+0.0, +1.0};
  42. if (parName == "Fl") return {+0.0, +1.0};
  43. if (parName == "S3") return {-0.5, +0.3};
  44. if (parName == "S4") return {-0.5, +0.3};
  45. if (parName == "S5") return {-0.5, +0.3};
  46. if (parName == "Afb") return {-0.2, +1.0};
  47. if (parName == "S7") return {-0.25, +0.25};
  48. if (parName == "S8") return {-0.25, +0.30};
  49. if (parName == "S9") return {-0.25, +0.25};
  50. //mass fit
  51. if (parName == "m_b") return {PDGMASS_B-10,PDGMASS_B+10};
  52. if (parName == "m_sigma_1") return {20.0, 40.0};
  53. if (parName == "alpha_1") return {0.5, 2.5};
  54. if (parName == "alpha_2") return {0.5, 1.5};
  55. if (parName == "n_1") return {0.1, 15.0};
  56. if (parName == "n_2") return {5.0, 15.0};
  57. if (parName == "m_lambda") return {-0.1, -0.00001};
  58. if (parName == "f_sig") return {0.0, 1.0};
  59. //angular bkg
  60. if (parName == "cbkgctl0") return {-10.0, 10.0};
  61. if (parName == "cbkgctl1") return {-10.0, 10.0};
  62. if (parName == "cbkgctl2") return {-10.0, 10.0};
  63. if (parName == "cbkgctl3") return {-10.0, 10.0};
  64. if (parName == "cbkgctl4") return {-10.0, 10.0};
  65. if (parName == "cbkgctk0") return {-10.0, 10.0};
  66. if (parName == "cbkgctk1") return {-10.0, 10.0};
  67. if (parName == "cbkgctk2") return {-10.0, 10.0};
  68. if (parName == "cbkgctk3") return {-10.0, 10.0};
  69. if (parName == "cbkgctk4") return {-10.0, 10.0};
  70. if (parName == "cbkgctk5") return {-10.0, 10.0};
  71. if (parName == "cbkgctk6") return {-10.0, 10.0};
  72. if (parName == "cbkgphi0") return {-10.0, 10.0};
  73. if (parName == "cbkgphi1") return {-10.0, 10.0};
  74. if (parName == "cbkgphi2") return {-10.0, 10.0};
  75. if (parName == "cbkgphi3") return {-10.0, 10.0};
  76. if (parName == "cbkgphi4") return {-10.0, 10.0};
  77. if (parName == "cbkgmkpi0") return {-10.0, 10.0};
  78. if (parName == "cbkgmkpi1") return {-10.0, 10.0};
  79. if (parName == "cbkgmkpi2") return {-10.0, 10.0};
  80. if (parName == "cbkgmkpi3") return {-10.0, 10.0};
  81. if (parName == "cbkgmkpi4") return {-10.0, 10.0};
  82. spdlog::critical("Wrong parameter tree name! Setting range to default -1.0, 1.0");
  83. return {-1.0,1.0};
  84. }
  85. void designTGraph(TGraphAsymmErrors *g, int markerStyle, int color){
  86. g->SetLineColor(color);
  87. g->SetMarkerColor(color);
  88. g->SetLineWidth(2);
  89. g->SetMarkerStyle(markerStyle);
  90. g->SetMarkerSize(3);
  91. g->SetFillColor(0);
  92. g->SetFillStyle(0);
  93. }
  94. TH1D *emptyHist(std::string observable, double min, double max, int nBins){
  95. TH1D* haxes = new TH1D("haxes", std::string(";#it{q}^{2} ["+GeVc_2()+"];"+observable).c_str(), nBins, Q2_MIN_RANGE, Q2_MAX_RANGE_B0);
  96. haxes->SetMinimum(min);
  97. haxes->SetMaximum(max);
  98. haxes->SetTitleSize(0.06, "XY");
  99. haxes->SetLabelSize(0.05, "XY");
  100. return haxes;
  101. }
  102. TH1D *emptyHist(std::string observable){
  103. double min = obsv_range(observable)[0]; //Set the range for each parameter
  104. double max = obsv_range(observable)[1]; //Needs to run twice but whatever
  105. return (emptyHist(observable,min,max,100));
  106. }
  107. TGraphAsymmErrors* get_TGraphFromFile(std::string fileName, std::string observable, bool isRef){
  108. //Open file
  109. spdlog::info("Opening " + fileName);
  110. TFile* file = new TFile(fileName.c_str(), "READ");
  111. if (!file->GetListOfKeys()->Contains(observable.c_str())){
  112. spdlog::critical("Wrong tree name " + observable + "! Abort.");
  113. assert(0);
  114. }
  115. TTree* tree = (TTree*)file->Get(observable.c_str());
  116. tree->SetBranchStatus("*",1); //Activate all branches
  117. //Read the q2 bins
  118. int totBins = DEFAULT_TREE_VAL;
  119. tree->SetBranchAddress("totBins", &totBins);
  120. tree->GetEntry(0);
  121. std::vector<double> q2min = get_TheQ2binsmin(totBins,isRef);
  122. std::vector<double> q2max = get_TheQ2binsmax(totBins,isRef);
  123. //Initilialize the TGraph
  124. //Initialize it on purpose with 0 points; in case something goes wrong with totBins, this makes sure there are no segfaults
  125. TGraphAsymmErrors* graph = new TGraphAsymmErrors(0);
  126. //Loop over nBins that are saved in the tree
  127. for (int b = 0; b < totBins; b++){
  128. double value = DEFAULT_TREE_VAL;
  129. double error = DEFAULT_TREE_ERR;
  130. double errorup = DEFAULT_TREE_ERR;
  131. double errordown= DEFAULT_TREE_ERR;
  132. int migrad = DEFAULT_TREE_INT;
  133. int cov = DEFAULT_TREE_INT;
  134. tree->SetBranchAddress("value", &value);
  135. tree->SetBranchAddress("error", &error);
  136. tree->SetBranchAddress("error_up", &errorup);
  137. tree->SetBranchAddress("error_down", &errordown);
  138. tree->SetBranchAddress("migrad", &migrad);
  139. tree->SetBranchAddress("status_cov", &cov);
  140. tree->GetEntry(b);
  141. //if opts.hesse is non-active, use error for both error_up and error_down
  142. if(errordown == DEFAULT_TREE_ERR) errordown = error;
  143. if(errorup == DEFAULT_TREE_ERR) errorup = error;
  144. //Set point in TGraph
  145. spdlog::debug("Setting point in bin {0:d} in Tgraph {1:s}", b, graph->GetName());
  146. spdlog::debug("bin center {0:f}, value {1:f}", bin_center_q2(q2min,q2max,b), value);
  147. spdlog::debug("bin width {0:f}, err up {1:f}, err down {2:f}",
  148. bin_halfWidth_q2(q2min,q2max,b), fabs(errordown), fabs(errorup));
  149. graph->SetPoint(graph->GetN(),bin_center_q2(q2min,q2max,b), value);
  150. graph->SetPointError(graph->GetN()-1,bin_halfWidth_q2(q2min,q2max,b), bin_halfWidth_q2(q2min,q2max,b), fabs(errordown), fabs(errorup));
  151. } //loop over bins
  152. spdlog::debug("Graph filled.");
  153. file->Close();
  154. return graph;
  155. }
  156. TH1D* hist_graphDiff(TGraphAsymmErrors* graph_a, TGraphAsymmErrors* graph_b,
  157. double range, std::string title){
  158. //Check they have the same number of points
  159. int n_points = graph_a->GetN();
  160. if (n_points!= graph_b->GetN()){
  161. spdlog::error("The input graphs have different number of points!");
  162. spdlog::error("Graph a: {0:d}\tGraph b: {1:d}", n_points, graph_b->GetN());
  163. assert(0);
  164. }
  165. //Technically one shoudl check matching x-axis values, but screw that
  166. TH1D* hist = emptyHist(title,-range,range,1000);
  167. //Make a histogram with the difference
  168. for (int p = 0; p<n_points; p++){
  169. double val = graph_a->GetY()[p] - graph_b->GetY()[p];
  170. double effErr = 0;
  171. if (val > 0) effErr = sqrt(pow(graph_a->GetErrorYlow(p),2) +pow(graph_b->GetErrorYhigh(p),2));
  172. else effErr = sqrt(pow(graph_a->GetErrorYhigh(p),2)+pow(graph_b->GetErrorYlow(p),2));
  173. double low_edge = hist->GetXaxis()->FindBin(graph_a->GetX()[p]-graph_a->GetErrorXlow(p));
  174. double high_edge = hist->GetXaxis()->FindBin(graph_a->GetX()[p]+graph_a->GetErrorXhigh(p));
  175. spdlog::debug("low_edge {0:d}", low_edge);
  176. spdlog::debug("high_edge {0:d}", high_edge);
  177. for (int b = low_edge+1; b<high_edge; b++){
  178. hist->SetBinContent(b,effErr == 0 ? 0 : val/effErr);
  179. }
  180. }
  181. return hist;
  182. }