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 119 of file generateMioctEncodingFile.py.

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

◆ main()

def generateMioctEncodingFile.main ( )

Definition at line 195 of file generateMioctEncodingFile.py.

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

◆ writeXML()

def generateMioctEncodingFile.writeXML (   g)

Definition at line 62 of file generateMioctEncodingFile.py.

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

Variable Documentation

◆ shiftPhi

generateMioctEncodingFile.shiftPhi

Definition at line 12 of file generateMioctEncodingFile.py.

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: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:808
generateMioctEncodingFile.main
def main()
Definition: generateMioctEncodingFile.py:195
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: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:119
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)