SND@LHC Software
Loading...
Searching...
No Matches
reverseMapping.py
Go to the documentation of this file.
1import os
2import boardMappingParser
3from XRootD import client
4import csv
5
7 " detector ID and SiPM channel nr to online board/tofpet_id/tofpet_channel "
8 def Init(self,path):
9 with client.File() as f:
10 f.open(path+"/board_mapping.json")
11 status, jsonStr = f.read()
13 self.slots = {0:'A',1:'A',2:'B',3:'B',4:'C',5:'C',6:'D',7:'D'}
14 self.MufiSystem = {}
15 for b in self.boardMaps['MuFilter']:
16 board_id = int(b.split('_')[1])
17 self.MufiSystem[board_id]={}
18 for x in self.boardMaps['MuFilter'][b]:
19 for slot in self.slots:
20 s = 0
21 tmp = self.boardMaps['MuFilter'][b][x].split('_')[0]
22 if tmp=='US': s = 1
23 elif tmp=='DS': s = 2
24 if self.slots[slot]==x: self.MufiSystem[board_id][slot]=s
25 self.SiPMmap={}
26 self.names = {'DS':2,'US':1,'Veto':0}
27 self.sdict = {3:'DS',2:'US',1:'Veto'}
28 for system in self.names:
29 sndswPath = os.environ['SNDSW_ROOT']
30 infile = sndswPath+"/geometry/"+system+"_SiPM_mapping.csv"
31 self.SiPMmap[system] = {}
32 if os.path.isdir(sndswPath+"/geometry"):
33 with open(infile, "r") as f:
34 reader = csv.DictReader(f, delimiter=',')
35 for i, row in enumerate(reader):
36 self.SiPMmap[system][int(row['SiPM'])] = [int(row['CN']), int(row['pin']), int(row['TOFPET']), int(row['CHANNEL'])]
37 self.offMap={}
38 for s in range(1,3):
39 for o in ['Left','Right']:
40 self.offMap['Veto_'+str(s)+o] =[10000 + (s-1)*1000+ 0,8,2] # first channel, nSiPMs, nSides, from bottom to top
41 self.offMap['Veto_3Vert'] = [10000+2*1000+0,8,1] # third vertical Veto plane
42 for s in range(1,6):
43 for o in ['Left','Right']:
44 self.offMap['US_'+str(s)+o] =[20000 + (s-1)*1000+ 9,-8,2] # from top to bottom
45 for s in range(1,5):
46 for o in ['Vert']:
47 self.offMap['DS_'+str(s)+o] =[30000 + (s-1)*1000+ 119, -1,1]
48 if s>3: continue
49 for o in ['Left','Right']:
50 self.offMap['DS_'+str(s)+o] =[30000 + (s-1)*1000+ 59,-1,2]
52 self.revBoardMaps['MuFilter'] = {}
53 for board in self.boardMaps['MuFilter']:
54 for slot in self.boardMaps['MuFilter'][board]:
55 key = self.boardMaps['MuFilter'][board][slot]
56 self.revBoardMaps['MuFilter'][key]=[board,slot]
57
58 self.revBoardMaps['Scifi'] = {}
59 for board in self.boardMaps['Scifi']:
60 station,mat = self.boardMaps['Scifi'][board]
61 if not station in self.revBoardMaps['Scifi']: self.revBoardMaps['Scifi'][station] = {}
62 self.revBoardMaps['Scifi'][station][mat] = board
63
64#
65 def daqChannel(self,aHit,channel=0):
66 if type(aHit).__name__ == 'int': fDetectorID = aHit
67 else: fDetectorID = aHit.GetDetectorID()
68 if not fDetectorID<1000000: #scifi hit
69 s = fDetectorID//1000000
70 mat = (fDetectorID%100000)//10000
71 orientation = (fDetectorID%1000000)//100000
72 chan = fDetectorID%1000
73 sipm = (fDetectorID%10000)//1000
74 sipmChannel = chan + sipm*128
75 station = 'M'+str(s)+'X'
76 if orientation ==0 : station = 'M'+str(s)+'Y'
77 board = self.revBoardMaps['Scifi'][station][mat]
78 return {"sipmChannel":sipmChannel,"board":board}
79 else:
80 subsystem = fDetectorID//10000
81 plane = fDetectorID//1000 - 10*subsystem
82 bar_number = fDetectorID%1000
83 nSiPMs = aHit.GetnSiPMs()
84 nSides = aHit.GetnSides()
85 if (subsystem==3 and bar_number>59) or (subsystem==1 and plane==2):
86 side="Vert"
87 elif channel < nSiPMs: side = 'Left'
88 else: side = 'Right'
89 tag = self.sdict[subsystem]+'_'+str(plane+1)+side
90 direction = int(self.offMap[tag][1]/nSiPMs)
91 sipmChannel = int( (fDetectorID - self.offMap[tag][0])/direction * nSiPMs)
92 sipmChannel+=channel%(nSiPMs) + 1
93 board = self.revBoardMaps['MuFilter'][tag]
94 result = self.SiPMmap[self.sdict[subsystem]][sipmChannel]
95 return {"sipmChannel":sipmChannel,"board":board,"channel":result[3],"tofpet":result[2],"pin":result[1],"CN":result[0]}
96
97 def test(nSiPMs = 8,subsystem = 2,plane = 3):
98 for side in ['Left','Right']:
99 for bar_number in range(10):
100 fDetectorID = 20000+plane*1000+bar_number
101 tag = tself.sdict[subsystem]+'_'+str(plane+1)+side
102 for n in range(nSiPMs):
103 direction = int(tself.offMap[tag][1]/nSiPMs)
104 sipmChannel = int( (fDetectorID - tself.offMap[tag][0])/direction * nSiPMs) + n + 1
105 result = tself.SiPMmap[tself.sdict[subsystem]][sipmChannel]
106 print(fDetectorID,n, " : ",sipmChannel,result)
107
daqChannel(self, aHit, channel=0)
test(nSiPMs=8, subsystem=2, plane=3)
getBoardMapping(jsonString)