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.

787 lines
29 KiB

10 months ago
  1. # Script for accessing histograms of reconstructible and
  2. # reconstructed tracks for different tracking categories
  3. # created by hlt1_reco_baseline_with_mcchecking
  4. #
  5. # The efficency is calculated usig TGraphAsymmErrors
  6. # and Bayesian error bars
  7. #
  8. # author: Furkan Cetin
  9. # date: 10/2023
  10. #
  11. # flake8: noqa
  12. #
  13. # Takes data from Recent_get_resolution_and_eff_data.py and calculates efficiencies
  14. # python scripts/CompareResidualEfficiency.py --filename data/resolutions_and_effs_B_residual.root data/resolutions_and_effs_B.root
  15. # --trackers BestLong --label Residual Normal --outfile data/compare_effs_B_residual.root
  16. #
  17. import os, sys
  18. import argparse
  19. from ROOT import TMultiGraph, TLatex, TCanvas, TFile, TGaxis
  20. from ROOT import kGreen, kBlue, kBlack, kAzure, kGray, kOrange, kMagenta, kCyan
  21. from ROOT import gROOT, gStyle, gPad
  22. from ROOT import TEfficiency
  23. from array import array
  24. gROOT.SetBatch(True)
  25. from utils.components import unique_name_ext_re, findRootObjByName
  26. def getEfficiencyHistoNames():
  27. return ["p", "pt", "phi", "eta", "nPV"]
  28. def getTrackers(trackers):
  29. return trackers
  30. def getCompCuts(compare_cuts):
  31. return compare_cuts
  32. # data/resolutions_and_effs_Bd2KstEE_MDmaster.root:Track/...
  33. def getOriginFolders():
  34. basedict = {
  35. "Velo": {},
  36. "Upstream": {},
  37. "Forward": {},
  38. "Match": {},
  39. "BestLong": {},
  40. "Seed": {},
  41. }
  42. # evtl anpassen wenn die folders anders heissen
  43. basedict["Velo"]["folder"] = "VeloTrackChecker/"
  44. basedict["Upstream"]["folder"] = "UpstreamTrackChecker/"
  45. basedict["Forward"]["folder"] = "ForwardTrackChecker" + unique_name_ext_re() + "/"
  46. basedict["Match"]["folder"] = "MatchTrackChecker" + unique_name_ext_re() + "/"
  47. basedict["BestLong"]["folder"] = "BestLongTrackChecker" + unique_name_ext_re() + "/"
  48. basedict["Seed"]["folder"] = "SeedTrackChecker" + unique_name_ext_re() + "/"
  49. return basedict
  50. def getTrackNames():
  51. basedict = {
  52. "Velo": {},
  53. "Upstream": {},
  54. "Forward": {},
  55. "Match": {},
  56. "BestLong": {},
  57. "Seed": {},
  58. }
  59. basedict["Velo"] = "Velo"
  60. basedict["Upstream"] = "VeloUT"
  61. basedict["Forward"] = "Forward"
  62. basedict["Match"] = "Match"
  63. basedict["BestLong"] = "BestLong"
  64. basedict["Seed"] = "Seed"
  65. return basedict
  66. def get_colors():
  67. return [
  68. kBlack,
  69. kAzure,
  70. kGreen + 2,
  71. kMagenta + 1,
  72. kOrange,
  73. kCyan + 2,
  74. kBlack,
  75. kAzure,
  76. kGreen + 3,
  77. kMagenta + 2,
  78. kOrange,
  79. kCyan + 2,
  80. ]
  81. def get_markers():
  82. return [20, 21, 24, 25, 22, 23, 26, 32]
  83. def get_fillstyles():
  84. return [1003, 3001, 3002, 3325, 3144, 3244, 3444]
  85. def getGhostHistoNames():
  86. basedict = {
  87. "Velo": {},
  88. "Upstream": {},
  89. "Forward": {},
  90. "Match": {},
  91. "BestLong": {},
  92. "Seed": {},
  93. }
  94. basedict["Velo"] = ["eta", "nPV"]
  95. basedict["Upstream"] = ["eta", "p", "pt", "nPV"]
  96. basedict["Forward"] = ["eta", "p", "pt", "nPV"]
  97. basedict["Match"] = ["eta", "p", "pt", "nPV"]
  98. basedict["BestLong"] = ["eta", "p", "pt", "nPV"]
  99. basedict["Seed"] = ["eta", "p", "pt", "nPV"]
  100. return basedict
  101. def argument_parser():
  102. parser = argparse.ArgumentParser(description="location of the tuple file")
  103. parser.add_argument(
  104. "--filename",
  105. type=str,
  106. default=["data/resolutions_and_effs_B.root"],
  107. nargs="+",
  108. help="input files, including path",
  109. )
  110. parser.add_argument(
  111. "--outfile",
  112. type=str,
  113. default="data/compare_efficiency.root",
  114. help="output file",
  115. )
  116. parser.add_argument(
  117. "--trackers",
  118. type=str,
  119. nargs="+",
  120. default=["Forward", "Match", "BestLong", "Seed"], # ---
  121. help="Trackers to plot.",
  122. )
  123. parser.add_argument(
  124. "--label",
  125. nargs="+",
  126. default=["Eff"],
  127. help="label for files",
  128. )
  129. parser.add_argument(
  130. "--savepdf",
  131. action="store_true",
  132. help="save plots in pdf format",
  133. )
  134. parser.add_argument(
  135. "--compare",
  136. default=True,
  137. action="store_true",
  138. help="compare efficiencies",
  139. )
  140. parser.add_argument(
  141. "--compare-cuts",
  142. type=str,
  143. nargs="+",
  144. default=["long", "long_fromB", "long_fromB_P>5GeV"],
  145. help="which cuts get compared",
  146. )
  147. parser.add_argument(
  148. "--plot-electrons",
  149. default=True,
  150. action="store_true",
  151. help="plot electrons",
  152. )
  153. parser.add_argument(
  154. "--plot-electrons-only",
  155. action="store_true",
  156. help="plot only electrons",
  157. )
  158. return parser
  159. def get_files(tf, filename, label):
  160. for i, f in enumerate(filename):
  161. tf[label[i]] = TFile(f, "read")
  162. return tf
  163. def get_nicer_var_string(var: str):
  164. nice_vars = dict(pt="p_{T}", eta="#eta", phi="#phi")
  165. try:
  166. return nice_vars[var]
  167. except KeyError:
  168. return var
  169. def get_eff(eff, hist, tf, histoName, label, var):
  170. eff = {}
  171. hist = {}
  172. var = get_nicer_var_string(var)
  173. for i, lab in enumerate(label):
  174. numeratorName = histoName + "_reconstructed"
  175. numerator = findRootObjByName(tf[lab], numeratorName)
  176. # numerator = tf[lab].Get(numeratorName)
  177. denominatorName = histoName + "_reconstructible"
  178. denominator = findRootObjByName(tf[lab], denominatorName)
  179. # denominator = tf[lab].Get(denominatorName)
  180. if numerator.GetEntries() == 0 or denominator.GetEntries() == 0:
  181. continue
  182. teff = TEfficiency(numerator, denominator)
  183. teff.SetStatisticOption(7)
  184. # print("TBetaAlpha: "+ str(teff.GetBetaAlpha()))
  185. # print("TBetaBeta: "+ str(teff.GetBetaBeta()))
  186. eff[lab] = teff.CreateGraph()
  187. eff[lab].SetName(lab)
  188. eff[lab].SetTitle(lab)
  189. if histoName.find("Forward") != -1:
  190. if histoName.find("electron") != -1:
  191. eff[lab].SetTitle(lab + " Forward, e^{-}")
  192. else:
  193. eff[lab].SetTitle(lab + " Forward")
  194. elif histoName.find("Match") != -1:
  195. if histoName.find("electron") != -1:
  196. eff[lab].SetTitle(lab + " Match, e^{-}")
  197. else:
  198. eff[lab].SetTitle(lab + " Match")
  199. elif histoName.find("Seed") != -1:
  200. if histoName.find("electron") != -1:
  201. eff[lab].SetTitle(lab + " Seed, e^{-}")
  202. else:
  203. eff[lab].SetTitle(lab + " Seed")
  204. elif histoName.find("BestLong") != -1:
  205. if histoName.find("electron") != -1:
  206. eff[lab].SetTitle(lab + " BestLong, e^{-}")
  207. else:
  208. eff[lab].SetTitle(lab + " BestLong")
  209. # eff[lab].SetTitle(lab + " not e^{-}")
  210. # if histoName.find("strange") != -1:
  211. # eff[lab].SetTitle(lab + " from stranges")
  212. # if histoName.find("electron") != -1:
  213. # eff[lab].SetTitle(lab + " e^{-}")
  214. hist[lab] = denominator.Clone()
  215. hist[lab].SetName("h_numerator_notElectrons")
  216. hist[lab].SetTitle(var + " distribution, not e^{-}")
  217. if histoName.find("strange") != -1:
  218. hist[lab].SetTitle(var + " distribution, stranges")
  219. if histoName.find("electron") != -1:
  220. hist[lab].SetTitle(var + " distribution, e^{-}")
  221. return eff, hist
  222. def get_ghost(eff, hist, tf, histoName, label):
  223. ghost = {}
  224. for i, lab in enumerate(label):
  225. numeratorName = histoName + "_Ghosts"
  226. denominatorName = histoName + "_Total"
  227. numerator = findRootObjByName(tf[lab], numeratorName)
  228. denominator = findRootObjByName(tf[lab], denominatorName)
  229. # numerator = tf[lab].Get(numeratorName)
  230. # denominator = tf[lab].Get(denominatorName)
  231. print("Numerator = " + numeratorName)
  232. print("Denominator = " + denominatorName)
  233. teff = TEfficiency(numerator, denominator)
  234. teff.SetStatisticOption(7)
  235. ghost[lab] = teff.CreateGraph()
  236. print(lab)
  237. ghost[lab].SetName(lab)
  238. return ghost
  239. def PrCheckerEfficiency(
  240. filename,
  241. outfile,
  242. label,
  243. trackers,
  244. savepdf,
  245. compare,
  246. compare_cuts,
  247. plot_electrons,
  248. plot_electrons_only,
  249. ):
  250. from utils.LHCbStyle import setLHCbStyle, set_style
  251. from utils.ConfigHistos import (
  252. efficiencyHistoDict,
  253. ghostHistoDict,
  254. categoriesDict,
  255. getCuts,
  256. )
  257. from utils.CompareConfigHistos import getCompare, getCompColors
  258. from utils.Legend import place_legend
  259. setLHCbStyle()
  260. markers = get_markers()
  261. colors = get_colors()
  262. styles = get_fillstyles()
  263. tf = {}
  264. tf = get_files(tf, filename, label)
  265. outputfile = TFile(outfile, "recreate")
  266. latex = TLatex()
  267. latex.SetNDC()
  268. latex.SetTextSize(0.05)
  269. efficiencyHistoDict = efficiencyHistoDict()
  270. efficiencyHistos = getEfficiencyHistoNames()
  271. ghostHistos = getGhostHistoNames()
  272. ghostHistoDict = ghostHistoDict()
  273. categories = categoriesDict()
  274. cuts = getCuts()
  275. compareDict = getCompare()
  276. compareCuts = getCompCuts(compare_cuts)
  277. compareColors = getCompColors()
  278. trackers = getTrackers(trackers)
  279. folders = getOriginFolders()
  280. for tracker in trackers:
  281. outputfile.cd()
  282. trackerDir = outputfile.mkdir(tracker)
  283. trackerDir.cd()
  284. for cut in cuts[tracker]:
  285. cutDir = trackerDir.mkdir(cut)
  286. cutDir.cd()
  287. folder = folders[tracker]["folder"]
  288. print(folder)
  289. histoBaseName = "Track/" + folder + tracker + "/" + cut + "_"
  290. # calculate efficiency
  291. for histo in efficiencyHistos:
  292. canvastitle = (
  293. "efficiency_" + histo + ", " + categories[tracker][cut]["title"]
  294. )
  295. # get efficiency for not electrons category
  296. histoName = histoBaseName + "" + efficiencyHistoDict[histo]["variable"]
  297. print("not electrons: " + histoName)
  298. eff = {}
  299. hist_den = {}
  300. eff, hist_den = get_eff(eff, hist_den, tf, histoName, label, histo)
  301. if categories[tracker][cut]["plotElectrons"] and plot_electrons:
  302. histoNameElec = (
  303. "Track/"
  304. + folder
  305. + tracker
  306. + "/"
  307. + categories[tracker][cut]["Electrons"]
  308. )
  309. histoName_e = (
  310. histoNameElec + "_" + efficiencyHistoDict[histo]["variable"]
  311. )
  312. print("electrons: " + histoName_e)
  313. eff_elec = {}
  314. hist_elec = {}
  315. eff_elec, hist_elec = get_eff(
  316. eff_elec,
  317. hist_elec,
  318. tf,
  319. histoName_e,
  320. label,
  321. histo,
  322. )
  323. name = "efficiency_" + histo
  324. canvas = TCanvas(name, canvastitle)
  325. canvas.SetRightMargin(0.1)
  326. mg = TMultiGraph()
  327. for i, lab in enumerate(label):
  328. if not plot_electrons_only:
  329. mg.Add(eff[lab])
  330. set_style(eff[lab], colors[i], markers[i], styles[i])
  331. if categories[tracker][cut]["plotElectrons"] and plot_electrons:
  332. mg.Add(eff_elec[lab])
  333. set_style(eff_elec[lab], colors[i], markers[i + 2], styles[i])
  334. mg.Draw("AP")
  335. mg.GetYaxis().SetRangeUser(0, 1.05)
  336. xtitle = efficiencyHistoDict[histo]["xTitle"]
  337. unit_l = xtitle.split("[")
  338. if "]" in unit_l[-1]:
  339. unit = unit_l[-1].replace("]", "")
  340. else:
  341. unit = ""
  342. print(unit)
  343. mg.GetXaxis().SetTitle(xtitle)
  344. mg.GetXaxis().SetTitleSize(0.06)
  345. mg.GetYaxis().SetTitle(
  346. "Efficiency of Long Tracks",
  347. ) # (" + str(round(hist_den[label[0]].GetBinWidth(1), 2)) + f"{unit})"+"^{-1}")
  348. mg.GetYaxis().SetTitleSize(0.06)
  349. mg.GetYaxis().SetTitleOffset(1.1)
  350. mg.GetXaxis().SetRangeUser(*efficiencyHistoDict[histo]["range"])
  351. mg.GetXaxis().SetNdivisions(10, 5, 0)
  352. mygray = 18
  353. myblue = kBlue - 9
  354. for i, lab in enumerate(label):
  355. rightmax = 1.05 * hist_den[lab].GetMaximum()
  356. scale = gPad.GetUymax() / rightmax
  357. hist_den[lab].Scale(scale)
  358. if categories[tracker][cut]["plotElectrons"] and plot_electrons:
  359. rightmax = 1.05 * hist_elec[lab].GetMaximum()
  360. scale = gPad.GetUymax() / rightmax
  361. hist_elec[lab].Scale(scale)
  362. if i == 0:
  363. if not plot_electrons_only:
  364. set_style(hist_den[lab], mygray, markers[i], styles[i])
  365. gStyle.SetPalette(2, array("i", [mygray - 1, myblue + 1]))
  366. hist_den[lab].Draw("HIST PLC SAME")
  367. if categories[tracker][cut]["plotElectrons"] and plot_electrons:
  368. set_style(hist_elec[lab], myblue, markers[i], styles[i])
  369. hist_elec[lab].SetFillColorAlpha(myblue, 0.35)
  370. hist_elec[lab].Draw("HIST PLC SAME")
  371. # else:
  372. # print(
  373. # "No distribution plotted for other labels.",
  374. # "Can be added by uncommenting the code below this print statement.",
  375. # )
  376. # set_style(hist_den[lab], mygray, markers[i], styles[i])
  377. # gStyle.SetPalette(2, array("i", [mygray - 1, myblue + 1]))
  378. # hist_den[lab].Draw("HIST PLC SAME")
  379. if histo == "p":
  380. pos = [0.53, 0.4, 1.01, 0.71]
  381. elif histo == "pt":
  382. pos = [0.5, 0.4, 0.98, 0.71]
  383. elif histo == "phi":
  384. pos = [0.3, 0.3, 0.9, 0.6]
  385. else:
  386. pos = [0.4, 0.37, 0.88, 0.68]
  387. legend = place_legend(
  388. canvas, *pos, header="LHCb Simulation", option="LPE"
  389. )
  390. for le in legend.GetListOfPrimitives():
  391. if "distribution" in le.GetLabel():
  392. le.SetOption("LF")
  393. legend.SetTextFont(132)
  394. legend.SetTextSize(0.04)
  395. legend.Draw()
  396. for lab in label:
  397. if not plot_electrons_only:
  398. eff[lab].Draw("P SAME")
  399. if categories[tracker][cut]["plotElectrons"] and plot_electrons:
  400. eff_elec[lab].Draw("P SAME")
  401. cutName = categories[tracker][cut]["title"]
  402. latex.DrawLatex(legend.GetX1() + 0.01, legend.GetY1() - 0.05, cutName)
  403. low = 0
  404. high = 1.05
  405. gPad.Update()
  406. axis = TGaxis(
  407. gPad.GetUxmax(),
  408. gPad.GetUymin(),
  409. gPad.GetUxmax(),
  410. gPad.GetUymax(),
  411. low,
  412. high,
  413. 510,
  414. "+U",
  415. )
  416. axis.SetTitleFont(132)
  417. axis.SetTitleSize(0.06)
  418. axis.SetTitleOffset(0.55)
  419. axis.SetTitle(
  420. "# Tracks " + get_nicer_var_string(histo) + " distribution [a.u.]",
  421. )
  422. axis.SetLabelSize(0)
  423. axis.Draw()
  424. canvas.RedrawAxis()
  425. if savepdf:
  426. filestypes = ["pdf"] # , "png", "eps", "C", "ps", "tex"]
  427. for ftype in filestypes:
  428. if not plot_electrons_only:
  429. canvasName = tracker + "_" + cut + "_" + histo + "." + ftype
  430. else:
  431. canvasName = (
  432. tracker + "Electrons_" + cut + "_" + histo + "." + ftype
  433. )
  434. canvas.SaveAs("checks/" + canvasName)
  435. # canvas.SetRightMargin(0.05)
  436. canvas.Write()
  437. # calculate ghost rate
  438. histoBaseName = "Track/" + folder + tracker + "/"
  439. for histo in ghostHistos[tracker]:
  440. trackerDir.cd()
  441. title = "ghost_rate_vs_" + histo
  442. gPad.SetTicks()
  443. histoName = histoBaseName + ghostHistoDict[histo]["variable"]
  444. ghost = {}
  445. hist_den = {}
  446. ghost = get_ghost(ghost, hist_den, tf, histoName, label)
  447. canvas = TCanvas(title, title)
  448. mg = TMultiGraph()
  449. for i, lab in enumerate(label):
  450. mg.Add(ghost[lab])
  451. set_style(ghost[lab], colors[i], markers[i], styles[i])
  452. xtitle = ghostHistoDict[histo]["xTitle"]
  453. mg.GetXaxis().SetTitle(xtitle)
  454. mg.GetYaxis().SetTitle("Fraction of fake tracks")
  455. mg.Draw("ap")
  456. mg.GetXaxis().SetTitleSize(0.06)
  457. mg.GetYaxis().SetTitleSize(0.06)
  458. mg.GetYaxis().SetTitleOffset(1.1)
  459. mg.GetXaxis().SetRangeUser(*efficiencyHistoDict[histo]["range"])
  460. mg.GetXaxis().SetNdivisions(10, 5, 0)
  461. # for lab in label:
  462. # ghost[lab].Draw("P SAME")
  463. if histo == "p":
  464. pos = [0.53, 0.4, 1.00, 0.71]
  465. elif histo == "pt":
  466. pos = [0.5, 0.4, 0.98, 0.71]
  467. elif histo == "eta":
  468. pos = [0.35, 0.6, 0.85, 0.9]
  469. elif histo == "phi":
  470. pos = [0.3, 0.3, 0.9, 0.6]
  471. else:
  472. pos = [0.4, 0.37, 0.80, 0.68]
  473. legend = place_legend(canvas, *pos, header="LHCb Simulation", option="LPE")
  474. legend.SetTextFont(132)
  475. legend.SetTextSize(0.04)
  476. legend.Draw()
  477. # if histo != "nPV":
  478. # latex.DrawLatex(0.7, 0.85, "LHCb simulation")
  479. # else:
  480. # latex.DrawLatex(0.2, 0.85, "LHCb simulation")
  481. # mg.GetYaxis().SetRangeUser(0, 0.4)
  482. if histo == "eta":
  483. mg.GetYaxis().SetRangeUser(0, 0.4)
  484. # track_name = names[tracker] + " tracks"
  485. # latex.DrawLatex(0.7, 0.75, track_name)
  486. # canvas.PlaceLegend()
  487. if savepdf:
  488. filestypes = ["pdf"] # , "png", "eps", "C", "ps", "tex"]
  489. for ftype in filestypes:
  490. canvas.SaveAs(
  491. "checks/" + tracker + "ghost_rate_" + histo + "." + ftype,
  492. )
  493. canvas.Write()
  494. #
  495. # Compare electron efficiencies of different trackers
  496. #
  497. plot_electrons_only = True
  498. if compare:
  499. print("\nCompare Efficiencies: ")
  500. outputfile.cd()
  501. compareDir = outputfile.mkdir("CompareEff")
  502. compareDir.cd()
  503. for jcut in compareCuts: # [long, long_fromB, long_fromB_P>5GeV]
  504. for histo in efficiencyHistos: # [p, pt, phi, eta, nPV]
  505. canvastitle = "efficiency_" + histo + "_" + jcut
  506. name = "efficiency_" + histo + "_" + jcut
  507. canvas = TCanvas(name, canvastitle)
  508. canvas.SetRightMargin(0.1)
  509. mg = TMultiGraph()
  510. dist_eff = {}
  511. dist_hist_den = {}
  512. dist_eff_elec = {}
  513. dist_hist_elec = {}
  514. First = True
  515. dist_tracker = ""
  516. markeritr = 0
  517. for tracker in trackers: # [BestLong, Forward, Match, Seed]
  518. cut = compareDict[jcut][tracker]
  519. folder = folders[tracker]["folder"]
  520. print(folder)
  521. jcolor = compareColors[tracker]
  522. histoName = (
  523. "Track/"
  524. + folder
  525. + tracker
  526. + "/"
  527. + cut
  528. + "_"
  529. + ""
  530. + efficiencyHistoDict[histo]["variable"]
  531. )
  532. print("not electrons: " + histoName)
  533. eff = {}
  534. hist_den = {}
  535. eff, hist_den = get_eff(eff, hist_den, tf, histoName, label, histo)
  536. if categories[tracker][cut]["plotElectrons"] and plot_electrons:
  537. histoNameElec = (
  538. "Track/"
  539. + folder
  540. + tracker
  541. + "/"
  542. + categories[tracker][cut]["Electrons"]
  543. )
  544. histoName_e = (
  545. histoNameElec + "_" + efficiencyHistoDict[histo]["variable"]
  546. )
  547. print("electrons: " + histoName_e)
  548. eff_elec = {}
  549. hist_elec = {}
  550. eff_elec, hist_elec = get_eff(
  551. eff_elec,
  552. hist_elec,
  553. tf,
  554. histoName_e,
  555. label,
  556. histo,
  557. )
  558. if First:
  559. dist_eff_elec = eff_elec
  560. dist_hist_elec = hist_elec
  561. if First:
  562. dist_tracker = tracker
  563. dist_eff = eff
  564. dist_hist_den = hist_den
  565. First = False
  566. for i, lab in enumerate(label):
  567. if categories[tracker][cut]["plotElectrons"] and plot_electrons:
  568. mg.Add(eff_elec[lab])
  569. set_style(
  570. eff_elec[lab],
  571. colors[jcolor + i],
  572. markers[i + markeritr],
  573. styles[i],
  574. )
  575. markeritr = markeritr + 1
  576. # set_style(
  577. # eff_elec[lab], colors[jcolor], markers[i], styles[i]
  578. # )
  579. markeritr = 0
  580. mg.Draw("AP")
  581. mg.GetYaxis().SetRangeUser(0, 1.05)
  582. xtitle = efficiencyHistoDict[histo]["xTitle"]
  583. unit_l = xtitle.split("[")
  584. if "]" in unit_l[-1]:
  585. unit = unit_l[-1].replace("]", "")
  586. else:
  587. unit = ""
  588. print(unit)
  589. mg.GetXaxis().SetTitle(xtitle)
  590. mg.GetXaxis().SetTitleSize(0.06)
  591. mg.GetYaxis().SetTitle(
  592. "Efficiency of Long Tracks",
  593. ) # (" + str(round(hist_den[label[0]].GetBinWidth(1), 2)) + f"{unit})"+"^{-1}")
  594. mg.GetYaxis().SetTitleSize(0.06)
  595. mg.GetYaxis().SetTitleOffset(1.1)
  596. mg.GetXaxis().SetRangeUser(*efficiencyHistoDict[histo]["range"])
  597. mg.GetXaxis().SetNdivisions(10, 5, 0)
  598. mygray = 16
  599. myblue = kBlue - 7
  600. dist_cut = compareDict[jcut][dist_tracker]
  601. for i, lab in enumerate(label):
  602. rightmax = 1.05 * dist_hist_den[lab].GetMaximum()
  603. scale = gPad.GetUymax() / rightmax
  604. dist_hist_den[lab].Scale(scale)
  605. if (
  606. categories[dist_tracker][dist_cut]["plotElectrons"]
  607. and plot_electrons
  608. ):
  609. rightmax = 1.05 * dist_hist_elec[lab].GetMaximum()
  610. scale = gPad.GetUymax() / rightmax
  611. dist_hist_elec[lab].Scale(scale)
  612. if i == len(label) - 1:
  613. if not plot_electrons_only:
  614. set_style(dist_hist_den[lab], mygray, markers[i], styles[i])
  615. # gStyle.SetPalette(2, array("i", [mygray - 1, myblue + 1]))
  616. dist_hist_den[lab].SetFillColorAlpha(mygray, 0.5)
  617. dist_hist_den[lab].Draw("HIST PLC SAME")
  618. if (
  619. categories[dist_tracker][dist_cut]["plotElectrons"]
  620. and plot_electrons
  621. ):
  622. set_style(
  623. dist_hist_elec[lab], mygray, markers[i], styles[i]
  624. )
  625. # gStyle.SetPalette(2, array("i", [mygray - 1, myblue + 1]))
  626. # dist_hist_elec[lab].SetFillColor(myblue)
  627. dist_hist_elec[lab].SetFillColorAlpha(myblue, 0.5)
  628. dist_hist_elec[lab].Draw("HIST PLC SAME")
  629. # else:
  630. # print(
  631. # "No distribution plotted for other labels.",
  632. # "Can be added by uncommenting the code below this print statement.",
  633. # )
  634. # set_style(dist_hist_den[lab], mygray, markers[i], styles[i])
  635. # gStyle.SetPalette(2, array("i", [mygray - 1, myblue + 1]))
  636. # dist_hist_den[lab].Draw("HIST PLC SAME")
  637. if histo == "p":
  638. pos = [0.53, 0.4, 1.01, 0.71]
  639. elif histo == "pt":
  640. pos = [0.5, 0.4, 0.98, 0.71]
  641. elif histo == "phi":
  642. pos = [0.3, 0.3, 0.9, 0.6]
  643. else:
  644. pos = [0.4, 0.37, 0.88, 0.68]
  645. legend = place_legend(
  646. canvas, *pos, header="LHCb Simulation", option="LPE"
  647. )
  648. for le in legend.GetListOfPrimitives():
  649. if "distribution" in le.GetLabel():
  650. le.SetOption("LF")
  651. legend.SetTextFont(132)
  652. legend.SetTextSize(0.04)
  653. legend.Draw()
  654. for lab in label:
  655. if not plot_electrons_only:
  656. dist_eff[lab].Draw("P SAME")
  657. if categories[tracker][cut]["plotElectrons"] and plot_electrons:
  658. dist_eff_elec[lab].Draw("P SAME")
  659. cutName = categories[tracker][cut]["title"]
  660. latex.DrawLatex(legend.GetX1() + 0.01, legend.GetY1() - 0.05, cutName)
  661. low = 0
  662. high = 1.05
  663. gPad.Update()
  664. axis = TGaxis(
  665. gPad.GetUxmax(),
  666. gPad.GetUymin(),
  667. gPad.GetUxmax(),
  668. gPad.GetUymax(),
  669. low,
  670. high,
  671. 510,
  672. "+U",
  673. )
  674. axis.SetTitleFont(132)
  675. axis.SetTitleSize(0.06)
  676. axis.SetTitleOffset(0.55)
  677. axis.SetTitle(
  678. "# Tracks " + get_nicer_var_string(histo) + " distribution [a.u.]",
  679. )
  680. axis.SetLabelSize(0)
  681. axis.Draw()
  682. canvas.RedrawAxis()
  683. if savepdf:
  684. filestypes = ["pdf"] # , "png", "eps", "C", "ps", "tex"]
  685. for ftype in filestypes:
  686. if not plot_electrons_only:
  687. canvasName = (
  688. "Compare_"
  689. + tracker
  690. + "_"
  691. + cut
  692. + "_"
  693. + histo
  694. + "."
  695. + ftype
  696. )
  697. else:
  698. canvasName = (
  699. "Compare_"
  700. + tracker
  701. + "Electrons_"
  702. + cut
  703. + "_"
  704. + histo
  705. + "."
  706. + ftype
  707. )
  708. canvas.SaveAs("checks/" + canvasName)
  709. # canvas.SetRightMargin(0.05)
  710. canvas.Write()
  711. outputfile.Write()
  712. outputfile.Close()
  713. if __name__ == "__main__":
  714. parser = argument_parser()
  715. args = parser.parse_args()
  716. PrCheckerEfficiency(**vars(args))