ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
SUSYPhys
SUSYTools
scripts
check-daod-stats.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
3
# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
4
import
sys
5
import
os
6
7
# keep ROOT from stealing our command line arguments
8
_orig_argv = sys.argv[:]
9
sys.argv = [_orig_argv[0]]
10
11
import
ROOT
12
from
ROOT
import
*
13
14
if
(
not
ROOT.xAOD.Init().isSuccess()):
print
"Failed xAOD.Init()"
15
16
sys.argv = _orig_argv
17
18
try
:
19
import
pyAMI.client
20
import
pyAMI.atlas.api
as
atlas_api
21
import
pyAMI.config
22
except
ImportError:
23
print
"Please call"
24
print
" lsetup PyAMI"
25
print
" voms-proxy-init -voms atlas"
26
print
"before using this script"
27
logging.error(
"Unable to find pyAMI client. Please try this command first: lsetup pyAMI"
)
28
sys.exit(1)
29
30
class
term
:
31
GREEN =
'\033[92m'
32
RED =
'\033[91m'
33
ENDC =
'\033[0m'
34
CLEAR_LINE =
"\33[2K\r"
35
36
def
get_ami_events
(ami_client, dataset):
37
results = atlas_api.get_dataset_info(ami_client, dataset)
38
if
len(results) != 1:
39
print
"WARNING: %d results returned from AMI, expected 1"
% len(results)
40
41
return
int(results[0][
"totalEvents"
])
42
43
def
get_xaod_name
(dataset):
44
if
":"
in
dataset:
45
dataset = dataset.split(
":"
)[1]
46
47
parts = dataset.split(
"."
)
48
xaod_parts = []
49
for
p
in
parts:
50
if
"DAOD"
in
p:
# remove derivation type
51
p =
"AOD"
52
53
if
"deriv"
in
p:
# recon.AOD instead of deriv.DAOD
54
p =
"recon"
55
56
if
"_p"
in
p:
# remove p-tag
57
if
p.endswith(
"/"
):
58
p = p[:-7]
# 7 == len("_p1234/")
59
else
:
60
p = p[:-6]
# 6 == len("_p1234")
61
62
xaod_parts.append(p)
63
64
return
"."
.join(xaod_parts)
65
66
def
get_cbk_events
(root_file):
67
tree = xAOD.MakeTransientMetaTree(root_file)
68
tree.GetEntry(0)
69
70
max_cycle = -1
71
all_events_cbk =
None
72
for
cbk
in
tree.CutBookkeepers:
73
if
cbk.cycle() > max_cycle
and
cbk.name() ==
"AllExecutedEvents"
and
cbk.inputStream() ==
"StreamAOD"
:
74
max_cycle = cbk.cycle()
75
all_events_cbk = cbk
76
77
return
all_events_cbk.nAcceptedEvents()
78
79
def
get_local_events
(files):
80
num_files = len(files)
81
82
daod_events = 0
83
cbk_events = 0
84
85
for
i
in
xrange
(num_files):
86
sys.stdout.write(
"Reading local statistics, file %d/%d (%d events so far)..."
% (i+1, num_files, daod_events))
87
sys.stdout.flush()
88
89
rf = TFile.Open(files[i])
90
daod_events += rf.Get(
"CollectionTree"
).
GetEntries
()
91
cbk_events +=
get_cbk_events
(rf)
92
rf.Close()
93
94
sys.stdout.write(term.CLEAR_LINE)
95
sys.stdout.flush()
96
97
return
daod_events, cbk_events
98
99
def
check_sample_stats
(ami_client, dataset, cbk_events):
100
xaod =
get_xaod_name
(dataset)
101
ami_events =
get_ami_events
(ami_client, xaod)
102
103
if
ami_events == cbk_events:
104
print
term.GREEN +
"CutBookkeepers good: %d events"
% ami_events, term.ENDC
105
else
:
106
print
term.RED +
"CutBookkeepers bad: %d events (local), %d events (AMI)"
% (cbk_events, ami_events), term.ENDC
107
108
return
ami_events == cbk_events
109
110
def
check_derivation_stats
(ami_client, dataset, daod_events):
111
ami_events =
get_ami_events
(ami_client, dataset)
112
113
if
ami_events == daod_events:
114
print
term.GREEN +
"Derviation events good: %d events"
% ami_events, term.ENDC
115
else
:
116
print
term.RED +
"Derviation events bad: %d events (local), %d events (AMI)"
% (daod_events, ami_events), term.ENDC
117
118
return
ami_events == daod_events
119
120
def
load_files
(opts):
121
infile = open(opts.file_list,
"r"
)
122
123
files = []
124
for
line
in
infile:
125
line = line.strip()
126
if
line ==
""
or
line.startswith(
"#"
):
127
continue
128
129
files.append(line)
130
131
return
files
132
133
def
parse_opts
():
134
import
argparse
135
136
parser = argparse.ArgumentParser()
137
parser.add_argument(
"dataset"
, help=
"Name of the dataset, something like mc15_13TeV.123456.SomeGenerator.DAOD_SUSY5.e1234_p4321"
)
138
parser.add_argument(
"file_list"
, help=
"List of files, belonging to the dataset"
)
139
140
opts = parser.parse_args()
141
142
return
opts
143
144
def
main
():
145
opts =
parse_opts
()
146
147
files =
load_files
(opts)
148
149
print
"Initializing PyAMI"
150
ami_client = pyAMI.client.Client(
"atlas"
)
151
atlas_api.init()
152
153
print
"Checking dataset %s with %d files"
% (opts.dataset, len(files))
154
155
daod_events, cbk_events =
get_local_events
(files)
156
157
good =
True
158
if
not
check_derivation_stats
(ami_client, opts.dataset, daod_events):
159
good =
False
160
if
not
check_sample_stats
(ami_client, opts.dataset, cbk_events):
161
good =
False
162
163
if
not
good:
164
sys.exit(1)
165
166
if
__name__ ==
'__main__'
:
167
main
()
if
if(pathvar)
Definition
SealSharedLib.cxx:168
GetEntries
TGraphErrors * GetEntries(TH2F *histo)
Definition
TRTCalib_makeplots.cxx:4025
check-daod-stats.term
Definition
check-daod-stats.py:30
xrange
void xrange(TH1 *h, bool symmetric)
Definition
computils.cxx:518
check-daod-stats.load_files
load_files(opts)
Definition
check-daod-stats.py:120
check-daod-stats.check_sample_stats
check_sample_stats(ami_client, dataset, cbk_events)
Definition
check-daod-stats.py:99
check-daod-stats.get_cbk_events
get_cbk_events(root_file)
Definition
check-daod-stats.py:66
check-daod-stats.get_xaod_name
get_xaod_name(dataset)
Definition
check-daod-stats.py:43
check-daod-stats.main
main()
Definition
check-daod-stats.py:144
check-daod-stats.get_local_events
get_local_events(files)
Definition
check-daod-stats.py:79
check-daod-stats.check_derivation_stats
check_derivation_stats(ami_client, dataset, daod_events)
Definition
check-daod-stats.py:110
check-daod-stats.parse_opts
parse_opts()
Definition
check-daod-stats.py:133
check-daod-stats.get_ami_events
get_ami_events(ami_client, dataset)
Definition
check-daod-stats.py:36
Generated on
for ATLAS Offline Software by
1.17.0