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.

248 lines
9.0 KiB

  1. #include "../GlobalFunctions.hh"
  2. #include "../HeidelbergFitter/LHCbStyle.h"
  3. using namespace std;
  4. using namespace RooFit ;
  5. //define mass regions:
  6. const UInt_t N = 2;
  7. //const Double_t low[N] = {5170., 5330., 5500.};
  8. //const Double_t high[N] = {5230., 5500., 5700.};
  9. const Double_t low[N] = {5170., 5350.};
  10. const Double_t high[N] = {5210., 5700.};
  11. std::vector<double>values[3][N];
  12. std::vector<double>errors[3][N];
  13. std::string angles_latex[3] = {"cos(#Theta_{L})", "cos(#Theta_{K})", "#phi"};
  14. std::string angles_names[3] = {"ctl", "ctk", "phi"};
  15. Int_t BkgCheck(Int_t Run = 1, std::string DDLL = "DD") {
  16. if(Run != 1 && Run != 2 && Run != 12){
  17. std::cout << "[ERROR]\t\tInvalid Run number given: " << Run << ". Exit program!" << std::endl;
  18. return 0;
  19. }
  20. const bool ScanChebyMaxOrder = false;
  21. const bool IncludeChebyFit = false;
  22. const UInt_t MaxOrderChebyPol = 3;
  23. gStyle -> SetOptStat(0);
  24. LHCbStyle();
  25. gROOT->SetBatch(kTRUE);
  26. TH1::SetDefaultSumw2(kTRUE);
  27. //load tree from FCNC file
  28. TChain * tree = new TChain("Events");
  29. tree->Add(Form("%s/data/*Run%i%s_FCNC.root",path_to_data.c_str(),Run, KshortChannel && SplitDDandLL ? ("_"+DDLL).c_str() : ""));
  30. if(tree->GetEntries() == 0){
  31. std::cout << "No entries found in file!" << std::endl;
  32. return 0;
  33. }
  34. //assign values to angles and mass
  35. double angles[3], m;
  36. tree->SetBranchAddress("m" , &m);
  37. tree->SetBranchAddress("costhetal" , &angles[0]);
  38. tree->SetBranchAddress("costhetak" , &angles[1]);
  39. tree->SetBranchAddress("phi" , &angles[2]);
  40. std::vector<TH1D*> h[3];
  41. const UInt_t nBins = 10;
  42. //create histograms
  43. for(UInt_t a = 0; a < 3; a++){
  44. for(UInt_t n = 0; n < N; n++){
  45. values[a][n].clear();
  46. errors[a][n].clear();
  47. TH1D* hist = new TH1D((angles_names[a]+"_"+std::to_string(low[n])+"-"+std::to_string(high[n])+"_MeV").c_str(),
  48. Form("%.1f-%.1f MeV;%s;norm. Events", low[n], high[n], angles_latex[a].c_str()),
  49. nBins, a == 2 ? -TMath::Pi() : -1., a == 2 ? +TMath::Pi() : +1.);
  50. h[a].push_back(hist);
  51. }
  52. }
  53. //fill all histograms with events, according to mass bin
  54. for(UInt_t e = 0; e < tree->GetEntries(); e++){
  55. tree->GetEntry(e);
  56. for(UInt_t n = 0; n < N; n++){
  57. if(m > low[n] && m <= high[n]){
  58. for(UInt_t a = 0; a < 3; a++){
  59. h[a].at(n)->Fill(angles[a]);
  60. }
  61. continue;
  62. }
  63. }
  64. }
  65. //put event numbers into hist names
  66. for(UInt_t a = 0; a < 3; a++){
  67. for(UInt_t n = 0; n < N; n++){
  68. h[a].at(n)->SetTitle(Form("%s (%.0f Events)", h[a].at(n)->GetTitle(), h[a].at(n)->Integral()));
  69. }
  70. }
  71. //make .eps plots:
  72. TCanvas * c = new TCanvas();
  73. c->cd();
  74. for(UInt_t a = 0; a < 3; a++){
  75. std::vector<TF1*> ff;
  76. c->Clear();
  77. for(UInt_t n = 0; n < N; n++){
  78. h[a].at(n)->Scale(1./h[a].at(n)->Integral()*nBins);
  79. h[a].at(n)->GetYaxis()->SetRangeUser(0, 2.5);///nBins);
  80. h[a].at(n)->SetLineColor(n+1);
  81. h[a].at(n)->SetMarkerStyle(n+20);
  82. h[a].at(n)->SetMarkerColor(n+1);
  83. h[a].at(n)->SetFillStyle(n == 1 ? 3345 : (n == 2 ? 3354 : 1));
  84. h[a].at(n)->SetFillColor(n+1);
  85. h[a].at(n)->Draw(n == 0 ? "PE3" : "PE3SAME");
  86. //Fit Chebyshev polynomials to histograms:
  87. /*
  88. std::string fitformular = "[0]*cheb0";
  89. for(UInt_t ch = 1; ch <= MaxOrderChebyPol; ch++){
  90. // fitformular.append(TString::Format(" + [%d]*cheb%d", ch, ch));
  91. fitformular = TString::Format("cheb%d", ch, ch);
  92. }
  93. TF1 * f = new TF1(("f_"+angles_names[a]+"_"+std::to_string(n)).c_str(),fitformular.c_str(), a == 2 ? -TMath::Pi() : -1., a == 2 ? +TMath::Pi() : +1.);
  94. f->SetLineColor(n+1);
  95. for(UInt_t ch = 0; ch <= MaxOrderChebyPol; ch++){
  96. f->SetParameter(ch, 0.8);
  97. }
  98. h[a].at(n)->Fit(f, "R+");
  99. ff.push_back(f);
  100. */
  101. UInt_t cheb = 1;
  102. if(ScanChebyMaxOrder){
  103. while(cheb <= MaxOrderChebyPol){
  104. TF1 * f = new TF1(("f_"+angles_names[a]+"_"+std::to_string(n)).c_str(), TString::Format("cheb%d", cheb), a == 2 ? -TMath::Pi() : -1., a == 2 ? +TMath::Pi() : +1.);
  105. f->FixParameter(0, 1.);
  106. h[a].at(n)->Fit(f, "RQ");
  107. if(TMath::Abs(f->GetParameter(cheb)) < TMath::Abs(f->GetParError(cheb))){
  108. cheb--;
  109. break;
  110. }
  111. cheb++;
  112. }
  113. }
  114. else{
  115. cheb = MaxOrderChebyPol;
  116. }
  117. //fit Chebyshev with according max order:
  118. if(IncludeChebyFit){
  119. TF1 * f = new TF1(("f_"+angles_names[a]+"_"+std::to_string(n)).c_str(), TString::Format("cheb%d", cheb), a == 2 ? -TMath::Pi() : -1., a == 2 ? +TMath::Pi() : +1.);
  120. f->SetLineColor(n+1);
  121. f->FixParameter(0, 1.);
  122. h[a].at(n)->Fit(f, "RQ+");
  123. for(UInt_t i = 0; i < cheb; i++){
  124. values[a][n].push_back(f->GetParameter(i));
  125. errors[a][n].push_back(f->GetParError(i));
  126. }
  127. ff.push_back(f);
  128. h[a].at(n)->GetListOfFunctions()->Clear();
  129. h[a].at(n)->SetTitle(Form("%s (Cheby %d)", h[a].at(n)->GetTitle(), cheb));
  130. }
  131. }
  132. c->BuildLegend(0.25, 0.75, 0.75, 0.92);
  133. for(UInt_t i = 0; i < ff.size(); i++)
  134. ff.at(i)->Draw("SAME");
  135. c->SaveAs((angles_names[a]+"_bkg_Run"+std::to_string(Run)+(KshortChannel && SplitDDandLL ? "_"+DDLL : "")+".eps").c_str());
  136. }
  137. delete c;
  138. for(UInt_t a = 0; a < 3; a++){
  139. for(UInt_t n = 0; n < N; n++){
  140. delete h[a].at(n);
  141. }
  142. }
  143. return 1;
  144. }
  145. Int_t BackgroundCheck(){
  146. if(BkgCheck(1, "DD") == 0){
  147. return 0;
  148. }
  149. std::cout << "/=====================\\" << std::endl;
  150. std::cout << "| Results Run 1, DD: |" << std::endl;
  151. std::cout << "\\=====================/" << std::endl;
  152. for(UInt_t a = 0; a < 3; a++){
  153. std::cout << ">> " << angles_names[a] << " <<" << std::endl;
  154. for(UInt_t v = 0; v < values[a][0].size(); v++){
  155. double ave_value = 0.0, ave_error = 0.0;
  156. for(UInt_t n = 0; n < N; n++){
  157. assert(values[a][n].size() == values[a][0].size());
  158. ave_value += values[a][n].at(v) / N;
  159. ave_error += TMath::Power(errors[a][n].at(v), 2);
  160. }
  161. ave_error = TMath::Sqrt(ave_error)/N;
  162. std::cout << "cheb" << v << ":\t" << ave_value << " +/- " << ave_error << std::endl;
  163. }
  164. }
  165. if(BkgCheck(2, "DD") == 0){
  166. return 0;
  167. }
  168. std::cout << "/=====================\\" << std::endl;
  169. std::cout << "| Results Run 2, DD: |" << std::endl;
  170. std::cout << "\\=====================/" << std::endl;
  171. for(UInt_t a = 0; a < 3; a++){
  172. std::cout << ">> " << angles_names[a] << " <<" << std::endl;
  173. for(UInt_t v = 0; v < values[a][0].size(); v++){
  174. double ave_value = 0.0, ave_error = 0.0;
  175. for(UInt_t n = 0; n < N; n++){
  176. assert(values[a][n].size() == values[a][0].size());
  177. ave_value += values[a][n].at(v) / N;
  178. ave_error += TMath::Power(errors[a][n].at(v), 2);
  179. }
  180. ave_error = TMath::Sqrt(ave_error)/N;
  181. std::cout << "cheb" << v << ":\t" << ave_value << " +/- " << ave_error << std::endl;
  182. }
  183. }
  184. if(KshortChannel && SplitDDandLL){
  185. if(BkgCheck(1, "LL") == 0){
  186. return 0;
  187. }
  188. std::cout << "/=====================\\" << std::endl;
  189. std::cout << "| Results Run 1, LL: |" << std::endl;
  190. std::cout << "\\=====================/" << std::endl;
  191. for(UInt_t a = 0; a < 3; a++){
  192. std::cout << ">> " << angles_names[a] << " <<" << std::endl;
  193. for(UInt_t v = 0; v < values[a][0].size(); v++){
  194. double ave_value = 0.0, ave_error = 0.0;
  195. for(UInt_t n = 0; n < N; n++){
  196. assert(values[a][n].size() == values[a][0].size());
  197. ave_value += values[a][n].at(v) / N;
  198. ave_error += TMath::Power(errors[a][n].at(v), 2);
  199. }
  200. ave_error = TMath::Sqrt(ave_error)/N;
  201. std::cout << "cheb" << v << ":\t" << ave_value << " +/- " << ave_error << std::endl;
  202. }
  203. }
  204. if(BkgCheck(2, "LL") == 0){
  205. return 0;
  206. }
  207. std::cout << "/=====================\\" << std::endl;
  208. std::cout << "| Results Run 2, LL: |" << std::endl;
  209. std::cout << "\\=====================/" << std::endl;
  210. for(UInt_t a = 0; a < 3; a++){
  211. std::cout << ">> " << angles_names[a] << " <<" << std::endl;
  212. for(UInt_t v = 0; v < values[a][0].size(); v++){
  213. double ave_value = 0.0, ave_error = 0.0;
  214. for(UInt_t n = 0; n < N; n++){
  215. assert(values[a][n].size() == values[a][0].size());
  216. ave_value += values[a][n].at(v) / N;
  217. ave_error += TMath::Power(errors[a][n].at(v), 2);
  218. }
  219. ave_error = TMath::Sqrt(ave_error)/N;
  220. std::cout << "cheb" << v << ":\t" << ave_value << " +/- " << ave_error << std::endl;
  221. }
  222. }
  223. }
  224. return 1;
  225. }