22 parser = argparse.ArgumentParser(description=
'Flattens Wrapper Files')
23 parser.add_argument(
'inname', metavar=
'inputfile', type=str,
24 help=
'input file name (should be FPGATrackSim Wrapper File)')
25 args = parser.parse_args()
30 printPB, printPE, printSB, printSE = [[]
for i
in range(7)],[[]
for i
in range(7)],[[]
for i
in range(7)],[[]
for i
in range(7)]
33 rmap =
open(
'alleta_allphi_kl_strip2_ATLAS-P2-ITK-23-00-01.rmap',
'w')
37 fileList = glob.glob("%s/*.root" % args.inname)
39 Data = ROOT.TChain("ExtrapolationEngineTest")
42 msg.info("Adding file " + file)
47 f = ROOT.TFile.Open(args.inname)
48 Data = f.Get(
"ExtrapolationEngineTest")
50 sys.stdout.write(
"start\n")
56 sys.stdout.write(
"reading track input\n")
61 num_entries = Data.GetEntries()
62 counter, events, perc = 0,0,0
66 for dic_idx
in np.arange(counter, counter + len(trk.SensitivePosX)):
68 hits[dic_idx][
"geom"] = trk.SensitiveIsPixel[hit_idx]
69 hits[dic_idx][
"ec"] = trk.SensitiveBarrelEndcap[hit_idx]
70 if trk.SensitiveIsPixel[hit_idx] == 0:
71 layer = 2*trk.SensitiveLayerDisc[hit_idx]+trk.SensitiveSide[hit_idx]
73 layer = trk.SensitiveLayerDisc[hit_idx]
75 # If you want to use the layer scheme in the pixel endcap where each disk is a unique layer:
76 if trk.SensitiveIsPixel[hit_idx] == 0: # strip
77 layer = 2*trk.SensitiveLayerDisc[hit_idx]+trk.SensitiveSide[hit_idx]
79 if trk.SensitiveBarrelEndcap[hit_idx] == 0: # pixel barrel
80 layer = trk.SensitiveLayerDisc[hit_idx]
82 # number of disks per layer in 23-00-01: [15, 29, 6, 11, 8, 8, 9, 9] --> [0, 15, 44, 50, 61, 69, 77, 86]
83 # number of disks per layer in 22-02-00: [17, 30, 11, 8, 9] --> [0,17,47,58,66]
84 etas_per_layer = [0, 15, 44, 50, 61, 69, 77, 86]
85 layer = etas_per_layer[trk.SensitiveLayerDisc[hit_idx]] + trk.SensitiveEtaModule[hit_idx]
87 hits[dic_idx][
"layer"] = layer
88 hits[dic_idx][
"z"] = trk.SensitivePosZ[hit_idx]
91 counter = counter + len(trk.SensitivePosX)
93 if events % 5000 == 0:
94 sys.stdout.write(
"%d %% complete\n" % perc)
98 sys.stdout.write(
"parse geom took %d seconds\n" % (t1-t0))
104 sys.stdout.write(
"\nfilling slices\n")
109 kl = {k:v
for (k,v)
in hits.items()
if hits[k][
'geom'] == 0
if hits[k][
'ec'] == 0
if hits[k][
'layer'] == 2}
110 max_z =
max(
int(l[
'z'])
for l
in kl.values())
111 min_z =
min(
int(l[
'z'])
for l
in kl.values())
112 slices = np.linspace(min_z,max_z, 7)
115 sliceDicts = [dict()
for x
in range(6)]
118 sys.stdout.write(
"\nstarting slice %d \n" % i)
119 sys.stdout.write(
"%.1f mm < z < %.1f mm \n" % (slices[i],slices[i+1]))
126 for hit
in range(len(trk.SensitivePosX)):
127 isPix = trk.SensitiveIsPixel[hit]
128 bEC = trk.SensitiveBarrelEndcap[hit]
130 layer = 2*trk.SensitiveLayerDisc[hit]+trk.SensitiveSide[hit]
132 layer = trk.SensitiveLayerDisc[hit]
134 z = trk.SensitivePosZ[hit]
136 if isPix == 0
and bEC == 0
and layer == 2
and z >= slices[i]
and z <= slices[i+1]:
140 for hit
in range(len(trk.SensitivePosX)):
142 s[dic_idx][
"geom"] = trk.SensitiveIsPixel[hit]
143 s[dic_idx][
"ec"] = trk.SensitiveBarrelEndcap[hit]
144 if trk.SensitiveIsPixel[hit] == 0:
145 layer = 2*trk.SensitiveLayerDisc[hit]+trk.SensitiveSide[hit]
147 layer = trk.SensitiveLayerDisc[hit]
148 s[dic_idx][
"layer"] = layer
149 s[dic_idx][
"phi"] = trk.SensitivePhiModule[hit]
150 s[dic_idx][
"eta"] = trk.SensitiveEtaModule[hit]
151 strip = trk.SensitivePhiIndex[hit]
153 if trk.SensitiveIsPixel[hit] == 0
and layer <= 3:
154 if strip >= 0
and strip < 1280:
156 elif strip >= 1280
and strip < 2560:
158 elif strip >= 2560
and strip < 3840:
160 elif strip >= 3840
and strip <= 5120:
164 s[dic_idx][
"eta"] = 4*s[dic_idx][
"eta"] + row
165 elif trk.SensitiveIsPixel[hit] == 0
and layer >1:
166 if strip >= 0
and strip < 1280:
168 elif strip >= 1280
and strip <= 2560:
172 s[dic_idx][
"eta"] = 2*s[dic_idx][
"eta"] + row
173 dic_idx = dic_idx + 1
177 sys.stdout.write(
"Find key hits and fill slices took %d seconds\n" % (t3-t2))
188 pb = {k:v
for (k,v)
in s.items()
if s[k][
'geom'] == 1
if s[k][
'ec'] == 0}
190 pe = {k:v
for (k,v)
in s.items()
if s[k][
'geom'] == 1
if s[k][
'ec'] != 0}
192 sb = {k:v
for (k,v)
in s.items()
if s[k][
'geom'] == 0
if s[k][
'ec'] == 0}
194 se = {k:v
for (k,v)
in s.items()
if s[k][
'geom'] == 0
if s[k][
'ec'] != 0}
197 pbmax =
max(
int(l[
'layer'])
for l
in pb.values()) + 1
199 msg.warning(
"pixel barrel had no hits in slice %d" % i)
202 pemax =
max(
int(l[
'layer'])
for l
in pe.values()) + 1
204 msg.warning(
"pixel endcap had no hits in slice %d" % i)
207 sbmax =
max(
int(l[
'layer'])
for l
in sb.values()) + 1
209 msg.warning(
"strip barrel had no hits in slice %d" % i)
212 semax =
max(
int(l[
'layer'])
for l
in se.values()) + 1
214 msg.warning(
"strip endcap had no hits in slice %d" % i)
217 for lyr
in range(
max(
int(l[
'layer']+1)
for l
in s.values())):
231 if pb[key][
'layer'] == (lyr):
232 phi_pb.add(pb[key][
"phi"])
233 eta_pb.add(pb[key][
"eta"])
234 printPB[i].
append(
"1 0 %d %d %d %d %d %d %d" % (lyr,
min(phi_pb),
max(phi_pb),len(phi_pb),
min(eta_pb),
max(eta_pb),len(eta_pb)))
239 if pe[key][
'layer'] == (lyr):
240 phi_pe.add(pe[key][
"phi"])
241 eta_pe.add(pe[key][
"eta"])
242 printPE[i].
append(
"1 1 %d %d %d %d %d %d %d" % (lyr,
min(phi_pe),
max(phi_pe),len(phi_pe),
min(eta_pe),
max(eta_pe),len(eta_pe)))
247 if sb[key][
'layer'] == (lyr):
248 phi_sb.add(sb[key][
"phi"])
249 eta_sb.add(sb[key][
"eta"])
250 printSB[i].
append(
"0 0 %d %d %d %d %d %d %d" % (lyr,
min(phi_sb),
max(phi_sb),len(phi_sb),
min(eta_sb),
max(eta_sb),len(eta_sb)))
255 if se[key][
'layer'] == (lyr):
256 phi_se.add(se[key][
"phi"])
257 eta_se.add(se[key][
"eta"])
258 printSE[i].
append(
"0 1 %d %d %d %d %d %d %d" % (lyr,
min(phi_se),
max(phi_se),len(phi_se),
min(eta_se),
max(eta_se),len(eta_se)))
264 printPE[i].
append(
"0 1 %d 0 0 0 0 0 0" % j)
269 printSE[i].
append(
"0 1 %d 0 0 0 0 0 0" % j)
272 rmap.write(
"towers 6 phi 16\n\n")
275 rmap.write(
"\n%d \n" % z)
277 for i
in range(0,len(printPB[z])):
278 rmap.write(printPB[z][i])
280 for i
in range(0,len(printPE[z])):
281 rmap.write(printPE[z][i])
283 for i
in range(0,len(printSB[z])):
284 rmap.write(printSB[z][i])
286 for i
in range(0,len(printSE[z])):
287 rmap.write(printSE[z][i])