ATLAS Offline Software
Functions | Variables
plotting.python_tools Namespace Reference

Functions

def get_grl (year, verbose=True)
 
def setAtlasStyle ()
 
def drawAtlasLabel (x, y, text="", color=R.kBlack)
 
def drawText (x, y, text, size=27, color=R.kBlack)
 
def make_bands (vec_in, stdev, yval)
 
def get_year (run)
 
def get_dfz (basedir, year, run, channel, standardcuts=True)
 
def local_fit (tg, start, end, year)
 

Variables

dictionary plotlabel = {}
 
int runlivetimecut = 10*60
 
int lblivetimecut = 9
 

Function Documentation

◆ drawAtlasLabel()

def plotting.python_tools.drawAtlasLabel (   x,
  y,
  text = "",
  color = R.kBlack 
)

Definition at line 106 of file python_tools.py.

106 def drawAtlasLabel(x, y, text = "", color = R.kBlack):
107  l = R.TLatex()
108  l.SetNDC()
109  l.SetTextFont(72)
110  l.SetTextColor(color)
111 
112  delx = 0.115*696*R.gPad.GetWh()/(472*R.gPad.GetWw())
113 
114  l.DrawLatex(x,y,"ATLAS")
115  if len(text) > 0:
116  p = R.TLatex()
117  p.SetNDC()
118  p.SetTextFont(42)
119  p.SetTextColor(color)
120  p.DrawLatex(x+delx,y,text)
121 

◆ drawText()

def plotting.python_tools.drawText (   x,
  y,
  text,
  size = 27,
  color = R.kBlack 
)

Definition at line 122 of file python_tools.py.

122 def drawText(x, y, text, size=27, color = R.kBlack):
123  l = R.TLatex()
124  l.SetNDC()
125  if size > 0:
126  l.SetTextSize(size)
127  l.SetTextFont(43)
128  l.SetTextColor(color)
129  l.DrawLatex(x,y,text)
130 

◆ get_dfz()

def plotting.python_tools.get_dfz (   basedir,
  year,
  run,
  channel,
  standardcuts = True 
)
Standard retrieval of Z counting Panda dataframe from CSV

Definition at line 158 of file python_tools.py.

158 def get_dfz(basedir, year, run, channel, standardcuts = True):
159  '''
160  Standard retrieval of Z counting Panda dataframe from CSV
161  '''
162  if year=="run3":
163  mydir = basedir + "data"+get_year(run)+"_13p6TeV/physics_Main/"
164  elif year=="run2":
165  mydir = basedir + "data"+get_year(run)+"_13TeV/physics_Main/"
166  elif int(year) >= 22:
167  mydir = basedir + "data" + year + "_13p6TeV/physics_Main/"
168  else:
169  mydir = basedir + "data" + year + "_13TeV/physics_Main/" # untested
170 
171  try:
172  dfz = pd.read_csv(mydir + "run_" + run + ".csv")
173  except FileNotFoundError:
174  print("WARNING: CVS for run", run, "not found, will skip.")
175  return -1., 0., 0., 0., 0., None
176 
177  dfz_small = dfz
178 
179  if channel is not None:
180  # reading a specific channel and calculating some integrated quantities
181  dfz_small['ZLumi'] = dfz_small[channel + 'Lumi']
182  dfz_small['ZLumiErr'] = dfz_small[channel + 'LumiErr']
183  if standardcuts:
184  dfz_small = dfz_small.drop(dfz_small[dfz_small.ZLumi == 0].index)
185  dfz_small = dfz_small.drop(dfz_small[(dfz_small['LBLive']<lblivetimecut) | (dfz_small['PassGRL']==0)].index)
186 
187  dfz_small['ZLumi'] *= dfz_small['LBLive']
188  dfz_small['ZLumiErr'] *= dfz_small['LBLive']
189  zlumi = dfz_small['ZLumi'].sum()
190 
191  dfz_small['ZLumiErr'] *= dfz_small['ZLumiErr']
192  zerr = math.sqrt(dfz_small['ZLumiErr'].sum())
193  else:
194  # reading both Zee and Zll, some preparatory calculations, but nothing final
195  if standardcuts:
196  dfz_small = dfz_small.drop(dfz_small[(dfz_small.ZeeLumi == 0) | (dfz_small.ZmumuLumi == 0)].index)
197  dfz_small = dfz_small.drop(dfz_small[(dfz_small['LBLive']<lblivetimecut) | (dfz_small['PassGRL']==0)].index)
198  dfz_small['ZeeLumi'] *= dfz_small['LBLive']
199  dfz_small['ZeeLumiErr'] *= dfz_small['LBLive']
200  dfz_small['ZeeLumiErr'] *= dfz_small['ZeeLumiErr']
201  dfz_small['ZmumuLumi'] *= dfz_small['LBLive']
202  dfz_small['ZmumuLumiErr'] *= dfz_small['LBLive']
203  dfz_small['ZmumuLumiErr'] *= dfz_small['ZmumuLumiErr']
204  zlumi, zerr = 0., 0.
205 
206  livetime = dfz_small['LBLive'].sum()
207 
208  # Calculate integrated ATLAS luminosity
209  dfz_small['OffLumi'] *= dfz_small['LBLive']
210  olumi = dfz_small['OffLumi'].sum()
211 
212  # Grab start of the run for plotting later on
213  try:
214  run_start = dfz_small['LBStart'].iloc[0]
215  timestamp = time.gmtime(run_start)
216  timestamp = R.TDatime(timestamp[0], timestamp[1], timestamp[2], timestamp[3], timestamp[4], timestamp[5])
217  timestamp = timestamp.Convert()
218  except IndexError:
219  timestamp = 0
220 
221  return livetime, zlumi, zerr, olumi, timestamp, dfz_small
222 
223 

◆ get_grl()

def plotting.python_tools.get_grl (   year,
  verbose = True 
)
Get a list of runs for a year from the baseline GRL

Definition at line 23 of file python_tools.py.

23 def get_grl(year, verbose=True):
24  '''
25  Get a list of runs for a year from the baseline GRL
26  '''
27  CVMFS = "/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists"
28  grl = {}
29  grl["15"] = CVMFS + "/data15_13TeV/20190708/data15_13TeV.periodAllYear_DetStatus-v105-pro22-13_Unknown_PHYS_StandardGRL_All_Good_25ns.xml"
30  grl["16"] = CVMFS + "/data16_13TeV/20190708/data16_13TeV.periodAllYear_DetStatus-v105-pro22-13_Unknown_PHYS_StandardGRL_All_Good_25ns_WITH_IGNORES.xml"
31  grl["17"] = CVMFS + "/data17_13TeV/20190708/data17_13TeV.periodAllYear_DetStatus-v105-pro22-13_Unknown_PHYS_StandardGRL_All_Good_25ns_Triggerno17e33prim.xml"
32  grl["18"] = CVMFS + "/data18_13TeV/20190708/data18_13TeV.periodAllYear_DetStatus-v105-pro22-13_Unknown_PHYS_StandardGRL_All_Good_25ns_Triggerno17e33prim.xml"
33  grl["22"] = CVMFS + "/data22_13p6TeV/20230207/data22_13p6TeV.periodAllYear_DetStatus-v109-pro28-04_MERGED_PHYS_StandardGRL_All_Good_25ns.xml"
34  grl["23"] = CVMFS + "/data23_13p6TeV/20230828/data23_13p6TeV.periodAllYear_DetStatus-v110-pro31-06_MERGED_PHYS_StandardGRL_All_Good_25ns.xml"
35  grl["24"] = "/eos/atlas/atlascerngroupdisk/perf-lumi/Zcounting/Run3/MergedOutputs/data24_13p6TeV/latest_GRL.xml"
36 
37  if year != "24":
38  pipe = Popen(["grep", "RunList", grl[year]], stdout=PIPE, stderr=PIPE)
39  runs = re.sub("[^0-9,]", "", str(pipe.communicate()[0])).split(",")
40 
41  elif year == "24":
42  # preliminary GRL does not include "RunList" field, concatenate <Run> fields
43  runs=subprocess.check_output("grep '<Run>' "+grl[year]+" | tr -dc ' [:digit:] '", shell=True).decode('ascii').split()
44  if verbose:
45  print("20"+year+": list or runs =", runs)
46 
47  return runs
48 

◆ get_year()

def plotting.python_tools.get_year (   run)

Definition at line 145 of file python_tools.py.

145 def get_year(run):
146  run=int(run)
147  if run >= 472553: return "24"
148  elif run >= 450227: return "23"
149  elif run >= 427394: return "22"
150  elif run >= 348885: return "18"
151  elif run >= 325713: return "17"
152  elif run >= 297730: return "16"
153  elif run >= 276262: return "15"
154  else:
155  print("ERROR: Cannot classify run", run)
156  exit(1)
157 

◆ local_fit()

def plotting.python_tools.local_fit (   tg,
  start,
  end,
  year 
)
Fit over a sub-range of the data and print the mean and chi^2/NDF. 
Useful to test the remaining trends after the global Run-3 normalisation.

Definition at line 224 of file python_tools.py.

224 def local_fit(tg, start, end, year):
225  """
226  Fit over a sub-range of the data and print the mean and chi^2/NDF.
227  Useful to test the remaining trends after the global Run-3 normalisation.
228  """
229 
230  tg.Fit('pol0', 'Rq0','0', start, end)
231  mean = tg.GetFunction('pol0').GetParameter(0)
232  chi2 = tg.GetFunction('pol0').GetChisquare()
233  ndf = tg.GetFunction('pol0').GetNDF()
234  print("|", year, "|", round(mean,3), "|", round(chi2/ndf, 2), "|")

◆ make_bands()

def plotting.python_tools.make_bands (   vec_in,
  stdev,
  yval 
)

Definition at line 131 of file python_tools.py.

131 def make_bands(vec_in, stdev, yval):
132  vec_y = array('d', [yval] * (len(vec_in) + 2))
133  vec_x = array('d', sorted(vec_in))
134  err_y = array('d', [stdev] * (len(vec_in) + 2))
135 
136  vec_x.insert(0, 0)
137  vec_x.append(9999999999)
138 
139  line = R.TGraphErrors(len(vec_x), vec_x, vec_y, R.nullptr, err_y)
140  line.SetFillColorAlpha(8, 0.35)
141  line.SetFillStyle(4050)
142 
143  return line
144 

◆ setAtlasStyle()

def plotting.python_tools.setAtlasStyle ( )

Definition at line 49 of file python_tools.py.

49 def setAtlasStyle():
50  R.gROOT.SetStyle("Plain")
51 
52  # use plain black on white colors
53  icol = 0
54  R.gStyle.SetFrameBorderMode(icol)
55  R.gStyle.SetFrameFillColor(icol)
56  R.gStyle.SetCanvasBorderMode(icol)
57  R.gStyle.SetCanvasColor(icol)
58  R.gStyle.SetPadBorderMode(icol)
59  R.gStyle.SetPadColor(icol)
60  R.gStyle.SetStatColor(icol)
61 
62  R.gStyle.SetLineColor(R.kBlack)
63 
64  # set the paper & margin sizes
65  R.gStyle.SetPaperSize(20,26)
66 
67  # set margin sizes
68  R.gStyle.SetPadTopMargin(0.05)
69  R.gStyle.SetPadRightMargin(0.05)
70  R.gStyle.SetPadBottomMargin(0.16)
71  R.gStyle.SetPadLeftMargin(0.16)
72 
73  # set title offsets (for axis label)
74  R.gStyle.SetTitleXOffset(1.4)
75  R.gStyle.SetTitleYOffset(1.4)
76 
77  # use large fonts
78  font=42 # Helvetica
79  tsize=0.05
80  R.gStyle.SetTextFont(font)
81  R.gStyle.SetTextSize(tsize)
82  R.gStyle.SetLegendFont(font)
83  R.gStyle.SetLabelFont(font,"xyz")
84  R.gStyle.SetTitleFont(font,"xyz")
85 
86  R.gStyle.SetLabelSize(tsize,"xyz")
87  R.gStyle.SetTitleSize(tsize,"xyz")
88 
89  # use bold lines and markers
90  R.gStyle.SetMarkerStyle(20)
91  R.gStyle.SetMarkerSize(1.2)
92  R.gStyle.SetLineStyleString(2,"[12 12]") # postscript dashes
93 
94  R.gStyle.SetEndErrorSize(0.)
95 
96  # do not display any of the standard histogram decorations
97  R.gStyle.SetOptTitle(0)
98  R.gStyle.SetOptStat(0)
99  R.gStyle.SetOptFit(0)
100 
101  # put tick marks on top and RHS of plots
102  R.gStyle.SetPadTickX(1)
103  R.gStyle.SetPadTickY(1)
104  R.gROOT.ForceStyle()
105 

Variable Documentation

◆ lblivetimecut

int plotting.python_tools.lblivetimecut = 9

Definition at line 21 of file python_tools.py.

◆ plotlabel

dictionary plotting.python_tools.plotlabel = {}

Definition at line 13 of file python_tools.py.

◆ runlivetimecut

int plotting.python_tools.runlivetimecut = 10*60

Definition at line 19 of file python_tools.py.

AtlasMcWeight::decode
double decode(number_type binnedWeight)
Convert weight from unsigned to double.
Definition: AtlasMcWeight.cxx:32
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
MuonGM::round
float round(const float toRound, const unsigned int decimals)
Definition: Mdt.cxx:27
plotting.python_tools.get_dfz
def get_dfz(basedir, year, run, channel, standardcuts=True)
Definition: python_tools.py:158
plotting.python_tools.drawAtlasLabel
def drawAtlasLabel(x, y, text="", color=R.kBlack)
Definition: python_tools.py:106
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
plotting.python_tools.get_year
def get_year(run)
Definition: python_tools.py:145
calibdata.exit
exit
Definition: calibdata.py:236
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
plotting.python_tools.drawText
def drawText(x, y, text, size=27, color=R.kBlack)
Definition: python_tools.py:122
array
plotting.python_tools.setAtlasStyle
def setAtlasStyle()
Definition: python_tools.py:49
plotting.python_tools.local_fit
def local_fit(tg, start, end, year)
Definition: python_tools.py:224
plotting.python_tools.make_bands
def make_bands(vec_in, stdev, yval)
Definition: python_tools.py:131
plotting.python_tools.get_grl
def get_grl(year, verbose=True)
Definition: python_tools.py:23
str
Definition: BTagTrackIpAccessor.cxx:11
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
Trk::split
@ split
Definition: LayerMaterialProperties.h:38