ATLAS Offline Software
validateBDTTau.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import sys
4 import os, os.path
5 import numpy as np
6 import json
7 from collections import OrderedDict
8 import re
9 
10 test_status = int(os.environ["ATLAS_CTEST_TESTSTATUS"])
11 if test_status != 0:
12  print(f"Post evaluation: ERROR: previous step went wrong (exit code {test_status})")
13  sys.exit(test_status)
14 
15 test_output_file = os.environ["ATLAS_CTEST_TESTNAME"]+".log"
16 bdt_config_file = os.environ["TAU_EFEX_BDT_CONFIG_PATH"]
17 
18 def get_vector(lines, startswith):
19  """
20  Extract a vector of numbers from a line that starts with a string from a list of Athena log file lines
21  """
22  vals = [x[x.rfind(':')+1:].split() for x in lines if startswith in x]
23  vals = np.array(vals).astype(int)
24  return vals
25 
26 out_log_content = open(test_output_file, "r").read()
27 
28 # Filter to get only BDT-related lines
29 bdt_algo_lines = [l for l in out_log_content.split('\n') if re.findall(r"eFEXDriver\..+eFEXtauBDTAlgo", l)]
30 
31 # Get supercells used to compute the variables, as appears in the test output. Check that they're the same as in the bdt config file
32 rgx_vartitle = re.compile(r"DEBUG\s+([0-9]+) is (l[0-4]_d[0-9_pld]*), sum of supercells$")
33 rgx_coretitle = re.compile(r"DEBUG\s+([0-9]+) is CORE, sum of supercells$")
34 rgx_etaphilayer = re.compile(r"DEBUG\s+eta=([0-9]+)\s+phi=([0-9]+)\s+layer=([0-9]+)$")
35 variables = OrderedDict()
36 last_var_line = [i for i,x in enumerate(bdt_algo_lines) if "Will use sum of supercells" in x][0]
37 for l in bdt_algo_lines[:last_var_line]:
38  vartitle = rgx_vartitle.findall(l)
39  coretitle = rgx_coretitle.findall(l)
40  etaphilayer = rgx_etaphilayer.findall(l)
41  if len(vartitle) > 0:
42  variables[vartitle[0][1]] = []
43  vt = vartitle[0][1]
44  elif len(coretitle) > 0:
45  vt="CORE"
46  variables[vt] = []
47  elif len(etaphilayer) > 0:
48  variables[vt].append([int(x) for x in etaphilayer[0]])
49 
50 bdt_config=json.load(open(bdt_config_file, "r"))
51 
52 assert set(v['name'] for v in bdt_config['variables']) == set(variables.keys()), "Variables as read from this test's log file are not as they appear in the data/bdt_config.json. They must be consistent with each other."
53 
54 for v in bdt_config['variables']:
55  assert sorted(v['scells']) == sorted(variables[v['name']]), f"For BDT variable {v['name']}, the supercells used to compute it are different in the log file vs. in data/bdt_config.json"
56 
57 # Check BDT scores are within range
58 bdt_scores=get_vector(bdt_algo_lines, 'DEBUG BDT Score: ').reshape(-1)
59 assert ((bdt_scores>500) &(bdt_scores < 2000)).all()
read
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)
Definition: openCoraCool.cxx:569
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
validateBDTTau.get_vector
def get_vector(lines, startswith)
Definition: validateBDTTau.py:18
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
Cut::all
@ all
Definition: SUSYToolsAlg.cxx:67
Trk::open
@ open
Definition: BinningType.h:40
Trk::split
@ split
Definition: LayerMaterialProperties.h:38