DrawTGraph.C 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  1. #include <TROOT.h>
  2. #include <TStyle.h>
  3. #include <TGraphErrors.h>
  4. #include <TFile.h>
  5. #include <TString.h>
  6. #include <TH1F.h>
  7. #include <TProfile.h>
  8. #include <TCanvas.h>
  9. #include <TPad.h>
  10. #include <TLegend.h>
  11. #include <TMath.h>
  12. #include <TLine.h>
  13. #include <TLatex.h>
  14. #include <iostream>
  15. // Draws 2 TGraphErrors (upper panel) with their gr1/gr2 ratio (lower pannel)
  16. TCanvas *DrawTGraph(TGraphErrors *const &gr1, TGraphErrors *const &gr2, TString str = "",
  17. Double_t yRatio_low = 0.89, Double_t yRatio_high = 1.11)
  18. {
  19. // Setting up global variables for the plot
  20. gROOT->SetStyle("Pub");
  21. gROOT->ForceStyle();
  22. gStyle->SetPalette(kDarkRainBow);
  23. gStyle->SetErrorX(0);
  24. // Read points
  25. Double_t *vx_gr1 = gr1->GetX();
  26. Double_t *vy_gr1 = gr1->GetY();
  27. Double_t *vx_gr2 = gr2->GetX();
  28. Double_t *vy_gr2 = gr2->GetY();
  29. // Read errors
  30. Double_t *ex_gr1 = gr1->GetEX();
  31. Double_t *ey_gr1 = gr1->GetEY();
  32. Double_t *ex_gr2 = gr2->GetEX();
  33. Double_t *ey_gr2 = gr2->GetEY();
  34. Int_t n1bins = gr1->GetN();
  35. // Initialization of the canvas & pads
  36. TCanvas *canv = new TCanvas(Form("canv"), Form("Canvas"), 900, 800);
  37. canv->cd();
  38. TPad *padUp = new TPad(Form("padUp"), "v2 vs pt", 0., 0.33, 1., 1., 0, -1, 0);
  39. TPad *padDown = new TPad(Form("padDown"), "Ratio v2", 0., 0., 1., 0.33, 0, -1, 0);
  40. double padUW;
  41. double padUH;
  42. double padDW;
  43. double padDH;
  44. padUp->SetBorderSize(0);
  45. padDown->SetBorderSize(0);
  46. padUp->SetBottomMargin(0.);
  47. padDown->SetTopMargin(0.005);
  48. padUW = padUp->GetWw() * padUp->GetAbsWNDC();
  49. padUH = padUp->GetWh() * padUp->GetAbsHNDC();
  50. padDW = padDown->GetWw() * padDown->GetAbsWNDC();
  51. padDH = padDown->GetWh() * padDown->GetAbsHNDC();
  52. padUp->Draw();
  53. padDown->Draw();
  54. // Setting up markers & colors for TGraphErrors
  55. gr1->SetMarkerStyle(26);
  56. gr1->SetMarkerSize(1.6);
  57. gr1->SetLineColor(kRed);
  58. gr1->SetMarkerColor(kRed);
  59. gr2->SetMarkerStyle(20);
  60. gr2->SetMarkerSize(1.6);
  61. gr2->SetLineColor(kBlack);
  62. gr2->SetMarkerColor(kBlack);
  63. // Draw TGraphErrors in the upper pad
  64. padUp->cd();
  65. gr1->GetXaxis()->SetLimits(0.95 * vx_gr1[0], 1.05 * vx_gr1[n1bins - 1]);
  66. gr1->GetXaxis()->SetLabelSize(0.06);
  67. gr1->GetYaxis()->SetLabelSize(0.06);
  68. gr1->GetXaxis()->SetTitleSize(0.07);
  69. gr1->GetYaxis()->SetTitleSize(0.07);
  70. gr1->GetYaxis()->SetTitleOffset(1.08);
  71. gr1->Draw("AP");
  72. gr2->Draw("P");
  73. TLegend *leg_pt = new TLegend(0.468, 0.04, 0.89, 0.309);
  74. leg_pt->SetBorderSize(0);
  75. leg_pt->SetHeader(str.Data(), "C");
  76. // leg_pt->SetHeader(Form("Au+Au,#sqrt{s_{NN}}=200 GeV"),"C");
  77. leg_pt->AddEntry(gr1, Form("%s", gr1->GetTitle()), "p");
  78. leg_pt->AddEntry(gr2, Form("%s", gr2->GetTitle()), "p");
  79. leg_pt->Draw();
  80. //Draw gr1/gr2 ratio in the bottom pad
  81. padDown->cd();
  82. std::vector<Double_t> v1X;
  83. std::vector<Double_t> v1Y;
  84. std::vector<Double_t> v1Xerr;
  85. std::vector<Double_t> v1Yerr;
  86. std::vector<Double_t> v2X;
  87. std::vector<Double_t> v2Y;
  88. std::vector<Double_t> v2Xerr;
  89. std::vector<Double_t> v2Yerr;
  90. std::vector<Double_t> vRatioY;
  91. std::vector<Double_t> vRatioYerr;
  92. for (int i = 0; i < gr1->GetN(); i++)
  93. {
  94. v1X.push_back(vx_gr1[i]);
  95. v1Y.push_back(vy_gr1[i]);
  96. v1Xerr.push_back(ex_gr1[i]);
  97. v1Yerr.push_back(ey_gr1[i]);
  98. v2Y.push_back((Double_t)gr2->Eval(v1X.at(i), 0, "S"));
  99. v2Yerr.push_back(ey_gr2[i]);
  100. vRatioY.push_back(v1Y.at(i) / v2Y.at(i));
  101. vRatioYerr.push_back(
  102. TMath::Sqrt(
  103. TMath::Power(v1Yerr.at(i) / v2Y.at(i), 2) +
  104. TMath::Power(v1Y.at(i) * v2Yerr.at(i) / (v2Y.at(i) * v2Y.at(i)), 2)));
  105. }
  106. TGraphErrors *grRatio = new TGraphErrors(v1X.size(), &v1X[0], &vRatioY[0], &v1Xerr[0], &vRatioYerr[0]);
  107. grRatio->GetXaxis()->SetLabelSize(0.11);
  108. grRatio->GetYaxis()->SetLabelSize(0.11);
  109. grRatio->GetXaxis()->SetTitleSize(0.12);
  110. grRatio->GetYaxis()->SetTitleSize(0.12);
  111. grRatio->GetYaxis()->SetTitle(Form("%s/%s", gr1->GetTitle(), gr2->GetTitle()));
  112. grRatio->GetYaxis()->SetTitleOffset(0.65);
  113. grRatio->GetXaxis()->SetTitle(Form("%s", gr1->GetXaxis()->GetTitle()));
  114. padDown->SetBottomMargin(0.3);
  115. grRatio->GetYaxis()->SetNdivisions(504);
  116. grRatio->GetXaxis()->SetTickLength(3 * 12 / padUH);
  117. grRatio->GetYaxis()->SetTickLength(2.6 * 12 / padUW);
  118. grRatio->GetYaxis()->SetRangeUser(yRatio_low, yRatio_high);
  119. // grRatio->GetYaxis()->SetRangeUser(0.81,1.19);
  120. grRatio->SetMarkerStyle(26);
  121. grRatio->SetMarkerSize(1.6);
  122. grRatio->SetLineColor(kRed);
  123. grRatio->SetMarkerColor(kRed);
  124. grRatio->GetXaxis()->SetLimits(0.95 * vx_gr1[0], 1.05 * vx_gr1[n1bins - 1]);
  125. grRatio->Draw("AP");
  126. TLine lineOne;
  127. lineOne.SetLineStyle(1);
  128. TLine line90;
  129. line90.SetLineWidth(2.);
  130. line90.SetLineStyle(2);
  131. TLine line110;
  132. line110.SetLineWidth(2.);
  133. line110.SetLineStyle(2);
  134. // lineOne.SetLineColor(kRed);
  135. lineOne.DrawLine(0.95 * vx_gr1[0], 1., 1.05 * vx_gr1[n1bins - 1], 1.);
  136. line90.DrawLine(0.95 * vx_gr1[0], .95, 1.05 * vx_gr1[n1bins - 1], .95);
  137. line110.DrawLine(0.95 * vx_gr1[0], 1.05, 1.05 * vx_gr1[n1bins - 1], 1.05);
  138. return canv;
  139. }
  140. // Draws N TGraphErrors (upper panel) with their grN/gr1 ratio (lower pannel)
  141. TCanvas *DrawTGraph(std::vector<TGraphErrors *> vgr, TString str,
  142. Double_t yRatio_low = 0.89, Double_t yRatio_high = 1.11,
  143. Double_t x_low = 0.0, Double_t x_high = 1.0,
  144. Double_t y_low = 0.0, Double_t y_high = 1.0,
  145. Double_t leg_x_low = 0.22, Double_t leg_y_low = 0.55,
  146. Double_t leg_x_high = 0.55, Double_t leg_y_high = 0.89,
  147. TString str_ratio = "Ratio", Bool_t isLogy = false,
  148. Bool_t isOnly1Line = false, Bool_t isPMC = true,
  149. std::vector<std::pair<Int_t, Int_t>> vBorders={})
  150. {
  151. // Setting up global variables for the plot
  152. gROOT->SetStyle("Pub");
  153. gROOT->ForceStyle();
  154. gStyle->SetPalette(kDarkRainBow);
  155. gStyle->SetErrorX(0);
  156. std::vector<Double_t *> vx_gr, vy_gr, ex_gr, ey_gr;
  157. std::vector<Int_t> nbins;
  158. for (int i = 0; i < vgr.size(); i++)
  159. {
  160. // Read points
  161. vx_gr.push_back(vgr.at(i)->GetX());
  162. vy_gr.push_back(vgr.at(i)->GetY());
  163. // Read errors
  164. ex_gr.push_back(vgr.at(i)->GetEX());
  165. ey_gr.push_back(vgr.at(i)->GetEY());
  166. nbins.push_back(vgr.at(i)->GetN());
  167. }
  168. // Initialization of the canvas & pads
  169. TCanvas *canv = new TCanvas(Form("canv"), Form("Canvas"), 900, 800);
  170. canv->cd();
  171. TPad *padUp = new TPad(Form("padUp"), "v2 vs pt", 0., 0.33, 1., 1., 0, -1, 0);
  172. TPad *padDown = new TPad(Form("padDown"), "Ratio v2", 0., 0., 1., 0.33, 0, -1, 0);
  173. double padUW;
  174. double padUH;
  175. double padDW;
  176. double padDH;
  177. padUp->SetBorderSize(0);
  178. padDown->SetBorderSize(0);
  179. padUp->SetBottomMargin(0.);
  180. padDown->SetTopMargin(0.005);
  181. padUW = padUp->GetWw() * padUp->GetAbsWNDC();
  182. padUH = padUp->GetWh() * padUp->GetAbsHNDC();
  183. padDW = padDown->GetWw() * padDown->GetAbsWNDC();
  184. padDH = padDown->GetWh() * padDown->GetAbsHNDC();
  185. padUp->Draw();
  186. padDown->Draw();
  187. // Draw TGraphErrors in the upper pad
  188. padUp->cd();
  189. if (isLogy)
  190. padUp->SetLogy();
  191. // gr1->GetXaxis()->SetLimits(0.95*vx_gr1[0],1.05*vx_gr1[n1bins-1]);
  192. vgr.at(0)->GetXaxis()->SetLimits(x_low, x_high);
  193. vgr.at(0)->GetYaxis()->SetRangeUser(y_low, y_high);
  194. vgr.at(0)->GetXaxis()->SetLabelSize(0.06);
  195. vgr.at(0)->GetYaxis()->SetLabelSize(0.06);
  196. vgr.at(0)->GetXaxis()->SetTitleSize(0.07);
  197. vgr.at(0)->GetYaxis()->SetTitleSize(0.07);
  198. vgr.at(0)->GetYaxis()->SetTitleOffset(1.08);
  199. if (isPMC)
  200. {
  201. vgr.at(0)->Draw("AP PLC PMC");
  202. for (int i = 1; i < vgr.size(); i++)
  203. {
  204. vgr.at(i)->Draw("P PLC PMC");
  205. }
  206. }
  207. else
  208. {
  209. vgr.at(0)->Draw("AP");
  210. for (int i = 1; i < vgr.size(); i++)
  211. {
  212. vgr.at(i)->Draw("P");
  213. }
  214. }
  215. TLine cutLine;
  216. cutLine.SetLineStyle(2);
  217. Int_t cutBin;
  218. Double_t cutY;
  219. if (vBorders.size()>0)
  220. {
  221. for (int i=0; i<vBorders.size(); i++)
  222. {
  223. cutLine.DrawLine(vBorders.at(i).first, y_low, vBorders.at(i).first, vgr.at(0)->Eval(vBorders.at(i).first));
  224. }
  225. }
  226. // TLegend *leg_pt = new TLegend(0.568,0.02,0.89,0.295);
  227. TLatex tex;
  228. TLegend *leg_pt = new TLegend(leg_x_low, leg_y_low - 0.02, leg_x_high, leg_y_high - 0.03);
  229. leg_pt->SetBorderSize(0);
  230. leg_pt->SetNColumns(2);
  231. // leg_pt->SetHeader(str.Data(),"C");
  232. std::vector<TGraphErrors*> vgr_clone;
  233. for (int i = 0; i < vgr.size(); i++)
  234. {
  235. vgr_clone.push_back((TGraphErrors*) vgr.at(i)->Clone(Form("clone_%s",vgr.at(i)->GetName())));
  236. vgr_clone.at(i)->SetMarkerSize(2.);
  237. }
  238. for (int i = 0; i < vgr.size(); i++)
  239. {
  240. leg_pt->AddEntry(vgr_clone.at(i), Form("%s", vgr.at(i)->GetTitle()), "p");
  241. }
  242. leg_pt->Draw();
  243. tex.DrawLatexNDC(leg_x_low, leg_y_high, Form("%s", str.Data()));
  244. //Draw grN/gr1 ratio in the bottom pad
  245. padDown->cd();
  246. std::vector<Double_t> v1X;
  247. std::vector<Double_t> v1Y;
  248. std::vector<Double_t> v1Xerr;
  249. std::vector<Double_t> v1Yerr;
  250. std::vector<Double_t> v2X;
  251. std::vector<Double_t> v2Y;
  252. std::vector<Double_t> v2Xerr;
  253. std::vector<Double_t> v2Yerr;
  254. std::vector<Double_t> vRatioY;
  255. std::vector<Double_t> vRatioYerr;
  256. std::vector<TGraphErrors *> vgrRatio;
  257. for (int igr = 1; igr < vgr.size(); igr++)
  258. {
  259. v1X.clear();
  260. v1Y.clear();
  261. v1Xerr.clear();
  262. v1Yerr.clear();
  263. v2X.clear();
  264. v2Y.clear();
  265. v2Xerr.clear();
  266. v2Yerr.clear();
  267. vRatioY.clear();
  268. vRatioYerr.clear();
  269. for (int i = 0; i < vgr.at(igr)->GetN(); i++)
  270. {
  271. v1X.push_back(vx_gr.at(igr)[i]);
  272. v1Y.push_back(vy_gr.at(igr)[i]);
  273. v1Xerr.push_back(ex_gr.at(igr)[i]);
  274. v1Yerr.push_back(ey_gr.at(igr)[i]);
  275. v2Y.push_back((Double_t)vgr.at(0)->Eval(v1X.at(i), 0, "S"));
  276. v2Yerr.push_back(ey_gr.at(0)[i]);
  277. vRatioY.push_back(v1Y.at(i) / v2Y.at(i));
  278. vRatioYerr.push_back(
  279. TMath::Sqrt(
  280. TMath::Power(v1Yerr.at(i) / v2Y.at(i), 2) +
  281. TMath::Power(v1Y.at(i) * v2Yerr.at(i) / (v2Y.at(i) * v2Y.at(i)), 2)));
  282. }
  283. vgrRatio.push_back(new TGraphErrors(v1X.size(), &v1X[0], &vRatioY[0], &v1Xerr[0], &vRatioYerr[0]));
  284. }
  285. padDown->SetBottomMargin(0.3);
  286. for (int igr = 0; igr < vgrRatio.size(); igr++)
  287. {
  288. vgrRatio.at(igr)->GetXaxis()->SetLabelSize(0.11);
  289. vgrRatio.at(igr)->GetYaxis()->SetLabelSize(0.11);
  290. vgrRatio.at(igr)->GetXaxis()->SetTitleSize(0.12);
  291. vgrRatio.at(igr)->GetYaxis()->SetTitleSize(0.12);
  292. // vgrRatio.at(igr)->GetYaxis()->SetTitle(Form("%s/%s",vgr.at(igr+1)->GetTitle(),vgr.at(0)->GetTitle()));
  293. vgrRatio.at(igr)->GetYaxis()->SetTitle(str_ratio.Data());
  294. vgrRatio.at(igr)->GetYaxis()->SetTitleOffset(0.65);
  295. vgrRatio.at(igr)->GetXaxis()->SetTitle(Form("%s", vgr.at(0)->GetXaxis()->GetTitle()));
  296. vgrRatio.at(igr)->GetYaxis()->SetNdivisions(504);
  297. vgrRatio.at(igr)->GetXaxis()->SetTickLength(3 * 12 / padUH);
  298. vgrRatio.at(igr)->GetYaxis()->SetTickLength(2.6 * 12 / padUW);
  299. vgrRatio.at(igr)->GetYaxis()->SetRangeUser(yRatio_low, yRatio_high);
  300. vgrRatio.at(igr)->SetMarkerStyle(vgr.at(igr + 1)->GetMarkerStyle());
  301. vgrRatio.at(igr)->SetMarkerSize(1.*vgr.at(igr + 1)->GetMarkerSize());
  302. vgrRatio.at(igr)->SetLineColor(vgr.at(igr + 1)->GetLineColor());
  303. vgrRatio.at(igr)->SetMarkerColor(vgr.at(igr + 1)->GetMarkerColor());
  304. // grRatio->GetXaxis()->SetLimits(0.95*vx_gr1[0],1.05*vx_gr1[n1bins-1]);
  305. if (isPMC)
  306. {
  307. if (igr == 0)
  308. {
  309. vgrRatio.at(igr)->GetXaxis()->SetLimits(x_low, x_high);
  310. vgrRatio.at(igr)->Draw("AP PLC PMC");
  311. }
  312. // else{
  313. vgrRatio.at(igr)->Draw("P PLC PMC");
  314. // }
  315. }
  316. else
  317. {
  318. if (igr == 0)
  319. {
  320. vgrRatio.at(igr)->GetXaxis()->SetLimits(x_low, x_high);
  321. vgrRatio.at(igr)->Draw("AP");
  322. }
  323. // else{
  324. vgrRatio.at(igr)->Draw("P");
  325. // }
  326. }
  327. TLine lineOne;
  328. lineOne.SetLineStyle(1);
  329. TLine line90;
  330. line90.SetLineWidth(2.);
  331. line90.SetLineStyle(2);
  332. TLine line110;
  333. line110.SetLineWidth(2.);
  334. line110.SetLineStyle(2);
  335. // lineOne.SetLineColor(kRed);
  336. lineOne.DrawLine(x_low, 1., x_high, 1.);
  337. if (!isOnly1Line)
  338. line90.DrawLine(x_low, .95, x_high, .95);
  339. if (!isOnly1Line)
  340. line110.DrawLine(x_low, 1.05, x_high, 1.05);
  341. }
  342. return canv;
  343. }
  344. // Draws N TGraphErrors (upper panel) with their grN/gr1 ratio (lower pannel)
  345. TCanvas *DrawTGraphNoRatioErrors(std::vector<TGraphErrors *> vgr, TString str,
  346. Double_t yRatio_low = 0.89, Double_t yRatio_high = 1.11,
  347. Double_t x_low = 0.0, Double_t x_high = 1.0,
  348. Double_t y_low = 0.0, Double_t y_high = 1.0,
  349. Double_t leg_x_low = 0.22, Double_t leg_y_low = 0.55,
  350. Double_t leg_x_high = 0.55, Double_t leg_y_high = 0.89, TString str_ratio = "Ratio", bool isEval = true, TString additional_text = "")
  351. {
  352. // Setting up global variables for the plot
  353. gROOT->SetStyle("Pub");
  354. gROOT->ForceStyle();
  355. gStyle->SetPalette(kDarkRainBow);
  356. gStyle->SetErrorX(0);
  357. std::vector<Double_t *> vx_gr, vy_gr, ex_gr, ey_gr;
  358. std::vector<Int_t> nbins;
  359. for (int i = 0; i < vgr.size(); i++)
  360. {
  361. // Read points
  362. vx_gr.push_back(vgr.at(i)->GetX());
  363. vy_gr.push_back(vgr.at(i)->GetY());
  364. // Read errors
  365. ex_gr.push_back(vgr.at(i)->GetEX());
  366. ey_gr.push_back(vgr.at(i)->GetEY());
  367. nbins.push_back(vgr.at(i)->GetN());
  368. }
  369. // Initialization of the canvas & pads
  370. TCanvas *canv = new TCanvas(Form("canv"), Form("Canvas"), 900, 800);
  371. canv->cd();
  372. TPad *padUp = new TPad(Form("padUp"), "v2 vs pt", 0., 0.33, 1., 1., 0, -1, 0);
  373. TPad *padDown = new TPad(Form("padDown"), "Ratio v2", 0., 0., 1., 0.33, 0, -1, 0);
  374. double padUW;
  375. double padUH;
  376. double padDW;
  377. double padDH;
  378. padUp->SetBorderSize(0);
  379. padDown->SetBorderSize(0);
  380. padUp->SetBottomMargin(0.);
  381. padDown->SetTopMargin(0.005);
  382. padUW = padUp->GetWw() * padUp->GetAbsWNDC();
  383. padUH = padUp->GetWh() * padUp->GetAbsHNDC();
  384. padDW = padDown->GetWw() * padDown->GetAbsWNDC();
  385. padDH = padDown->GetWh() * padDown->GetAbsHNDC();
  386. padUp->Draw();
  387. padDown->Draw();
  388. // Draw TGraphErrors in the upper pad
  389. padUp->cd();
  390. // gr1->GetXaxis()->SetLimits(0.95*vx_gr1[0],1.05*vx_gr1[n1bins-1]);
  391. vgr.at(0)->GetXaxis()->SetLimits(x_low, x_high);
  392. vgr.at(0)->GetYaxis()->SetRangeUser(y_low, y_high);
  393. vgr.at(0)->GetXaxis()->SetLabelSize(0.06);
  394. vgr.at(0)->GetYaxis()->SetLabelSize(0.06);
  395. vgr.at(0)->GetXaxis()->SetTitleSize(0.07);
  396. vgr.at(0)->GetYaxis()->SetTitleSize(0.07);
  397. vgr.at(0)->GetYaxis()->SetTitleOffset(1.08);
  398. vgr.at(0)->Draw("AP PLC PMC");
  399. for (int i = 1; i < vgr.size(); i++)
  400. {
  401. vgr.at(i)->Draw("P PLC PMC");
  402. }
  403. // TLegend *leg_pt = new TLegend(0.568,0.02,0.89,0.295);
  404. TLegend *leg_pt = new TLegend(leg_x_low, leg_y_low, leg_x_high, leg_y_high);
  405. TLatex tex;
  406. leg_pt->SetBorderSize(0);
  407. // leg_pt->SetHeader(str.Data(),"C");
  408. for (int i = 0; i < vgr.size(); i++)
  409. {
  410. leg_pt->AddEntry(vgr.at(i), Form("%s", vgr.at(i)->GetTitle()), "p");
  411. }
  412. leg_pt->Draw();
  413. tex.DrawLatexNDC(leg_x_low, leg_y_high, Form("%s", str.Data()));
  414. if (additional_text != "")
  415. {
  416. tex.SetTextSize(0.07);
  417. tex.DrawLatexNDC(0.73, 0.08, Form("%s", additional_text.Data()));
  418. }
  419. //Draw grN/gr1 ratio in the bottom pad
  420. padDown->cd();
  421. std::vector<Double_t> v1X;
  422. std::vector<Double_t> v1Y;
  423. std::vector<Double_t> v1Xerr;
  424. std::vector<Double_t> v1Yerr;
  425. std::vector<Double_t> v2X;
  426. std::vector<Double_t> v2Y;
  427. std::vector<Double_t> v2Xerr;
  428. std::vector<Double_t> v2Yerr;
  429. std::vector<Double_t> vRatioY;
  430. std::vector<Double_t> vRatioYerr;
  431. std::vector<TGraphErrors *> vgrRatio;
  432. for (int igr = 1; igr < vgr.size(); igr++)
  433. {
  434. v1X.clear();
  435. v1Y.clear();
  436. v1Xerr.clear();
  437. v1Yerr.clear();
  438. v2X.clear();
  439. v2Y.clear();
  440. v2Xerr.clear();
  441. v2Yerr.clear();
  442. vRatioY.clear();
  443. vRatioYerr.clear();
  444. for (int i = 0; i < vgr.at(igr)->GetN(); i++)
  445. {
  446. v1X.push_back(vx_gr.at(igr)[i]);
  447. v1Y.push_back(vy_gr.at(igr)[i]);
  448. v1Xerr.push_back(ex_gr.at(igr)[i]);
  449. v1Yerr.push_back(ey_gr.at(igr)[i]);
  450. if (isEval)
  451. v2Y.push_back((Double_t)vgr.at(0)->Eval(v1X.at(i), 0, "S"));
  452. if (!isEval)
  453. v2Y.push_back(vy_gr.at(0)[i]);
  454. v2Yerr.push_back(ey_gr.at(0)[i]);
  455. vRatioY.push_back(v1Y.at(i) / v2Y.at(i));
  456. vRatioYerr.push_back(0.);
  457. }
  458. vgrRatio.push_back(new TGraphErrors(v1X.size(), &v1X[0], &vRatioY[0], &v1Xerr[0], &vRatioYerr[0]));
  459. }
  460. padDown->SetBottomMargin(0.3);
  461. for (int igr = 0; igr < vgrRatio.size(); igr++)
  462. {
  463. vgrRatio.at(igr)->GetXaxis()->SetLabelSize(0.11);
  464. vgrRatio.at(igr)->GetYaxis()->SetLabelSize(0.11);
  465. vgrRatio.at(igr)->GetXaxis()->SetTitleSize(0.12);
  466. vgrRatio.at(igr)->GetYaxis()->SetTitleSize(0.12);
  467. // vgrRatio.at(igr)->GetYaxis()->SetTitle(Form("%s/%s",vgr.at(igr+1)->GetTitle(),vgr.at(0)->GetTitle()));
  468. vgrRatio.at(igr)->GetYaxis()->SetTitle(str_ratio.Data());
  469. vgrRatio.at(igr)->GetYaxis()->SetTitleOffset(0.65);
  470. vgrRatio.at(igr)->GetXaxis()->SetTitle(Form("%s", vgr.at(0)->GetXaxis()->GetTitle()));
  471. vgrRatio.at(igr)->GetYaxis()->SetNdivisions(504);
  472. vgrRatio.at(igr)->GetXaxis()->SetTickLength(3 * 12 / padUH);
  473. vgrRatio.at(igr)->GetYaxis()->SetTickLength(2.6 * 12 / padUW);
  474. vgrRatio.at(igr)->GetYaxis()->SetRangeUser(yRatio_low, yRatio_high);
  475. vgrRatio.at(igr)->SetMarkerStyle(vgr.at(igr + 1)->GetMarkerStyle());
  476. vgrRatio.at(igr)->SetMarkerSize(1.6);
  477. vgrRatio.at(igr)->SetLineColor(kRed);
  478. vgrRatio.at(igr)->SetMarkerColor(kRed);
  479. // grRatio->GetXaxis()->SetLimits(0.95*vx_gr1[0],1.05*vx_gr1[n1bins-1]);
  480. if (igr == 0)
  481. {
  482. vgrRatio.at(igr)->GetXaxis()->SetLimits(x_low, x_high);
  483. vgrRatio.at(igr)->Draw("AP PLC PMC");
  484. }
  485. // else{
  486. vgrRatio.at(igr)->Draw("P PLC PMC");
  487. // }
  488. TLine lineOne;
  489. lineOne.SetLineStyle(1);
  490. TLine line90;
  491. line90.SetLineWidth(2.);
  492. line90.SetLineStyle(2);
  493. TLine line110;
  494. line110.SetLineWidth(2.);
  495. line110.SetLineStyle(2);
  496. // lineOne.SetLineColor(kRed);
  497. lineOne.DrawLine(x_low, 1., x_high, 1.);
  498. line90.DrawLine(x_low, .95, x_high, .95);
  499. line110.DrawLine(x_low, 1.05, x_high, 1.05);
  500. }
  501. return canv;
  502. }
  503. // Return ratio gr2/gr1
  504. TGraphErrors *GetGraphRatio(TGraphErrors *gr1, TGraphErrors *gr2, bool isEval = true)
  505. {
  506. std::vector<Double_t *> vx_gr, vy_gr, ex_gr, ey_gr;
  507. std::vector<Int_t> nbins;
  508. TGraphErrors *grRatio;
  509. // Read points
  510. vx_gr.push_back(gr1->GetX());
  511. vx_gr.push_back(gr2->GetX());
  512. vy_gr.push_back(gr1->GetY());
  513. vy_gr.push_back(gr2->GetY());
  514. // Read errors
  515. ex_gr.push_back(gr1->GetEX());
  516. ex_gr.push_back(gr2->GetEX());
  517. ey_gr.push_back(gr1->GetEY());
  518. ey_gr.push_back(gr2->GetEY());
  519. nbins.push_back(gr1->GetN());
  520. nbins.push_back(gr2->GetN());
  521. std::vector<Double_t> v1X;
  522. std::vector<Double_t> v1Y;
  523. std::vector<Double_t> v1Xerr;
  524. std::vector<Double_t> v1Yerr;
  525. std::vector<Double_t> v2X;
  526. std::vector<Double_t> v2Y;
  527. std::vector<Double_t> v2Xerr;
  528. std::vector<Double_t> v2Yerr;
  529. std::vector<Double_t> vRatioY;
  530. std::vector<Double_t> vRatioYerr;
  531. v1X.clear();
  532. v1Y.clear();
  533. v1Xerr.clear();
  534. v1Yerr.clear();
  535. v2X.clear();
  536. v2Y.clear();
  537. v2Xerr.clear();
  538. v2Yerr.clear();
  539. vRatioY.clear();
  540. vRatioYerr.clear();
  541. for (int i = 0; i < gr2->GetN(); i++)
  542. {
  543. v1X.push_back(vx_gr.at(1)[i]);
  544. v1Y.push_back(vy_gr.at(1)[i]);
  545. v1Xerr.push_back(ex_gr.at(1)[i]);
  546. v1Yerr.push_back(ey_gr.at(1)[i]);
  547. if (isEval)
  548. v2Y.push_back((Double_t)gr1->Eval(v1X.at(i), 0, "S"));
  549. if (!isEval)
  550. v2Y.push_back(vy_gr.at(0)[i]);
  551. v2Yerr.push_back(ey_gr.at(0)[i]);
  552. vRatioY.push_back(v1Y.at(i) / v2Y.at(i));
  553. vRatioYerr.push_back(
  554. TMath::Sqrt(
  555. TMath::Power(v1Yerr.at(i) / v2Y.at(i), 2) +
  556. TMath::Power(v1Y.at(i) * v2Yerr.at(i) / (v2Y.at(i) * v2Y.at(i)), 2)));
  557. }
  558. grRatio = new TGraphErrors(v1X.size(), &v1X[0], &vRatioY[0], &v1Xerr[0], &vRatioYerr[0]);
  559. return grRatio;
  560. }
  561. // Return ratio gr2/gr1
  562. TGraphErrors *GetGraphRatioNoErrors(TGraphErrors *gr1, TGraphErrors *gr2, bool isEval = true)
  563. {
  564. std::vector<Double_t *> vx_gr, vy_gr, ex_gr, ey_gr;
  565. std::vector<Int_t> nbins;
  566. TGraphErrors *grRatio;
  567. // Read points
  568. vx_gr.push_back(gr1->GetX());
  569. vx_gr.push_back(gr2->GetX());
  570. vy_gr.push_back(gr1->GetY());
  571. vy_gr.push_back(gr2->GetY());
  572. nbins.push_back(gr1->GetN());
  573. nbins.push_back(gr2->GetN());
  574. std::vector<Double_t> v1X;
  575. std::vector<Double_t> v1Y;
  576. std::vector<Double_t> v1Xerr;
  577. std::vector<Double_t> v1Yerr;
  578. std::vector<Double_t> v2X;
  579. std::vector<Double_t> v2Y;
  580. std::vector<Double_t> v2Xerr;
  581. std::vector<Double_t> v2Yerr;
  582. std::vector<Double_t> vRatioY;
  583. std::vector<Double_t> vRatioYerr;
  584. v1X.clear();
  585. v1Y.clear();
  586. v1Xerr.clear();
  587. v1Yerr.clear();
  588. v2X.clear();
  589. v2Y.clear();
  590. v2Xerr.clear();
  591. v2Yerr.clear();
  592. vRatioY.clear();
  593. vRatioYerr.clear();
  594. for (int i = 0; i < gr2->GetN(); i++)
  595. {
  596. v1X.push_back(vx_gr.at(1)[i]);
  597. v1Y.push_back(vy_gr.at(1)[i]);
  598. v1Xerr.push_back(0.);
  599. v1Yerr.push_back(0.);
  600. if (isEval)
  601. v2Y.push_back((Double_t)gr1->Eval(v1X.at(i), 0, "S"));
  602. if (!isEval)
  603. v2Y.push_back(vy_gr.at(0)[i]);
  604. v2Yerr.push_back(0.);
  605. vRatioY.push_back(v1Y.at(i) / v2Y.at(i));
  606. vRatioYerr.push_back(0.);
  607. }
  608. grRatio = new TGraphErrors(v1X.size(), &v1X[0], &vRatioY[0], &v1Xerr[0], &vRatioYerr[0]);
  609. return grRatio;
  610. }
  611. TGraphErrors *GetGraphResolution(TGraphErrors *gr1)
  612. {
  613. TGraphErrors *grRes;
  614. if (!gr1)
  615. {
  616. std::cerr << "Error: empty TGraphErrors!" << std::endl;
  617. return grRes;
  618. }
  619. std::vector<Double_t> v1X;
  620. std::vector<Double_t> v1Y;
  621. std::vector<Double_t> v1Xerr;
  622. std::vector<Double_t> v1Yerr;
  623. v1X.clear();
  624. v1Y.clear();
  625. v1Xerr.clear();
  626. v1Yerr.clear();
  627. for (int i = 0; i < gr1->GetN(); i++)
  628. {
  629. if (gr1->GetPointY(i) == 0)
  630. continue;
  631. v1X.push_back(gr1->GetPointX(i));
  632. v1Y.push_back(gr1->GetErrorY(i) / gr1->GetPointY(i));
  633. v1Xerr.push_back(0.);
  634. v1Yerr.push_back(0.);
  635. }
  636. grRes = new TGraphErrors(v1X.size(), &v1X[0], &v1Y[0], &v1Xerr[0], &v1Yerr[0]);
  637. return grRes;
  638. }
  639. // Draws N TGraphErrors (upper panel) with their grN/gr1 ratio (lower pannel)
  640. TCanvas *DrawTGraphNoRatio(std::vector<TGraphErrors *> vgr, TString str,
  641. Double_t x_low = 0.0, Double_t x_high = 1.0,
  642. Double_t y_low = 0.0, Double_t y_high = 1.0,
  643. Double_t leg_x_low = 0.22, Double_t leg_y_low = 0.55,
  644. Double_t leg_x_high = 0.55, Double_t leg_y_high = 0.89, TString additional_text = "")
  645. {
  646. // Setting up global variables for the plot
  647. gROOT->SetStyle("Pub");
  648. gROOT->ForceStyle();
  649. gStyle->SetPalette(kDarkRainBow);
  650. gStyle->SetErrorX(0);
  651. std::vector<Double_t *> vx_gr, vy_gr, ex_gr, ey_gr;
  652. std::vector<Int_t> nbins;
  653. for (int i = 0; i < vgr.size(); i++)
  654. {
  655. // Read points
  656. vx_gr.push_back(vgr.at(i)->GetX());
  657. vy_gr.push_back(vgr.at(i)->GetY());
  658. // Read errors
  659. ex_gr.push_back(vgr.at(i)->GetEX());
  660. ey_gr.push_back(vgr.at(i)->GetEY());
  661. nbins.push_back(vgr.at(i)->GetN());
  662. }
  663. // Initialization of the canvas & pads
  664. TCanvas *canv = new TCanvas(Form("canv"), Form("Canvas"), 800, 500);
  665. canv->cd();
  666. // gr1->GetXaxis()->SetLimits(0.95*vx_gr1[0],1.05*vx_gr1[n1bins-1]);
  667. vgr.at(0)->GetXaxis()->SetLimits(x_low, x_high);
  668. vgr.at(0)->GetYaxis()->SetRangeUser(y_low, y_high);
  669. vgr.at(0)->GetXaxis()->SetLabelSize(0.06);
  670. vgr.at(0)->GetYaxis()->SetLabelSize(0.06);
  671. vgr.at(0)->GetXaxis()->SetTitleSize(0.07);
  672. vgr.at(0)->GetYaxis()->SetTitleSize(0.07);
  673. vgr.at(0)->GetYaxis()->SetTitleOffset(1.08);
  674. vgr.at(0)->Draw("AP PLC PMC");
  675. for (int i = 1; i < vgr.size(); i++)
  676. {
  677. vgr.at(i)->Draw("P PLC PMC");
  678. }
  679. // TLegend *leg_pt = new TLegend(0.568,0.02,0.89,0.295);
  680. TLegend *leg_pt = new TLegend(leg_x_low, leg_y_low, leg_x_high, leg_y_high);
  681. TLatex tex;
  682. leg_pt->SetBorderSize(0);
  683. // leg_pt->SetHeader(str.Data(),"C");
  684. for (int i = 0; i < vgr.size(); i++)
  685. {
  686. leg_pt->AddEntry(vgr.at(i), Form("%s", vgr.at(i)->GetTitle()), "p");
  687. }
  688. leg_pt->Draw();
  689. tex.DrawLatexNDC(leg_x_low, leg_y_high, Form("%s", str.Data()));
  690. if (additional_text != "")
  691. {
  692. tex.SetTextSize(0.07);
  693. tex.DrawLatexNDC(0.73, 0.08, Form("%s", additional_text.Data()));
  694. }
  695. return canv;
  696. }
  697. // Save TGraphs in file
  698. void SaveTGraph(TString outFileName, TGraphErrors *const &gr1, TGraphErrors *const &gr2)
  699. {
  700. TFile *fo = new TFile(outFileName.Data(), "recreate");
  701. fo->cd();
  702. TCanvas *canv = (TCanvas *)DrawTGraph(gr1, gr2);
  703. gr1->Write();
  704. gr2->Write();
  705. canv->Write();
  706. }
  707. // Convert TProfile into TGraphErrors
  708. TGraphErrors *ConvertProfile(TProfile *const &pr,
  709. Double_t scaleX=1.0, Double_t scaleY=1.0,
  710. Double_t scaleEX=1.0, Double_t scaleEY=1.0)
  711. {
  712. std::vector<Double_t> vX, vY, vEx, vEy;
  713. for (int ibin = 0; ibin < pr->GetNbinsX(); ibin++)
  714. {
  715. vX.push_back(scaleX*pr->GetBinCenter(ibin + 1));
  716. vEx.push_back(scaleEX*0.);
  717. vY.push_back(scaleY*pr->GetBinContent(ibin + 1));
  718. vEy.push_back(scaleEY*pr->GetBinError(ibin + 1));
  719. }
  720. TGraphErrors *gr = new TGraphErrors(vX.size(), &vX[0], &vY[0], &vEx[0], &vEy[0]);
  721. gr->SetTitle(pr->GetTitle());
  722. gr->SetName(pr->GetName());
  723. gr->GetXaxis()->SetTitle(pr->GetXaxis()->GetTitle());
  724. gr->GetYaxis()->SetTitle(pr->GetYaxis()->GetTitle());
  725. gr->SetMarkerStyle(pr->GetMarkerStyle());
  726. gr->SetMarkerStyle(pr->GetMarkerStyle());
  727. gr->SetMarkerColor(pr->GetMarkerColor());
  728. gr->SetLineColor(pr->GetLineColor());
  729. return gr;
  730. }
  731. // Convert TH1D into TGraphErrors
  732. TGraphErrors *ConvertProfile(TH1D *const &pr)
  733. {
  734. std::vector<Double_t> vX, vY, vEx, vEy;
  735. for (int ibin = 0; ibin < pr->GetNbinsX(); ibin++)
  736. {
  737. if (pr->GetBinContent(ibin + 1)==0) continue;
  738. vX.push_back(pr->GetBinCenter(ibin + 1));
  739. vEx.push_back(0.);
  740. vY.push_back(pr->GetBinContent(ibin + 1));
  741. vEy.push_back(pr->GetBinError(ibin + 1));
  742. }
  743. TGraphErrors *gr = new TGraphErrors(vX.size(), &vX[0], &vY[0], &vEx[0], &vEy[0]);
  744. gr->SetTitle(pr->GetTitle());
  745. gr->SetName(Form("gr_%s",pr->GetName()));
  746. gr->GetXaxis()->SetTitle(pr->GetXaxis()->GetTitle());
  747. gr->GetYaxis()->SetTitle(pr->GetYaxis()->GetTitle());
  748. gr->SetMarkerStyle(pr->GetMarkerStyle());
  749. gr->SetMarkerStyle(pr->GetMarkerStyle());
  750. gr->SetMarkerColor(pr->GetMarkerColor());
  751. gr->SetMarkerColor(pr->GetMarkerColor());
  752. return gr;
  753. }
  754. // Convert TH1F into TGraphErrors
  755. TGraphErrors *ConvertProfile(TH1F *const &pr)
  756. {
  757. std::vector<Double_t> vX, vY, vEx, vEy;
  758. for (int ibin = 0; ibin < pr->GetNbinsX(); ibin++)
  759. {
  760. if (pr->GetBinContent(ibin + 1)==0) continue;
  761. vX.push_back(pr->GetBinCenter(ibin + 1));
  762. vEx.push_back(0.);
  763. vY.push_back(pr->GetBinContent(ibin + 1));
  764. vEy.push_back(pr->GetBinError(ibin + 1));
  765. }
  766. TGraphErrors *gr = new TGraphErrors(vX.size(), &vX[0], &vY[0], &vEx[0], &vEy[0]);
  767. gr->SetTitle(pr->GetTitle());
  768. gr->SetName(pr->GetName());
  769. gr->GetXaxis()->SetTitle(pr->GetXaxis()->GetTitle());
  770. gr->GetYaxis()->SetTitle(pr->GetYaxis()->GetTitle());
  771. gr->SetMarkerStyle(pr->GetMarkerStyle());
  772. gr->SetMarkerStyle(pr->GetMarkerStyle());
  773. gr->SetMarkerColor(pr->GetMarkerColor());
  774. gr->SetMarkerColor(pr->GetMarkerColor());
  775. return gr;
  776. }
  777. TGraphErrors *ConvertFunction(TF1 *const &func, Double_t Norm = 5e5)
  778. {
  779. std::vector<Double_t> vX, vY, vEx, vEy;
  780. Double_t xmin, xmax;
  781. func->GetRange(xmin, xmax);
  782. int nbins = func->GetNumberFitPoints();
  783. for (int ibin = 0; ibin < nbins; ibin++)
  784. {
  785. vX.push_back((ibin + 0.5) * (xmax - xmin) / nbins);
  786. vEx.push_back(0.);
  787. vY.push_back(func->Eval(vX.at(ibin)) * Norm);
  788. // vEy.push_back( 1/sqrt(vY.at(ibin)*Norm) );
  789. vEy.push_back(0.);
  790. }
  791. auto graph = new TGraphErrors(vX.size(), &vX[0], &vY[0], &vEx[0], &vEy[0]);
  792. graph->SetTitle(func->GetTitle());
  793. graph->SetName(func->GetName());
  794. graph->GetXaxis()->SetTitle(func->GetXaxis()->GetTitle());
  795. graph->GetYaxis()->SetTitle(func->GetYaxis()->GetTitle());
  796. graph->SetMarkerStyle(func->GetMarkerStyle());
  797. graph->SetMarkerStyle(func->GetMarkerStyle());
  798. graph->SetMarkerColor(func->GetMarkerColor());
  799. graph->SetMarkerColor(func->GetMarkerColor());
  800. return graph;
  801. }
  802. TH1F *ConvertFunction(TF1 *const &func, Int_t nbins=2500, Double_t xmin=0, Double_t xmax=2500, Int_t Nevents=5e5)
  803. {
  804. TH1F *hist = new TH1F(Form("hist_fit_%s",func->GetName()),Form("histogram from %s", func->GetTitle()), nbins, xmin, xmax);
  805. double x_coord;
  806. for (int i=0; i<Nevents; i++)
  807. {
  808. x_coord = func->GetRandom(xmin,xmax);
  809. hist->Fill(x_coord);
  810. }
  811. hist->GetXaxis()->SetTitle(func->GetXaxis()->GetTitle());
  812. hist->GetYaxis()->SetTitle(func->GetYaxis()->GetTitle());
  813. hist->SetMarkerStyle(func->GetMarkerStyle());
  814. hist->SetMarkerStyle(func->GetMarkerStyle());
  815. hist->SetMarkerColor(func->GetMarkerColor());
  816. hist->SetMarkerColor(func->GetMarkerColor());
  817. return hist;
  818. }
  819. TGraphErrors *ShiftX(TGraphErrors *const &gr, double shift)
  820. {
  821. std::vector<double> x, y, ex, ey;
  822. for (int i = 0; i < gr->GetN(); i++)
  823. {
  824. x.push_back(gr->GetPointX(i) + shift);
  825. y.push_back(gr->GetPointY(i));
  826. ex.push_back(gr->GetErrorX(i));
  827. ey.push_back(gr->GetErrorY(i));
  828. }
  829. auto graph = new TGraphErrors(x.size(), &x[0], &y[0], &ex[0], &ey[0]);
  830. graph->SetName(Form("shifted_%s", gr->GetName()));
  831. graph->SetTitle(Form("%s", gr->GetTitle()));
  832. graph->GetXaxis()->SetTitle(Form("%s", gr->GetXaxis()->GetTitle()));
  833. graph->GetYaxis()->SetTitle(Form("%s", gr->GetYaxis()->GetTitle()));
  834. return graph;
  835. }
  836. TH1D *ConvertTH1I2TH1D(TH1I *const& hist, bool is_resample = false)
  837. {
  838. TH1D *result = new TH1D(Form("th1i2th1d_%s", hist->GetName()), Form("converted %s", hist->GetTitle()), hist->GetNbinsX(), hist->GetXaxis()->GetXmin(), hist->GetXaxis()->GetXmax());
  839. if (!is_resample)
  840. {
  841. for (int ibin=0; ibin<hist->GetNbinsX(); ibin++)
  842. {
  843. result->SetBinContent(ibin+1, hist->GetBinContent(ibin+1));
  844. result->SetBinError(ibin+1, hist->GetBinError(ibin+1));
  845. result->SetEntries(hist->GetEntries());
  846. }
  847. }
  848. if (is_resample)
  849. {
  850. for (int ientry=0; ientry<hist->GetEntries(); ientry++)
  851. {
  852. result->Fill(hist->GetRandom());
  853. }
  854. }
  855. return result;
  856. }
  857. // Test function. Shows basic usage of DrawTGraph()
  858. void Test()
  859. {
  860. // cent 0-10%
  861. const std::vector<Double_t> vPt_cent1 = {0.247, 0.348, 0.448, 0.548, 0.648, 0.748, 0.848, 0.948, 1.092, 1.292, 1.492, 1.692, 1.892, 2.200, 2.703, 3.343};
  862. const std::vector<Double_t> vV2_cent1 = {0.01342, 0.01488, 0.01231, 0.02085, 0.01557, 0.02236, 0.02656, 0.03014, 0.04275, 0.03826, 0.03859, 0.04492, 0.06318, 0.06910, 0.07798, 0.07481};
  863. const std::vector<Double_t> ePt_cent1 = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
  864. const std::vector<Double_t> eV2_cent1 = {0.00114, 0.00131, 0.00133, 0.00170, 0.00166, 0.00203, 0.00233, 0.00265, 0.00268, 0.00304, 0.00367, 0.00476, 0.00654, 0.00672, 0.01123, 0.01667};
  865. const std::vector<Double_t> sysl_cent1 = {0.00972, 0.00130, 0.00123, 0.00187, 0.00112, 0.00129, 0.00116, 0.00121, 0.00145, 0.00110, 0.00091, 0.00120, 0.00167, 0.00168, 0.00224, 0.00294};
  866. const std::vector<Double_t> sysh_cent1 = {0.00972, 0.00130, 0.00123, 0.00187, 0.00112, 0.00129, 0.00116, 0.00121, 0.00145, 0.00110, 0.00091, 0.00120, 0.00167, 0.00168, 0.00224, 0.00294};
  867. const std::vector<Double_t> eePt_cent1 = {0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05};
  868. // cent 10-20%
  869. const std::vector<Double_t> vPt_cent2 = {0.247, 0.348, 0.448, 0.548, 0.648, 0.748, 0.848, 0.948, 1.092, 1.292, 1.492, 1.692, 1.892, 2.200, 2.703, 3.343};
  870. const std::vector<Double_t> vV2_cent2 = {0.02194, 0.02987, 0.03696, 0.04342, 0.05052, 0.05556, 0.06572, 0.07064, 0.07773, 0.09169, 0.10236, 0.11847, 0.13255, 0.13748, 0.15166, 0.14679};
  871. const std::vector<Double_t> ePt_cent2 = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
  872. const std::vector<Double_t> eV2_cent2 = {0.00061, 0.00070, 0.00078, 0.00088, 0.00098, 0.00110, 0.00125, 0.00141, 0.00122, 0.00155, 0.00204, 0.00275, 0.00365, 0.00363, 0.00640, 0.00945, 0.02444, 0.05846};
  873. const std::vector<Double_t> sysl_cent2 = {0.00506, 0.00264, 0.00283, 0.00348, 0.00269, 0.00236, 0.00224, 0.00213, 0.00207, 0.00202, 0.00227, 0.00238, 0.00308, 0.00270, 0.00313, 0.00322, 0.00505, 0.00160};
  874. const std::vector<Double_t> sysh_cent2 = {0.00506, 0.00264, 0.00283, 0.00348, 0.00269, 0.00236, 0.00224, 0.00213, 0.00207, 0.00202, 0.00227, 0.00238, 0.00308, 0.00270, 0.00313, 0.00322, 0.00505, 0.00160};
  875. const std::vector<Double_t> eePt_cent2 = {0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05};
  876. TGraphErrors *grPHENIX[2];
  877. grPHENIX[0] = new TGraphErrors(vPt_cent1.size(), &vPt_cent1[0], &vV2_cent1[0], &ePt_cent1[0], &eV2_cent1[0]);
  878. grPHENIX[1] = new TGraphErrors(vPt_cent2.size(), &vPt_cent2[0], &vV2_cent2[0], &ePt_cent2[0], &eV2_cent2[0]);
  879. // Make titile names for graph and axes.
  880. // Those names will be used in DrawTGraph() to plot legend and axis names
  881. grPHENIX[0]->SetTitle("0-10%");
  882. grPHENIX[0]->GetXaxis()->SetTitle("p_{T}, [GeV/c]");
  883. grPHENIX[0]->GetYaxis()->SetTitle("v_{2}");
  884. grPHENIX[1]->SetTitle("10-20%");
  885. grPHENIX[1]->GetXaxis()->SetTitle("p_{T}, [GeV/c]");
  886. grPHENIX[1]->GetYaxis()->SetTitle("v_{2}");
  887. TCanvas *canv = (TCanvas *)DrawTGraph(grPHENIX[0], grPHENIX[1]);
  888. SaveTGraph("outfile.root", grPHENIX[0], grPHENIX[1]);
  889. }