ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
SampleHandler
python
SampleHandler_QueryAMI.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3
4
import
ROOT
5
import
pyAMI.client
6
from
pyAMI.atlas.api
import
get_dataset_info
7
8
def
SampleHandler_QueryAmi
(samples):
9
# set up an AMI client
10
# This is the basic minimum - and it will look for an encrypted file
11
# with your user credentials. If it does not find that it will try
12
# for a VOMS proxy. Make the encrypted file by running "ami auth"
13
# first. See https://atlas-ami.cern.ch/AMI/pyAMI/examples/api.html
14
15
amiClient = pyAMI.client.Client(
'atlas'
)
16
17
# The quantities in the class MetaDataSample are pretty much all I need:
18
# * whether it is data or MC
19
# * the luminosity of the sample
20
# * the k-factor of the sample (only for MC)
21
# * the number of events in the sample
22
# * the cross section of the sample (only for MC)
23
# * the filter efficiency
24
25
data = ROOT.SH.MetaDataQuery()
26
data.messages =
'done by ami query'
27
# I am assuming that "samples" is a list of dataset names, and that
28
# the user already checked that they exist and are valid
29
for
sample
in
samples:
30
sample_noscope = sample.split(
':'
)[-1]
31
32
mydata = ROOT.SH.MetaDataSample(sample)
33
# The first question you ask is whether it is data or MC.
34
# description: 1 for data, 0 for MC, or -1 if this is not known.
35
mydata.source =
'https://atlas-ami.cern.ch/AMI/pyAMI/'
36
mydata.unknown = 0
37
38
if
sample.startswith(
"mc"
):
39
mydata.isData = 0
40
elif
sample.startswith(
"data"
):
41
mydata.isData = 1
42
else
:
43
mydata.isData = -1
44
45
# AMI does not specifically catalogue TID datasets, so strip the
46
# suffix off the name that is actually queried (sample_noscope).
47
if
"_tid"
in
sample_noscope:
48
print
(
"Stripping tid suffix from "
+ sample_noscope)
49
sample_noscope = sample_noscope.split(
"_tid"
)[0]
50
51
# All datasets should have the number of events. If the dataset
52
# is not known to AMI, flag it and move on rather than aborting
53
# the whole query.
54
try
:
55
amiinfo = get_dataset_info(amiClient, sample_noscope)[0]
56
except
Exception
as
e:
57
print
(
"failed to get AMI info for "
+ sample_noscope +
": "
+ str(e))
58
mydata.unknown = 1
59
data.addSample(mydata)
60
continue
61
62
mydata.nevents = int(amiinfo[
'totalEvents'
])
63
64
# AMI does not yet have a function for getting luminosity, and we
65
# have no k-factor information, so those are placeholders.
66
if
mydata.isData == 1:
67
mydata.crossSection = -1
68
mydata.filterEfficiency = -1
69
else
:
70
mydata.luminosity = -1
71
# MC - can get cross-section and filter efficiency
72
try
:
73
xsec = float(amiinfo[
'approx_crossSection'
])
74
effic = float(amiinfo[
'approx_GenFiltEff'
])
75
except
KeyError
as
e:
76
print
(
"AMI info missing cross-section/filter efficiency for "
+ sample_noscope +
": "
+ str(e))
77
mydata.unknown = 1
78
data.addSample(mydata)
79
continue
80
mydata.crossSection = xsec
81
mydata.filterEfficiency = effic
82
if
mydata.crossSection > 0
and
mydata.filterEfficiency > 0:
83
mydata.luminosity = float(float(mydata.nevents) / (mydata.crossSection * mydata.filterEfficiency))
84
85
data.addSample(mydata)
86
return
data
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
SampleHandler_QueryAMI.SampleHandler_QueryAmi
SampleHandler_QueryAmi(samples)
Definition
SampleHandler_QueryAMI.py:8
Generated on
for ATLAS Offline Software by
1.17.0