ATLAS Offline Software
Classes | Functions | Variables
generateMioctEncodingFile Namespace Reference

Classes

class  Entry
 

Functions

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

Variables

 shiftPhi
 

Function Documentation

◆ getTopoCellPosition()

def generateMioctEncodingFile.getTopoCellPosition (   rois)

Definition at line 120 of file generateMioctEncodingFile.py.

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

◆ main()

def generateMioctEncodingFile.main ( )

Definition at line 196 of file generateMioctEncodingFile.py.

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

◆ writeXML()

def generateMioctEncodingFile.writeXML (   g)

Definition at line 63 of file generateMioctEncodingFile.py.

63 def writeXML(g):
64  filename = os.path.basename(sys.argv[1]).replace('.dat','.xml')
65  xml = open(filename,"w")
66  print('<?xml version="1.0" ?>\n', file=xml)
67  print('<!DOCTYPE MuCTPiGeometry SYSTEM "MUCTPIGeometry.dtd">\n', file=xml)
68  print('<MuCTPiGeometry>', file=xml)
69  for mioct in sorted(g.keys()):
70 
71  allSlots = set()
72  allSectorNames = set()
73  for sector in g[mioct].values():
74  allSlots.update( [e.slot for e in sector] )
75  allSectorNames.update( [e.sectorname for e in sector] )
76  if len(allSlots) != 1:
77  raise RuntimeError("More than one slot defined for MIOCT %i" % mioct)
78  slot = allSlots.pop()
79  allSectorNames = sorted(list( allSectorNames ))
80 
81  print(' <MIOCT id="%i" slot="%s">' % ( mioct, slot ), file=xml)
82  print(' <!-- contains sectors %s -->' % ", ".join(allSectorNames), file=xml)
83  for connector in sorted(g[mioct].keys()):
84  sector = sorted(g[mioct][connector], key=attrgetter('eta','phi','etacode','phicode'))
85  print(' <Sector connector="%s" name="%s">' % (connector, ", ".join(set([str(e.sectorname) for e in sector])) ), file=xml)
86  print(' <!-- contains %i ROIs -->' % len(sector), file=xml)
87  print(' <!-- mapping from ROI to coding scheme -->', file=xml)
88  for e in sector:
89  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)
90  print(' </Sector>', file=xml)
91 
92  allROIsInMIOCT = []
93  map(allROIsInMIOCT.extend, g[mioct].values()) # add all ROIs in this MIOCT
94 
95  print(' <Decode>', file=xml)
96 
97  for (eta_code,phi_code), rois in groupby(sorted(allROIsInMIOCT,key=attrgetter('etacode','phicode')), key=attrgetter('etacode','phicode')):
98 
99  (eta, phi, ieta, iphi, etamin, etamax, phimin, phimax) = getTopoCellPosition(rois)
100 
101  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)
102  print(' </Decode>', file=xml)
103  print(' </MIOCT>', file=xml)
104  # hardcoding the PT at the moment
105  print(' <PtEncoding>', file=xml)
106  print(' <PtCodeElement pt="1" code="0" value="4"/>', file=xml)
107  print(' <PtCodeElement pt="2" code="1" value="6"/>', file=xml)
108  print(' <PtCodeElement pt="3" code="2" value="10"/>', file=xml)
109  print(' <PtCodeElement pt="4" code="2" value="11"/>', file=xml)
110  print(' <PtCodeElement pt="5" code="2" value="15"/>', file=xml)
111  print(' <PtCodeElement pt="6" code="2" value="20"/>', file=xml)
112  print(' </PtEncoding>', file=xml)
113  print('</MuCTPiGeometry>', file=xml)
114  xml.close()
115  print("Wrote %s" % filename)
116 
117 
118 
119 

Variable Documentation

◆ shiftPhi

generateMioctEncodingFile.shiftPhi

Definition at line 13 of file generateMioctEncodingFile.py.

replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
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:805
generateMioctEncodingFile.main
def main()
Definition: generateMioctEncodingFile.py:196
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
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:25
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:120
str
Definition: BTagTrackIpAccessor.cxx:11
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
writeXML
StatusCode writeXML(const string &name, int type)