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.

705 lines
26 KiB

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