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.

1276 lines
43 KiB

  1. //Helper function for making pretty plots
  2. //Renata Kopecna
  3. #include "Design.hpp"
  4. using namespace std;
  5. void design_markers(TH1F *histogram, string xaxis_name, string yaxis_name, Color_t color){
  6. gStyle->SetOptStat(0);
  7. histogram->SetMarkerStyle(8);
  8. histogram->SetMarkerColor(color);
  9. histogram->GetXaxis()->SetTitle(xaxis_name.c_str());
  10. histogram->GetYaxis()->SetTitle(yaxis_name.c_str());
  11. histogram->GetYaxis()->SetTitleOffset(1.9);
  12. histogram->GetXaxis()->SetTitleOffset(1.0);
  13. histogram->GetXaxis()->SetTitleSize(0.05);
  14. histogram->GetYaxis()->SetTitleSize(0.05);
  15. histogram->GetXaxis()->SetLabelSize(0.045);
  16. histogram->GetYaxis()->SetLabelSize(0.045);
  17. histogram->SetLineColor(color);
  18. }
  19. void design_markers(TH1D *histogram, string xaxis_name, string yaxis_name, Color_t color){
  20. gStyle->SetOptStat(0);
  21. histogram->SetMarkerStyle(8);
  22. histogram->SetMarkerColor(color);
  23. histogram->GetXaxis()->SetTitle(xaxis_name.c_str());
  24. histogram->GetYaxis()->SetTitle(yaxis_name.c_str());
  25. histogram->GetYaxis()->SetTitleOffset(1.9);
  26. histogram->GetXaxis()->SetTitleOffset(1.0);
  27. histogram->GetXaxis()->SetTitleSize(0.05);
  28. histogram->GetYaxis()->SetTitleSize(0.05);
  29. histogram->GetXaxis()->SetLabelSize(0.045);
  30. histogram->GetYaxis()->SetLabelSize(0.045);
  31. histogram->SetLineColor(color);
  32. }
  33. void design_markers(TEfficiency *histogram, string xaxis_name, string yaxis_name, Color_t color){ //TODO
  34. gStyle->SetOptStat(0);
  35. histogram->SetMarkerStyle(8);
  36. histogram->SetMarkerColor(color);
  37. histogram->SetLineColor(color);
  38. }
  39. void design_lines(TH1F *histogram, string xaxis_name, string yaxis_name, Color_t color){
  40. gStyle->SetOptStat(0);
  41. histogram->SetLineWidth(3);
  42. histogram->GetXaxis()->SetTitle(xaxis_name.c_str());
  43. histogram->GetYaxis()->SetTitle(yaxis_name.c_str());
  44. histogram->GetYaxis()->SetTitleOffset(1.3);
  45. histogram->GetXaxis()->SetTitleOffset(1.1);
  46. histogram->GetYaxis()->SetTitleSize(0.05);
  47. histogram->GetXaxis()->SetTitleSize(0.05);
  48. histogram->GetYaxis()->SetLabelSize(0.04);
  49. histogram->GetXaxis()->SetLabelSize(0.04);
  50. histogram->SetLineColor(color);
  51. }
  52. void design_lines(TH1D *histogram, string xaxis_name, string yaxis_name, Color_t color){
  53. gStyle->SetOptStat(0);
  54. histogram->SetLineWidth(3);
  55. histogram->GetXaxis()->SetTitle(xaxis_name.c_str());
  56. histogram->GetYaxis()->SetTitle(yaxis_name.c_str());
  57. histogram->GetYaxis()->SetTitleOffset(1.3);
  58. histogram->GetXaxis()->SetTitleOffset(1.05);
  59. histogram->GetYaxis()->SetTitleSize(0.05);
  60. histogram->GetXaxis()->SetTitleSize(0.05);
  61. histogram->GetYaxis()->SetLabelSize(0.04);
  62. histogram->GetXaxis()->SetLabelSize(0.04);
  63. histogram->SetLineColor(color);
  64. }
  65. void design_lines(TH1 *histogram, string xaxis_name, string yaxis_name, Color_t color){
  66. gStyle->SetOptStat(0);
  67. histogram->SetLineWidth(3);
  68. histogram->GetXaxis()->SetTitle(xaxis_name.c_str());
  69. histogram->GetYaxis()->SetTitle(yaxis_name.c_str());
  70. histogram->GetYaxis()->SetTitleOffset(1.3);
  71. histogram->GetXaxis()->SetTitleOffset(1.05);
  72. histogram->GetYaxis()->SetTitleSize(0.05);
  73. histogram->GetXaxis()->SetTitleSize(0.05);
  74. histogram->GetYaxis()->SetLabelSize(0.04);
  75. histogram->GetXaxis()->SetLabelSize(0.04);
  76. histogram->SetLineColor(color);
  77. }
  78. void design_filled_plot(TH1F *histogram, string xaxis_name, string yaxis_name, Color_t fill_color, int fill_style){
  79. gStyle->SetOptStat(0);
  80. histogram->SetLineWidth(2);
  81. histogram->GetXaxis()->SetTitle(xaxis_name.c_str());
  82. histogram->GetYaxis()->SetTitle(yaxis_name.c_str());
  83. histogram->GetYaxis()->SetTitleOffset(1.0);
  84. histogram->GetXaxis()->SetTitleOffset(1.0);
  85. histogram->GetYaxis()->SetTitleSize(0.05);
  86. histogram->GetXaxis()->SetTitleSize(0.05);
  87. histogram->GetYaxis()->SetLabelSize(0.05);
  88. histogram->GetXaxis()->SetLabelSize(0.05);
  89. histogram->SetFillColor(fill_color);
  90. histogram->SetFillStyle(fill_style);
  91. }
  92. void design_filled_plot(TH1D *histogram, string xaxis_name, string yaxis_name, Color_t fill_color, int fill_style){
  93. gStyle->SetOptStat(0);
  94. histogram->SetLineWidth(2);
  95. histogram->GetXaxis()->SetTitle(xaxis_name.c_str());
  96. histogram->GetYaxis()->SetTitle(yaxis_name.c_str());
  97. histogram->GetYaxis()->SetTitleOffset(1.0);
  98. histogram->GetXaxis()->SetTitleOffset(1.0);
  99. histogram->GetYaxis()->SetTitleSize(0.05);
  100. histogram->GetXaxis()->SetTitleSize(0.05);
  101. histogram->GetYaxis()->SetLabelSize(0.05);
  102. histogram->GetXaxis()->SetLabelSize(0.05);
  103. histogram->SetFillColor(fill_color);
  104. histogram->SetFillStyle(fill_style);
  105. }
  106. void design_filled_plot(TH1F *histogram, string xaxis_name, string yaxis_name, Color_t fill_color, int fill_style, Color_t line_color){
  107. design_filled_plot(histogram,xaxis_name,yaxis_name,fill_color,fill_style);
  108. histogram->SetLineColor(line_color);
  109. }
  110. void design_filled_plot(TH1D *histogram, string xaxis_name, string yaxis_name, Color_t fill_color, int fill_style , Color_t line_color){
  111. design_filled_plot(histogram,xaxis_name,yaxis_name,fill_color,fill_style);
  112. histogram->SetLineColor(line_color);
  113. }
  114. void design_canvas(TCanvas *canvas){
  115. canvas->SetRightMargin(0.05);
  116. canvas->SetTopMargin(0.1);
  117. canvas->SetLeftMargin(0.13);
  118. canvas->SetBottomMargin(0.12);
  119. }
  120. void design_canvas(TCanvas *canvas, string title){
  121. design_canvas(canvas);
  122. canvas->SetTitle(title.c_str());
  123. }
  124. void design_canvas_Bmass(TCanvas *canvas){
  125. canvas->SetRightMargin(0.03);
  126. canvas->SetTopMargin(0.1);
  127. canvas->SetLeftMargin(0.09);
  128. canvas->SetBottomMargin(0.12);
  129. }
  130. void design_canvas_Bmass(TCanvas *canvas, string title){
  131. design_canvas_Bmass(canvas);
  132. canvas->SetTitle(title.c_str());
  133. }
  134. TCanvas *c_TH2F(string c_name){
  135. TCanvas *c_eff = new TCanvas(c_name.c_str(),c_name.c_str(),750, 700);
  136. c_eff->SetRightMargin(0.14);
  137. gStyle->SetOptStat(0);
  138. c_eff->SetLeftMargin(0.14);
  139. c_eff->SetTopMargin(0.075);
  140. c_eff->SetBottomMargin(0.12);
  141. return c_eff;
  142. }
  143. void design_canvas_TH2F(TCanvas *canvas){
  144. canvas->SetRightMargin(0.15);
  145. canvas->SetTopMargin(0.04);
  146. canvas->SetBottomMargin(0.25);
  147. canvas->SetLeftMargin(0.25);
  148. }
  149. void design_canvas_fancy(TCanvas *canvas){
  150. canvas->SetRightMargin(0.515);
  151. canvas->SetTopMargin(0.05);
  152. canvas->SetBottomMargin(0.12);
  153. canvas->SetLeftMargin(0.3);
  154. }
  155. void design_TH2F(TH2F *histogram, string xaxis_name, string yaxis_name, string zaxis_name){
  156. gStyle->SetOptStat(0);
  157. histogram->GetXaxis()->SetTitle(xaxis_name.c_str());
  158. histogram->GetYaxis()->SetTitle(yaxis_name.c_str());
  159. histogram->GetZaxis()->SetTitle(zaxis_name.c_str());
  160. histogram->GetXaxis()->SetTitleOffset(0.95);
  161. histogram->GetYaxis()->SetTitleOffset(1.5);
  162. histogram->GetZaxis()->SetTitleOffset(0.8);
  163. histogram->GetXaxis()->SetTitleSize(0.05);
  164. histogram->GetYaxis()->SetTitleSize(0.05);
  165. histogram->GetZaxis()->SetTitleSize(0.04);
  166. histogram->GetXaxis()->SetLabelSize(0.04);
  167. histogram->GetYaxis()->SetLabelSize(0.04);
  168. histogram->GetZaxis()->SetLabelSize(0.04);
  169. //histogram->GetZaxis()->CenterTitle(kTRUE);
  170. histogram->SetTitle("");
  171. }
  172. void design_TH2F(TH2D *histogram, string xaxis_name, string yaxis_name, string zaxis_name){
  173. gStyle->SetOptStat(0);
  174. histogram->GetXaxis()->SetTitle(xaxis_name.c_str());
  175. histogram->GetYaxis()->SetTitle(yaxis_name.c_str());
  176. histogram->GetZaxis()->SetTitle(zaxis_name.c_str());
  177. histogram->GetXaxis()->SetTitleOffset(0.95);
  178. histogram->GetYaxis()->SetTitleOffset(1.5);
  179. histogram->GetZaxis()->SetTitleOffset(0.8);
  180. histogram->GetXaxis()->SetTitleSize(0.05);
  181. histogram->GetYaxis()->SetTitleSize(0.05);
  182. histogram->GetZaxis()->SetTitleSize(0.04);
  183. histogram->GetXaxis()->SetLabelSize(0.04);
  184. histogram->GetYaxis()->SetLabelSize(0.04);
  185. histogram->GetZaxis()->SetLabelSize(0.04);
  186. //histogram->GetZaxis()->CenterTitle(kTRUE);
  187. histogram->SetTitle("");
  188. }
  189. void design_TH2F(TH2F *histogram, string xaxis_name, string yaxis_name, string zaxis_name, int palette){
  190. design_TH2F(histogram,xaxis_name,yaxis_name,zaxis_name);
  191. gStyle->SetPalette(palette);
  192. }
  193. void design_TH2F(TH2D *histogram, string xaxis_name, string yaxis_name, string zaxis_name, int palette){
  194. design_TH2F(histogram,xaxis_name,yaxis_name,zaxis_name);
  195. gStyle->SetPalette(palette);
  196. }
  197. void design_TH2F_ratio(TH2F *histogram, string xaxis_name, string yaxis_name, string zaxis_name, int palette){
  198. gStyle->SetOptStat(0);
  199. histogram->GetXaxis()->SetTitle(xaxis_name.c_str());
  200. histogram->GetYaxis()->SetTitle(yaxis_name.c_str());
  201. string zaxis_name_offset = " " + zaxis_name;
  202. histogram->GetZaxis()->SetTitle(zaxis_name_offset.c_str());
  203. histogram->GetXaxis()->SetTitleOffset(1.2);
  204. histogram->GetYaxis()->SetTitleOffset(1.2);
  205. histogram->GetZaxis()->SetTitleOffset(1.2);
  206. histogram->GetZaxis()->SetLabelSize(0.03);
  207. histogram->GetZaxis()->CenterTitle(kTRUE);
  208. histogram->SetTitle("");
  209. gStyle->SetPalette(palette);
  210. }
  211. void design_TH2F_ratio(TH2D *histogram, string xaxis_name, string yaxis_name, string zaxis_name, int palette){
  212. gStyle->SetOptStat(0);
  213. histogram->GetXaxis()->SetTitle(xaxis_name.c_str());
  214. histogram->GetYaxis()->SetTitle(yaxis_name.c_str());
  215. string zaxis_name_offset = " " + zaxis_name;
  216. histogram->GetZaxis()->SetTitle(zaxis_name_offset.c_str());
  217. histogram->GetXaxis()->SetTitleOffset(1.2);
  218. histogram->GetYaxis()->SetTitleOffset(1.2);
  219. histogram->GetZaxis()->SetTitleOffset(1.2);
  220. histogram->GetZaxis()->SetLabelSize(0.03);
  221. histogram->GetZaxis()->CenterTitle(kTRUE);
  222. histogram->SetTitle("");
  223. gStyle->SetPalette(palette);
  224. }
  225. void design_function(TF1 *graph, Color_t color){
  226. gStyle->SetOptStat(0);
  227. graph->SetLineWidth(3);
  228. graph->SetLineColor(color);
  229. }
  230. void design_function(TF1 *graph, Color_t color, int style){
  231. design_function(graph,color);
  232. graph->SetLineStyle(style);
  233. }
  234. void design_TH1F(TH1F *histogram, string xaxis_name, string yaxis_name, Color_t color){
  235. gStyle->SetOptStat(0);
  236. design_markers(histogram, xaxis_name, yaxis_name, color);
  237. histogram->SetMarkerSize(3);
  238. histogram->GetXaxis()->SetTitleOffset(1.0);
  239. histogram->GetYaxis()->SetTitleOffset(1.6);
  240. histogram->SetTitle("");
  241. histogram->GetXaxis()->SetLabelSize(0.05);
  242. histogram->GetYaxis()->SetLabelSize(0.04);
  243. histogram->GetXaxis()->SetTitleSize(0.05);
  244. histogram->GetYaxis()->SetTitleSize(0.05);
  245. }
  246. void design_TH1D(TH1D *histogram, string xaxis_name, string yaxis_name, Color_t color){
  247. gStyle->SetOptStat(0);
  248. design_markers(histogram, xaxis_name, yaxis_name, color);
  249. histogram->SetMarkerSize(3);
  250. histogram->GetXaxis()->SetTitleOffset(1.0);
  251. histogram->GetYaxis()->SetTitleOffset(1.6);
  252. histogram->SetTitle("");
  253. histogram->GetXaxis()->SetLabelSize(0.05);
  254. histogram->GetYaxis()->SetLabelSize(0.04);
  255. histogram->GetXaxis()->SetTitleSize(0.05);
  256. histogram->GetYaxis()->SetTitleSize(0.05);
  257. }
  258. void design_TH1F(TH1F *histogram, string xaxis_name, string yaxis_name, Color_t color, int marker_style){
  259. design_TH1F(histogram,xaxis_name,yaxis_name,color);
  260. histogram->SetMarkerStyle(marker_style);
  261. }
  262. void design_TH1D(TH1D *histogram, string xaxis_name, string yaxis_name, Color_t color, int marker_style){
  263. design_TH1D(histogram,xaxis_name,yaxis_name,color);
  264. histogram->SetMarkerStyle(marker_style);
  265. }
  266. void design_TH1F(TH1F *histogram, string xaxis_name, string yaxis_name, Color_t color, int marker_style, double x_low, double x_up, double y_low, double y_up){
  267. design_TH1F(histogram,xaxis_name,yaxis_name,color,marker_style);
  268. histogram->GetXaxis()->SetRangeUser(x_low, x_up);
  269. histogram->GetYaxis()->SetRangeUser(y_low, y_up);
  270. }
  271. void design_TH1D(TH1D *histogram, string xaxis_name, string yaxis_name, Color_t color, int marker_style, double x_low, double x_up, double y_low, double y_up){
  272. design_TH1D(histogram,xaxis_name,yaxis_name,color,marker_style);
  273. histogram->GetXaxis()->SetRangeUser(x_low, x_up);
  274. histogram->GetYaxis()->SetRangeUser(y_low, y_up);
  275. }
  276. TLine *design_cut_line(float x1, float y1, float x2, float y2, Color_t color){
  277. TLine *line = new TLine(x1,y1,x2,y2);
  278. line->SetLineColor(color);
  279. line->SetLineWidth(5);
  280. return line;
  281. }
  282. TLine *design_ratio_line(float x1, float x2, Color_t color){
  283. TLine *line = new TLine(x1,1,x2,1);
  284. line->SetLineColor(color);
  285. line->SetLineWidth(3);
  286. line->SetLineStyle(2);
  287. return line;
  288. }
  289. TLine *design_veto_line(float x1, float y1, float x2, float y2, Color_t color){
  290. TLine *line = new TLine(x1,y1,x2,y2);
  291. line->SetLineColor(color);
  292. line->SetLineWidth(1);
  293. return line;
  294. }
  295. ////////////////////////////////////
  296. ///
  297. ///
  298. /// TMVA plots
  299. ///
  300. ///
  301. ////////////////////////////////////
  302. bool DesignCorrelationPlots(TH2F *h_corr){
  303. h_corr->SetMarkerColor(kBlack); //in order for the text Draw option to be black
  304. h_corr->GetXaxis()->SetLabelSize(0.04);
  305. h_corr->GetYaxis()->SetLabelSize(0.04);
  306. gStyle->SetPalette(kRainBow);
  307. return true;
  308. }
  309. TCanvas *c_Correlation(string type){
  310. string c_name = "c_Correlation" + type;
  311. TCanvas *c_corr = new TCanvas(c_name.c_str(),c_name.c_str(),800, 750);
  312. c_corr->SetRightMargin(0.13);
  313. c_corr->SetLeftMargin(0.23);
  314. c_corr->SetTopMargin(0.075);
  315. c_corr->SetBottomMargin(0.12);
  316. return c_corr;
  317. }
  318. bool designVariablesSignalVsBackground(TH1F *h_variableS, TH1F *h_variableB){
  319. //Set plot height (find max(S,B) and add 10%
  320. double height = max(h_variableS->GetMaximum(),h_variableB->GetMaximum());
  321. height*=1.1;
  322. h_variableS->GetYaxis()->SetRangeUser(0,height);
  323. h_variableS->GetYaxis()->SetTitleOffset(1.23);
  324. //Add dN/N
  325. string YaxisTitle = h_variableS->GetYaxis()->GetTitle();
  326. replace(YaxisTitle,"dN","dN/N");
  327. h_variableS->GetYaxis()->SetTitle(YaxisTitle.c_str());
  328. //Add color
  329. h_variableS->SetLineColor(kBlue+2);
  330. h_variableS->SetFillStyle(1001);
  331. h_variableS->SetFillColor(38);
  332. h_variableS->SetLineWidth(2);
  333. h_variableB->SetLineColor(kRed+2);
  334. h_variableB->SetFillStyle(3354);
  335. h_variableB->SetFillColor(kRed);
  336. h_variableB->SetLineWidth(2);
  337. return 1;
  338. }
  339. bool designResponseSignalVsBackground(TH1F *h_responseS, TH1F *h_responseB, string method){
  340. //Set plot height (find max(S,B) and add 20%
  341. double height = max(h_responseS->GetMaximum(),h_responseB->GetMaximum());
  342. height*= (method != "BDT" ? 5.0 : 1.4);
  343. h_responseS->GetYaxis()->SetRangeUser( (method == "BDT" ? 0.00 : 0.01) ,height); //prevent log from crashing
  344. h_responseS->GetYaxis()->SetTitleOffset(1.25);
  345. //Set axis titles
  346. string XaxisTitle = method + " response";
  347. string YaxisTitle = "(1/N) dN/dx";
  348. h_responseS->GetXaxis()->SetTitle(XaxisTitle.c_str());
  349. h_responseS->GetYaxis()->SetTitle(YaxisTitle.c_str());
  350. h_responseS->SetTitle(XaxisTitle.c_str());
  351. //Set Xaxis range
  352. //if (method != "MLP") h_responseS->GetXaxis()->SetRangeUser(-1,1);
  353. //else h_responseS->GetXaxis()->SetRangeUser(0,1);
  354. //Add color
  355. h_responseS->SetFillStyle(1001);
  356. h_responseS->SetFillColor(38);
  357. h_responseS->SetLineWidth(0);
  358. h_responseS->SetLineColor(kBlue+2);
  359. h_responseS->SetLineWidth(1);
  360. h_responseS->SetMarkerSize(0);
  361. h_responseB->SetFillStyle(3354);
  362. h_responseB->SetFillColor(kRed);
  363. h_responseB->SetLineColor(kRed+2);
  364. h_responseB->SetLineWidth(1);
  365. h_responseB->SetMarkerSize(0);
  366. return 1;
  367. }
  368. bool designOvertraining(TH1F *h_responseS, TH1F *h_responseB){
  369. //Add color
  370. h_responseS->SetLineColor(kBlue+2);
  371. h_responseS->SetLineWidth(3);
  372. h_responseS->SetMarkerColor(kBlue+2);
  373. h_responseS->SetMarkerStyle(20);
  374. h_responseB->SetLineColor(kRed+2);
  375. h_responseB->SetLineWidth(3);
  376. h_responseB->SetMarkerColor(kRed+2);
  377. h_responseB->SetMarkerStyle(20);
  378. return 1;
  379. }
  380. TCanvas *c_VariablesSignalVsBackground(string variable){
  381. string c_name = "c_" + variable;
  382. TCanvas *c_Var = new TCanvas(c_name.c_str(),c_name.c_str(),750, 600);
  383. gStyle->SetOptStat(0);
  384. c_Var->SetRightMargin(0.05);
  385. c_Var->SetLeftMargin(0.18);
  386. c_Var->SetTopMargin(0.05);
  387. c_Var->SetBottomMargin(0.17);
  388. return c_Var;
  389. }
  390. TCanvas *c_Efficiency(string c_name){
  391. TCanvas *c_eff = new TCanvas(c_name.c_str(),c_name.c_str(),750, 525);
  392. c_eff->SetRightMargin(0.13);
  393. gStyle->SetOptStat(0);
  394. c_eff->SetLeftMargin(0.23);
  395. c_eff->SetTopMargin(0.075);
  396. c_eff->SetBottomMargin(0.12);
  397. return c_eff;
  398. }
  399. bool designEfficiency(TH1F *h_efficiencySignal,TH1F *h_efficiencyBackground,TH1F *h_purity,TH1F *h_significance, string method){
  400. //Set axis titles
  401. string XaxisTitle = "Cut value applied on " + method + " output";
  402. h_efficiencySignal->GetXaxis()->SetTitle(XaxisTitle.c_str());
  403. h_efficiencySignal->GetYaxis()->SetTitle("Efficiency (purity)");
  404. h_significance->GetYaxis()->SetTitle("Significance");
  405. //Set titles
  406. h_efficiencySignal->SetTitle("Cut efficiencies and optimal cut value");
  407. h_significance->SetTitle("");
  408. //Add top margin for legend boxes
  409. h_efficiencySignal->GetYaxis()->SetRangeUser(0,1.24);
  410. h_significance->GetYaxis()->SetRangeUser(0,h_significance->GetMaximum()*1.24);
  411. //Add color
  412. h_efficiencySignal->SetLineColor(kBlue+2);
  413. h_efficiencySignal->SetLineWidth(3);
  414. h_efficiencyBackground->SetLineColor(kRed);
  415. h_efficiencyBackground->SetLineWidth(3);
  416. h_purity->SetLineColor(kMagenta);
  417. h_purity->SetLineWidth(3);
  418. h_significance->SetLineColor(kGreen+2);
  419. h_significance->SetLineWidth(3);
  420. h_significance->GetYaxis()->SetLabelColor(kGreen+2);
  421. h_significance->GetYaxis()->SetTitleColor(kGreen+2);
  422. return 1;
  423. }
  424. TPaveText *significanceText(double xmin, int nSig, int nBkg, double maxSignificance, double maxSignificanceMLPcut){
  425. TPaveText *text = new TPaveText(xmin+0.01,0.05,(1-xmin)*0.8,0.3);
  426. text->SetFillColor(0);
  427. text->SetFillStyle(0);
  428. text->SetTextAlign(12);
  429. text->SetTextSize(0.04);
  430. text->SetBorderSize(0);
  431. string s_text = "For " + to_string(nSig) + " sigEvts and " + to_string(nBkg) + " bkgEvts";
  432. text->AddText(s_text.c_str());
  433. stringstream stream; //workaround for to_string() precision
  434. stream << fixed << setprecision(2) << maxSignificance;
  435. s_text = "the maximum significance is " + stream.str();
  436. text->AddText(s_text.c_str());
  437. stream.str(""); //clear stream
  438. stream << fixed << setprecision(2) << maxSignificanceMLPcut;
  439. s_text = "when cutting at " + stream.str() + ".";
  440. text->AddText(s_text.c_str());
  441. return text;
  442. }
  443. TPaveText *text_effFromPi0(double yieldSig, double yieldBkg, double ymax){
  444. TPaveText *text = new TPaveText(145,ymax*0.9,160,ymax*1.15);
  445. text->SetFillColor(0);
  446. text->SetFillStyle(0);
  447. text->SetTextAlign(12);
  448. text->SetTextSize(0.04);
  449. text->SetBorderSize(0);
  450. text->AddText(Form("Sig yield: %i",int(yieldSig)));
  451. text->AddText(Form("Bkg yield: %i",int(yieldBkg)));
  452. return text;
  453. }
  454. TCanvas *c_ROCplot(string c_name){
  455. TCanvas *c_ROCs = new TCanvas(c_name.c_str(),c_name.c_str(),650, 600);
  456. gStyle->SetOptStat(0);
  457. c_ROCs->SetRightMargin(0.055);
  458. c_ROCs->SetLeftMargin(0.175);
  459. c_ROCs->SetTopMargin(0.055);
  460. c_ROCs->SetBottomMargin(0.175);
  461. c_ROCs->SetGridx();
  462. c_ROCs->SetGridy();
  463. return c_ROCs;
  464. }
  465. void designROC(TH1F* h_ROC, int index){
  466. if ( 9 <= index ) index += 20; //remove ugly white-ish colors
  467. h_ROC->SetLineColor(index+1);
  468. h_ROC->SetLineWidth(2);
  469. h_ROC->GetXaxis()->SetTitleOffset(0.95);
  470. h_ROC->GetYaxis()->SetTitleOffset(1.1);
  471. h_ROC->GetXaxis()->SetLabelSize(0.05);
  472. h_ROC->GetYaxis()->SetLabelSize(0.05);
  473. h_ROC->GetYaxis()->SetNdivisions(505);
  474. h_ROC->GetXaxis()->SetRangeUser(0.5,1.0);
  475. h_ROC->GetYaxis()->SetRangeUser(0.5,1.0);
  476. h_ROC->SetTitle("ROCs");
  477. }
  478. TCanvas *c_L0MuonEff(string c_name){
  479. TCanvas *c_L0Muon = new TCanvas(c_name.c_str(),c_name.c_str(),650, 600);
  480. gStyle->SetOptStat(0);
  481. c_L0Muon->SetRightMargin(0.075);
  482. c_L0Muon->SetLeftMargin(0.18);
  483. c_L0Muon->SetTopMargin(0.05);
  484. c_L0Muon->SetBottomMargin(0.19);
  485. return c_L0Muon;
  486. }
  487. void designL0MuonEffHistos(TH1D *L0MuonEffData,TH1D *L0MuonEffMC, TH1D *L0MuonEffRatio){
  488. L0MuonEffData->GetYaxis()->SetRangeUser(0.5,1.3);
  489. L0MuonEffData->SetTitle("L0Muon efficiencies");
  490. L0MuonEffData->GetYaxis()->SetTitle("Efficiency");
  491. L0MuonEffData->GetXaxis()->SetTitle("max(#mu^{-}_{p_{T}},#mu^{+}_{p_{T}})");
  492. L0MuonEffData->GetXaxis()->SetTitleOffset(1.2);
  493. L0MuonEffData->GetYaxis()->SetTitleOffset(1.2);
  494. L0MuonEffMC->GetYaxis()->SetTitle("Efficiency");
  495. L0MuonEffMC->GetXaxis()->SetTitle("max(#mu^{-}_{p_{T}},#mu^{+}_{p_{T}})");
  496. L0MuonEffMC->GetXaxis()->SetTitleOffset(1.2);
  497. L0MuonEffMC->GetYaxis()->SetTitleOffset(1.2);
  498. L0MuonEffData->GetYaxis()->SetTitle("Efficiency");
  499. L0MuonEffRatio->GetXaxis()->SetTitle("max(#mu^{-}_{p_{T}},#mu^{+}_{p_{T}})");
  500. L0MuonEffData->GetXaxis()->SetTitleOffset(1.2);
  501. L0MuonEffRatio->GetYaxis()->SetTitleOffset(1.2);
  502. L0MuonEffData->SetLineColor(kBlack);
  503. L0MuonEffMC->SetLineColor(kRed);
  504. L0MuonEffRatio->SetLineColor(kBlue);
  505. L0MuonEffData->SetLineWidth(2);
  506. L0MuonEffMC->SetLineWidth(2);
  507. L0MuonEffRatio->SetLineWidth(2);
  508. L0MuonEffData->SetMarkerColor(kBlack);
  509. L0MuonEffMC->SetMarkerColor(kRed);
  510. L0MuonEffRatio->SetMarkerColor(kBlue);
  511. L0MuonEffData->SetMarkerStyle(0);
  512. L0MuonEffMC->SetMarkerStyle(0);
  513. L0MuonEffRatio->SetMarkerStyle(0);
  514. }
  515. //TODO: make it compile on its own possibly
  516. TCanvas * designL0MuonEfficiencies(string year, string magnet,TH1D *L0MuonEffData,TH1D *L0MuonEffMC, TH1D *L0MuonEffRatio, string extraString){
  517. string name = "eff_" + extraString;
  518. TCanvas *c_L0Eff = c_L0MuonEff(name.c_str());
  519. c_L0Eff->cd();
  520. designL0MuonEffHistos(L0MuonEffData, L0MuonEffMC, L0MuonEffRatio);
  521. //line at 1
  522. TLine *line = design_ratio_line(L0MuonEffData->GetXaxis()->GetXmin(),L0MuonEffData->GetXaxis()->GetXmax(),kBlack);
  523. line->SetLineWidth(1);
  524. line->SetLineStyle(1);
  525. //Add legend
  526. TLegend *leg = new TLegend(0.45,0.25,0.9,0.45);
  527. leg->AddEntry(L0MuonEffData, "Data eff","l");
  528. string s_leg = extraString + " eff";
  529. leg->AddEntry(L0MuonEffMC, s_leg.c_str(),"l");
  530. leg->AddEntry(L0MuonEffRatio, "Data eff/MC eff","l");
  531. leg->SetTextSize(0.05);
  532. L0MuonEffData->Draw();
  533. line->Draw("SAME");
  534. L0MuonEffMC->Draw("SAME");
  535. L0MuonEffRatio->Draw("SAME");
  536. addLHCbtag(0.56, 0.87, year , 1.0);
  537. leg->Draw("SAME");
  538. string output_name = GetEfficiencyFile("L0Muon",year,magnet,false,false,false,false,false,false,false,false,extraString);
  539. replace (output_name,".root",".eps");
  540. c_L0Eff->SaveAs(output_name.c_str());
  541. return c_L0Eff;
  542. }
  543. void designBasicEfficiency(TGraphErrors *graph, string title, string xAxisName, string effName, double lowRange, double highRange){
  544. graph->SetName(title.c_str());
  545. graph->SetLineColor(kGreen+3);
  546. graph->SetMarkerStyle(20);
  547. graph->SetMarkerColor(kGreen+3);
  548. graph->GetXaxis()->SetTitle(xAxisName.c_str());
  549. graph->GetYaxis()->SetTitle(Form("#varepsilon_%s",effName.c_str()));
  550. graph->GetYaxis()->SetTitleSize(0.07);
  551. graph->GetYaxis()->SetRangeUser(lowRange,highRange);
  552. }
  553. void designBasicEfficiency(TGraphErrors *graph, string title, string xAxisName, string effName, double lowRange, double highRange, Color_t color){
  554. graph->SetName(title.c_str());
  555. graph->SetLineColor(color);
  556. graph->SetMarkerStyle(20);
  557. graph->SetMarkerColor(color);
  558. graph->GetXaxis()->SetTitle(xAxisName.c_str());
  559. graph->GetYaxis()->SetTitle(Form("#varepsilon_%s",effName.c_str()));
  560. graph->GetYaxis()->SetTitleSize(0.05);
  561. graph->GetYaxis()->SetRangeUser(lowRange,highRange);
  562. }
  563. void designMultiGraphEfficiency(TMultiGraph *graph, string title, string xAxisName, string effName, double lowRange, double highRange){
  564. graph->SetName(title.c_str());
  565. graph->GetXaxis()->SetTitle(xAxisName.c_str());
  566. graph->GetYaxis()->SetTitle(Form("#varepsilon_%s",effName.c_str()));
  567. graph->GetYaxis()->SetTitleSize(0.05);
  568. graph->GetYaxis()->SetRangeUser(lowRange,highRange);
  569. }
  570. ////////////////////////////////////
  571. ///
  572. ///
  573. /// generic plots
  574. ///
  575. ///
  576. ////////////////////////////////////
  577. TCanvas *c_canvas(string name){
  578. TCanvas *canvas = new TCanvas(name.c_str(),name.c_str(),750, 600);
  579. gStyle->SetOptStat(0);
  580. canvas->SetRightMargin(0.08);
  581. canvas->SetTopMargin(0.05);
  582. canvas->SetBottomMargin(0.12);
  583. canvas->SetLeftMargin(0.15);
  584. return canvas;
  585. }
  586. void designTGraph(TGraphErrors *graph, string title, string xAxisName, string yAxisName, Color_t color, Int_t markerStyle){
  587. graph->SetName(title.c_str());
  588. graph->SetLineColor(color);
  589. //graph->SetLineWidth(0);
  590. graph->SetMarkerStyle(markerStyle);
  591. graph->SetMarkerColor(color);
  592. graph->GetXaxis()->SetTitle(xAxisName.c_str());
  593. graph->GetYaxis()->SetTitle(yAxisName.c_str());
  594. gStyle->SetOptStat(0);
  595. graph->GetXaxis()->SetTitleOffset(1.0);
  596. graph->GetYaxis()->SetTitleOffset(1.7);
  597. graph->SetTitle("");
  598. graph->GetXaxis()->SetLabelSize(0.07);
  599. graph->GetYaxis()->SetLabelSize(0.05);
  600. graph->GetXaxis()->SetTitleSize(0.05);
  601. graph->GetYaxis()->SetTitleSize(0.04);
  602. return;
  603. }
  604. TH1D *generalHistogram(string hist_name, string title, int nBins, double low_edge, double high_edge, string xaxis_name, string yaxis_name, Color_t color){
  605. TH1D *histogram = new TH1D(hist_name.c_str(), title.c_str(),nBins,low_edge,high_edge);
  606. design_TH1D(histogram, xaxis_name, yaxis_name, color);
  607. return histogram;
  608. }
  609. TH1D *BmassHistogram(string hist_name, string title, string xaxis_name,Color_t color){
  610. TH1D *histogram = generalHistogram(hist_name, title, 100, cut_B_plus_M_low, cut_B_plus_M_high, xaxis_name, "Counts a.u.", color);
  611. histogram->SetLineWidth(2);
  612. return histogram;
  613. }
  614. void TM_canvas(string name, TH1D *all, TH1D *TMed, TH1D *notTMed, string year, bool ReferenceChannel, bool PHSP, bool B0, bool K1, bool Inc){
  615. string path = getTMplotsPath(name, year, ReferenceChannel, PHSP, B0, K1, Inc);
  616. TCanvas *canvas = c_canvas(name);
  617. canvas->cd();
  618. all->SetLineWidth(2);
  619. TMed->SetLineWidth(2);
  620. notTMed->SetLineWidth(2);
  621. all->Draw();
  622. TMed->Draw("SAME");
  623. notTMed->Draw("SAME");
  624. canvas->Print(path.c_str(),"eps");
  625. replace(path,".eps",".root");
  626. canvas->Print(path.c_str(),"root");
  627. delete canvas;
  628. return;
  629. }
  630. void designMultiGraph(TMultiGraph *multGraph, string name, string xaxis_name, string yaxis_name, double lowx, double highx, double lowy, double highy){
  631. designMultiGraph(multGraph, name, xaxis_name, yaxis_name);
  632. multGraph->GetXaxis()->SetRangeUser(lowx, highx);
  633. multGraph->GetYaxis()->SetRangeUser(lowy, highy);
  634. return;
  635. }
  636. void designMultiGraph(TMultiGraph *multGraph, string name, string xaxis_name, string yaxis_name){
  637. //One needs to draw the multGraph first!
  638. multGraph->SetName(name.c_str());
  639. multGraph->GetXaxis()->SetTitle(xaxis_name.c_str());
  640. multGraph->GetYaxis()->SetTitle(yaxis_name.c_str());
  641. gStyle->SetOptStat(0);
  642. multGraph->GetXaxis()->SetTitleOffset(0.9);
  643. multGraph->GetYaxis()->SetTitleOffset(1.1);
  644. multGraph->SetTitle("");
  645. multGraph->GetXaxis()->SetLabelSize(0.05);
  646. multGraph->GetYaxis()->SetLabelSize(0.05);
  647. multGraph->GetXaxis()->SetTitleSize(0.05);
  648. multGraph->GetYaxis()->SetTitleSize(0.05);
  649. return;
  650. }
  651. void addYearTag(Float_t x = 0.6, Float_t y = 0.85, string year = "", int Run = 0, Int_t color = 1, Float_t Scaling = 1.0){
  652. TLatex* lhcbtext = new TLatex();
  653. lhcbtext->SetTextFont(132);
  654. lhcbtext->SetTextColor(color);
  655. lhcbtext->SetTextSize(0.07*Scaling);
  656. lhcbtext->SetTextAlign(13);
  657. lhcbtext->SetNDC(1);
  658. lhcbtext->DrawLatex(x,y,getYearRunTag(Run,year).c_str());
  659. return;
  660. }
  661. void addAnyTag(Float_t x = 0.6, Float_t y = 0.85, string text = "", Int_t color = 1, Float_t Scaling = 1.0){
  662. TLatex* lhcbtext = new TLatex();
  663. lhcbtext->SetTextFont(132);
  664. lhcbtext->SetTextColor(color);
  665. lhcbtext->SetTextSize(0.07*Scaling);
  666. lhcbtext->SetTextAlign(13);
  667. lhcbtext->SetNDC(1);
  668. lhcbtext->DrawLatex(x,y,text.c_str());
  669. return;
  670. }
  671. ////////////////////////////////////
  672. ///
  673. ///
  674. /// Truth-matching stuff
  675. ///
  676. ///
  677. ////////////////////////////////////
  678. TCanvas *c_for_TH2D(string name){
  679. TCanvas *c_TH2D = new TCanvas(name.c_str(),name.c_str(),800, 750);
  680. c_TH2D->SetRightMargin(0.13);
  681. c_TH2D->SetLeftMargin(0.13);
  682. c_TH2D->SetTopMargin(0.075);
  683. c_TH2D->SetBottomMargin(0.13);
  684. return c_TH2D;
  685. }
  686. bool designTH2D(TH2F *hist){
  687. hist->SetMarkerColor(kBlack); //in order for the text Draw option to be black
  688. hist->GetXaxis()->SetLabelSize(0.04);
  689. hist->GetYaxis()->SetLabelSize(0.04);
  690. gStyle->SetPalette(kRainBow);
  691. return true;
  692. }
  693. TH1D *hist_cosThetaK(string hist_name, string title, Color_t color, bool cos){
  694. TH1D *histogram = generalHistogram(hist_name, title, 75, cos ? -1.0 : 0.0, cos ? 1.0 : 3.15, cos ? "cos(#theta_{K})" : "#theta_{K}", "Counts a.u.", color);
  695. histogram->SetLineWidth(2);
  696. return histogram;
  697. }
  698. TH1D *hist_cosAngle(string angle, string hist_name, string title, Color_t color, bool cos, bool norm){
  699. if (angle == "thetak") angle = "#theta_{K}";
  700. else if (angle == "thetal") angle = "#theta_{L}";
  701. else if (angle == "phi") angle = "#phi";
  702. else{
  703. coutERROR("Wrong angle selected! Select from thetak, thetal and phi.");
  704. return 0;
  705. }
  706. if (cos) angle = "cos(" + angle + ")";
  707. TH1D *histogram = generalHistogram(hist_name, title, norm ? 20 : 50, cos ? -1.0 : 0.0, cos ? 1.0 : 3.15, angle.c_str(), "Counts a.u.", color);
  708. histogram->SetLineWidth(2);
  709. histogram->SetMarkerSize(1.0);
  710. return histogram;
  711. }
  712. ////////////////////////////////////
  713. ///
  714. ///
  715. /// Mass Fit stuff
  716. ///
  717. ///
  718. ////////////////////////////////////
  719. void designMassFitFrame(RooPlot* frame, float pullHeight){
  720. float textsize = gStyle->GetTextSize();
  721. if (Kst2Kpluspi0Resolved && UseDTF)frame->SetTitle("event distribution #B^{+} with fixed M_{#pi^{0}}");
  722. else frame->SetTitle("event distribution #B^{+}");
  723. frame->GetXaxis()->SetNoExponent(); //<-- spoils MaxDigits settings, so don't use it on other axis
  724. frame->GetXaxis()->SetLabelSize(0.0);//don't print labels
  725. frame->GetYaxis()->SetRangeUser(0.001, frame->GetMaximum()*1.2);//don't print 0-label
  726. frame->GetXaxis()->SetTickLength(frame->GetXaxis()->GetTickLength()/(1-pullHeight));
  727. frame->GetXaxis()->SetNdivisions(gStyle->GetNdivisions("X"));
  728. frame->GetYaxis()->SetTitleSize(textsize/(1-pullHeight));
  729. frame->GetYaxis()->SetLabelSize(textsize/(1-pullHeight));
  730. frame->GetYaxis()->SetNdivisions(gStyle->GetNdivisions("Y"));
  731. frame->GetYaxis()->SetTitleOffset(1.06*(1-pullHeight));
  732. return;
  733. }
  734. void designPullFrame(RooPlot *pullFrame, RooPlot *frame_m, float pullHeight){
  735. RooHist* frame2 = frame_m->pullHist("data", "pdf") ;
  736. float textsize = gStyle->GetTextSize();
  737. float pullFrameRange = 6.5; //This is +/- boundaries of the pull
  738. //make red boxes
  739. pullFrame->addPlotable(frame2,"X0 B");
  740. pullFrame->getAttFill()->SetFillColor(kRed+1);
  741. //format the x- and y-axis of the pull plot
  742. TGaxis::SetExponentOffset(1e+9,1e+9,"x");//offset = pad size * 1e+7
  743. pullFrame->GetXaxis()->SetRangeUser(get_cut_B_plus_M_low(2), cut_B_plus_M_high); //TODO: sort low B mass cut
  744. pullFrame->GetXaxis()->SetTitleOffset(1.05);
  745. pullFrame->GetXaxis()->SetTitleSize (textsize/pullHeight);
  746. pullFrame->GetXaxis()->SetLabelSize (textsize/pullHeight);
  747. pullFrame->GetXaxis()->SetTickLength (frame_m->GetXaxis()->GetTickLength()/(pullHeight/(1-pullHeight)));
  748. pullFrame->GetXaxis()->SetNdivisions (gStyle->GetNdivisions("X"));
  749. pullFrame->GetYaxis()->SetLabelSize (textsize/pullHeight);
  750. pullFrame->GetYaxis()->SetTitleSize (textsize/pullHeight);
  751. pullFrame->GetYaxis()->SetNdivisions (3, 9, 0, kTRUE);//gStyle->GetNdivisions("Y"));
  752. pullFrame->GetYaxis()->SetTitleOffset(1.06*pullHeight);
  753. pullFrame->GetYaxis()->SetRangeUser (-pullFrameRange, pullFrameRange);
  754. pullFrame->GetYaxis()->SetTitle("Pull");
  755. return ;
  756. }
  757. TLine *threeSigmaLine (bool plus){
  758. TLine * line = new TLine(get_cut_B_plus_M_low("2016"), plus ? +3. : -3, cut_B_plus_M_high, plus ? +3. : -3); //TODO: sort low B mass cut
  759. line->SetLineStyle(5);
  760. line->SetLineWidth(gStyle->GetLineWidth());
  761. return line;
  762. }
  763. ////////////////////////////////////
  764. ///
  765. ///
  766. /// reweighting control plots
  767. ///
  768. ///
  769. ////////////////////////////////////
  770. void drawKolmogorovTest(TH1D *hist_nTracks, TH1D * hist_nTracks_MC, string canvasPath, string TMtype){
  771. TCanvas* c1 = new TCanvas("c1", "c1");
  772. //get yRange
  773. double maxY= hist_nTracks->GetMaximum();
  774. if(hist_nTracks_MC->GetMaximum()>maxY)maxY=hist_nTracks_MC->GetMaximum();
  775. hist_nTracks->SetMinimum(0.);
  776. hist_nTracks->SetMaximum(maxY*1.2);
  777. design_TH1D(hist_nTracks, firstMClatex.c_str(),"Events ( norm. )", kBlack);
  778. hist_nTracks->SetMarkerSize(1);
  779. //format colors and draw
  780. hist_nTracks_MC->SetLineStyle(0);
  781. hist_nTracks_MC->GetXaxis()->SetTitle(firstMClatex.c_str());
  782. hist_nTracks_MC->GetYaxis()->SetTitle("Events ( norm. )");
  783. hist_nTracks_MC->SetLineColor(kRed);
  784. hist_nTracks_MC->SetFillColor(kRed);
  785. hist_nTracks_MC->SetMarkerColor(kRed);
  786. hist_nTracks_MC->SetMarkerSize(0);
  787. hist_nTracks_MC->SetMinimum(0.);
  788. hist_nTracks_MC->SetMaximum(maxY*1.2);
  789. hist_nTracks_MC->Draw("E2");
  790. hist_nTracks->Draw("SAME");
  791. //define plot for Kolmogorov test
  792. //Kolmogorov test shouldn't be used at binned data (one should use TMath::Kolmogorov)
  793. //<<1 means NOT compatible
  794. double KolmoTest = hist_nTracks->KolmogorovTest(hist_nTracks_MC);
  795. TPaveText *KolmOut= new TPaveText(0.55,0.6,0.85,0.7,"NDC");
  796. KolmOut->AddText(Form("Kolmogorov Test : %.3f ", KolmoTest));
  797. KolmOut->SetLineColor(kWhite);
  798. KolmOut->SetFillColor(kWhite);
  799. KolmOut->SetShadowColor(0);
  800. KolmOut->SetTextSize(0.04);
  801. KolmOut->SetTextColor(kRed);
  802. TLegend *leg = new TLegend(0.55,0.7,0.85,0.85);
  803. leg->SetHeader(" ");
  804. leg->AddEntry(hist_nTracks,"Data","LEP");
  805. leg->AddEntry(hist_nTracks_MC,"MC","F");
  806. leg->SetLineColor(kWhite);
  807. leg->SetFillColor(kWhite);
  808. leg->SetTextSize(0.05);
  809. KolmOut->Draw();
  810. leg->Draw();
  811. addLHCbtag(0.65, 0.88, "");
  812. replace(canvasPath,".root",TMtype+".root");
  813. c1->SaveAs(canvasPath.c_str());
  814. replace(canvasPath,".root",".eps");
  815. c1->Print(canvasPath.c_str());
  816. delete leg;
  817. c1->Clear();
  818. delete c1;
  819. return;
  820. }
  821. void drawWeightRatio(TH1D *hist_w, string canvasPath, bool is2D, string TMtype){
  822. TCanvas* c2 = new TCanvas("c2", "c2");
  823. c2->SetGridy();
  824. c2->cd();
  825. //format colors and draw
  826. hist_w->GetYaxis()->SetRangeUser(-2., 6.);
  827. if (is2D) design_TH1D(hist_w,seconMClatex,"2 x 1D Weights of sim. Events",kBlue);
  828. else design_TH1D(hist_w,firstMClatex,"1D Weights of sim. Events",kBlue);
  829. hist_w->SetMarkerSize(1);
  830. hist_w->Draw("E1");
  831. addLHCbtag(0.25, 0.9, "");
  832. replace(canvasPath,".root",TMtype+".root");
  833. c2->SaveAs(canvasPath.c_str());
  834. replace(canvasPath,".root",".eps");
  835. c2->Print(canvasPath.c_str());
  836. c2->Clear();
  837. delete c2;
  838. return;
  839. }
  840. void drawWeightCorrelation(TH2D *hCorrelationCheck, double CorrelationCoefficent, string canvasPath){
  841. TCanvas * c4 = new TCanvas("c4", "c4");
  842. c4->SetRightMargin(0.19);
  843. c4->cd();
  844. //Adjust NTrack range
  845. hCorrelationCheck->GetXaxis()->SetRangeUser(0,150);
  846. //hCorrelationCheck->GetZaxis()->SetRangeUser(-5,270);
  847. hCorrelationCheck->GetZaxis()->SetTitleOffset(0.9);
  848. //format colors and draw
  849. hCorrelationCheck->GetXaxis()->SetTitle(firstMClatex.c_str());
  850. hCorrelationCheck->GetYaxis()->SetTitle("log(p_{T}(B^{+})) [MeV]");
  851. hCorrelationCheck->GetZaxis()->SetTitle("Entries [a.u.]");
  852. hCorrelationCheck->Draw("COLZ"); //TODO
  853. addLHCbtag(0.4, 0.9, "data", 0);
  854. TLatex* CorrCoe = new TLatex();
  855. CorrCoe->SetTextFont(132);
  856. CorrCoe->SetTextColor(0);
  857. CorrCoe->SetTextSize(0.05);
  858. CorrCoe->SetTextAlign(13);
  859. CorrCoe->SetNDC(1);
  860. CorrCoe->DrawLatex(0.4,0.83,Form("Correlation coefficient: %.3f", CorrelationCoefficent));
  861. c4->SaveAs(canvasPath.c_str());
  862. replace(canvasPath,".root",".eps");
  863. c4->Print(canvasPath.c_str());
  864. c4->Clear();
  865. delete c4;
  866. return;
  867. }
  868. ////////////////////////////////////
  869. ///
  870. ///
  871. /// BDT scan
  872. ///
  873. ///
  874. ////////////////////////////////////
  875. void designYieldGraph(TGraphErrors *graph, int Run, string year, string tag, string basicPath, TFile *TGraphOutput, bool fineScan){
  876. if (graph == NULL){
  877. coutWarning("Graph " + tag + " is void.");
  878. return;
  879. }
  880. coutInfo("Saving " + tag + " to file and plotting.");
  881. string graphName = string(TMVAmethod) + " ";
  882. graphName.append(tag);
  883. graphName.append( Run == 0 ? year : string("Run" + to_string(Run)) );
  884. designTGraph(graph,graphName,string(TMVAmethod)+"response", graphName, kBlue+3, 20);
  885. graph->SetMarkerSize(0.6);
  886. if (fineScan) graph->GetXaxis()->SetRangeUser(0.9,1.0);
  887. //Save in a file
  888. TGraphOutput->cd();
  889. graph->Write("",TObject::kWriteDelete);
  890. //Save in a canvas
  891. TCanvas * c1 = new TCanvas("c1", "c1");
  892. c1->cd();
  893. graph->Draw("ap");
  894. string path = basicPath;
  895. replace(path,".root","_"+tag+".eps");
  896. c1->SaveAs(path.c_str(),"eps");
  897. return;
  898. }
  899. ////////////////////////////////////
  900. ///
  901. ///
  902. /// Yiled plots
  903. ///
  904. ///
  905. ////////////////////////////////////
  906. void design_YieldInQ2(int Run, TGraphErrors *graphSig, TGraphErrors *graphBkg, TGraphErrors *graphSignificance, TGraphErrors *CMS, bool fixRange){
  907. string mainName = "Q2_Run" + to_string(Run);
  908. designTGraph(graphSig,"Signal","Q2","Yield",kBlack,20);
  909. designTGraph(graphBkg,"Background","Q2","Yield",kRed,20);
  910. graphSig->SetLineStyle(1);
  911. graphSig->SetLineWidth(1);
  912. graphSig->SetMarkerSize(0.5);
  913. graphBkg->SetLineStyle(1);
  914. graphBkg->SetLineWidth(1);
  915. graphBkg->SetMarkerSize(0.65);
  916. designTGraph(graphSignificance,"Significance","Q2","S/(S+B)",kBlue,20);
  917. designTGraph(CMS,"Significance_CMS","Q2","S/(S+B)",kGreen+2,20);
  918. graphSignificance->GetYaxis()->SetRangeUser(0.0,graphSignificance->GetY()[0]*1.5);
  919. graphSignificance->GetXaxis()->SetRangeUser(0.01,20);
  920. CMS->GetXaxis()->SetRangeUser(0.01,20);
  921. graphSignificance->SetLineWidth(3);
  922. CMS->SetLineWidth(3);
  923. //Create multigraphs
  924. TMultiGraph *mg = new TMultiGraph();
  925. mg->Add(graphSig,"AP");
  926. mg->Add(graphBkg,"AP");
  927. mg->Draw("AP");
  928. mg->GetYaxis()->SetTitle("Yield");
  929. mg->GetYaxis()->SetRangeUser(0.0,graphBkg->GetY()[1]*1.5);
  930. mg->GetXaxis()->SetRangeUser(0.01,20);
  931. mg->GetXaxis()->SetTitle("");
  932. TMultiGraph *mg_FoM = new TMultiGraph();
  933. mg_FoM->Add(graphSignificance,"AP");
  934. mg_FoM->Add(CMS,"AP");
  935. mg_FoM->Draw("AP");
  936. mg_FoM->GetYaxis()->SetTitle("S/(S+B)");
  937. mg_FoM->GetXaxis()->SetRangeUser(0.01,20);
  938. mg_FoM->GetXaxis()->SetTitle("q^{2} [GeV^{2}]");
  939. //Create a TCanvas
  940. TCanvas *c = c_Efficiency(mainName.c_str());
  941. c->cd();
  942. //Create two pads (to get significance y-axis on the right)
  943. TPad *pad1 = new TPad("pad1","",0,0,1,1);
  944. TPad *pad2 = new TPad("pad2","",0,0,1,1);
  945. pad2->SetFillStyle(4000); //will be transparent
  946. pad2->SetFrameFillStyle(0);
  947. pad1->SetRightMargin(0.16);
  948. pad2->SetRightMargin(0.16);
  949. pad1->Draw();
  950. pad1->cd();
  951. //Add legends
  952. TLegend *leg = new TLegend(0.15,0.93,0.52,0.82);
  953. leg->AddEntry(graphSig, "Signal yield","l");
  954. leg->AddEntry(graphBkg, "Background yield","l");
  955. TLegend *legSignificance = new TLegend(0.52,0.93,0.8,0.82);
  956. legSignificance->AddEntry(graphSignificance, "Significance","l");
  957. legSignificance->AddEntry(CMS, "CMS","l");
  958. //Plot it
  959. pad1->cd();
  960. gStyle->SetGridColor(kGray);
  961. pad1->SetGridy();
  962. pad1->SetGridx();
  963. mg->Draw("SAME");
  964. mg->GetYaxis()->SetTitle("Yield");
  965. mg->GetYaxis()->SetRangeUser(0.0,graphBkg->GetY()[1]*1.5);
  966. mg->GetXaxis()->SetRangeUser(0.01,20);
  967. mg->GetXaxis()->SetLabelSize(0);
  968. mg->GetYaxis()->SetTickLength(0);
  969. leg->Draw("SAME");
  970. pad1->Update();
  971. c->cd();
  972. pad2->Draw();
  973. pad2->cd();
  974. //Get axis on the left side
  975. TGaxis *axis = new TGaxis(20,0.01,20,graphSignificance->GetY()[0]*1.5,0,graphSignificance->GetY()[0]*1.75,510,"+L");
  976. axis->SetTitle("S/sqrt(S+B)");
  977. axis->SetTextFont(21);
  978. mg_FoM->Draw("AP");
  979. mg_FoM->GetXaxis()->SetRangeUser(0.01,20);
  980. mg_FoM->GetYaxis()->SetRangeUser(0.0,graphSignificance->GetY()[0]*1.5);
  981. mg_FoM->GetYaxis()->SetLabelSize(0);
  982. mg_FoM->GetYaxis()->SetTickLength(0);
  983. mg_FoM->GetYaxis()->SetTitle("");
  984. axis->Draw("SAME");
  985. legSignificance->Draw("SAME");
  986. pad2->Update();
  987. c->cd();
  988. //Save it
  989. string path = GetBDTScanFile("","both",Run,false,false,false);
  990. replace(path,"BDTscan","Q2");
  991. if (!fixRange) replace(path,".root","_sigma.root");
  992. TFile *file = new TFile (path.c_str(), "RECREATE");
  993. file->cd();
  994. graphSig->Write();
  995. graphBkg->Write();
  996. graphSignificance->Write();
  997. CMS->Write();
  998. c->Write();
  999. file->Close();
  1000. replace(path,".root",".eps");
  1001. c->SaveAs(path.c_str());
  1002. return;
  1003. }
  1004. void design_SignificanceInQ2(int Run, TGraphErrors *graphSignificance, TGraphErrors *CMS, bool fixRange){
  1005. string mainName = "Q2_Run" + to_string(Run);
  1006. designTGraph(graphSignificance,"Significance","Q2","S/(S+B)",kBlue,20);
  1007. designTGraph(CMS,"Significance_CMS","Q2","S/(S+B)",kGreen+2,20);
  1008. graphSignificance->GetYaxis()->SetRangeUser(0.0,graphSignificance->GetY()[0]*1.5);
  1009. graphSignificance->GetXaxis()->SetRangeUser(0.01,20);
  1010. CMS->GetXaxis()->SetRangeUser(0.01,20);
  1011. graphSignificance->SetLineWidth(3);
  1012. CMS->SetLineWidth(3);
  1013. //Create multigraph
  1014. TMultiGraph *mg_FoM = new TMultiGraph();
  1015. mg_FoM->Add(graphSignificance,"AP");
  1016. mg_FoM->Add(CMS,"AP");
  1017. mg_FoM->Draw("AP");
  1018. //Create a TCanvas
  1019. TCanvas *c = c_canvas(mainName.c_str());
  1020. gStyle->SetGridColor(kGray);
  1021. c->SetGridy();
  1022. c->SetGridx();
  1023. c->SetBottomMargin(0.16);
  1024. //Add legend
  1025. TLegend *legSignificance = new TLegend(0.35,0.9,0.65,0.75);
  1026. legSignificance->AddEntry(graphSignificance, "Significance","l");
  1027. legSignificance->AddEntry(CMS, "CMS","l");
  1028. //Plot it
  1029. c->cd();
  1030. mg_FoM->Draw("AP");
  1031. mg_FoM->GetYaxis()->SetTitle("S/(S+B)");
  1032. mg_FoM->GetXaxis()->SetRangeUser(0.01,20);
  1033. mg_FoM->GetYaxis()->SetRangeUser(0.0,graphSignificance->GetY()[0]*1.5);
  1034. mg_FoM->GetXaxis()->SetTitle("q^{2} [GeV^{2}]");
  1035. legSignificance->Draw("SAME");
  1036. c->Update();
  1037. //Save it
  1038. string path = GetBDTScanFile("","both",Run,false,false,false);
  1039. replace(path,"BDTscan","Q2_sigOnly");
  1040. if (!fixRange) replace(path,".root","_sigma.root");
  1041. TFile *file = new TFile (path.c_str(), "RECREATE");
  1042. file->cd();
  1043. graphSignificance->Write();
  1044. CMS->Write();
  1045. c->Write();
  1046. file->Close();
  1047. replace(path,".root",".eps");
  1048. c->SaveAs(path.c_str());
  1049. return;
  1050. }