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.

684 lines
25 KiB

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