ATLAS Offline Software
Loading...
Searching...
No Matches
plot_kinematics.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3
4import ROOT as R
5import python_tools as pt
6import numpy as np
7import os
8import argparse
9import re
10
11parser = argparse.ArgumentParser()
12parser.add_argument('--infile', type=str, help='input file path')
13parser.add_argument('--outdir', type=str, help='output directory')
14
15args = parser.parse_args()
16infilename = args.infile
17'''
18if "mc" in infilename:
19 run_number = "410000"
20 run_folder = "run_"+run_number
21else:
22 run_number = infilename.replace('/eos/atlas/atlascerngroupdisk/perf-lumi/Zcounting/Run3/MergedOutputs/HighMu/data22_13p6TeV/mc16e_cf/tree_', '')
23 run_number = run_number.replace('.root', '')
24 run_folder = "run_"+run_number
25'''
26pattern = re.compile(r"tree_(\d+)\.root")
27match = pattern.search(infilename)
28if match:
29 run_number = match.group(1)
30else:
31 run_number = "410000"
32run_folder = "run_"+run_number
33
34#os.system("mkdir -p " +outdir+"/"+run_number+"/kinematics")
35
36def main():
37
38 plotter_GeV("m_Z_mass_opsmu", "Z#rightarrow#mu#mu (op. sign) Mass", "m_{#mu#mu} [GeV]", 66, 116, "Entries/GeV")
39 plotter_GeV("m_leadingmu_pt", "Leading #mu p_{T}", "p^{#mu}_{T} [GeV]", 27, 200, "Entries/GeV")
40 plotter_GeV("m_subleadingmu_pt", "Subleading #mu p_{T}", "p^{#mu}_{T} [GeV]", 27, 200, "Entries/GeV")
41 plotter("m_leadingmu_eta", "Leading #mu #eta", "#eta^{#mu}", -2.5, 2.5, "Entries")
42 plotter("m_subleadingmu_eta", "Subleading #mu #eta", "#eta^{#mu}", -2.5, 2.5, "Entries")
43 plotter("m_leadingmu_phi", "Leading #mu #phi", "#phi^{#mu}", -3.4, 3.4, "Entries")
44 plotter("m_subleadingmu_phi", "Subleading #mu #phi", "#phi^{#mu}",-3.4, 3.4, "Entries")
45
46 plotter_GeV("m_Z_mass_opsele", "Z#rightarrow ee (op. sign) Mass", "m_{ee} [GeV]", 66, 116, "Entries/GeV")
47 plotter_GeV("m_leadingele_pt", "Leading e p_{T}", "p^{e}_{T} [GeV]", 27, 200, "Entries/GeV")
48 plotter_GeV("m_subleadingele_pt", "Subleading e p_{T}", "p^{e}_{T} [GeV]", 27, 200, "Entries/GeV")
49 plotter("m_leadingele_eta", "Leading e #eta", "#eta^{e}", -2.5, 2.5, "Entries")
50 plotter("m_subleadingele_eta", "Subleading e #eta", "#eta^{e}", -2.5, 2.5, "Entries")
51 plotter("m_leadingele_phi", "Leading e #phi", "#phi^{e}", -3.4, 3.4, "Entries")
52 plotter("m_subleadingele_phi", "Subleading e #phi", "#phi^{e}",-3.4, 3.4, "Entries")
53
54def plotter_GeV(histname, title, xlabel, xmin, xmax, ylabel):
55
56 c1 = R.TCanvas()
57 pad1 = R.TPad("pad1", "pad1", 0, 0, 1, 1)
58 pad1.SetRightMargin
59 rfile = R.TFile(infilename)
60
61 bins = get_bins(histname)
62
63 hist1 = rfile.Get(run_folder+"/GLOBAL/DQTGlobalWZFinder/" + histname)
64 hist2 = R.TH1F(histname, title, len(bins)-1, bins)
65 for i in range(0, hist1.GetNbinsX()):
66 hist2.SetBinContent(i, hist1.GetBinContent(i))
67 hist2.Draw("E0")
68
69 hist2.GetXaxis().SetTitle(xlabel)
70 hist2.GetXaxis().SetRangeUser(xmin, xmax)
71 hist2.GetYaxis().SetTitle(ylabel)
72
73 if "pt" in histname:
74 R.gPad.SetLogx()
75 hist2.GetXaxis().SetMoreLogLabels()
76 R.gPad.SetLogy()
77 pt.drawAtlasLabel(0.2, 0.56, "Internal")
78 pt.drawText(0.2, 0.50, "Data 2022")
79 pt.drawText(0.2, 0.44, "#sqrt{s} = 13.6 TeV")
80 pt.drawText(0.2, 0.38, "run "+run_number)
81 if "mu" in histname:
82 pt.drawText(0.2, 0.32, "p^{#mu}_{T} > 27 GeV")
83 pt.drawText(0.2, 0.26, "|#eta^{#mu}| < 2.4")
84 pt.drawText(0.2, 0.20, "66 < m_{#mu#mu} < 116 GeV")
85 else:
86 pt.drawText(0.2, 0.32, "p^{e}_{T} > 27 GeV")
87 pt.drawText(0.2, 0.26, "|#eta^{e}| < 1.37 or 1.52 < |#eta^{e}| < 2.4")
88 pt.drawText(0.2, 0.20, "66 < m_{ee} < 116 GeV")
89
90 else:
91 hist2.GetYaxis().SetRangeUser(0, hist2.GetMaximum()*1.2)
92 pt.drawAtlasLabel(0.2, 0.86, "Internal")
93 pt.drawText(0.2, 0.80, "Data 2022")
94 pt.drawText(0.2, 0.74, "#sqrt{s} = 13.6 TeV")
95 pt.drawText(0.2, 0.68, "run "+run_number)
96 if "mu" in histname:
97 pt.drawText(0.6, 0.86, "p^{#mu}_{T} > 27 GeV")
98 pt.drawText(0.6, 0.80, "|#eta^{#mu}| < 2.4")
99 pt.drawText(0.6, 0.74, "66 < m_{#mu#mu} < 116 GeV")
100 else:
101 pt.drawText(0.6, 0.86, "p^{e}_{T} > 27 GeV")
102 pt.drawText(0.6, 0.80, "|#eta^{e}| < 1.37 OR")
103 pt.drawText(0.6, 0.74, "1.52 < |#eta^{e}| < 2.4")
104 pt.drawText(0.6, 0.68, "66 < m_{ee} < 116 GeV")
105
106 c1.SaveAs(os.path.join(args.outdir, histname + ".pdf"))
107
108def plotter(histname, title, xlabel, xmin, xmax, ylabel):
109
110 c1 = R.TCanvas()
111 pad1 = R.TPad("pad1", "pad1", 0, 0, 1, 1)
112 pad1.SetRightMargin
113 rfile = R.TFile(infilename)
114
115 get_bins(histname)
116
117 hist = rfile.Get(run_folder+"/GLOBAL/DQTGlobalWZFinder/" + histname)
118
119 hist.Draw("HIST")
120
121 hist.GetXaxis().SetTitle(xlabel)
122 hist.GetXaxis().SetRangeUser(xmin, xmax)
123 hist.GetYaxis().SetRangeUser(0, hist.GetMaximum()*1.7)
124 hist.GetYaxis().SetTitle(ylabel)
125
126 pt.drawAtlasLabel(0.2, 0.86, "Internal")
127 pt.drawText(0.2, 0.80, "Data 2022")
128 pt.drawText(0.2, 0.74, "#sqrt{s} = 13.6 TeV")
129 pt.drawText(0.2, 0.68, "run "+run_number)
130 if "mu" in histname:
131 pt.drawText(0.6, 0.86, "p^{#mu}_{T} > 27 GeV")
132 pt.drawText(0.6, 0.80, "|#eta^{#mu}| < 2.4")
133 pt.drawText(0.6, 0.74, "66 < m_{#mu#mu} < 116 GeV")
134 else:
135 pt.drawText(0.6, 0.86, "p^{e}_{T} > 27 GeV")
136 pt.drawText(0.6, 0.80, "|#eta^{e}| < 1.37 OR")
137 pt.drawText(0.6, 0.74, "1.52 < |#eta^{e}| < 2.4")
138 pt.drawText(0.6, 0.68, "66 < m_{ee} < 116 GeV")
139
140 c1.SaveAs(os.path.join(args.outdir, histname + ".pdf"))
141
142def get_bins(histname):
143
144 zCutLow = 66
145 zCutHigh = 116
146 nzbins = int(zCutHigh - zCutLow)
147
148 if "mass" in histname:
149 bins = np.linspace(zCutLow, zCutHigh, nzbins+1)
150 elif "pt" in histname:
151 bins = np.linspace(0, 200, 201)
152 elif "eta" in histname:
153 bins = np.linspace(-2.5, 2.5, 50)
154 elif "phi" in histname:
155 bins = np.linspace(-3.4, 3.4, 34)
156 else:
157 bins = np.linspace(0, 100, 101)
158
159 return bins
160
161if __name__ == "__main__":
162 pt.setAtlasStyle()
163 R.gROOT.SetBatch(R.kTRUE)
164 main()
plotter_GeV(histname, title, xlabel, xmin, xmax, ylabel)
plotter(histname, title, xlabel, xmin, xmax, ylabel)