test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
geometry.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 ##########################################################################
4 # Classes which provide the geometry information.
5 ##
6 
7 import itertools
8 import os
9 
10 from ROOT import TFile, TTree
11 
12 from Alignment.MillePedeAlignmentAlgorithm.mpsvalidate import geometrydata
13 
14 
15 class Alignables:
16  """ Creates a list of the aligned strucutres. Get the fields out of the
17  TrackerTree.root file.
18  """
19 
20  def __init__(self, config):
21  # list of Structure objects, contains structures which were aligned
22  self.structures = []
23  self.config = config
24 
25  def get_name_by_objid(self, objid):
26  return geometrydata.data[objid].name
27 
28  def get_subdetid(self, objid):
29  return geometrydata.data[objid].subdetid
30 
31  def get_discriminator(self, objid):
32  return geometrydata.data[objid].discriminator
33 
34  def get_ndiscriminator(self, objid):
35  return geometrydata.data[objid].ndiscriminator
36 
37  def create_list(self, MillePedeUser):
38  # loop over output TTree
39  for line in MillePedeUser:
40  # check which structures were aligned
41  if (line.ObjId != 1 and 999999 not in map(abs, line.Par)):
42  # check if structure is not yet in the list
43  if not any(x.name == self.get_name_by_objid(line.ObjId) for x in self.structures):
44  # create new structure object
45  name = self.get_name_by_objid(line.ObjId)
46  subdetid = self.get_subdetid(line.ObjId)
47  discriminator = self.get_discriminator(line.ObjId)
48  ndiscriminator = self.get_ndiscriminator(line.ObjId)
49  # create structure
50  self.structures.append(
51  Structure(name, subdetid, discriminator, ndiscriminator))
52  # add detids which belong to this structure
53  self.structures[-1].detids = self.get_detids(subdetid)
54 
56  for struct in self.structures:
57  # loop over discriminators -> create patterns
58  # pattern {"half": 2, "side": 2, "layer": 6, ...}
59  ranges = struct.ndiscriminator
60  pranges = [range(1, x+1) for x in ranges]
61  # loop over all possible combinations of the values of the
62  # discriminators
63  for number in itertools.product(*pranges):
64  # create pattern dict
65  pattern = dict(zip(struct.discriminator, number))
66  # name out of patten
67  name = " ".join("{0} {1}".format(key, value)
68  for (key, value) in pattern.items())
69  # get detids of child
70  detids = self.get_detids(struct.subdetid, pattern)
71  # create child and add it to parent
72  child = Structure(name, struct.subdetid, detids=detids)
73  struct.children.append(child)
74 
75  def get_detids(self, subdetid, pattern={}):
76  # list of all detids in the structure
77  detids = []
78  # open TrackerTree.root file
79  treeFile = TFile(os.path.join(self.config.mpspath, "TrackerTree.root"))
80  tree = treeFile.Get("TrackerTreeGenerator/TrackerTree/TrackerTree")
81 
82  for line in tree:
83  # check if line is part of the structure
84  if (line.SubdetId == subdetid):
85 
86  # to create a child also check the pattern
87  if ("half" in pattern):
88  if (line.Half != pattern["half"]):
89  continue
90 
91  if ("side" in pattern):
92  if (line.Side != pattern["side"]):
93  continue
94 
95  if ("layer" in pattern):
96  if (line.Layer != pattern["layer"]):
97  continue
98 
99  if ("rod" in pattern):
100  if (line.Rod != pattern["rod"]):
101  continue
102 
103  if ("ring" in pattern):
104  if (line.Ring != pattern["ring"]):
105  continue
106 
107  if ("petal" in pattern):
108  if (line.Petal != pattern["petal"]):
109  continue
110 
111  if ("blade" in pattern):
112  if (line.Blade != pattern["blade"]):
113  continue
114 
115  if ("panel" in pattern):
116  if (line.Panel != pattern["panel"]):
117  continue
118 
119  if ("outerinner" in pattern):
120  if (line.OuterInner != pattern["outerinner"]):
121  continue
122 
123  if ("module" in pattern):
124  if (line.Module != pattern["module"]):
125  continue
126 
127  detids.append(line.RawId)
128  return detids
129 
130 
131 class Structure:
132  """ A object represents a physical strucutre
133  """
134 
135  def __init__(self, name, subdetid, discriminator=[], ndiscriminator=[], detids=[]):
136  # name of the structure
137  self.name = name
138  # fields to identify the DetIds which belong to the structure
139  self.subdetid = subdetid
140  # fields which allow to discriminate the parts of the structure
141  self.discriminator = discriminator
142  # number per discriminator
143  self.ndiscriminator = ndiscriminator
144  # all DetIds which belong to this structure
145  self.detids = detids
146  # fieldss of all parts of the structure
147  self.children = []
148 
149  def get_name(self):
150  return self.name
151 
152  def get_children(self):
153  return self.children
154 
155  def contains_detid(self, detid):
156  if detid in self.detids:
157  return True
158  return False
bool any(const std::vector< T > &v, const T &what)
Definition: ECalSD.cc:34
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def create_children_list
Definition: geometry.py:55