Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule.py
More file actions
Latest commit
189 lines (161 loc) · 7.76 KB
/
Copy pathModule.py
File metadata and controls
189 lines (161 loc) · 7.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
from __future__ importprint_function
importROOTasr
importsys
importos
dirpath=os.path.dirname(os.path.abspath(__file__))
r.gROOT.ProcessLine(".L {}/ModuleDetIdParser.cxx".format(dirpath))
classModule:
def__init__(self, detid, moduleTypeInfo=None):
self.detid=int(detid)
self.moduleSDL=r.SDL.Module(self.detid)
ifmoduleTypeInfo!=None:
self.moduleSDL=r.SDL.Module(self.detid, int(moduleTypeInfo))
maxBarrelxyModules= {1:18,2:26,3:36,4:48,5:60,6:78}
#[layer][ring]
maxEndcapxyModules={
1:{1:20,2:24,3:24,4:28,5:32,6:32,7:36,8:40,9:40,10:44,11:52,12:60,13:64,14:62,15:76},
2:{1:20,2:24,3:24,4:28,5:32,6:32,7:36,8:40,9:40,10:44,11:52,12:60,13:64,14:62,15:76},
3:{1:28,2:28,3:32,4:36,5:36,6:40,7:44,8:52,9:56,10:64,11:72,12:76},
4:{1:28,2:28,3:32,4:36,5:36,6:40,7:44,8:52,9:56,10:64,11:72,12:76},
5:{1:28,2:28,3:32,4:36,5:36,6:40,7:44,8:52,9:56,10:64,11:72,12:76},
}
maxBarrelFlatZModules= {1:7,2:11,3:15,4:24,5:24,6:24}
maxBarrelTiltedZModules= {1:12,2:12,3:12,4:12,5:12,6:12}
maxRings= {1:15,2:15,3:12,4:12,5:12}
defdetId(self): returnint(self.detid)
defpartnerDetId(self): returnint(self.moduleSDL.partnerDetId())
defsubdet(self): returnint(self.moduleSDL.subdet())
defside(self): returnint(self.moduleSDL.side())
deflayer(self): returnint(self.moduleSDL.layer())
deflogicalLayer(self): returnint(self.moduleSDL.layer()) + (6ifself.subdet() ==4else0)
defrod(self): returnint(self.moduleSDL.rod())
defring(self): returnint(self.moduleSDL.ring())
defmodule(self): returnint(self.moduleSDL.module())
defisLower(self): returnint(self.moduleSDL.isLower())
defisInverted(self): returnint(self.moduleSDL.isInverted())
defmoduleType(self): returnint(self.moduleSDL.moduleType())
defmoduleLayerType(self): returnint(self.moduleSDL.moduleLayerType())
defisBarrelFlat(self): return (self.side() ==3andself.subdet() ==5)
defisBarrelTilted(self): return (self.subdet() ==5andself.side() !=3)
defplusPhiDetId(self):
plusPhiDetId=int(self.detid)
ifself.isBarrelFlat():
ifself.rod() ==self.maxBarrelxyModules[self.layer()]:
plusPhiDetId-= (self.maxBarrelxyModules[self.layer()] -1) <<10
else:
plusPhiDetId+=1<<10
elifself.isBarrelTilted():
ifself.module() ==self.maxBarrelxyModules[self.layer()]:
plusPhiDetId-= (self.maxBarrelxyModules[self.layer()] -1) <<2
else:
plusPhiDetId+=1<<2
else: #endcap
ifself.module() ==self.maxEndcapxyModules[self.layer()][self.ring()]:
plusPhiDetId-= (self.maxEndcapxyModules[self.layer()][self.ring()] -1) <<2
else:
plusPhiDetId+=1<<2
returnint(plusPhiDetId)
defminusPhiDetId(self):
minusPhiDetId=int(self.detid)
ifself.isBarrelFlat():
ifself.rod() ==1:
minusPhiDetId+= (self.maxBarrelxyModules[self.layer()] -1) <<10
else:
minusPhiDetId-=1<<10
elifself.isBarrelTilted():
ifself.module() ==1:
minusPhiDetId+= (self.maxBarrelxyModules[self.layer()] -1) <<2
else:
minusPhiDetId-=1<<2
else: #endcap
ifself.module() ==1:
minusPhiDetId+= (self.maxEndcapxyModules[self.layer()][self.ring()] -1) <<2
else:
minusPhiDetId-=1<<2
returnint(minusPhiDetId)
defplusEtaDetId(self):
plusEtaDetId=int(self.detid)
ifself.isBarrelFlat():
ifself.module() ==self.maxBarrelFlatZModules[self.layer()] andself.layer() <=3:
plusEtaDetId-=1<<18#side changed from 3 to 2
plusEtaDetId-=self.rod()<<10#Rod reset
plusEtaDetId-=self.module() <<2#Module reset
plusEtaDetId+=self.rod()<<2#rod of flat assigned to module of tilted
plusEtaDetId+=1<<10#rod of tilted reset to 1 (1st module in tilted)
elifself.layer() >3:
print("Max eta range reached in flat barrel! Transition not implemented yet!")
else:
plusEtaDetId+=1<<2
elifself.isBarrelTilted():
ifself.rod() ==self.maxBarrelTiltedZModules[self.layer()]:
print("Max eta range reached in tilted barrel! Transition not implemented yet!")
else:
plusEtaDetId+=1<<10
else: #Endcap - jump to next layer
ifself.layer() <5:
plusEtaDetId+=1<<18
returnplusEtaDetId
defminusEtaDetId(self):
minusEtaDetId=int(self.detid)
ifself.isBarrelFlat():
ifself.module() ==1andself.layer() <=3 :
#Implement the jump from barrel to tilted
minusEtaDetId-=2<<18#side changed from 3 to 1
minusEtaDetId-=self.rod()<<10#Rod reset
minusEtaDetId-=self.module() <<2#Module reset
minusEtaDetId+=self.rod()<<2#rod of flat assigned to module of tilted
minusEtaDetId+=12<<10#rod of tilted reset to 12 (last module in tilted)
elifself.layer() >3:
print("Max eta range reached in flat barrel! Transition not implemented yet!")
else:
minusEtaDetId-=1<<2
elifself.isBarrelTilted():
ifself.rod() ==1:
print("Max eta range reached in tilted barrel! Transition not implemented yet!")
else:
minusEtaDetId-=1<<10
else: #Endcap - jump to previous layer
ifself.layer() >1:
minusEtaDetId-=1<<18
returnminusEtaDetId
defplusRDetId(self):
plusRDetId=int(self.detid)
ifself.subdet() ==4:
ifself.ring() <self.maxRings[self.layer()]:
plusRDetId+=1<<12
else:
print("No Plus R for barrel module!")
returnplusRDetId
defminusRDetId(self):
minusRDetId=int(self.detid)
ifself.subdet() ==4:
ifself.ring() >1:
minusRDetId-=1<<12
else:
print("No Minus R for barrel module!")
returnminusRDetId
# def __str__(self):
# return "detid={} logicalLayer={} side={} moduleType={} ring={}".format(self.detId(), self.logicalLayer(), self.side(), self.moduleType(), self.ring())
def__str__(self):
printstr="detId={}, partnerDetId={},subdet={},side={},layer={},rod={},ring={},module={},moduleType={},isLower={}".format(self.detId(),self.partnerDetId(),self.subdet(),self.side(),self.layer(),self.rod(),self.ring(),self.module(),self.moduleType(),self.isLower())
returnprintstr
if__name__=="__main__":
try:
module=Module(int(sys.argv[1]))
except:
module=Module(443354118)
print("subdet = "+str(module.subdet()))
print("layer = "+str(module.layer()))
print("isLower = "+str(module.isLower()))
print("ring = "+str(module.ring()))
print("rod = "+str(module.rod()))
print("moduleType = "+str(module.moduleType()))
print("moduleLayerType = "+str(module.moduleLayerType()))
print("Current module\n",module)
print("Next module in phi\n",Module(module.plusPhiDetId()))
print("Previous module in phi\n",Module(module.minusPhiDetId()))
print("Next module in eta\n",Module(module.plusEtaDetId()))
print("Previous module in eta\n",Module(module.minusEtaDetId()))
ifmodule.subdet() ==4:
print("Next module in R\n",Module(module.plusRDetId()))
print("Previous module in R\n",Module(module.minusRDetId()))