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.

593 lines
25 KiB

  1. //Create plots that compare the distributions for differnet truth-matching methods
  2. //Renata Kopecna
  3. #include "../GlobalFunctions.hh"
  4. #include "../Design.hpp"
  5. #include "../Paths.hpp"
  6. #include <sys/stat.h> //mkdir
  7. #include <boost/algorithm/string.hpp>
  8. using namespace std;
  9. TChain *GetTMfiles(int year, bool Reference, bool PHSP, bool B0 = false, bool K1 = false, bool Inc = false){
  10. TChain * tree = new TChain("DecayTreeTruthMatched");
  11. if (B0 || K1 || Inc){ //possible TODO: year check
  12. tree->Add(GetInputFileBkg(year,"down",true,Reference,B0, K1, Inc).c_str());
  13. coutDebug("Getting the trees " + GetInputFileBkg(year,"down",true,Reference,B0, K1, Inc));
  14. tree->Add(GetInputFileBkg(year,"up",true,Reference,B0, K1, Inc).c_str());
  15. coutDebug("Getting the trees " + GetInputFileBkg(year,"up",true,Reference,B0, K1, Inc));
  16. }
  17. else{
  18. if (!checkYear(year,true,Reference,PHSP)) return NULL;
  19. coutDebug("Getting the trees " + GetInputFile(year,"down",true,Reference,false, false, false));
  20. tree->Add(GetInputFile(year,"down",true, true, Reference, PHSP, false).c_str());
  21. coutDebug("Getting the trees " + GetInputFile(year,"up",true,Reference,false, false, false));
  22. tree->Add(GetInputFile(year,"up",true, true, Reference, PHSP, false).c_str());
  23. }
  24. coutDebug("Tree obtained.");
  25. return tree;
  26. }
  27. TChain *GetTMfilesRun(int Run, bool Reference, bool PHSP){
  28. TChain * tree = new TChain("DecayTreeTruthMatched");
  29. for (auto yr: yearsMC(Reference,PHSP,Run)){
  30. coutDebug("Getting the trees " + GetInputFile(yr,"down",true,Reference,false, false, false));
  31. tree->Add(GetInputFile(yr,"down",true, true, Reference, PHSP, false).c_str());
  32. coutDebug("Getting the trees " + GetInputFile(yr,"up",true,Reference,false, false, false));
  33. tree->Add(GetInputFile(yr,"up",true, true, Reference, PHSP, false).c_str());
  34. }
  35. coutDebug("Tree obtained.");
  36. return tree;
  37. }
  38. //--------------------------------------------------------------------------------------------
  39. // Compare what gamma types we have
  40. //--------------------------------------------------------------------------------------------
  41. int plotGammaTMcomparison(string firstBranch, string secondBranch,string year, bool Reference, bool PHSP, bool B0 = false, bool K1 = false, bool Inc = false){
  42. gSystem->Load("Design_cpp.so");
  43. gROOT->SetBatch(kTRUE);
  44. coutInfo("Getting the TChain.");
  45. TChain *tree = GetTMfiles(std::stoi(year),Reference,PHSP,B0,K1,Inc);
  46. TH2D *h2_compare = new TH2D("h2_compare","h2_compare",6,0.5,6.5,6,0.5,6.5);
  47. string drawCommand = firstBranch + ":" + secondBranch + ">>" + h2_compare->GetName();
  48. coutDebug("Drawing this: " + drawCommand);
  49. tree->Draw(drawCommand.c_str());
  50. //design the histogram
  51. design_TH2F(h2_compare,secondBranch,firstBranch,"");
  52. h2_compare->GetXaxis()->SetTitleSize(0.03);
  53. h2_compare->GetYaxis()->SetTitleSize(0.03);
  54. h2_compare->GetXaxis()->SetTitleOffset(1.6);
  55. h2_compare->GetYaxis()->SetTitleOffset(3.0);
  56. h2_compare->GetXaxis()->SetBinLabel(1,"Both OK");
  57. h2_compare->GetXaxis()->SetBinLabel(2,"OK+Conv");
  58. h2_compare->GetXaxis()->SetBinLabel(3,"Both Conv");
  59. h2_compare->GetXaxis()->SetBinLabel(4,"OK+Rnd");
  60. h2_compare->GetXaxis()->SetBinLabel(5,"Conv+Rnd");
  61. h2_compare->GetXaxis()->SetBinLabel(6,"Both Rnd");
  62. h2_compare->GetYaxis()->SetBinLabel(1,"Both OK");
  63. h2_compare->GetYaxis()->SetBinLabel(2,"OK+Conv");
  64. h2_compare->GetYaxis()->SetBinLabel(3,"Both Conv");
  65. h2_compare->GetYaxis()->SetBinLabel(4,"OK+Rnd");
  66. h2_compare->GetYaxis()->SetBinLabel(5,"Conv+Rnd");
  67. h2_compare->GetYaxis()->SetBinLabel(6,"Both Rnd");
  68. //Save it in a canvas
  69. coutDebug("Saving the canvas.");
  70. TCanvas *canvas = new TCanvas("","",800, 750);
  71. canvas->cd();
  72. canvas->SetTopMargin(0.03);
  73. canvas->SetLeftMargin(0.18);
  74. canvas->SetRightMargin(0.03);
  75. canvas->SetBottomMargin(0.12);
  76. h2_compare->Draw("COLTEXT");
  77. string path = getTMplotsPath("compare_" + firstBranch + "_" + secondBranch, year, Reference, PHSP, B0, K1, Inc);
  78. canvas->SaveAs(path.c_str());
  79. replace(path,".eps",".root");
  80. canvas->SaveAs(path.c_str());
  81. tree->Clear();
  82. h2_compare->Clear();
  83. canvas->Clear();
  84. delete canvas;
  85. return 1;
  86. }
  87. int plotGammaTMcomparisonAllBranches(string year, bool Reference, bool PHSP, bool B0 = false, bool K1 = false, bool Inc = false){
  88. string firstBranch = "TM_gammas";
  89. vector<string> secondBranch = {"TM_gammas_noPi0", "TM_gammas_noPi0_noBplus", "TM_gammas_noPi0_noKst_noBplus"};
  90. for (auto secBr : secondBranch){
  91. if (plotGammaTMcomparison(firstBranch,secBr,year,Reference,PHSP,B0,K1,Inc)==0) return 0;
  92. }
  93. return 1;
  94. }
  95. int plotGammaTMcomparisonAllYears(bool Reference, bool PHSP, bool B0 = false, bool K1 = false, bool Inc = false){
  96. vector<string> years = (B0||K1||Inc) ? yearsBkgMC(Reference,B0,K1,Inc,12) : yearsMC(Reference,PHSP,12);
  97. for (auto yr: years){
  98. if (plotGammaTMcomparisonAllBranches(yr,Reference,PHSP,B0,K1,Inc)==0) return 0;
  99. }
  100. return 1;
  101. }
  102. int plotGammaTMcomparisonAll(){
  103. if (plotGammaTMcomparisonAllYears( 0, 0, 0, 0, 0)==0) return 0;
  104. if (plotGammaTMcomparisonAllYears( 1, 0, 0, 0, 0)==0) return 0;
  105. if (plotGammaTMcomparisonAllYears( 0, 1, 0, 0, 0)==0) return 0;
  106. if (plotGammaTMcomparisonAllYears( 1, 0, 0, 0, 1)==0) return 0;
  107. return 1;
  108. }
  109. //--------------------------------------------------------------------------------------------
  110. // Compare different gamma contributions in the B mass (TODO: pi mass?)
  111. //--------------------------------------------------------------------------------------------
  112. int plotAllGammaContributions(string branch, string year, bool Reference, bool PHSP, bool B0 = false, bool K1 = false, bool Inc = false, bool log = true){
  113. gSystem->Load("Design_cpp.so");
  114. gROOT->SetBatch(kTRUE);
  115. coutInfo("Getting the TChain.");
  116. TChain *tree = GetTMfiles(std::stoi(year),Reference,PHSP,B0,K1,Inc);
  117. TH1D *AllTMed = BmassHistogram("AllTMed", "", "B^{+} mass [MeV]", kBlack);
  118. TH1D *TMedWithGamma1 = BmassHistogram("TMedWithGamma1", "", "B^{+} mass [MeV]", kRed);
  119. TH1D *TMedWithGamma2 = BmassHistogram("TMedWithGamma2", "", "B^{+} mass [MeV]", kGreen);
  120. TH1D *TMedWithGamma3 = BmassHistogram("TMedWithGamma3", "", "B^{+} mass [MeV]", kBlue);
  121. TH1D *TMedWithGamma4 = BmassHistogram("TMedWithGamma4", "", "B^{+} mass [MeV]", kMagenta);
  122. TH1D *TMedWithGamma5 = BmassHistogram("TMedWithGamma5", "", "B^{+} mass [MeV]", kAzure);
  123. TH1D *TMedWithGamma6 = BmassHistogram("TMedWithGamma6", "", "B^{+} mass [MeV]", kOrange);
  124. //Fill the histograms, just using DTF cause screw it
  125. string cond = "TMed==1&&"+branch;
  126. tree->Draw("B_plus_M_DTF>>AllTMed","TMed==1");
  127. tree->Draw("B_plus_M_DTF>>TMedWithGamma1",string(cond+"==1").c_str());
  128. tree->Draw("B_plus_M_DTF>>TMedWithGamma2",string(cond+"==2").c_str());
  129. tree->Draw("B_plus_M_DTF>>TMedWithGamma3",string(cond+"==3").c_str());
  130. tree->Draw("B_plus_M_DTF>>TMedWithGamma4",string(cond+"==4").c_str());
  131. tree->Draw("B_plus_M_DTF>>TMedWithGamma5",string(cond+"==5").c_str());
  132. tree->Draw("B_plus_M_DTF>>TMedWithGamma6",string(cond+"==6").c_str());
  133. //Set the legend
  134. TLegend *leg = new TLegend(0.63,0.51,0.92,0.95);
  135. leg->AddEntry(AllTMed, "TMed all", "l");
  136. leg->AddEntry(TMedWithGamma1,"TMed+both OK", "l");
  137. leg->AddEntry(TMedWithGamma2,"TMed+OK+Conv", "l");
  138. leg->AddEntry(TMedWithGamma3,"TMed+both Conv", "l");
  139. leg->AddEntry(TMedWithGamma4,"TMed+OK+Rnd", "l");
  140. leg->AddEntry(TMedWithGamma5,"TMed+Conv+Rnd", "l");
  141. leg->AddEntry(TMedWithGamma6,"TMed+both Rnd", "l");
  142. //make the plot
  143. coutDebug("Saving the canvas.");
  144. TCanvas *canvas = c_canvas("");
  145. canvas->cd();
  146. if (log) canvas->SetLogy();
  147. AllTMed->Draw();
  148. TMedWithGamma1->Draw("SAME");
  149. TMedWithGamma2->Draw("SAME");
  150. TMedWithGamma3->Draw("SAME");
  151. TMedWithGamma4->Draw("SAME");
  152. TMedWithGamma5->Draw("SAME");
  153. TMedWithGamma6->Draw("SAME");
  154. leg->Draw("SAME");
  155. string path = getTMplotsPath("TMed_AllGammaContributions"+ string(log ? "_log" : ""), year, Reference, PHSP, B0, K1, Inc);
  156. canvas->SaveAs(path.c_str());
  157. replace(path,".eps",".root");
  158. canvas->SaveAs(path.c_str());
  159. tree->Clear();
  160. AllTMed->Clear();
  161. TMedWithGamma1->Clear();
  162. TMedWithGamma2->Clear();
  163. TMedWithGamma3->Clear();
  164. TMedWithGamma4->Clear();
  165. TMedWithGamma5->Clear();
  166. TMedWithGamma6->Clear();
  167. canvas->Clear();
  168. delete canvas;
  169. coutInfo("Done plotting.");
  170. return 1;
  171. }
  172. int plotAllGammaContributionsAllYears(bool Reference, bool PHSP, bool B0 = false, bool K1 = false, bool Inc = false){
  173. vector<string> years = (B0||K1||Inc) ? yearsBkgMC(Reference,B0,K1,Inc,12) : yearsMC(Reference,PHSP,12);
  174. for (auto yr: years){
  175. if (plotAllGammaContributions("TM_gammas",yr,Reference,PHSP,B0,K1,Inc, true)==0) return 0;
  176. if (plotAllGammaContributions("TM_gammas",yr,Reference,PHSP,B0,K1,Inc, false)==0) return 0;
  177. }
  178. return 1;
  179. }
  180. int plotAllGammaContributionsAll(){
  181. if (plotAllGammaContributionsAllYears( 0, 0, 0, 0, 0)==0) return 0;
  182. if (plotAllGammaContributionsAllYears( 1, 0, 0, 0, 0)==0) return 0;
  183. if (plotAllGammaContributionsAllYears( 0, 1, 0, 0, 0)==0) return 0;
  184. if (plotAllGammaContributionsAllYears( 1, 0, 0, 0, 1)==0) return 0;
  185. return 1;
  186. }
  187. //--------------------------------------------------------------------------------------------
  188. // Compare different gamma contributions in costhetak //--------------------------------------------------------------------------------------------
  189. int plotCosAngle(string branch, string year, int Run, bool Reference, bool PHSP, bool B0 = false, bool K1 = false, bool Inc = false, string angle = "thetak", bool cos = true, bool norm = false, bool fancy = true){
  190. gSystem->Load("Design_cpp.so");
  191. gROOT->SetBatch(kTRUE);
  192. TH1::SetDefaultSumw2(kTRUE);
  193. coutInfo("Getting the TChain.");
  194. TChain *tree ;
  195. if (Run ==0) tree = GetTMfiles(std::stoi(year),Reference,PHSP,B0,K1,Inc);
  196. else tree = GetTMfilesRun(Run,Reference,PHSP);
  197. TH1D *AllTMed = hist_cosAngle(angle, "AllTMed", "", kBlack, cos, norm);
  198. TH1D *TMedWithGamma1 = hist_cosAngle(angle, "TMedWithGamma1", "", kRed, cos, norm);
  199. TH1D *TMedWithGamma2 = hist_cosAngle(angle, "TMedWithGamma2", "", kOrange, cos, norm);
  200. TH1D *TMedWithGamma3 = hist_cosAngle(angle, "TMedWithGamma3", "", kBlue, cos, norm);
  201. TH1D *TMedWithGamma4 = hist_cosAngle(angle, "TMedWithGamma4", "", kMagenta, cos, norm);
  202. TH1D *TMedWithGamma5 = hist_cosAngle(angle, "TMedWithGamma5", "", kAzure, cos, norm);
  203. TH1D *TMedWithGamma6 = hist_cosAngle(angle, "TMedWithGamma6", "", kGreen+2, cos, norm);
  204. TH1D *TMedTrue = hist_cosAngle(angle, "TMedTrue", "", kRed, cos, norm);
  205. TH1D *TMedTrueRnd = hist_cosAngle(angle, "TMedRnd", "", kBlue, cos, norm);
  206. TH1D *Ratio = hist_cosAngle(angle, "Ratio", "", kBlack, cos, norm);
  207. //Fill the histograms, just using DTF cause screw it
  208. boost::to_lower(angle);
  209. replace(angle,"_","");
  210. string var = "";
  211. if (angle == "thetak") var = "B_plus_ThetaK";
  212. else if (angle == "thetal") var = "B_plus_ThetaL";
  213. else if (angle == "phi") var = "B_plus_Phi";
  214. else{
  215. coutERROR("Wrong angle selected! Select from thetak, thetal and phi.");
  216. return 0;
  217. }
  218. string command = cos ? "TMatch::cos("+var+")" : var;
  219. string cond = "TMed==1&&"+branch;
  220. tree->Draw(string(command+">>AllTMed").c_str(),"TMed==1");
  221. tree->Draw(string(command+">>TMedWithGamma1").c_str(),string(cond+"==1").c_str());
  222. tree->Draw(string(command+">>TMedWithGamma2").c_str(),string(cond+"==2").c_str());
  223. tree->Draw(string(command+">>TMedWithGamma3").c_str(),string(cond+"==3").c_str());
  224. tree->Draw(string(command+">>TMedWithGamma4").c_str(),string(cond+"==4").c_str());
  225. tree->Draw(string(command+">>TMedWithGamma5").c_str(),string(cond+"==5").c_str());
  226. tree->Draw(string(command+">>TMedWithGamma6").c_str(),string(cond+"==6").c_str());
  227. //Add together both OK, one from conversion, both from conversion
  228. if (fancy){
  229. TMedTrue->Add(TMedWithGamma1);
  230. TMedTrue->Add(TMedWithGamma2);
  231. TMedTrue->Add(TMedWithGamma3);
  232. //Add together one random + one OK/ from conversion
  233. TMedTrueRnd->Add(TMedWithGamma4);
  234. TMedTrueRnd->Add(TMedWithGamma5);
  235. }
  236. //Set the legend
  237. TLegend *leg = new TLegend(0.68,0.75,0.92,0.95);
  238. leg->AddEntry(AllTMed, "TMed all", "l");
  239. leg->AddEntry(TMedWithGamma1,"TMed+both OK", "l");
  240. leg->AddEntry(TMedWithGamma2,"TMed+OK+Conv", "l");
  241. if (!norm)leg->AddEntry(TMedWithGamma3,"TMed+both Conv", "l");
  242. leg->AddEntry(TMedWithGamma4,"TMed+OK+Rnd", "l");
  243. if (!norm)leg->AddEntry(TMedWithGamma5,"TMed+Conv+Rnd", "l");
  244. if (!norm)leg->AddEntry(TMedWithGamma6,"TMed+both Rnd", "l");
  245. TLegend *legFancy;
  246. if (fancy){
  247. if (norm){
  248. if (cos){
  249. legFancy = new TLegend(0.25,0.65,0.61,0.9);
  250. legFancy->SetTextSize(0.05);
  251. }
  252. else{
  253. legFancy = new TLegend(0.55,0.65,0.93,0.9);
  254. legFancy->SetTextSize(0.05);
  255. }
  256. }
  257. else{
  258. legFancy = new TLegend(0.5,0.65,0.9,0.9);
  259. legFancy->SetTextSize(0.04);
  260. }
  261. legFancy->AddEntry(AllTMed, "All #gamma#gamma","l");
  262. legFancy->AddEntry(TMedTrue, "True #gamma#gamma","l");
  263. legFancy->AddEntry(TMedTrueRnd, "True #gamma and random #gamma","l");
  264. if (!norm) legFancy->AddEntry(TMedWithGamma6, "Random #gamma#gamma","l");
  265. }
  266. //Normalize
  267. double allEntries = AllTMed->GetEntries();
  268. if (norm){
  269. AllTMed->Scale(1.0/allEntries);
  270. TMedWithGamma1->Scale(1.0/TMedWithGamma1->GetEntries());
  271. TMedWithGamma2->Scale(1.0/TMedWithGamma2->GetEntries());
  272. TMedWithGamma3->Scale(1.0/TMedWithGamma3->GetEntries());
  273. TMedWithGamma4->Scale(1.0/TMedWithGamma4->GetEntries());
  274. TMedWithGamma5->Scale(1.0/TMedWithGamma5->GetEntries());
  275. TMedWithGamma6->Scale(1.0/TMedWithGamma6->GetEntries());
  276. if(fancy){
  277. TMedTrue->Scale(1.0/TMedTrue->GetEntries());
  278. TMedTrueRnd->Scale(1.0/TMedTrueRnd->GetEntries());
  279. Ratio->Divide(TMedTrue,TMedTrueRnd);
  280. }
  281. AllTMed->GetYaxis()->SetTitle("Counts/nEntries [a.u.]");
  282. }
  283. //make the plot
  284. coutDebug("Saving the canvas.");
  285. TCanvas *canvas = c_canvas("");
  286. canvas->cd();
  287. if (!norm) canvas->SetLogy();
  288. if (!norm) AllTMed->GetYaxis()->SetRangeUser(0.1,AllTMed->GetMaximum()*30);
  289. else AllTMed->GetYaxis()->SetRangeUser(0.0,AllTMed->GetMaximum()*2);
  290. coutDebug("Histogram maximum: "+to_string(AllTMed->GetMaximum()));
  291. AllTMed->Draw();
  292. TMedWithGamma1->Draw("SAME");
  293. TMedWithGamma2->Draw("SAME");
  294. if (!norm)TMedWithGamma3->Draw("SAME");
  295. TMedWithGamma4->Draw("SAME");
  296. if (!norm)TMedWithGamma5->Draw("SAME");
  297. if (!norm)TMedWithGamma6->Draw("SAME");
  298. leg->Draw("SAME");
  299. coutDebug("Canvas saved!");
  300. TCanvas *canvasFancy = c_canvas("fancy");
  301. if (fancy){ //TODO: legend for black line, add ratio of the normalized histograms
  302. coutDebug("Plotting fancy canvas");
  303. canvasFancy->cd();
  304. coutDebug("Histogram maximum: "+to_string(AllTMed->GetMaximum()));
  305. if (norm){
  306. //canvasFancy->SetBottomMargin(0.1);
  307. float lowerPlotHeight = 0.3;
  308. TPad *pad1 = new TPad("pad1", "plot",0.0,lowerPlotHeight,1.0,1.0,0);
  309. TPad *pad2 = new TPad("pad2", "ratio",0.0,0.0,1.0,lowerPlotHeight,0);
  310. pad1->Draw();
  311. pad2->Draw();
  312. //modifiy pad for the ratio
  313. pad2->Clear();
  314. pad2->SetBorderSize (0);
  315. pad2->SetTopMargin (1e-6);
  316. pad2->SetBottomMargin(0.3);
  317. pad2->cd();
  318. Ratio->SetMarkerSize(1.0);
  319. Ratio->GetYaxis()->SetRangeUser(0.5 , 1.5);
  320. Ratio->GetYaxis()->SetNdivisions(505);
  321. Ratio->GetYaxis()->SetTitleOffset(0.5);
  322. Ratio->GetYaxis()->SetTitleSize(0.12);
  323. Ratio->GetYaxis()->SetLabelSize(0.1);
  324. Ratio->GetYaxis()->SetTitle("#gamma_{T}#gamma_{T}/#gamma_{T}#gamma_{R}");
  325. Ratio->GetXaxis()->SetTitleOffset(0.9);
  326. Ratio->GetXaxis()->SetTitleSize(0.15);
  327. Ratio->GetXaxis()->SetLabelSize(0.14);
  328. Ratio->Draw("E1");
  329. TLine * unityline = new TLine( cos ? -1.0 : 0.0, 1, cos ? 1.0 : 3.15, 1);
  330. unityline->SetLineStyle(2);
  331. unityline->SetLineColor(4);
  332. unityline->Draw("SAME");
  333. //modifiy pad for main plot
  334. pad1->Clear();
  335. pad1->SetBorderSize (0);
  336. pad1->SetBottomMargin(1e-6);
  337. pad1->SetTopMargin(pad1->GetTopMargin() / ( 1.0 - lowerPlotHeight) );
  338. pad1->cd();
  339. TMedTrue->GetYaxis()->SetRangeUser(0.0,TMedTrue->GetMaximum()*1.5);
  340. TMedTrue->GetYaxis()->SetTitleOffset(1.20);
  341. TMedTrue->GetYaxis()->SetLabelSize(0.05);
  342. TMedTrue->Draw();
  343. AllTMed->Draw("SAME");
  344. TMedTrueRnd->Draw("SAME");
  345. legFancy->Draw("SAME");
  346. }
  347. else{
  348. canvasFancy->SetLogy();
  349. AllTMed->GetYaxis()->SetRangeUser(0.1,AllTMed->GetMaximum()*30);
  350. AllTMed->Draw();
  351. TMedTrue->Draw("SAME");
  352. TMedTrueRnd->Draw("SAME");
  353. TMedWithGamma6->Draw("SAME");
  354. legFancy->Draw("SAME");
  355. }
  356. }
  357. string path = getTMplotsPath("TMed_"+angle+"_AllGammaContributions"+string(norm ? "_normalized" : ""), year, Reference, PHSP, B0, K1, Inc);
  358. if (Run != 0) replace(path,year,"Run_"+to_string(Run));
  359. if (cos) replace(path,angle,"cos"+angle);
  360. coutDebug("Saving plot into " + path);
  361. canvas->SaveAs(path.c_str());
  362. replace(path,".eps",".root");
  363. canvas->SaveAs(path.c_str());
  364. if (fancy){
  365. replace(path,".root","_fancy.eps");
  366. coutDebug("Saving fancy plot into " + path);
  367. canvasFancy->SaveAs(path.c_str());
  368. replace(path,".eps",".root");
  369. canvasFancy->SaveAs(path.c_str());
  370. }
  371. tree->Clear();
  372. AllTMed->Clear();
  373. TMedWithGamma1->Clear();
  374. TMedWithGamma2->Clear();
  375. TMedWithGamma3->Clear();
  376. TMedWithGamma4->Clear();
  377. TMedWithGamma5->Clear();
  378. TMedWithGamma6->Clear();
  379. TMedTrue->Clear();
  380. TMedTrueRnd->Clear();
  381. canvas->Clear();
  382. delete canvas;
  383. coutInfo("Done plotting.");
  384. return 1;
  385. }
  386. int plotAllCosAngleAllAngles(string year, int Run, bool Reference, bool PHSP, bool B0 = false, bool K1 = false, bool Inc = false, bool cos = false, bool norm = false){
  387. if (plotCosAngle("TM_gammas",year,Run,Reference,PHSP,B0,K1,Inc, "thetak", cos, norm)==0) return 0;
  388. if (plotCosAngle("TM_gammas",year,Run,Reference,PHSP,B0,K1,Inc, "thetal", cos, norm)==0) return 0;
  389. if (plotCosAngle("TM_gammas",year,Run,Reference,PHSP,B0,K1,Inc, "phi", cos, norm)==0) return 0;
  390. return 1;
  391. }
  392. int plotAllCosAngleAllYears(bool Reference, bool PHSP, bool B0 = false, bool K1 = false, bool Inc = false){
  393. vector<string> years = (B0||K1||Inc) ? yearsBkgMC(Reference,B0,K1,Inc,12) : yearsMC(Reference,PHSP,12);
  394. for (auto yr: years){
  395. if (plotAllCosAngleAllAngles(yr,0,Reference,PHSP,B0,K1,Inc, true, true)==0) return 0;
  396. if (plotAllCosAngleAllAngles(yr,0,Reference,PHSP,B0,K1,Inc, false, true)==0) return 0;
  397. if (plotAllCosAngleAllAngles(yr,0,Reference,PHSP,B0,K1,Inc, true, false)==0) return 0;
  398. if (plotAllCosAngleAllAngles(yr,0,Reference,PHSP,B0,K1,Inc, false, false)==0) return 0;
  399. }
  400. if (plotAllCosAngleAllAngles("2011",1,Reference,PHSP,false,false,false, false, false)==0) return 0;
  401. if (plotAllCosAngleAllAngles("2011",12,Reference,PHSP,false,false,false, false, false)==0) return 0;
  402. if (plotAllCosAngleAllAngles("2016",2,Reference,PHSP,false,false,false, false, false)==0) return 0;
  403. return 1;
  404. }
  405. int plotAllCosAngleAllRuns(bool Reference, bool PHSP){
  406. if (plotAllCosAngleAllAngles("2011",1,Reference,PHSP,false,false,false, false, false)==0) return 0;
  407. if (plotAllCosAngleAllAngles("2011",1,Reference,PHSP,false,false,false, false, true)==0) return 0;
  408. //if (plotAllCosAngleAllAngles("2011",12,Reference,PHSP,false,false,false, false, false)==0) return 0;
  409. if (plotAllCosAngleAllAngles("2016",2,Reference,PHSP,false,false,false, false, false)==0) return 0;
  410. if (plotAllCosAngleAllAngles("2016",2,Reference,PHSP,false,false,false, false, true)==0) return 0;
  411. return 1;
  412. }
  413. int plotAllCosAngleAll(){
  414. if (plotAllCosAngleAllYears( 0, 0, 0, 0, 0)==0) return 0;
  415. if (plotAllCosAngleAllYears( 1, 0, 0, 0, 0)==0) return 0;
  416. if (plotAllCosAngleAllYears( 0, 1, 0, 0, 0)==0) return 0;
  417. if (plotAllCosAngleAllYears( 1, 0, 0, 0, 1)==0) return 0;
  418. return 1;
  419. }
  420. //--------------------------------------------------------------------------------------------
  421. // Compare different gamma contributions for different TM methods //--------------------------------------------------------------------------------------------
  422. int plotGammaTMdiffTM(string branch, string year, bool Reference, bool PHSP, bool B0 = false, bool K1 = false, bool Inc = false){
  423. //Load the files
  424. coutInfo("Getting the TChain.");
  425. TChain *tree = GetTMfiles(std::stoi(year),Reference,PHSP,B0,K1,Inc);
  426. TH1D *h_TMed = generalHistogram("h_TMed", "",6,0.5,6.5, branch.c_str(), "Counts a.u.", kRed);
  427. h_TMed->SetFillColor(kRed);
  428. TH1D *h_BKGCAT = generalHistogram("h_BKGCAT", "",6,0.5,6.5, branch.c_str(), "Counts a.u.", kBlack);
  429. h_BKGCAT->SetFillColor(kBlack);
  430. TH1D *h_TMed_noPi0 = generalHistogram("h_TMed_noPi0", "",6,0.5,6.5, branch.c_str(), "Counts a.u.", kBlue);
  431. h_TMed_noPi0->SetFillColor(kBlue);
  432. TH1D *h_TMed_noPi0_noBplus = generalHistogram("h_TMed_noPi0_noBplus","",6,0.5,6.5, branch.c_str(), "Counts a.u.", kGreen);
  433. h_TMed_noPi0_noBplus->SetFillColor(kGreen);
  434. h_TMed->GetXaxis()->SetBinLabel(1,"Both OK");
  435. h_TMed->GetXaxis()->SetBinLabel(2,"OK+Conv");
  436. h_TMed->GetXaxis()->SetBinLabel(3,"Both Conv");
  437. h_TMed->GetXaxis()->SetBinLabel(4,"OK+Rnd");
  438. h_TMed->GetXaxis()->SetBinLabel(5,"Conv+Rnd");
  439. h_TMed->GetXaxis()->SetBinLabel(6,"Both Rnd");
  440. tree->Draw(string(branch+">>h_TMed").c_str(), "TMed==1");
  441. tree->Draw(string(branch+">>h_BKGCAT").c_str(), "TMedBKGCAT==1");
  442. tree->Draw(string(branch+">>h_TMed_noPi0").c_str(), "TMed_noPi0==1");
  443. tree->Draw(string(branch+">>h_TMed_noPi0_noBplus").c_str(), "TMed_noPi0_noBplus==1");
  444. //Set the legend
  445. TLegend *leg = new TLegend(0.68,0.61,0.92,0.95);
  446. leg->AddEntry(h_TMed, "TRUEID", "f");
  447. leg->AddEntry(h_BKGCAT, "BKGCAT", "f");
  448. leg->AddEntry(h_TMed_noPi0, "TRUEID wo #pi^{0}", "f");
  449. //leg->AddEntry(h_TMed_noPi0_noBplus, "TRUEID wo #pi^{0}, B^{+}", "l");
  450. //make the plot
  451. coutDebug("Saving the canvas.");
  452. TCanvas *canvas = c_canvas("");
  453. canvas->cd();
  454. //Create a TH stack
  455. THStack *hs = new THStack("hs","");
  456. hs->Add(h_TMed);
  457. hs->Add(h_BKGCAT);
  458. hs->Add(h_TMed_noPi0);
  459. //hs->Add(h_TMed_noPi0_noBplus);
  460. hs->Draw("nostackb"); //Draw it first so you can change the yaxis title....
  461. hs->GetYaxis()->SetTitle("Counts a.u.");
  462. hs->GetYaxis()->SetTitleOffset(1.6);
  463. hs->GetXaxis()->SetLabelSize(0.05);
  464. hs->Draw("nostackb");
  465. leg->Draw("SAME");
  466. string path = getTMplotsPath("GammaTM_compareTMmethods", year, Reference, PHSP, B0, K1, Inc);
  467. canvas->SaveAs(path.c_str());
  468. replace(path,".eps",".root");
  469. canvas->SaveAs(path.c_str());
  470. //Free the memory
  471. tree->Clear();
  472. h_TMed->Clear();
  473. h_BKGCAT->Clear();
  474. h_TMed_noPi0->Clear();
  475. h_TMed_noPi0_noBplus->Clear();
  476. canvas->Clear();
  477. delete canvas;
  478. coutInfo("Done plotting.");
  479. return 1;
  480. }
  481. int plotGammaTMdiffTMAllYears(bool Reference, bool PHSP, bool B0 = false, bool K1 = false, bool Inc = false){
  482. vector<string> years = (B0||K1||Inc) ? yearsBkgMC(Reference,B0,K1,Inc,12) : yearsMC(Reference,PHSP,12);
  483. for (auto yr: years){
  484. if (plotGammaTMdiffTM("TM_gammas",yr,Reference,PHSP,B0,K1,Inc)==0) return 0;
  485. if (plotGammaTMdiffTM("TM_gammas",yr,Reference,PHSP,B0,K1,Inc)==0) return 0;
  486. }
  487. return 1;
  488. }
  489. int plotGammaTMdiffTMAll(){
  490. if (plotGammaTMdiffTMAllYears( 0, 0, 0, 0, 0)==0) return 0;
  491. if (plotGammaTMdiffTMAllYears( 1, 0, 0, 0, 0)==0) return 0;
  492. if (plotGammaTMdiffTMAllYears( 0, 1, 0, 0, 0)==0) return 0;
  493. if (plotGammaTMdiffTMAllYears( 1, 0, 0, 0, 1)==0) return 0;
  494. return 1;
  495. }
  496. //--------------------------------------------------------------------------------------------
  497. // Test functions //--------------------------------------------------------------------------------------------
  498. bool testFunction(){
  499. setVerboseLevel(1);
  500. plotGammaTMdiffTM("TM_gammas","2011",0,0,0,0,0);
  501. return true;
  502. }
  503. void test(){
  504. if (testFunction()) cout << cGREEN << "All good!" << cRESET << endl;
  505. else coutERROR("Test failed!");
  506. }