ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
DataQuality
DataQualityUtils
python
doZLumi.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2
3
def
getRun
(fname):
4
import
ROOT
5
fin = ROOT.TFile.Open(fname)
6
if
not
fin:
return
None
7
runname =
None
8
for
key
in
fin.GetListOfKeys():
9
if
key.GetName().startswith(
'run_'
):
10
runname = key.GetName()
11
break
12
if
runname:
return
int(runname[4:])
13
else
:
return
None
14
15
def
checkDirExists
(fname):
16
# Does DQTGlobalWZFinder directory even exist?
17
import
ROOT
18
run =
getRun
(fname)
19
if
not
run:
return
False
20
fin = ROOT.TFile.Open(fname,
'READ'
)
21
if
not
fin:
return
False
22
dobj = fin.Get(f
'run_{run}/GLOBAL/DQTGlobalWZFinder'
)
23
if
not
dobj:
return
False
24
return
True
25
26
def
copyPlot
(infname, outfname):
27
import
ROOT
28
run =
getRun
(outfname)
29
if
not
run:
return
30
fin = ROOT.TFile.Open(infname,
'READ'
)
31
if
not
fin:
return
32
fout = ROOT.TFile.Open(outfname,
'UPDATE'
)
33
if
not
fout:
return
34
for
objname
in
[
'z_lumi'
,
'z_lumi_ratio'
]:
35
obj = fin.Get(objname)
36
if
obj:
37
d = fout.Get(
'run_%d/GLOBAL/DQTGlobalWZFinder'
% run)
38
if
d:
39
d.WriteTObject(obj, objname)
40
fin.Close(); fout.Close()
41
42
def
makeGRL
(run, defect, fname):
43
import
DQUtils, DQDefects
44
45
tag =
'HEAD'
46
runs = [run]
47
print
(
'Query run information...'
, end=
''
)
48
from
DQUtils.db
import
fetch_iovs
49
dbinstance =
'CONDBR2'
50
eor = fetch_iovs(
'EOR'
, (
min
(runs) << 32) | 1,
51
(
max
(runs) << 32) | 0xFFFFFFFF,
52
with_channel=
False
, what=[], database=
'COOLONL_TDAQ/%s'
% dbinstance)
53
eor = eor.trim_iovs
54
eor = DQUtils.IOVSet(iov
for
iov
in
eor
if
iov.since.run
in
runs)
55
print
(
'done'
)
56
print
(
'Query defects...'
, end=
''
)
57
ddb = DQDefects.DefectsDB(
'COOLOFL_GLOBAL/%s'
% dbinstance, tag=tag)
58
ignores = {_
for
_
in
ddb.defect_names
if
'UNCHECKED'
in
_}
59
try
:
60
defectiovs = ddb.retrieve(since =
min
(runs) << 32 | 1,
61
until =
max
(runs) << 32 | 0xffffffff,
62
channels = [defect],
63
evaluate_full =
False
,
64
ignore=ignores)
65
except
Exception
as
e:
66
print
(e)
67
raise
68
print
(
'Doing exclusions...'
, end=
''
)
69
okiovs = eor.logical_and(eor, defectiovs.logical_not())
70
print
(
'done'
)
71
72
print
(
'Generating GRL...'
, end=
''
)
73
data = DQUtils.grl.make_grl(okiovs,
''
,
'2.1'
)
74
with
open(fname,
'w'
)
as
outf:
75
outf.write(data)
76
77
def
go
(fname):
78
import
subprocess, os, shutil
# noqa: F401
79
if
'DQ_STREAM'
in
os.environ:
80
if
(os.environ.get(
'DQPRODUCTION'
,
'0'
) ==
'1'
81
and
os.environ[
'DQ_STREAM'
] !=
'physics_Main'
):
82
return
83
if
'DISPLAY'
in
os.environ: del os.environ[
'DISPLAY'
]
84
runno =
getRun
(fname)
85
print
(
'Seen run'
, runno)
86
if
not
checkDirExists
(fname):
87
print
(
'But DQTGlobalWZFinder directory does not exist: code probably did not run. Exiting'
)
88
return
89
grlcmd = []
# noqa: F841
90
if
runno >= 325000:
91
makeGRL
(runno,
'PHYS_StandardGRL_All_Good'
,
'grl.xml'
)
92
grlcmd = [
'--grl'
,
'grl.xml'
]
# noqa: F841
93
else
:
94
print
(
'Run number'
, runno,
'not 2017 data'
)
95
96
# Temporarily comment. Run 3 version of this code will be inserted soon
97
subprocess.check_call([
'dqt_zlumi_pandas.py'
,
'--infile'
, fname,
'--dblivetime'
,
'--outdir'
,
''
,
'--campaign'
,
'mc21'
] + grlcmd)
98
subprocess.check_call([
'dqt_csv_luminosity.sh'
,
'--infile'
, f
'run_{runno}.csv'
,
'--outdir'
,
''
,
'--absolute'
,
'--t0'
])
99
if
os.path.isfile(f
'run_{runno}.csv'
):
100
shutil.move(f
'run_{runno}.csv'
,
'zlumi.csv'
)
101
if
os.path.isfile(
'zlumi.root'
):
102
copyPlot
(
'zlumi.root'
, fname)
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
min
#define min(a, b)
Definition
cfImp.cxx:40
max
#define max(a, b)
Definition
cfImp.cxx:41
python.doZLumi.checkDirExists
checkDirExists(fname)
Definition
doZLumi.py:15
python.doZLumi.getRun
getRun(fname)
Definition
doZLumi.py:3
python.doZLumi.copyPlot
copyPlot(infname, outfname)
Definition
doZLumi.py:26
python.doZLumi.go
go(fname)
Definition
doZLumi.py:77
python.doZLumi.makeGRL
makeGRL(run, defect, fname)
Definition
doZLumi.py:42
Generated on
for ATLAS Offline Software by
1.17.0