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.

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