ATLAS Offline Software
Loading...
Searching...
No Matches
DeMoLib Namespace Reference

Functions

 MakeTProfile (name, xtitle, ytitle, xmin, xmax, nbins, color)
 MakeTH1 (name, xtitle, ytitle, xmin, xmax, nbins, color)
 SetXLabel (h, list)
 MakeLegend (xmin, ymin, xmax, ymax)
 returnPeriod (runNb, system, year, tag)
 Return the data period of a run based on the information stored in YearStats-[system]/[year]/[tag]/runs-ALL.dat.
 retrieveYearTagProperties (year, tag)
 Return the year/tag properties (defect/veto/lumi tags...) stored in YearStats-common/DeMoConfig-[year]-[tag].dat.
 strLumi (lumi, unit="ub", latex=True, floatNumber=False)
 Return a string with the luminosity in a human readable way If the unit is %%, this is a percentage.
 plotStack (name, histo, index, indexName, histoIntLumi, lumiBool, resStack, resCanvas, resLegend, recovBool=True, compBool=False, approvedPlots=False)
 initializeMonitoredDefects (system, partitions, defects0, defectVeto, veto, signOff, year, tag, runlist={})

Variables

int iColor = 0
list colorPalette = [kBlue+3,kRed+1,kGreen-2,kOrange,kBlue-4,kMagenta+2,kYellow+1,kSpring-9,kAzure+6,kViolet-4,kPink,kBlue-9,kPink-6]

Function Documentation

◆ initializeMonitoredDefects()

DeMoLib.initializeMonitoredDefects ( system,
partitions,
defects0,
defectVeto,
veto,
signOff,
year,
tag,
runlist = {} )

Definition at line 294 of file DeMoLib.py.

294def initializeMonitoredDefects(system,partitions,defects0,defectVeto,veto,signOff,year,tag,runlist = {}):
295
296 runlist["filename"] = "runlist-%s-%s.dat"%(year,tag)
297

◆ MakeLegend()

DeMoLib.MakeLegend ( xmin,
ymin,
xmax,
ymax )

Definition at line 46 of file DeMoLib.py.

46def MakeLegend(xmin,ymin,xmax,ymax):
47 l = TLegend(xmin,ymin,xmax,ymax)
48 l.SetFillColor(kWhite)
49 l.SetTextSize(0.03)
50 l.SetBorderSize(0)
51 return l
52

◆ MakeTH1()

DeMoLib.MakeTH1 ( name,
xtitle,
ytitle,
xmin,
xmax,
nbins,
color )

Definition at line 30 of file DeMoLib.py.

30def MakeTH1(name,xtitle,ytitle,xmin,xmax,nbins,color):
31 h = TH1F(name,name,nbins, xmin,xmax)
32 h.SetYTitle(ytitle)
33 h.SetXTitle(xtitle)
34 h.SetLineColor(1)
35 h.SetMarkerStyle(22)
36 h.SetMarkerColor(color)
37 h.SetFillColor(color)
38 h.Sumw2()
39 return h
40

◆ MakeTProfile()

DeMoLib.MakeTProfile ( name,
xtitle,
ytitle,
xmin,
xmax,
nbins,
color )

Definition at line 18 of file DeMoLib.py.

18def MakeTProfile(name,xtitle,ytitle,xmin,xmax,nbins,color):
19 h = TProfile(name,name, nbins, xmin, xmax)
20 h.SetYTitle(ytitle)
21 h.SetXTitle(xtitle)
22 h.SetMarkerStyle(22)
23 h.SetMarkerColor(color)
24 h.SetLineColor(1)
25 h.SetFillColor(color)
26 h.SetStats(0)
27 h.SetTitle("")
28 return h
29

◆ plotStack()

DeMoLib.plotStack ( name,
histo,
index,
indexName,
histoIntLumi,
lumiBool,
resStack,
resCanvas,
resLegend,
recovBool = True,
compBool = False,
approvedPlots = False )

Definition at line 118 of file DeMoLib.py.

118def plotStack(name,histo,index,indexName,histoIntLumi,lumiBool,resStack,resCanvas,resLegend,recovBool = True,compBool = False,approvedPlots = False):
119# name: Mainly an index of the output. Also used to define TAxis Title
120# histo: dict of histograms or TProfile to be displayed
121# index: list of keys of histo to be displayed
122# indexName: dict of namesof index used for the TLegend
123# histoIntLumi : integrated lumi with the same x binning as histo
124# lumiBool : display results in term of lumi and not percent
125# resStack, resCanvas, resLegend: dict of (stacks, canvas, legend) outputs
126# recovBool: display the recoverable histograms (referenced as %%%__recov in histo
127# compBool: this is a >=2 yearTag plots. Write all numbers in TLegend and not only last bin (that is not meaningful in yearTag)
128
129 # unit is the main unit. unitAux is the complementary one used only the TLegend
130 if (lumiBool):
131 unit = "pb^{-1}"
132 unitAux = "%%"
133 else:
134 unit = "%%"
135 unitAux = "pb^{-1}"
136
137 nameSplitted = name.split("--") # Assume that the name is "Veto/defect (y axis) - Year/Run (x axis)- Dataset name"
138 xAxisTitle = nameSplitted[1]
139 if unit == "%%":
140 yAxisTitle = "Lost luminosity due to %s [%%]"%(nameSplitted[0])
141 else:
142 yAxisTitle = "Lost luminosity due to %s [%s]"%(nameSplitted[0],unit)
143 legendHeader = "%s - %s"%(nameSplitted[2],time.strftime("%d %b", time.localtime()))
144
145 resCanvas[name] = TCanvas(name,"%s - %s"%(yAxisTitle,xAxisTitle),100, 10, 1350, 500)
146 resCanvas[name].SetLeftMargin(0.08)
147 resCanvas[name].SetRightMargin(0.35)
148 resCanvas[name].SetGridy(1)
149 resStack[name] = THStack("%s_stack"%name,"")
150 resLegend[name] = MakeLegend(0.66,0.8,0.98,0.95) # Y1 will be redefined later according to the number of entries
151 resLegend[name].AddEntry(0, "", "")
152
153 first = True
154
155 nBinsX = histoIntLumi.GetNbinsX()
156 totalIneff = 0.
157 if (compBool):
158 totalIneff_comp = nBinsX * [0.]
159
160 totalIntegratedLumi = histoIntLumi.GetBinContent(nBinsX)
161 if lumiBool:
162 auxScaleFactor = 100./totalIntegratedLumi
163 else:
164 auxScaleFactor = totalIntegratedLumi/100.
165
166 tmpColor = [kBlue-4,kOrange-7,kTeal+1,kMagenta-4,kPink-3,kGreen+3,kSpring-3,kViolet+4,kAzure-8,kCyan+1]
167 tmpColorIndex = 0
168
169 for iIndex in sorted(index,reverse=True):
170 if first: # Create a recoverable histograms just in case of
171 resStack["%s__recov"%name] = MakeTH1("h1_%s__recovTotal"%(name),"Recoverable","",-0.5,-0.5+nBinsX,nBinsX,1)
172 resStack["%s__recov"%name].SetMarkerStyle(23)
173 first = False
174 iIndexName = iIndex.split("_")[0]
175
176 # Define a "temporary" color for the defect histogram for which it was not yet defined
177 # Mandatory for defect that are not yet known as impacting the system (i.e. with a loss-[defect].dat file
178 # Especially useful for weekly reports with a new type of defect affecting the system
179 if (histo[iIndex].GetFillColor() == kBlack and tmpColorIndex < len(tmpColor) and histo[iIndex].GetBinContent(histo[iIndex].GetNbinsX()) != 0):
180 histo[iIndex].SetFillColor(tmpColor[tmpColorIndex])
181 tmpColorIndex = tmpColorIndex + 1
182
183 # Fill histo["%s_toStack"] the main histo
184 # and histo["%s_aux"] the complementary one used only for TLegend
185 if (histo[iIndex]).IsA().InheritsFrom("TProfile"):
186 histo['%s_toStack'%iIndex] = histo[iIndex].ProjectionX()
187 histo['%s_toStack'%iIndex].SetFillColor(histo[iIndex].GetFillColor())
188 else:
189 histo['%s_toStack'%iIndex] = histo[iIndex]
190 if lumiBool:
191 histo['%s_toStack'%iIndex].Multiply(histo['%s_toStack'%iIndex],histoIntLumi,0.01)
192 histo['%s_toStack'%iIndex].LabelsOption("v")
193 resStack[name].Add(histo['%s_toStack'%iIndex])
194
195 entryNb = 0
196 for iIndex in sorted(index): # Reverse order to have the TLegend ordered as the stacks
197 iIndexName = iIndex.split("__")[0] # Trick needed to get the defect name for the recoverable defect histogram
198 baseEntry = "%s"%(strLumi(histo['%s_toStack'%iIndex].GetBinContent(nBinsX),unit))
199 auxEntry = "%s"%(strLumi(histo['%s_toStack'%iIndex].GetBinContent(nBinsX)*auxScaleFactor,unitAux))
200
201 if (recovBool and "%s__recov"%iIndex in list(histo.keys()) and histo["%s__recov"%iIndex].GetBinContent(nBinsX) != 0.):
202 baseEntryRecov = "%s"%(strLumi(histo["%s__recov"%iIndex].GetBinContent(nBinsX),unit))
203 entry = "#splitline{%s}{%s(recov:%s) / %s}"%(indexName[iIndexName],baseEntry,baseEntryRecov,auxEntry) # Second part of Legend to fix
204 for iBin in range(nBinsX+1):
205 resStack["%s__recov"%name].Fill(iBin-1,histo["%s__recov"%iIndex].GetBinContent(iBin))
206 else:
207 entry = "#splitline{%s}{%s / %s}"%(indexName[iIndex],baseEntry,auxEntry)
208
209 if (compBool): # This is a >=2 yearTag histograms
210 if histo[iIndex].GetNbinsX() >= 2 and histo[iIndex].GetNbinsX()<5:
211 if histo[iIndex].GetBinContent(1) != 0.:
212 entry = "#splitline{%s}{%s"%(indexName[iIndexName],strLumi(histo[iIndex].GetBinContent(1),unit))
213 else:
214 entry = "#splitline{%s}{ - "%(indexName[iIndexName])
215 for iTag in range(2,histo[iIndex].GetNbinsX()+1):
216 if histo[iIndex].GetBinContent(iTag) != 0.:
217 entry += " / %s "%(strLumi(histo[iIndex].GetBinContent(iTag),unit))
218 else:
219 entry += " / - "
220 entry += "}"
221 else:
222 entry = "%s"%(indexName[iIndexName])
223
224 if (histo[iIndex].GetMaximum() != 0):
225 resLegend[name].AddEntry(histo[iIndex],entry,"f")
226 entryNb = entryNb+1
227
228 # Extract the total inefficiency
229 allIndex = ""
230 if ("allIntol" in list(histo.keys())):
231 allIndex = "allIntol"
232 if ("allVeto" in list(histo.keys())):
233 allIndex = "allVeto"
234
235 if allIndex != "":
236 if compBool:
237 for iBin in range(1,nBinsX+1):
238 totalIneff_comp[iBin-1] = histo[allIndex].GetBinContent(iBin)
239 else:
240 totalIneff = histo[allIndex].GetBinContent(nBinsX)
241
242 mx = resStack[name].GetMaximum()*1.2
243 resStack[name].SetMaximum(mx)
244 resStack[name].Draw("hist")
245 resStack[name].GetXaxis().LabelsOption("v")
246 resStack[name].GetXaxis().SetLabelSize(0.04)
247 resStack[name].GetXaxis().SetTitle("%s"%xAxisTitle)
248 resStack[name].GetXaxis().SetTitleOffset(1.45)
249 resStack[name].GetYaxis().SetTitle("%s"%yAxisTitle)
250 resStack[name].GetYaxis().SetTitleOffset(0.7)
251 if resStack[name].GetMaximum()>10.:
252 resCanvas[name].SetLogy(1)
253
254 if compBool:
255 resStack[name].GetXaxis().SetLabelSize(0.065)
256 if histo[iIndex].GetNbinsX() == 2:
257 resLegend[name].SetHeader("#splitline{%s}{Total loss: %s / %s}"%(legendHeader,strLumi(totalIneff_comp[0],unit),strLumi(totalIneff_comp[1],unit)))
258 elif histo[iIndex].GetNbinsX() == 3:
259 resLegend[name].SetHeader("#splitline{%s}{Total loss: %s / %s / %s}"%(legendHeader,strLumi(totalIneff_comp[0],unit),strLumi(totalIneff_comp[1],unit),strLumi(totalIneff_comp[2],unit)))
260 elif histo[iIndex].GetNbinsX() == 4:
261 resLegend[name].SetHeader("#splitline{%s}{Total loss: %s / %s / %s / %s}"%(legendHeader,strLumi(totalIneff_comp[0],unit),strLumi(totalIneff_comp[1],unit),strLumi(totalIneff_comp[2],unit),strLumi(totalIneff_comp[3],unit)))
262 else:
263 resLegend[name].SetHeader("%s"%(legendHeader))
264 else:
265 totalIneffAux = totalIneff*auxScaleFactor
266 if (approvedPlots):
267 resLegend[name].SetHeader("#splitline{%s}{Total loss: %s / %s}"%(legendHeader,strLumi(totalIneff,unit),strLumi(totalIneffAux,unitAux)))
268 else:
269 if (totalIneff != 0.):
270 resLegend[name].SetHeader("#splitline{%s (%s)}{Total loss: %s / %s}"%(legendHeader,strLumi(totalIntegratedLumi,"pb"),strLumi(totalIneff,unit),strLumi(totalIneffAux,unitAux)))
271 else:
272 resLegend[name].SetHeader("%s (%s)"%(legendHeader,strLumi(totalIntegratedLumi,"pb")))
273 if resStack["%s__recov"%name].GetEntries() != 0.:
274 resStack["%s__recov"%name].SetMarkerStyle(20)
275 resStack["%s__recov"%name].SetMarkerColor(kAzure+8)
276 resStack["%s__recov"%name].Draw("PSAME HIST")
277 resLegend[name].AddEntry(resStack["%s__recov"%name],"#splitline{Recoverable}{total: %.2f%%}"%(resStack["%s__recov"%name].GetBinContent(nBinsX)),"p")
278 entryNb = entryNb + 1
279
280 if (entryNb<9):
281 resLegend[name].SetTextSize(0.035)
282 else:
283 resLegend[name].SetTextSize(0.028)
284
285 resLegend[name].SetY1(max(0.83-entryNb*0.098,0.05))
286 resLegend[name].Draw()
287
288 resCanvas[name].Update()
289
290 return totalIneff # totalIneff is used only with the savePage1 option in DeMoStatus
291
TGraphErrors * GetEntries(TH2F *histo)
#define max(a, b)
Definition cfImp.cxx:41
#define IsA
Declare the TObject style functions.

◆ retrieveYearTagProperties()

DeMoLib.retrieveYearTagProperties ( year,
tag )

Return the year/tag properties (defect/veto/lumi tags...) stored in YearStats-common/DeMoConfig-[year]-[tag].dat.

Definition at line 68 of file DeMoLib.py.

68def retrieveYearTagProperties(year,tag):
69 ytp = {"Description":"","Defect tag":"","Veto tag":"","OflLumi tag":"","OflLumiAcct tag":""}
70 DeMoConfigFile = open("YearStats-common/%s/DeMoConfig-%s-%s.dat"%(year,year,tag),"r")
71 for line in DeMoConfigFile:
72 for i_ytp in ytp.keys():
73 if ("%s: "%i_ytp in line):
74 ytp[i_ytp] = (line.split("%s: "%i_ytp)[1]).replace("\n","")
75 DeMoConfigFile.close()
76
77 for i_ytp in ytp.keys():
78 if (ytp[i_ytp] == ""):
79 print("ERROR: Missing (%s) in YearStats-common/%s/DeMoConfig-%s-%s.dat -> Please check or define it with DeMoSetup.py"%(i_ytp,year,year,tag))
80
81 return ytp
82
void print(char *figname, TCanvas *c1)
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310

◆ returnPeriod()

DeMoLib.returnPeriod ( runNb,
system,
year,
tag )

Return the data period of a run based on the information stored in YearStats-[system]/[year]/[tag]/runs-ALL.dat.

Definition at line 56 of file DeMoLib.py.

56def returnPeriod(runNb,system,year,tag):
57 p = subprocess.Popen(["grep","%d"%runNb,"YearStats-%s/%s/%s/runs-ALL.dat"%(system,year,tag)],stdout = subprocess.PIPE)
58 (o,e) = p.communicate()
59 tmp = o.decode().split("(")
60 if len(tmp)>0:
61 tmp2 = tmp[1].split(")")[0]
62
63 return tmp2
64
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

◆ SetXLabel()

DeMoLib.SetXLabel ( h,
list )

Definition at line 41 of file DeMoLib.py.

41def SetXLabel(h,list):
42 for i in range(len(list)):
43 h.GetXaxis().SetBinLabel(i+1,str(list[i]))
44 return
45

◆ strLumi()

DeMoLib.strLumi ( lumi,
unit = "ub",
latex = True,
floatNumber = False )

Return a string with the luminosity in a human readable way If the unit is %%, this is a percentage.

Definition at line 86 of file DeMoLib.py.

86def strLumi(lumi,unit="ub",latex = True,floatNumber = False):
87 if (unit == "%%"):
88 string0 = "%.2f%% "%(lumi)
89 else:
90 if (unit == "pb" or unit == "pb^{-1}" or unit == "pb-1"):
91 lumi = lumi*1e6
92
93 if lumi < 1e3:
94 if latex:
95 if (floatNumber):string0 = "%.2f #mub"%(lumi)
96 else:string0 = "%.0f #mub"%(lumi)
97 else:
98 if (floatNumber):string0 = "%.2f ub"%(lumi)
99 else:string0 = "%.0f ub"%(lumi)
100 elif lumi<1e6:
101 if (floatNumber):string0 = "%.2f nb"%(lumi/1e3)
102 else: string0 = "%.0f nb"%(lumi/1e3)
103 elif lumi<1e9:
104 if (floatNumber):string0 = "%.2f pb"%(lumi/1e6)
105 else:string0 = "%.0f pb"%(lumi/1e6)
106 else:
107 if (floatNumber):string0 = "%.3f fb"%(lumi/1e9)
108 else:string0 = "%.1f fb"%(lumi/1e9)
109 if latex:
110 string0= string0+"^{-1}"
111 else:
112 string0= string0+"-1"
113
114 return string0
115
116

Variable Documentation

◆ colorPalette

list DeMoLib.colorPalette = [kBlue+3,kRed+1,kGreen-2,kOrange,kBlue-4,kMagenta+2,kYellow+1,kSpring-9,kAzure+6,kViolet-4,kPink,kBlue-9,kPink-6]

Definition at line 1070 of file DeMoLib.py.

◆ iColor

int DeMoLib.iColor = 0

Definition at line 1067 of file DeMoLib.py.