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.

621 lines
20 KiB

  1. //Renata Kopecna
  2. #include <design.hh>
  3. #include <constants.hh>
  4. #include <helpers.hh>
  5. #include <TROOT.h>
  6. #include <TBox.h>
  7. #include <TPaveText.h>
  8. #include <TF1.h>
  9. #include <TLegend.h>
  10. #include <TMultiGraph.h>
  11. #include <TStyle.h>
  12. #include <TFile.h>
  13. #include <TGaxis.h>
  14. #include <sstream>
  15. #include <iostream>
  16. //=========================================
  17. //
  18. // Latex in plots
  19. //
  20. //=========================================
  21. std::string latex_decay(bool DTF){
  22. //return "K_{S}^{0}#pi^{+}#mu^{+}#mu^{-}";
  23. if (DTF) return "K^{+}#pi^{0}#mu^{+}#mu^{-}";
  24. else return "#K^{+}#gamma#gamma#mu^{+}#mu^{-}";
  25. }
  26. std::string latex_Kst_decay(bool DTF){
  27. if (DTF) return "K^{+}#pi^{0}";
  28. else return "#K^{+}#gamma#gamma";
  29. }
  30. std::string MeVc(){
  31. return "MeV";
  32. }
  33. std::string GeVc(){
  34. return "GeV";
  35. }
  36. std::string GeVc_2(){
  37. return "GeV^{2}";
  38. }
  39. std::string latex_pull(){
  40. return "(x-x_{0})/#sigma";
  41. }
  42. std::string latex_angle(std::string angle, bool &is_ctl, bool &is_ctk, bool &is_phi){
  43. if(strcmp(angle.c_str(), "ctk") == 0){
  44. is_ctk = true;
  45. return "cos(#Theta_{K})";
  46. }
  47. else if(strcmp(angle.c_str(), "ctl") == 0){
  48. is_ctl = true;
  49. return "cos(#Theta_{L})";
  50. }
  51. else if(strcmp(angle.c_str(), "phi") == 0){
  52. is_phi = true;
  53. return "#phi [rad]";
  54. }
  55. return "";
  56. }
  57. //Define the angles as chars, because ROOT
  58. //Very not cool, but also very not cool
  59. //of ROOT to not accept strings and I cannot be bothered
  60. const char *LATEX_Q2_CH() { return LATEX_Q2.c_str(); }
  61. const char *LATEX_TL_CH() { return LATEX_TL.c_str(); }
  62. const char *LATEX_CTL_CH(){ return LATEX_CTL.c_str();}
  63. const char *LATEX_TK_CH() { return LATEX_TK.c_str(); }
  64. const char *LATEX_CTK_CH(){ return LATEX_CTK.c_str();}
  65. const char *LATEX_PHI_CH(){ return LATEX_PHI.c_str();}
  66. std::string q2_label(double low_q2, double high_q2){
  67. std::ostringstream qqbin; //TODO
  68. qqbin << std::fixed << std::setprecision(2) <<low_q2<< " < q^{2} < " << high_q2;
  69. return qqbin.str();
  70. }
  71. //=========================================
  72. //
  73. // General
  74. //
  75. //=========================================
  76. void set_gStyle(){
  77. gStyle->SetOptStat(0);
  78. gStyle->SetOptFit(0);
  79. gStyle->SetLabelFont(132, "xyz");
  80. gStyle->SetTitleFont(132, "xyz");
  81. gStyle->SetLegendFont(132);
  82. gStyle->SetStatFont(132);
  83. gStyle->SetPaintTextFormat(".1f");
  84. }
  85. //Save canvas with a given name and automatically append the type
  86. //Type should be specified without the dot, so eg "eps" instead of ".eps
  87. void saveTCanvas(TCanvas *c, std::string name, std::string type){
  88. c->Print((name+"."+type).c_str(), type.c_str());
  89. return;
  90. }
  91. //Save several file types in one go
  92. void saveTCanvas(TCanvas *c, std::string name, std::vector<std::string> types){
  93. for (auto type: types) saveTCanvas(c,name,type);
  94. return;
  95. }
  96. TLine *threeSigmaLine(double min, double max, bool plus){
  97. int sigma = plus ? +3.0 : -3.0;
  98. TLine * line = new TLine(min, sigma, max, sigma);
  99. line->SetLineStyle(5);
  100. line->SetLineWidth(gStyle->GetLineWidth());
  101. return line;
  102. }
  103. TLine *oneSigmaLine(double min, double max, bool plus){
  104. int sigma = plus ? +1.0 : -1.0;
  105. TLine * line = new TLine(min, sigma, max, sigma);
  106. line->SetLineStyle(7);
  107. line->SetLineWidth(gStyle->GetLineWidth());
  108. return line;
  109. }
  110. void plotAndSave(TH1D *hist, std::string canvasName, std::string targetPath, std::string plotType){
  111. TCanvas* cnvs = new TCanvas(canvasName.c_str(), canvasName.c_str(), 1600, 1200);
  112. cnvs->cd();
  113. hist->Draw();
  114. saveTCanvas(cnvs,targetPath, plotType);
  115. delete cnvs;
  116. return;
  117. }
  118. void plotAndSave(TH2D *hist, std::string canvasName, std::string targetPath, std::string plotType){
  119. TCanvas* cnvs = new TCanvas(canvasName.c_str(), canvasName.c_str(), 1600, 1200);
  120. cnvs->cd();
  121. hist->Draw("COLZ");
  122. saveTCanvas(cnvs,targetPath, plotType);
  123. delete cnvs;
  124. return;
  125. }
  126. void plotAndSaveWithLine(TH1D* hist, TF1 *line, std::string canvasName, std::string targetPath, std::string plotType){
  127. //Create canvas
  128. TCanvas* cnvs = new TCanvas(canvasName.c_str(), canvasName.c_str(), 1600, 1200);
  129. cnvs->cd();
  130. //Add legend
  131. //TLatex cannot do break lines and I cannot. Even.
  132. TPaveText *leg = new TPaveText(0.55,0.65,0.87,0.87);
  133. leg->Paint("NDC");
  134. leg->SetFillColor(kWhite);
  135. leg->SetTextFont(132);
  136. //Loop over params and print them
  137. for (int n = 0; n < line->GetNpar(); n++){
  138. std::ostringstream sParams;
  139. sParams << line->GetParName(n) << ": " << std::fixed << std::setprecision(4) << line->GetParameter(n) << "#pm" << line->GetParError(n);
  140. leg->AddText(sParams.str().c_str());
  141. }
  142. //Draw
  143. hist->Draw("E1");
  144. line->Draw("same");
  145. leg->Draw("same");
  146. //Save
  147. cnvs->Print((targetPath+"."+plotType).c_str(), plotType.c_str());
  148. //Delete and return
  149. delete leg;
  150. delete cnvs;
  151. return;
  152. }
  153. //Sets TLatex
  154. TLatex *getPrettyTex(double TextFontSize, int TextAlign){
  155. TLatex *tex = new TLatex();
  156. tex->SetNDC(true);
  157. tex->SetTextFont(132);
  158. tex->SetTextSize(TextFontSize);
  159. tex->SetTextAlign(TextAlign);
  160. return tex;
  161. }
  162. //Add myThesis tag
  163. void addThesistag(double x = 0.6, double y = 0.85, int color = 1, double scaling = 1.0){
  164. if (!PLOT_THISTHESIS_TAG) return;
  165. TLatex* lhcbtext = getPrettyTex(0.07*scaling, 13);
  166. lhcbtext->SetTextColor(color);
  167. lhcbtext->DrawLatex(x,y,THISTHESIS_TAG.c_str());
  168. return;
  169. }
  170. //Add lhcb tag
  171. void addLHCbtag(double x = 0.6, double y = 0.85, std::string suffix = "", int color = 1, double scaling = 1.0){
  172. TLatex* lhcbtext = getPrettyTex(0.07*scaling, 13);
  173. lhcbtext->SetTextColor(color);
  174. lhcbtext->DrawLatex(x,y,("LHCb "+suffix).c_str());
  175. return;
  176. }
  177. //=========================================
  178. //
  179. // Angular correction plots
  180. //
  181. //=========================================
  182. //plot eff histograms for angular corrections
  183. void plotAngular(TH1D *hist, TH1D *moments, bool write,std::string name,
  184. std::string appendix, std::string q2region,
  185. TLatex *tex, std::string folderName){
  186. TCanvas* c0 = new TCanvas("c0", "c0", 1600, 1200);
  187. c0->cd();
  188. hist->Scale(hist->GetNbinsX()/hist->Integral());
  189. hist->SetMinimum(0.0);
  190. hist->Draw();
  191. hist->GetYaxis()->SetTitle("Normalized entries (a.u.)");
  192. moments->Scale(moments->GetNbinsX()/moments->Integral());
  193. addLHCbtag(0.15,0.27,"simulation",1,1.0);
  194. addThesistag(0.15,0.20,1,0.9);
  195. moments->Draw("samel");
  196. if (q2region != "") tex->DrawLatex(0.85, 0.15, q2region.c_str());
  197. if (write) saveTCanvas(c0,folderName+name+appendix,"eps");
  198. delete c0;
  199. }
  200. //Overload the plot without plotting q2 region
  201. void plotAngular(TH1D *hist, TH1D *moments, bool write,std::string name, std::string appendix, std::string folderName){
  202. TLatex *tex = new TLatex();
  203. plotAngular(hist, moments, write, name, appendix, "", tex, folderName);
  204. }
  205. //plot 2D histograms for angular corrections
  206. void plotAngular(TH2D *hist, TH2D *moments, bool write, std::string name, std::string appendix, std::string q2region, TLatex *tex, std::string folderName){
  207. TCanvas* c0 = new TCanvas("c0", "c0", 1600, 800);
  208. c0->Divide(2,1);
  209. c0->cd(1);
  210. hist->Scale(hist->GetNbinsX()*hist->GetNbinsY()/hist->Integral());
  211. hist->SetMinimum(0.0);
  212. hist->SetMaximum(1.4);
  213. hist->Draw("colz");
  214. c0->cd(2);
  215. moments->Scale(moments->GetNbinsX()*moments->GetNbinsY()/moments->Integral());
  216. moments->SetMinimum(0.0);
  217. moments->SetMaximum(1.4);
  218. moments->Draw("colz");
  219. if (q2region != "") tex->DrawLatex(0.85, 0.15, q2region.c_str());
  220. if (write) saveTCanvas(c0,folderName+name+appendix,"eps");
  221. delete c0;
  222. }
  223. //Overload the plot without plotting q2 region
  224. void plotAngular(TH2D *hist, TH2D *moments, bool write,std::string name, std::string appendix, std::string folderName){
  225. TLatex *tex = new TLatex();
  226. plotAngular(hist, moments, write, name, appendix, "", tex, folderName);
  227. }
  228. //Plot all the angular corrections in one canvas
  229. void plotAngularInOne(TCanvas *c, int whichC, TH1D *moments, TH1D *ub, TH1D *hist, TH1D* ml, bool run_minuit, double q2min, double q2max, double y, bool cross){
  230. c->cd(whichC)->SetMargin(0.15,0.05,0.1,0.05);
  231. moments->Draw("l");
  232. TLine* line= new TLine();
  233. line->SetLineStyle(kDashed);
  234. if (cross){
  235. line->SetLineColor(kGray+1);
  236. line->DrawLine(q2min, -0.5, q2max, +0.5);
  237. line->DrawLine(q2min, +0.5, q2max, -0.5);
  238. }
  239. else{
  240. ub->Draw("same");
  241. hist->Draw("same");
  242. if (run_minuit) ml->Draw("lsame");
  243. line->SetLineColor(kRed);
  244. line->DrawLine(q2min, y, q2max, y);
  245. }
  246. }
  247. //Label axes for angular correction polynomial scan
  248. void labelAngularScan(std::vector<int>scan_low, std::vector<int>scan_range,TH2D *hist){
  249. //label the x-axis
  250. //loop over the range in thetak and thetal and print all possible combination
  251. for(int tk = 0; tk < scan_range.at(1); tk++){
  252. for(int tl = 0; tl < scan_range.at(2); tl++){
  253. hist->GetXaxis()->SetBinLabel(tk * scan_range.at(2) + tl + 1, //+1 because bins start at 1
  254. ("#bf{"+std::to_string(tk+scan_low.at(1))+"} - "+std::to_string(tl+scan_low.at(2))).c_str());
  255. }
  256. }
  257. //label the y-axis
  258. for(int qq = 0; qq < scan_range.at(0); qq++){
  259. for(int fi =0; fi < scan_range.at(3); fi++){
  260. hist->GetYaxis()->SetBinLabel(qq * scan_range.at(3) + fi + 1,
  261. ("#bf{"+std::to_string(qq+scan_low.at(0))+"} - "+std::to_string(fi+scan_low.at(3))).c_str());
  262. }
  263. }
  264. //draw labels on x-axis vertically
  265. hist->GetXaxis()->LabelsOption("v");
  266. return;
  267. }
  268. //=========================================
  269. //
  270. // Fit results plots
  271. //
  272. //=========================================
  273. int design_pull_basic(TH1D *pull, Float_t textsize, double eff_pullHeight){
  274. pull->GetXaxis()->SetNoExponent(); //<-- spoils MaxDigits settings, so don't use it on other axis
  275. pull->GetXaxis()->SetNdivisions(gStyle->GetNdivisions("X"));
  276. pull->GetYaxis()->SetTitleSize(textsize/eff_pullHeight);
  277. pull->GetYaxis()->SetLabelSize(textsize/eff_pullHeight);
  278. pull->GetYaxis()->SetTitleOffset(gStyle->GetTitleOffset()*eff_pullHeight);
  279. return 0;
  280. }
  281. int design_pull(TH1D *pull, Color_t lineColor, Color_t fillColor, double eff_pullHeight, double pullFrameRange){
  282. Float_t textsize = gStyle->GetTextSize();
  283. pull->GetXaxis()->SetTitleOffset(1.05);
  284. design_pull_basic(pull, textsize, eff_pullHeight);
  285. pull->GetXaxis()->SetTitleSize (textsize/eff_pullHeight);
  286. pull->GetXaxis()->SetLabelSize (textsize/eff_pullHeight);
  287. pull->GetXaxis()->SetTickLength (pull->GetXaxis()->GetTickLength()/(eff_pullHeight/(1-eff_pullHeight)));
  288. pull->GetYaxis()->CenterTitle();
  289. pull->GetYaxis()->SetNdivisions (3, 9, 0, kTRUE);//gStyle->GetNdivisions("Y"));
  290. pull->GetYaxis()->SetRangeUser (-pullFrameRange, pullFrameRange);
  291. pull->SetFillColor(fillColor);
  292. pull->SetLineColor(lineColor);
  293. pull->SetLineWidth(1);
  294. return 0;
  295. }
  296. int design_pull(TGraphErrors *pull, Color_t lineColor, Color_t fillColor, double eff_pullHeight, double pullFrameRange){
  297. Float_t textsize = gStyle->GetTextSize();
  298. pull->GetXaxis()->SetTitleOffset(1.05);
  299. pull->GetXaxis()->SetNoExponent(); //<-- spoils MaxDigits settings, so don't use it on other axis
  300. pull->GetYaxis()->SetTitleSize(textsize/eff_pullHeight);
  301. pull->GetYaxis()->SetLabelSize(textsize/eff_pullHeight);
  302. pull->GetYaxis()->SetTitleOffset(gStyle->GetTitleOffset()*eff_pullHeight);
  303. pull->GetXaxis()->SetTitleSize (textsize/eff_pullHeight);
  304. pull->GetXaxis()->SetLabelSize (textsize/eff_pullHeight);
  305. pull->GetXaxis()->SetTickLength (pull->GetXaxis()->GetTickLength()/(eff_pullHeight/(1-eff_pullHeight)));
  306. pull->GetYaxis()->CenterTitle();
  307. pull->GetYaxis()->SetRangeUser (-pullFrameRange, pullFrameRange);
  308. pull->SetFillColor(fillColor);
  309. pull->SetLineColor(lineColor);
  310. pull->SetLineWidth(1);
  311. return 0;
  312. }
  313. void drawResonances(TCanvas *c, double min, double max){
  314. c->cd();
  315. TBox* box = new TBox();
  316. box->SetFillColor(21);
  317. box->SetLineColor(21);
  318. box->SetFillStyle(1001);
  319. box->DrawBox(0.98, min, 1.10, max);
  320. box->DrawBox(8.0, min, 11.0, max);
  321. box->DrawBox(12.5, min, 15.0, max);
  322. c->Update(); //Probably not needed, but just ot be sure
  323. return;
  324. }
  325. void drawResonances(TPad *c, double min, double max){
  326. c->cd();
  327. TBox* box = new TBox();
  328. box->SetFillColor(21);
  329. box->SetLineColor(21);
  330. box->SetFillStyle(1001);
  331. box->DrawBox(0.98, min, 1.10, max);
  332. box->DrawBox(8.0, min, 11.0, max);
  333. box->DrawBox(12.5, min, 15.0, max);
  334. c->Update(); //Probably not needed, but just ot be sure
  335. return;
  336. }
  337. void designTGraph(TGraphErrors *graph, std::string title, std::string xAxisName, std::string yAxisName, Color_t color, Int_t markerStyle){
  338. graph->SetName(title.c_str());
  339. graph->SetLineColor(color);
  340. //graph->SetLineWidth(0);
  341. graph->SetMarkerStyle(markerStyle);
  342. graph->SetMarkerColor(color);
  343. graph->GetXaxis()->SetTitle(xAxisName.c_str());
  344. graph->GetYaxis()->SetTitle(yAxisName.c_str());
  345. graph->GetXaxis()->SetTitleOffset(1.0);
  346. graph->GetYaxis()->SetTitleOffset(1.7);
  347. graph->SetTitle("");
  348. graph->GetXaxis()->SetLabelSize(0.09);
  349. graph->GetYaxis()->SetLabelSize(0.09);
  350. graph->GetXaxis()->SetTitleSize(0.07);
  351. graph->GetYaxis()->SetTitleSize(0.05);
  352. return;
  353. }
  354. void designMultiGraph(TMultiGraph *multGraph, std::string title, std::string xAxisName, std::string yAxisName){
  355. //One needs to draw the multGraph first!
  356. multGraph->SetName(title.c_str());
  357. multGraph->GetXaxis()->SetTitle(xAxisName.c_str());
  358. multGraph->GetYaxis()->SetTitle(yAxisName.c_str());
  359. gStyle->SetOptStat(0);
  360. multGraph->GetXaxis()->SetTitleOffset(1.0);
  361. multGraph->GetYaxis()->SetTitleOffset(1.4);
  362. multGraph->SetTitle("");
  363. multGraph->GetXaxis()->SetLabelSize(0.05);
  364. multGraph->GetYaxis()->SetLabelSize(0.05);
  365. multGraph->GetXaxis()->SetTitleSize(0.05);
  366. multGraph->GetYaxis()->SetTitleSize(0.055);
  367. return;
  368. }
  369. int design_YieldInQ2(int Run, TGraphErrors *graphSig, TGraphErrors *graphBkg, TGraphErrors *graphSignificance, TGraphErrors *CMS, bool fixRange, std::string savePath, std::vector<std::string> extensions){
  370. std::string mainName = "Q2_Run" + std::to_string(Run);
  371. double y_scale = 1.5;
  372. double y_scale_1 = (Run==1) ? 2.5 : 1.75;
  373. //Create a TCanvas
  374. TCanvas *c = new TCanvas(mainName.c_str(),mainName.c_str(),750, 575);
  375. c->SetRightMargin(0.13);
  376. c->SetLeftMargin(0.23);
  377. c->SetTopMargin(0.075);
  378. c->SetBottomMargin(0.12);
  379. c->cd();
  380. designTGraph(graphSig,"Signal","Q2","Yield",kBlack,20);
  381. designTGraph(graphBkg,"Background","Q2","Yield",kRed,20);
  382. graphSig->SetLineStyle(1);
  383. graphSig->SetLineWidth(1);
  384. graphSig->SetMarkerSize(0.5);
  385. graphBkg->SetLineStyle(1);
  386. graphBkg->SetLineWidth(1);
  387. graphBkg->SetMarkerSize(0.65);
  388. designTGraph(graphSignificance,"Significance","Q2","S/(S+B)",kBlue,20);
  389. designTGraph(CMS,"Significance_CMS","Q2","S/(S+B)",kGreen+2,20);
  390. graphSignificance->GetYaxis()->SetRangeUser(0.0,graphSignificance->GetY()[0]*y_scale);
  391. graphSignificance->GetXaxis()->SetRangeUser(Q2_MIN_RANGE,Q2_MAX_RANGE);
  392. CMS->GetXaxis()->SetRangeUser(Q2_MIN_RANGE,Q2_MAX_RANGE);
  393. graphSignificance->SetLineWidth(3);
  394. CMS->SetLineWidth(3);
  395. //Create multigraphs
  396. TMultiGraph *mg = new TMultiGraph();
  397. mg->Add(graphSig,"AP");
  398. mg->Add(graphBkg,"AP");
  399. mg->Draw("AP");
  400. mg->GetYaxis()->SetRangeUser(0.0,graphBkg->GetY()[1]*y_scale);
  401. mg->GetXaxis()->SetRangeUser(Q2_MIN_RANGE,Q2_MAX_RANGE);
  402. designMultiGraph(mg,"","q^{2} [GeV^{2}]","Yield");
  403. TMultiGraph *mg_FoM = new TMultiGraph();
  404. mg_FoM->Add(graphSignificance,"AP");
  405. mg_FoM->Add(CMS,"AP");
  406. mg_FoM->Draw("AP");
  407. mg_FoM->GetXaxis()->SetRangeUser(Q2_MIN_RANGE,Q2_MAX_RANGE);
  408. designMultiGraph(mg_FoM,"","q^{2} [GeV^{2}]","S/(S+B)");
  409. //Create two pads (to get significance y-axis on the right)
  410. TPad *pad1 = new TPad("pad1","",0,0,1,1);
  411. TPad *pad2 = new TPad("pad2","",0,0,1,1);
  412. pad2->SetFillStyle(4000); //will be transparent
  413. pad2->SetFrameFillStyle(0);
  414. pad1->SetRightMargin(0.13);
  415. pad1->SetLeftMargin(0.15);
  416. pad1->SetTopMargin(0.07);
  417. pad1->SetBottomMargin(0.12);
  418. pad2->SetRightMargin(0.13);
  419. pad2->SetLeftMargin(0.15);
  420. pad2->SetTopMargin(0.07);
  421. pad2->SetBottomMargin(0.12);
  422. pad1->Draw();
  423. pad1->cd();
  424. //Add legends
  425. TLegend *leg = new TLegend(0.15,0.93,0.52,0.82);
  426. leg->AddEntry(graphSig, "Signal yield","l");
  427. leg->AddEntry(graphBkg, "Background yield","l");
  428. TLegend *legSignificance = new TLegend(0.52,0.93,0.8,0.82);
  429. legSignificance->AddEntry(graphSignificance, "Significance","l");
  430. legSignificance->AddEntry(CMS, "CMS","l");
  431. //Plot it
  432. pad1->cd();
  433. gStyle->SetGridColor(kGray);
  434. pad1->SetGridy();
  435. pad1->SetGridx();
  436. mg->Draw("SAME");
  437. mg->GetYaxis()->SetTitle("Yield");
  438. mg->GetYaxis()->SetRangeUser(0.0,graphBkg->GetY()[1]*y_scale);
  439. mg->GetXaxis()->SetRangeUser(Q2_MIN_RANGE,Q2_MAX_RANGE);
  440. mg->GetXaxis()->SetLabelSize(0);
  441. mg->GetYaxis()->SetTickLength(0);
  442. leg->Draw("SAME");
  443. pad1->Update();
  444. c->cd();
  445. pad2->Draw();
  446. pad2->cd();
  447. //Get axis on the left side
  448. TGaxis *axis = new TGaxis(Q2_MAX_RANGE,0.0,Q2_MAX_RANGE,graphSignificance->GetY()[0]*y_scale_1,0,graphSignificance->GetY()[0]*y_scale_1,510,"+L");
  449. axis->SetTitle("S/sqrt(S+B)");
  450. axis->SetTextFont(21);
  451. mg_FoM->Draw("AP");
  452. mg_FoM->GetXaxis()->SetRangeUser(Q2_MIN_RANGE,Q2_MAX_RANGE);
  453. mg_FoM->GetYaxis()->SetRangeUser(0.0,graphSignificance->GetY()[0]*y_scale_1);
  454. mg_FoM->GetYaxis()->SetLabelSize(0);
  455. mg_FoM->GetYaxis()->SetTickLength(0);
  456. mg_FoM->GetYaxis()->SetTitle("");
  457. axis->Draw("SAME");
  458. legSignificance->Draw("SAME");
  459. pad2->Update();
  460. c->cd();
  461. //Save it
  462. if (!fixRange) savePath = savePath + "_sigma";
  463. TFile *file = new TFile ((savePath+".root").c_str(), "RECREATE");
  464. file->cd();
  465. graphSig->Write();
  466. graphBkg->Write();
  467. graphSignificance->Write();
  468. CMS->Write();
  469. c->Write();
  470. file->Close();
  471. saveTCanvas(c,savePath,extensions);
  472. return 0;
  473. }
  474. int design_SignificanceInQ2(int Run, TGraphErrors *graphSignificance, TGraphErrors *CMS, bool fixRange, std::string savePath, std::vector<std::string>extensions){
  475. std::string mainName = "Q2_Run" + std::to_string(Run);
  476. double y_scale = 1.4;
  477. //Create a TCanvas
  478. TCanvas *c = new TCanvas(mainName.c_str(),mainName.c_str(),750, 600);
  479. c->SetRightMargin(0.13);
  480. c->SetLeftMargin(0.15);
  481. c->SetTopMargin(0.07);
  482. c->SetBottomMargin(0.12);
  483. gStyle->SetGridColor(kGray);
  484. c->SetGridy();
  485. c->SetGridx();
  486. c->SetBottomMargin(0.16);
  487. designTGraph(graphSignificance,"Significance","Q2","S/(S+B)",kBlue,20);
  488. designTGraph(CMS,"Significance_CMS","Q2","S/(S+B)",kGreen+2,20);
  489. graphSignificance->GetYaxis()->SetRangeUser(0.0,graphSignificance->GetY()[0]*y_scale);
  490. graphSignificance->GetXaxis()->SetRangeUser(Q2_MIN_RANGE,Q2_MAX_RANGE);
  491. CMS->GetXaxis()->SetRangeUser(Q2_MIN_RANGE,Q2_MAX_RANGE);
  492. graphSignificance->SetLineWidth(3);
  493. CMS->SetLineWidth(3);
  494. //Create multigraph
  495. TMultiGraph *mg_FoM = new TMultiGraph();
  496. mg_FoM->Add(graphSignificance,"AP");
  497. mg_FoM->Add(CMS,"AP");
  498. mg_FoM->Draw("AP");
  499. designMultiGraph(mg_FoM,"","q^{2} [GeV^{2}]","S/(S+B)");
  500. //Add legend
  501. TLegend *legSignificance = new TLegend(0.35,0.9,0.65,0.75);
  502. legSignificance->AddEntry(graphSignificance, "Significance","l");
  503. legSignificance->AddEntry(CMS, "CMS","l");
  504. //Plot it
  505. c->cd();
  506. mg_FoM->Draw("AP");
  507. mg_FoM->GetYaxis()->SetTitle("S/(S+B)");
  508. mg_FoM->GetXaxis()->SetRangeUser(Q2_MIN_RANGE,Q2_MAX_RANGE);
  509. mg_FoM->GetYaxis()->SetRangeUser(0.0,graphSignificance->GetY()[0]*y_scale);
  510. mg_FoM->GetXaxis()->SetTitle("q^{2} [GeV^{2}]");
  511. legSignificance->Draw("SAME");
  512. c->Update();
  513. //Save it
  514. if (!fixRange) savePath = savePath + "_sigma";
  515. TFile *file = new TFile ((savePath+".root").c_str(), "RECREATE");
  516. file->cd();
  517. graphSignificance->Write();
  518. CMS->Write();
  519. c->Write();
  520. file->Close();
  521. saveTCanvas(c,savePath,extensions);
  522. return 0;
  523. }