ATLAS Offline Software
Classes | Functions
generateMioctEncodingFile Namespace Reference

Classes

class  Entry
 

Functions

def writeXML (g)
 
def getTopoCellPosition (rois)
 
def main ()
 

Function Documentation

◆ getTopoCellPosition()

def generateMioctEncodingFile.getTopoCellPosition (   rois)

Definition at line 112 of file generateMioctEncodingFile.py.

112 def getTopoCellPosition(rois):
113 
114  rois = list(rois)
115 
116  # ETA
117 
118  # eta min and max are different in the RPC (barrel) and TGC (endcap and forward)
119  # in the RPC: abs(etamin)<abs(etamax)
120  # in the TGC: etamin<etamax
121  # we are going to use the TGC definition: etamin<etamax
122 
123  cellsEta = [(min(e.etamin,e.etamax), max(e.etamin,e.etamax)) for e in rois]
124  etamins, etamaxs = zip(*cellsEta) # transpose
125  etamin = min( [ min(e.etamin,e.etamax) for e in rois] )
126  etamax = max( [ max(e.etamin,e.etamax) for e in rois] )
127  eta = (etamin+etamax)/2
128 
129 
130  # PHI CONVENTION
131 
132 
133  cellsPhi = [(e.phimin, e.phimax) for e in rois]
134 
135  # check if there are cells on both sides of the PI boundary
136  upperedge = any([e.phi>6.2 for e in rois])
137  loweredge = any([e.phi<0.2 for e in rois])
138  splitTopoCell = upperedge and loweredge
139 
140 
141  if splitTopoCell:
142  maxAtLowerEdge = max([e.phimax for e in rois if e.phi<1])
143  minAtUpperEdge = min([e.phimin for e in rois if e.phi>5])
144  centerTopoCell = minAtUpperEdge + maxAtLowerEdge
145  if centerTopoCell>=2*PI: # shift down
146  phimin = minAtUpperEdge - 2 * PI
147  phimax = maxAtLowerEdge
148  else: # shift up
149  phimin = minAtUpperEdge
150  phimax = maxAtLowerEdge + 2 * PI
151  phi = (phimin+phimax)/2
152  #print "JOERG centerTopoCell = ", centerTopoCell, "=>", phi,"[", phimin, "-", phimax, "] (" , minAtUpperEdge," " , maxAtLowerEdge , ")"
153  else:
154 
155  phimins, phimaxs = zip(*cellsPhi) # transpose
156  phimin = min(phimins)
157  phimax = max(phimaxs)
158  phi = (phimin+phimax)/2
159 
160 
161  ieta = round(eta*10)
162  iphi = round(phi*10)
163 
164  #if (phimin * phimax) < -100:
165  # print "eta ", eta
166  # print "phimin ", phimin
167  # print "phimax ", phimax
168  # print "phi ", phi
169  # print "iphi ", iphi
170  # print ""
171 
172 
173  #test = (phimin * phimax) < 0
174  #if test:
175  # print '\n'.join([str(x) for x in cells])
176  # print "\n\n\n"
177 
178 
179  return (eta, phi, ieta, iphi, etamin, etamax, phimin, phimax)
180 
181 
182 
183 
184 
185 
186 
187 

◆ main()

def generateMioctEncodingFile.main ( )

Definition at line 188 of file generateMioctEncodingFile.py.

188 def main():
189  if len(sys.argv)!=2:
190  print("Usage: %s <geomety.dat>" % os.path.basename(sys.argv[0]))
191  return
192 
193  # read in the data files containing the ROI information
194  data = open(sys.argv[1])
195  lines = [Entry(*l.rstrip().split()) for l in data.readlines() if not l.startswith('#')]
196  lines = sorted(lines, key = attrgetter('mioct','connector') )
197  data.close()
198 
199  groups = {}
200  for k, g in groupby(lines, key=attrgetter('mioct')):
201  groups[k] = {}
202  for k2, g2 in groupby(g, key = attrgetter('connector')):
203  groups[k][k2] = list(g2)
204 
205  writeXML(groups)
206 
207  return 0
208 
209 
210 
211 

◆ writeXML()

def generateMioctEncodingFile.writeXML (   g)

Definition at line 55 of file generateMioctEncodingFile.py.

55 def writeXML(g):
56  filename = os.path.basename(sys.argv[1]).replace('.dat','.xml')
57  xml = open(filename,"w")
58  print('<?xml version="1.0" ?>\n', file=xml)
59  print('<!DOCTYPE MuCTPiGeometry SYSTEM "MUCTPIGeometry.dtd">\n', file=xml)
60  print('<MuCTPiGeometry>', file=xml)
61  for mioct in sorted(g.keys()):
62 
63  allSlots = set()
64  allSectorNames = set()
65  for sector in g[mioct].values():
66  allSlots.update( [e.slot for e in sector] )
67  allSectorNames.update( [e.sectorname for e in sector] )
68  if len(allSlots) != 1:
69  raise RuntimeError("More than one slot defined for MIOCT %i" % mioct)
70  slot = allSlots.pop()
71  allSectorNames = sorted(list( allSectorNames ))
72 
73  print(' <MIOCT id="%i" slot="%s">' % ( mioct, slot ), file=xml)
74  print(' <!-- contains sectors %s -->' % ", ".join(allSectorNames), file=xml)
75  for connector in sorted(g[mioct].keys()):
76  sector = sorted(g[mioct][connector], key=attrgetter('eta','phi','etacode','phicode'))
77  print(' <Sector connector="%s" name="%s">' % (connector, ", ".join(set([str(e.sectorname) for e in sector])) ), file=xml)
78  print(' <!-- contains %i ROIs -->' % len(sector), file=xml)
79  print(' <!-- mapping from ROI to coding scheme -->', file=xml)
80  for e in sector:
81  print(' <ROI eta="%f" phi="%f" etacode="%s" phicode="%s" etamin="%f" etamax="%f" phimin="%f" phimax="%f" roiid="%i"/>' % (e.eta, e.phi, e.etacode, e.phicode, e.etamin, e.etamax, e.phimin, e.phimax, e.roi), file=xml)
82  print(' </Sector>', file=xml)
83 
84  allROIsInMIOCT = []
85  map(allROIsInMIOCT.extend, g[mioct].values()) # add all ROIs in this MIOCT
86 
87  print(' <Decode>', file=xml)
88 
89  for (eta_code,phi_code), rois in groupby(sorted(allROIsInMIOCT,key=attrgetter('etacode','phicode')), key=attrgetter('etacode','phicode')):
90 
91  (eta, phi, ieta, iphi, etamin, etamax, phimin, phimax) = getTopoCellPosition(rois)
92 
93  print(' <TopoCell etacode="%s" phicode="%s" eta="%f" phi="%f" ieta="%i" iphi="%i" etamin="%f" etamax="%f" phimin="%f" phimax="%f"/>' % (eta_code, phi_code, eta, phi, ieta, iphi, etamin, etamax, phimin, phimax), file=xml)
94  print(' </Decode>', file=xml)
95  print(' </MIOCT>', file=xml)
96  # hardcoding the PT at the moment
97  print(' <PtEncoding>', file=xml)
98  print(' <PtCodeElement pt="1" code="0" value="4"/>', file=xml)
99  print(' <PtCodeElement pt="2" code="1" value="6"/>', file=xml)
100  print(' <PtCodeElement pt="3" code="2" value="10"/>', file=xml)
101  print(' <PtCodeElement pt="4" code="2" value="11"/>', file=xml)
102  print(' <PtCodeElement pt="5" code="2" value="15"/>', file=xml)
103  print(' <PtCodeElement pt="6" code="2" value="20"/>', file=xml)
104  print(' </PtEncoding>', file=xml)
105  print('</MuCTPiGeometry>', file=xml)
106  xml.close()
107  print("Wrote %s" % filename)
108 
109 
110 
111 
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename R::value_type > sorted(const R &r, PROJ proj={})
Helper function to create a sorted vector from an unsorted range.
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:310
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
MuonGM::round
float round(const float toRound, const unsigned int decimals)
Definition: Mdt.cxx:27
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:808
generateMioctEncodingFile.main
def main()
Definition: generateMioctEncodingFile.py:188
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
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:26
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
Trk::open
@ open
Definition: BinningType.h:40
generateMioctEncodingFile.getTopoCellPosition
def getTopoCellPosition(rois)
Definition: generateMioctEncodingFile.py:112
str
Definition: BTagTrackIpAccessor.cxx:11
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:801
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
writeXML
StatusCode writeXML(const string &name, int type)