Basic wrapper around pyAMI for getting MC dataset cross sections & maniuplating dataset name strings.
More...
Basic wrapper around pyAMI for getting MC dataset cross sections & maniuplating dataset name strings.
Definition at line 9 of file GetCrossSectionAMITool.py.
◆ __init__()
def python.GetCrossSectionAMITool.GetCrossSectionAMI.__init__ |
( |
|
self | ) |
|
Definition at line 10 of file GetCrossSectionAMITool.py.
11 self.log = logging.getLogger(
'GetCrossSectionAMI')
15 import pyAMI.atlas.api
as api
17 self.log.fatal(
'Unable to import the pyAMI client. Did you run "lsetup pyami; voms-proxy-init -voms atlas"?')
21 self.ami_client = pyAMI.client.Client(
'atlas')
◆ cleanupDatasetName()
def python.GetCrossSectionAMITool.GetCrossSectionAMI.cleanupDatasetName |
( |
|
self, |
|
|
|
dataset |
|
) |
| |
Definition at line 42 of file GetCrossSectionAMITool.py.
42 def cleanupDatasetName(self, dataset):
43 dataset = re.sub(
'_tid[0-9]{8}_[0-9]{2}',
'', dataset)
44 dataset = re.sub(
'_sub[0-9]{10}',
'', dataset)
45 dataset = re.sub(
'/$',
'', dataset)
◆ convertDatasetNameToEVNT()
def python.GetCrossSectionAMITool.GetCrossSectionAMI.convertDatasetNameToEVNT |
( |
|
self, |
|
|
|
dataset |
|
) |
| |
Definition at line 48 of file GetCrossSectionAMITool.py.
48 def convertDatasetNameToEVNT(self, dataset):
49 dsid = dataset.split(
'.')[1]
51 res_d = self.ami_api.get_dataset_prov(self.ami_client, dataset)
52 except Exception
as reason:
53 self.log.fatal(
'Unable to query AMI. Do you have a grid certificate? "voms-proxy-init -voms atlas"')
54 self.log.fatal(
'You can also supply the MCCrossSection and MCFilterEfficiency by hand for this sample')
55 self.log.fatal(f
'The reason for failure was: {reason}')
59 n
for n
in res_d[
'node']
60 if 'logicalDatasetName' in n.keys()
and n[
'logicalDatasetName'].
split(
'.')[1] == dsid
and 'EVNT' in n[
'logicalDatasetName']
63 sorted_nodes =
sorted(previous_nodes, key=
lambda n: n[
'distance'])
65 evnt_dataset = sorted_nodes[0][
'logicalDatasetName']
67 if 'EVNT' in evnt_dataset:
68 self.log.
info(
'Found the original EVNT dataset using AMI provenance.')
69 self.log.
info(f
'Went from: {dataset}')
70 self.log.
info(f
' to: {evnt_dataset}')
73 self.log.fatal(
'Unable to get the original EVNT dataset from AMI provenance, you must supply it yourself as MCDatasetName')
74 self.log.fatal(
'You can also supply the MCCrossSection and MCFilterEfficiency by hand for this sample')
◆ crossSection()
def python.GetCrossSectionAMITool.GetCrossSectionAMI.crossSection |
( |
|
self | ) |
|
◆ filterEfficiency()
def python.GetCrossSectionAMITool.GetCrossSectionAMI.filterEfficiency |
( |
|
self | ) |
|
◆ getDatasetNameFromPath()
def python.GetCrossSectionAMITool.GetCrossSectionAMI.getDatasetNameFromPath |
( |
|
self, |
|
|
|
path |
|
) |
| |
Definition at line 32 of file GetCrossSectionAMITool.py.
32 def getDatasetNameFromPath(self, path):
34 datasetRegex =
r'mc.._.*TeV\..*|valid.\..*'
35 parts = path.split(
'/')
37 if re.match(datasetRegex, part):
40 self.log.
error(
'Unable to figure out the MC dataset name from the path, you must supply it yourself as MCDatasetName')
◆ queryAmi()
def python.GetCrossSectionAMITool.GetCrossSectionAMI.queryAmi |
( |
|
self, |
|
|
|
dataset |
|
) |
| |
Definition at line 77 of file GetCrossSectionAMITool.py.
77 def queryAmi(self, dataset):
78 if 'EVNT' not in dataset:
79 dataset = self.convertDatasetNameToEVNT(self.cleanupDatasetName(dataset))
80 self.dataset = dataset
81 self.log.
info(f
'Looking up details of {self.dataset} on AMI')
84 fields =
'cross_section,generator_filter_efficiency'
86 res_l = self.ami_api.list_datasets(self.ami_client, patterns=self.dataset, fields=fields)
87 except Exception
as reason:
88 self.log.fatal(
'Unable to query AMI. Do you have a grid certificate? "voms-proxy-init -voms atlas"')
89 self.log.fatal(
'You can also supply the MCCrossSection and MCFilterEfficiency by hand for this sample')
90 self.log.fatal(f
'The reason for failure was: {reason}')
94 self.log.fatal(f
'The dataset "{dataset}" was not found in AMI')
95 self.log.fatal(
'You can also supply the MCCrossSection and MCFilterEfficiency by hand for this sample')
98 self.log.fatal(f
'More than one dataset "{dataset}" was found in AMI.')
101 xsec = res_l[0][
'cross_section']
102 gfe = res_l[0][
'generator_filter_efficiency']
104 if xsec ==
'NULL' or gfe ==
'NULL':
105 self.log.fatal(f
'NULL cross section/filter efficiency values set on AMI for the dataset "{dataset}"')
106 self.log.fatal(
'You can supply the MCCrossSection and MCFilterEfficiency by hand for this sample')
110 self.xsec =
float(xsec)
111 self.filtereff =
float(gfe)
113 self.log.fatal(
'Coudn\'t convert cross section/filter efficiency values to floats')
114 self.log.fatal(f
' Cross Section: {xsec}')
115 self.log.fatal(f
'Filter Efficiency: {gfe}')
116 self.log.fatal(
'You can supply the MCCrossSection and MCFilterEfficiency by hand for this sample')
119 if self.xsec
and self.filtereff:
120 self.log.
info(
'################## ################## AMI Query Complete ################## ################## ')
121 self.log.
info(f
' Cross section: {self.xsec} nb')
122 self.log.
info(f
'Filter efficiency: {self.filtereff}')
123 self.log.
info(
'You may want to supply these numbers directly in future as MCCrossSection and MCFilterEfficiency for speed')
124 self.log.
info(
'################## ################## ################## ################## ################### ')
126 self.log.fatal(f
'The cross section and/or filter efficiency values for the dataset "{dataset}" are set to 0 on AMI')
127 self.log.fatal(
'You can supply the MCCrossSection and MCFilterEfficiency by hand for this sample')
◆ ami_api
python.GetCrossSectionAMITool.GetCrossSectionAMI.ami_api |
◆ ami_client
python.GetCrossSectionAMITool.GetCrossSectionAMI.ami_client |
◆ dataset
python.GetCrossSectionAMITool.GetCrossSectionAMI.dataset |
◆ filtereff
python.GetCrossSectionAMITool.GetCrossSectionAMI.filtereff |
◆ log
python.GetCrossSectionAMITool.GetCrossSectionAMI.log |
◆ xsec
python.GetCrossSectionAMITool.GetCrossSectionAMI.xsec |
The documentation for this class was generated from the following file: