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.

431 lines
16 KiB

  1. //Renata Kopecna
  2. #include "GenLvlvsMC.hh"
  3. #include <TH1D.h>
  4. #include <TFile.h>
  5. #include <TLegend.h>
  6. #include <string>
  7. #include <TGraphAsymmErrors.h>
  8. #include <TGraphErrors.h>
  9. #include <TGraph.h>
  10. #include <design.hh>
  11. #include <paths.hh>
  12. #include <parse.hh>
  13. #include <iostream>
  14. #include <vector>
  15. #include <helpers.hh>
  16. #include "ScriptHelpers.hh"
  17. std::string plotPath(std::string observable, std::string tag){
  18. return PLOTS_PATH+"MCfit/"+ "GenLvl_vs_MC_" + observable + tag +".eps";
  19. }
  20. std::vector<std::vector<double>> DavidsGenLvl = {
  21. { 0.5120, 0.1800, 0.1370, 0.1930, 0.2750, 0.4170, 0.4840, 0.5030}, //S1s
  22. { 0.2450, 0.6996, 0.7993, 0.7384, 0.6414, 0.4201, 0.3513, 0.3344}, //S1c
  23. { 0.1448, 0.0749, 0.0514, 0.0662, 0.0900, 0.1449, 0.1620, 0.1662}, //S2s
  24. {-0.1953,-0.6639,-0.7774,-0.7254,-0.6334,-0.4171,-0.3497,-0.3332}, //S2c
  25. { 0.0000, 0.0020,-0.0080,-0.0120,-0.0240,-0.0620,-0.1520,-0.2330}, //S3
  26. { 0.0870, 0.0040,-0.1080,-0.1950,-0.2510,-0.2770,-0.2900,-0.3040}, //S4
  27. { 0.2440, 0.0950,-0.1590,-0.3050,-0.4140,-0.4210,-0.3400,-0.2490}, //S5
  28. {-0.1270,-0.2070,-0.0860, 0.0950, 0.3020, 0.5140, 0.5570, 0.4700}, //S6s
  29. { 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000}, //S6c
  30. {-0.0060,-0.0100,-0.0030, 0.0020, 0.0030,-0.0020,-0.0020, 0.0050}, //S7
  31. { 0.0010,-0.0030,-0.0040,-0.0030,-0.0010, 0.0030,-0.0010, 0.0030}, //S8
  32. {-0.0020, 0.0000, 0.0020, 0.0040,-0.0020,-0.0010,-0.0010, 0.0010} //S9
  33. }; //I would kill for a dictionary in C++ now
  34. double getDavidsValue(std::string observable, int bin){ //Not the most efficienc implementation, but oh well, hard to live without numpy
  35. if (observable == "Fl") return (1-4.0/3.0*DavidsGenLvl[0][bin]);
  36. if (observable == "S1s") return DavidsGenLvl[0][bin];
  37. if (observable == "S1c") return DavidsGenLvl[1][bin];
  38. if (observable == "S2s") return DavidsGenLvl[2][bin];
  39. if (observable == "S2c") return DavidsGenLvl[3][bin];
  40. if (observable == "S3") return DavidsGenLvl[4][bin];
  41. if (observable == "S4") return DavidsGenLvl[5][bin];
  42. if (observable == "S5") return DavidsGenLvl[6][bin];
  43. if (observable == "S6s") return DavidsGenLvl[7][bin];
  44. if (observable == "Afb") return 3.0/4.0*DavidsGenLvl[7][bin];
  45. if (observable == "S6c") return DavidsGenLvl[8][bin];
  46. if (observable == "S7") return DavidsGenLvl[9][bin];
  47. if (observable == "S8") return DavidsGenLvl[10][bin];
  48. if (observable == "S9") return DavidsGenLvl[11][bin];
  49. spdlog::critical("I don't know observable "+observable);
  50. spdlog::critical("Throwing an error now.");
  51. assert(0);
  52. return 0;
  53. }
  54. TGraphAsymmErrors* DavidsGenLvlGraph(std::string observable){
  55. int nBins = DavidsGenLvl[0].size(); //In case the vector above changes, this should be secure
  56. std::vector<double> q2min = get_TheQ2binsmin(nBins,false);
  57. std::vector<double> q2max = get_TheQ2binsmax(nBins,false);
  58. //Initilialize the TGraph
  59. //Initialize it on purpose with 0 points; in case something goes wrong with nBins, this makes sure there are no segfaults
  60. TGraphAsymmErrors* graph = new TGraphAsymmErrors(0);
  61. //Loop over bins to fill TGraph from DavidsGenLvl
  62. for (int b = 0; b < nBins; b++){
  63. graph->SetPoint(graph->GetN(),bin_center_q2(q2min,q2max,b), getDavidsValue(observable,b));
  64. graph->SetPointError(graph->GetN()-1,bin_halfWidth_q2(q2min,q2max,b), bin_halfWidth_q2(q2min,q2max,b), 0, 0);
  65. }
  66. return graph;
  67. }
  68. int compareGenLvlMC(std::vector<TGraphAsymmErrors*> graphs,
  69. std::vector<std::string> legends,
  70. std::vector<int> color,
  71. std::vector<int> markerStyle,
  72. std::string observable, std::string plotPath,
  73. std::vector<int> plotDiff){ //What two plots should be considered for plotting the "pulls"? Marked with 1 and 2, plotting 1-2
  74. int idx_1 = find(plotDiff.begin(), plotDiff.end(), 1)-plotDiff.begin();
  75. int idx_2 = find(plotDiff.begin(), plotDiff.end(), 2)-plotDiff.begin();
  76. bool plotD = (idx_1 != int(graphs.size()) && idx_2 != int(graphs.size()));
  77. spdlog::debug("plot diff? " + boolToString(plotD));
  78. spdlog::debug("Idx_1: {0:d}\tIdx_2: {1:d}", idx_1, idx_2);
  79. //Create a canvas
  80. TCanvas *c_compare = new TCanvas("c_compare", "c_compare", 1600, 1200);
  81. const double pullHeight = 0.27;
  82. const double pullFrameRange = 3.5;
  83. TPad *pad1 = new TPad("pad1", "plot",0.0,pullHeight,1.0,1.0,0);
  84. TPad *pad2 = new TPad("pad2", "pull",0.0,0.0,1.0,pullHeight,0);
  85. if(plotD){
  86. pad1->Draw();
  87. pad2->Draw();
  88. pad1->SetBorderSize (0);
  89. pad1->SetMargin(0.125,0.05,1e-6,1.25/(1.0 - pullHeight));
  90. pad1->SetTickx();
  91. pad1->SetTicky();
  92. pad1->cd();
  93. }
  94. else{
  95. c_compare->cd();
  96. c_compare->SetMargin(0.125,0.05,0.1,0.1);
  97. c_compare->SetTickx();
  98. c_compare->SetTicky();
  99. }
  100. //Create an empty hist for the axes
  101. TH1D* haxes = emptyHist(observable);
  102. haxes->Draw("AXIS");
  103. //Draw boxes for resonances
  104. drawResonances(plotD ? pad1 : c_compare, obsv_range(observable)[0], obsv_range(observable)[1]);
  105. haxes->SetFillStyle(0);
  106. haxes->Draw("AXIS SAME");
  107. TLegend* leg = new TLegend(0.62,0.70,0.94,0.94);
  108. leg->SetBorderSize(0);
  109. leg->SetTextFont(132);
  110. leg->SetFillColor(0);
  111. for_indexed(auto g: graphs){
  112. designTGraph(g, markerStyle[i], color[i]);
  113. if (legends[i]!="") leg->AddEntry(g, legends[i].c_str());
  114. g->Draw("P");
  115. }
  116. leg->Draw("SAME");
  117. TH1D *diff = nullptr;
  118. if (plotD){ //If there are no tags 1 and 2, don't do anything
  119. pad2->Clear();
  120. pad2->SetMargin(0.125,0.05,0.1/ pullHeight, 1e-6);
  121. pad2->SetTickx();
  122. pad2->cd();
  123. std::string y_title = "Diff [#sigma]";//legends[idx_1] + "-" + legends[idx_2];
  124. diff = hist_graphDiff(graphs[idx_1],graphs[idx_2],pullFrameRange, y_title);
  125. double max = haxes->GetBinLowEdge(haxes->GetNbinsX()+1);
  126. double min = haxes->GetBinLowEdge(1);
  127. //I hate that I have to workaround ranges of an efin histogram
  128. TLine *sigmaUp_3 = threeSigmaLine(min,max, true);
  129. TLine *sigmaLow_3 = threeSigmaLine(min,max, false);
  130. TLine *sigmaUp_1 = oneSigmaLine(min,max, true);
  131. TLine *sigmaLow_1 = oneSigmaLine(min,max, false);
  132. design_pull(diff, 9011, 9011, pullHeight+0.1, pullFrameRange);
  133. diff->GetYaxis()->SetNdivisions(110);
  134. diff->Draw("");
  135. sigmaUp_3->Draw("same");
  136. sigmaLow_3->Draw("same");
  137. sigmaUp_1->Draw("same");
  138. sigmaLow_1->Draw("same");
  139. }
  140. spdlog::info("Saving into "+ plotPath);
  141. c_compare->Print(plotPath.c_str(), "eps");
  142. if (spdlog_debug()){ //When debugging save also the root file
  143. replace(plotPath,".eps",".root");
  144. c_compare->Print(plotPath.c_str(), "root");
  145. }
  146. delete c_compare;
  147. delete haxes;
  148. delete diff;
  149. return 0;
  150. }
  151. int plotComparison_Toy_GenVsMC(std::string observable, bool isRef){
  152. bool onlySig = false;
  153. bool onlyBkg = false;
  154. bool onlyAngles = false;
  155. bool onlyMass = false;
  156. bool bkgFromLowMass = false;
  157. bool bkgFromHighMass = true;
  158. basic_params params_MC = basic_params();
  159. params_MC.Run = 12;
  160. params_MC.nBins = isRef ? 1 : 4;
  161. params_MC.reference = isRef;
  162. basic_params params_Toys = basic_params();
  163. params_Toys.Run = 12;
  164. params_Toys.nBins = isRef ? 1 : 4;
  165. params_Toys.reference = isRef;
  166. std::vector<std::string> legends;
  167. std::vector<int> color;
  168. std::vector<int> markerStyle;
  169. std::vector<TGraphAsymmErrors*> graphs;
  170. std::vector<int> difference; //makes a plot with difference of grpahs with a tag of 1-2
  171. //I shoudl write a class for this, but too much effort
  172. //Add init parameters
  173. std::string path = final_result_name_MC(params_MC, params_Toys.nBins, isRef, false, true, false, false);
  174. graphs.push_back(get_TGraphFromFile(path,observable,isRef));
  175. legends.push_back("MC"); //Don't plot legend as it is same as sigMC
  176. color.push_back(9012);
  177. markerStyle.push_back(27);
  178. difference.push_back(1);
  179. //Fill the toy init parameters
  180. path = init_params_name_toys(1,isRef,params_Toys.nBins, true, params_Toys, params_Toys.Run, onlyAngles, onlyMass, onlySig, onlyBkg, bkgFromLowMass, bkgFromHighMass);
  181. graphs.push_back(get_TGraphFromFile(path,observable,isRef));
  182. legends.push_back("Toy");
  183. color.push_back(9007);
  184. markerStyle.push_back(34);
  185. difference.push_back(2);
  186. std::string plotPath = PLOTS_PATH+"Toys/"+ "MC_vs_Init_" + observable +".eps";
  187. return compareGenLvlMC(graphs,legends,color,markerStyle,observable, plotPath, difference);
  188. }
  189. //This one compares the data-like fit to the init toy values
  190. int plotComparison_Toy_InitVsAcutalFit(std::string observable, bool isRef){
  191. bool onlySig = false;
  192. bool onlyBkg = false;
  193. bool onlyAngles = false;
  194. bool onlyMass = false;
  195. bool bkgFromLowMass = false;
  196. bool bkgFromHighMass = false;
  197. double fractionOfStats = 1.0;
  198. basic_params params_Init= basic_params();
  199. params_Init.Run = 12;
  200. params_Init.nBins = isRef ? 1 : 4;
  201. params_Init.reference = isRef;
  202. params_Init.jobID = -1;
  203. basic_params params_Fit= basic_params();
  204. params_Fit.Run = 12;
  205. params_Fit.nBins = isRef ? 1 : 4;
  206. params_Fit.reference = isRef;
  207. std::vector<std::string> legends;
  208. std::vector<int> color;
  209. std::vector<int> markerStyle;
  210. std::vector<TGraphAsymmErrors*> graphs;
  211. std::vector<int> difference; //makes a plot with difference of grpahs with a tag of 1-2
  212. //I shoudl write a class for this, but too much effort
  213. //Add init parameters
  214. std::string paramFile = init_params_name_toys(-1,params_Init.reference, params_Init.nBins, true, params_Init, params_Init.Run, onlyAngles, onlyMass, onlySig, onlyBkg, bkgFromLowMass, bkgFromHighMass);
  215. graphs.push_back(get_TGraphFromFile(paramFile,observable,isRef));
  216. legends.push_back("Init"); //Don't plot legend as it is same as sigMC
  217. color.push_back(9012);
  218. markerStyle.push_back(27);
  219. difference.push_back(1);
  220. //Add fitted parameters
  221. std::string fitFile = final_result_name(isRef, false, params_Fit,
  222. true, params_Fit.nBins, params_Fit.Run,
  223. true, fractionOfStats,
  224. false, -1);
  225. graphs.push_back(get_TGraphFromFile(fitFile,observable,isRef));
  226. legends.push_back("Fit");
  227. color.push_back(9007);
  228. markerStyle.push_back(34);
  229. difference.push_back(2);
  230. std::string plotPath = PLOTS_PATH+"Toys/"+ "FinalToy_Init_vs_Fit_" + observable + std::string(isRef ? "_Ref" : "" )+".eps";
  231. return compareGenLvlMC(graphs,legends,color,markerStyle,observable, plotPath, difference);
  232. }
  233. int plotComparison_Toy_GenVsFit(std::string observable, bool isRef){
  234. bool onlySig = false;
  235. bool onlyBkg = false;
  236. bool onlyAngles = false;
  237. bool onlyMass = false;
  238. bool bkgFromLowMass = false;
  239. bool bkgFromHighMass = true;
  240. basic_params params_Init= basic_params();
  241. params_Init.Run = 12;
  242. params_Init.nBins = isRef ? 1 : 4;
  243. params_Init.reference = isRef;
  244. basic_params params_Fit= basic_params();
  245. params_Fit.Run = 12;
  246. params_Fit.nBins = isRef ? 1 : 4;
  247. params_Fit.reference = isRef;
  248. std::vector<std::string> legends;
  249. std::vector<int> color;
  250. std::vector<int> markerStyle;
  251. std::vector<TGraphAsymmErrors*> graphs;
  252. std::vector<int> difference; //makes a plot with difference of grpahs with a tag of 1-2
  253. //I shoudl write a class for this, but too much effort
  254. //Add init parameters
  255. std::string path = init_params_name_toys(1,isRef,params_Init.nBins, true, params_Init, params_Init.Run, onlyAngles, onlyMass, onlySig, onlyBkg, bkgFromLowMass, bkgFromHighMass);
  256. graphs.push_back(get_TGraphFromFile(path,observable,isRef));
  257. legends.push_back("Init"); //Don't plot legend as it is same as sigMC
  258. color.push_back(9012);
  259. markerStyle.push_back(27);
  260. difference.push_back(1);
  261. //Add fitted parameters
  262. path = final_result_name_toys(1,isRef,params_Fit.nBins, true, params_Fit, params_Fit.Run, onlyAngles, onlyMass, onlySig, onlyBkg, bkgFromLowMass, bkgFromHighMass);
  263. graphs.push_back(get_TGraphFromFile(path,observable,isRef));
  264. legends.push_back("Fit");
  265. color.push_back(9007);
  266. markerStyle.push_back(34);
  267. difference.push_back(2);
  268. std::string plotPath = PLOTS_PATH+"Toys/"+ "Init_vs_Fit_" + observable + std::string(isRef ? "_Ref" : "" )+".eps";
  269. return compareGenLvlMC(graphs,legends,color,markerStyle,observable, plotPath, difference);
  270. }
  271. int plotComparisonMCFolding(std::string observable){
  272. basic_params params_MC= basic_params();
  273. params_MC.Run = 12;
  274. params_MC.nBins = 4;
  275. params_MC.reference = false;
  276. std::vector<std::string> legends;
  277. std::vector<int> color;
  278. std::vector<int> markerStyle;
  279. std::vector<TGraphAsymmErrors*> graphs;
  280. std::vector<int> difference; //makes a plot with difference of grpahs with a tag of 1-2
  281. for (int f = -1; f <5; f++){
  282. params_MC.folding = f;
  283. if (f == -1) difference.push_back(1);
  284. if (plotObsv(f,observable)){
  285. graphs.push_back(get_TGraphFromFile(final_result_name_MC(params_MC,params_MC.nBins, false, false, true, false, false),observable,false));
  286. legends.push_back("Fld " + std::to_string(f));
  287. color.push_back(9009+f);
  288. markerStyle.push_back(25+f);
  289. difference.push_back(2);
  290. }
  291. }
  292. std::string tag = "";
  293. std::string plotPath = PLOTS_PATH+"MCfit/"+ "Folding_" + observable + tag +".eps";
  294. assert(!compareGenLvlMC(graphs,legends,color,markerStyle,observable, plotPath, difference));
  295. return 0;
  296. }
  297. int plotComparison(std::string observable){
  298. basic_params params_genLvl = basic_params();
  299. params_genLvl.Run = 2;
  300. params_genLvl.year = 2017;
  301. params_genLvl.nBins = 8;
  302. bool PHSP = false;
  303. std::vector<std::string> legends;
  304. std::vector<int> color;
  305. std::vector<int> markerStyle;
  306. std::vector<TGraphAsymmErrors*> graphs;
  307. std::vector<int> difference; //makes a plot with difference of grpahs with a tag of 1-2
  308. //I shoudl write a class for this, but too much effort
  309. //First make a comparison between my and David's genLvl
  310. //---------------------------------------------------//
  311. //Add genLvl
  312. graphs.push_back(get_TGraphFromFile(final_result_name_genLvlMC(params_genLvl, 8, PHSP, true, false),observable,false));
  313. legends.push_back("GenLvl MC"); //Don't plot legend as it is same as sigMC
  314. color.push_back(9012);
  315. markerStyle.push_back(27);
  316. difference.push_back(1);
  317. //Fill David's results first
  318. graphs.push_back(DavidsGenLvlGraph(observable));
  319. legends.push_back("David's GenLvl results");
  320. color.push_back(9007);
  321. markerStyle.push_back(34);
  322. difference.push_back(2);
  323. std::string tag = "_MyVsDavids";
  324. std::string plotPath = PLOTS_PATH+"MCfit/"+ "GenLvl_vs_MC_" + observable + tag +".eps";
  325. assert(!compareGenLvlMC(graphs,legends,color,markerStyle,observable, plotPath, difference));
  326. //Delete David's graphs
  327. graphs.clear();
  328. legends.clear();
  329. color.clear();
  330. markerStyle.clear();
  331. difference.clear();
  332. //---------------------------------------------------//
  333. //Compare my fit of genLvl mc and processed MC
  334. //---------------------------------------------------//
  335. //Add MC as it should be done
  336. basic_params params_MC= basic_params();
  337. params_MC.Run = 12;
  338. params_MC.nBins = 4;
  339. params_MC.reference = false;
  340. graphs.push_back(get_TGraphFromFile(final_result_name_MC(params_MC, 4, false, PHSP, true, false, false),observable,false));
  341. legends.push_back("LHCb simulation");
  342. color.push_back(9016);
  343. markerStyle.push_back(24);
  344. difference.push_back(1);
  345. //Add genLvl MC
  346. params_genLvl.nBins = 4;
  347. graphs.push_back(get_TGraphFromFile(final_result_name_genLvlMC(params_genLvl, 4, PHSP, true, false),observable,false));
  348. legends.push_back("Generator level");
  349. color.push_back(9010);
  350. markerStyle.push_back(25);
  351. difference.push_back(2);
  352. plotPath = PLOTS_PATH+"MCfit/"+ "GenLvl_vs_MC_" + observable + ".eps";
  353. return compareGenLvlMC(graphs,legends,color,markerStyle,observable, plotPath, difference);
  354. //---------------------------------------------------//
  355. }