File indexing completed on 2024-04-06 11:56:35
0001
0002
0003
0004
0005 from builtins import range
0006 import itertools
0007 import os
0008
0009 import ROOT
0010 ROOT.PyConfig.IgnoreCommandLineOptions = True
0011 ROOT.gROOT.SetBatch()
0012
0013 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.geometrydata as mpsv_geometrydata
0014
0015
0016 class Alignables:
0017 """ Creates a list of the aligned strucutres. Get the fields out of the
0018 TrackerTree.root file.
0019 """
0020
0021 def __init__(self, config):
0022
0023 self.structures = []
0024 self.config = config
0025
0026 def get_subdetid(self, objid):
0027 return mpsv_geometrydata.data[objid].subdetid
0028
0029 def get_discriminator(self, objid):
0030 return mpsv_geometrydata.data[objid].discriminator
0031
0032 def get_ndiscriminator(self, objid):
0033 subdetid = self.get_subdetid(objid)
0034 discriminator = self.get_discriminator(objid)
0035 ndiscriminator = {key: [] for key in discriminator}
0036
0037 treeFile = ROOT.TFile(os.path.join(self.config.jobDataPath,
0038 ".TrackerTree.root"))
0039 tree = treeFile.Get("TrackerTreeGenerator/TrackerTree/TrackerTree")
0040
0041 for entry in tree:
0042
0043 if (entry.SubdetId == subdetid):
0044 for structure in discriminator:
0045 ndiscriminator[structure].append(getattr(entry, structure))
0046 for structure in discriminator:
0047 ndiscriminator[structure] = [x for x in ndiscriminator[structure] if x != 0]
0048
0049 return [len(set(ndiscriminator[structure]))
0050 for structure in discriminator]
0051
0052 def create_list(self, MillePedeUser):
0053
0054 for entry in MillePedeUser:
0055
0056 if (entry.ObjId != 1 and 999999 not in map(abs, entry.Par)):
0057
0058 if not any(x.name == str(entry.Name) for x in self.structures):
0059
0060 name = str(entry.Name)
0061 subdetid = self.get_subdetid(entry.ObjId)
0062 discriminator = self.get_discriminator(entry.ObjId)
0063 ndiscriminator = self.get_ndiscriminator(entry.ObjId)
0064
0065 self.structures.append(
0066 Structure(name, subdetid, discriminator, ndiscriminator))
0067
0068 self.structures[-1].detids = self.get_detids(subdetid)
0069
0070 def create_children_list(self):
0071 for struct in self.structures:
0072
0073
0074 ranges = struct.ndiscriminator
0075 pranges = [list(range(1, x+1)) for x in ranges]
0076
0077
0078 for number in itertools.product(*pranges):
0079
0080 pattern = dict(zip(map(lambda x: x.lower(), struct.discriminator), number))
0081
0082 name = " ".join("{0} {1}".format(key.lower(), value)
0083 for (key, value) in pattern.items())
0084
0085 detids = self.get_detids(struct.subdetid, pattern)
0086
0087 child = Structure(name, struct.subdetid, detids=detids)
0088 struct.children.append(child)
0089
0090
0091 def get_detids(self, subdetid, pattern={}):
0092
0093 detids = []
0094
0095 treeFile = ROOT.TFile(os.path.join(self.config.jobDataPath,
0096 ".TrackerTree.root"))
0097 tree = treeFile.Get("TrackerTreeGenerator/TrackerTree/TrackerTree")
0098
0099 for entry in tree:
0100
0101 if (entry.SubdetId == subdetid):
0102
0103 structure_found = False
0104 for structure in ("Half", "Side", "Layer", "Rod", "Ring",
0105 "Petal", "Blade", "Panel", "OuterInner",
0106 "Module"):
0107 if structure.lower() in pattern:
0108 if getattr(entry, structure) != pattern[structure.lower()]:
0109 structure_found = True
0110 break
0111 if structure_found: continue
0112
0113 detids.append(entry.RawId)
0114 return detids
0115
0116
0117 class Structure:
0118 """ A object represents a physical strucutre
0119 """
0120
0121 def __init__(self, name, subdetid, discriminator=[], ndiscriminator=[], detids=[]):
0122
0123 self.name = name
0124
0125 self.subdetid = subdetid
0126
0127 self.discriminator = discriminator
0128
0129 self.ndiscriminator = ndiscriminator
0130
0131 self.detids = detids
0132
0133 self.children = []
0134
0135 def get_name(self):
0136 return self.name
0137
0138 def get_children(self):
0139 return self.children
0140
0141 def contains_detid(self, detid):
0142 if detid in self.detids:
0143 return True
0144 return False