ATLAS Offline Software
Functions | Variables
module_selector_from_json Namespace Reference

Functions

def find (bec=None, layer_disk=None, phi=None, eta=None, side=None, asdec=False, input_data="geometry.json", output_file=None)
 
def merge (file_1="selected_modules_1.json", file_2="selected_modules_2.json", output_file=None)
 
def select_random (frac=None, input_data=None, output_file=None)
 

Variables

def data = find(bec = 0, layer_disk = 0, phi = [0,1,2,3,4], asdec = True, output_file="test_selected_modules.json")
 

Function Documentation

◆ find()

def module_selector_from_json.find (   bec = None,
  layer_disk = None,
  phi = None,
  eta = None,
  side = None,
  asdec = False,
  input_data = "geometry.json",
  output_file = None 
)

Definition at line 12 of file module_selector_from_json.py.

12 def find(bec=None, layer_disk=None, phi=None, eta=None, side=None, asdec=False, input_data="geometry.json", output_file=None):
13  data = {}
14 
15  with open(input_data) as f:
16  if input_data.endswith(".json"):
17  data = json.load(f)
18  else:
19  print("Unexpected input file or format.")
20  return []
21 
22  IDs = []
23 
24  for ID, info in data.items():
25  if bec is not None and info["BEC"] != str(bec):
26  continue
27 
28  if layer_disk is not None and info["LayerDisk"] != str(layer_disk):
29  continue
30 
31  if phi is not None and info["PhiModule"] not in str([i for i in phi]):
32  continue
33 
34  if eta is not None and info["EtaModule"] > str(eta):
35  continue
36 
37  if side is not None and info["Side"] != str(side):
38  continue
39 
40  if asdec:
41  info["Decimal_ID"] = str(int(ID, 16))
42 
43  IDs.append(ID)
44 
45  with open(output_file, "w") as f:
46  selected_data = {ID: data[ID] for ID in IDs}
47  json.dump(selected_data, f, indent=4)
48 
49  return IDs
50 
51 

◆ merge()

def module_selector_from_json.merge (   file_1 = "selected_modules_1.json",
  file_2 = "selected_modules_2.json",
  output_file = None 
)

Definition at line 52 of file module_selector_from_json.py.

52 def merge(file_1="selected_modules_1.json", file_2="selected_modules_2.json", output_file=None):
53  data1 = {}
54  data2 = {}
55  IDs = []
56 
57  with open(file_1) as f1:
58  if file_1.endswith(".json"):
59  data1 = json.load(f1)
60  else:
61  print("Unexpected input file_1 or format.")
62  return []
63 
64  IDs.extend(data1.keys())
65 
66  with open(file_2) as f2:
67  if file_2.endswith(".json"):
68  data2 = json.load(f2)
69  else:
70  print("Unexpected input file_2 or format.")
71  return []
72 
73  IDs.extend(data2.keys())
74 
75  with open(output_file, "w") as f3:
76  selected_data = {}
77  for ID in IDs:
78  if ID in data1:
79  selected_data[ID] = data1[ID]
80  elif ID in data2:
81  selected_data[ID] = data2[ID]
82  json.dump(selected_data, f3, indent=4)
83 
84  return IDs
85 

◆ select_random()

def module_selector_from_json.select_random (   frac = None,
  input_data = None,
  output_file = None 
)

Definition at line 86 of file module_selector_from_json.py.

86 def select_random(frac = None, input_data=None, output_file=None):
87  data = {}
88 
89  with open(input_data) as f:
90  if input_data.endswith(".json"):
91  data = json.load(f)
92  else:
93  print("Unexpected input file or format.")
94  return []
95 
96  IDs = []
97 
98  num = int(round(frac * len(data), 0))
99  IDs = random.choices(list(data.keys()), k=num)
100 
101  for ID, info in data.items():
102  info["Decimal_ID"] = str(int(ID, 16))
103 
104  with open(output_file, "w") as f:
105  selected_data = {ID: data[ID] for ID in IDs}
106  json.dump(selected_data, f, indent=4)
107 
108  return IDs
109 
110 

Variable Documentation

◆ data

def module_selector_from_json.data = find(bec = 0, layer_disk = 0, phi = [0,1,2,3,4], asdec = True, output_file="test_selected_modules.json")

Definition at line 113 of file module_selector_from_json.py.

find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
MuonGM::round
float round(const float toRound, const unsigned int decimals)
Definition: Mdt.cxx:27
module_selector_from_json.merge
def merge(file_1="selected_modules_1.json", file_2="selected_modules_2.json", output_file=None)
Definition: module_selector_from_json.py:52
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
Trk::open
@ open
Definition: BinningType.h:40
module_selector_from_json.select_random
def select_random(frac=None, input_data=None, output_file=None)
Definition: module_selector_from_json.py:86
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
str
Definition: BTagTrackIpAccessor.cxx:11