Skip to content
Snippets Groups Projects
Commit 8806b980 authored by johannes bilk's avatar johannes bilk
Browse files

fixed a grave error in the fancy dict where method

parent b4750559
No related branches found
No related tags found
No related merge requests found
......@@ -78,15 +78,17 @@ class FancyDict:
value = eval(value)
mask &= np.isin(self.data[key], value)
else:
if value.replace('.', '').isdigit():
comparisionValue = float(value)
fieldValues = self.data[key].astype(float)
elif value.lower() == 'true' or value.lower() == 'false':
comparisionValue = True if value.lower() == 'true' else False
fieldValues = self.data[key]
else:
try:
# Attempt to convert value to float or boolean
if value.lower() in ['true', 'false']:
comparisionValue = value.lower() == 'true'
else:
comparisionValue = float(value)
except ValueError:
# If conversion fails, treat it as a string
comparisionValue = value
fieldValues = self.data[key]
fieldValues = self.data[key]
# Determine the correct comparison to apply
operation = {
......@@ -109,7 +111,7 @@ class FancyDict:
return self.__class__(data=filteredData)
def __repr__(self) -> str:
return str(self.data)
return f'fancyDict({repr(self.data)})'
def __iter__(self) -> Iterable:
keys = list(self.data.keys())
......
......@@ -133,15 +133,15 @@ class ClusterCoordinates:
looks up the corresponding layers and ladders for every cluster
"""
layersLadders = {}
n = len(self.data['sensorID'])
layers = np.empty(n, dtype=int)
ladders = np.empty(n, dtype=int)
length = len(sensorIDs)
layers = np.empty(length, dtype=int)
ladders = np.empty(length, dtype=int)
for i, id in enumerate(self.data['sensorID']):
for i, id in enumerate(sensorIDs):
layers[i], ladders[i] = self.layersLadders[id]
layersLadders['layer'] = np.array(layers, dtype=int)
layersLadders['ladder'] = np.array(ladders, dtype=int)
return {'layer': np.array(layers, dtype=int),
'ladder': np.array(ladders, dtype=int)}
def sphericals(self, xPosition: np.ndarray, yPosition: np.ndarray, zPosition: np.ndarray) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
"""
......
......@@ -237,6 +237,15 @@ class PXD(FancyDict):
self.set(key, data)
self.gotCoordinates = True
def getLayers(self, eventTree: TTree = None) -> None:
if eventTree:
self.getClusters(eventTree)
layers = self.clusterCoordinates.layers(self['sensorID'])
for key, data in layers.items():
self.set(key, data)
self.gotLayers = True
def getMCData(self, eventTree: TTree, includeUnselected: bool = False) -> None:
"""
this loads the monte carlo from the root file
......
......@@ -42,7 +42,7 @@ class Rootable:
return {'pxd': self.pxd.data}
def __repr__(self) -> str:
return {'pxd': self.pxd.data}
return repr({'pxd': self.pxd.data})
def __iter__(self) -> Iterable:
return iter(self.pxd.data)
......@@ -55,7 +55,9 @@ class Rootable:
this makes the class subscriptable, one can retrieve one coloumn by using
strings as keywords, or get a row by using integer indices or arrays
"""
if isinstance(index, str):
if index == 'pxd':
return FancyDict(self.data['pxd'])
elif isinstance(index, str):
return self.data['pxd'][index]
return FancyDict({key: value[index] for key, value in self.data['pxd'].items()})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment