ATLAS Offline Software
Loading...
Searching...
No Matches
checkRpcDigits.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3from HitIdentifier import RpcIdentifier
4from ROOT import TVector3, TVector2, TFile
5from argparse import ArgumentParser
6
7
9 def __init__(self,
10 stationIndex=-1, stationEta=-1, stationPhi=-1,
11 doubletR = -1, doubletPhi = -1, doubletZ = -1,
12 gasGap =-1, measuresPhi = False, strip = -1,
13 globPosX= -1, globPosY = -1., globPosZ = -1,
14 locPosX = -1, locPosY= -1,
15 time = -1.
16 ) -> None:
17 self.__id = RpcIdentifier(stationIndex=stationIndex, stationEta = stationEta, stationPhi = stationPhi,
18 doubletR= doubletR, doubletPhi = doubletPhi, doubletZ = doubletZ,
19 gasGap = gasGap, measuresPhi = measuresPhi, strip = strip)
20
21 self.__globPos = TVector3(globPosX, globPosY, globPosZ)
22 self.__locPos = TVector2(locPosX, locPosY)
23 self.__time = time
24
25 def identify(self):
26 return self.__id
27
28 def globalPosition(self):
29 return self.__globPos
30
31 def localPosition(self):
32 return self.__locPos
33
34 def time(self):
35 return self.__time
36
37 def __str__(self) -> str:
38 return "Rpc digit {id}, time {time:.2f}, localPos ({locX:.2f}, {locY:.2f}) globalPos ({globX:.2f}, {globY:.2f}, {globZ:.2f})".format(id = str(self.identify()),
39 time = self.__time,
40 locX = self.localPosition().X(),
41 locY = self.localPosition().Y(),
42 globX = self.globalPosition().X(),
43 globY = self.globalPosition().Y(),
44 globZ = self.globalPosition().Z())
45 def __eq__(self, other) -> bool:
46 return self.identify() == other.identify() and \
47 (self.localPosition() - other.localPosition()).Mod() < 0.01
48
49
51 def __init__(self, stationIndex=-1, stationEta=-1, stationPhi=-1,
52 doubletR=-1, doubletPhi=-1, doubletZ=-1, gasGap=-1,
53 measuresPhi=False, strip=-1,
54 globPosX=-1, globPosY=-1, globPosZ=-1,
55 locPosX=-1, locPosY=-1,
56 time=-1, barcode = -1) -> None:
57 super().__init__(stationIndex, stationEta, stationPhi,
58 doubletR, doubletPhi, doubletZ,
59 gasGap, measuresPhi, strip,
60 globPosX, globPosY, globPosZ,
61 locPosX, locPosY, time)
62
63 self.__barcode = barcode
64 def barcode (self):
65 return self.__barcode
66
67 def __str__(self) -> str:
68 return "Rpc SDO {id}, time {time:.2f}, localPos ({locX:.2f}, {locY:.2f}), globalPos ({globX:.2f}, {globY:.2f}, {globZ:.2f}), barcode {barcode}".format(id = str(self.identify()),
69 time = self.time(),
70 locX = self.localPosition().X(),
71 locY = self.localPosition().Y(),
72 globX = self.globalPosition().X(),
73 globY = self.globalPosition().Y(),
74 globZ = self.globalPosition().Z(),
75 barcode = self.barcode())
76
77def readDigitTree(in_file, treeName = "HitValidTree"):
78
79 t_file = TFile.Open(in_file, "READ")
80 if not t_file:
81 print(f"Failed to open {in_file}")
82 exit(1)
83 tree = t_file.Get(treeName)
84 if not tree:
85 print("Failed to read tree {treeName} from {file}".format(treeName=treeName, file=t_file.GetName()))
86 exit(1)
87 allDigits = {}
88 for entry in range(tree.GetEntries()):
89 tree.GetEntry(entry)
90 evt= tree.eventNumber
91 digits = []
92 for digit in range(len(tree.Digits_RPC_stationIndex)):
93 digits.append(RpcDigit(stationIndex = ord(tree.Digits_RPC_stationIndex[digit]),
94 stationEta = ord(tree.Digits_RPC_stationEta[digit]),
95 stationPhi = ord(tree.Digits_RPC_stationPhi[digit]),
96 doubletR = ord(tree.Digits_RPC_doubletR[digit]),
97 doubletPhi= ord(tree.Digits_RPC_doubletPhi[digit]),
98 gasGap = ord(tree.Digits_RPC_gasGap[digit]),
99 measuresPhi=tree.Digits_RPC_measuresPhi[digit],
100 strip = ord(tree.Digits_RPC_strip[digit]),
101 globPosX= tree.Digits_RPC_globalPosX[digit],
102 globPosY= tree.Digits_RPC_globalPosY[digit],
103 globPosZ= tree.Digits_RPC_globalPosZ[digit],
104
105 locPosX = tree.Digits_RPC_localPosX[digit],
106 locPosY = tree.Digits_RPC_localPosY[digit],
107 time = tree.Digits_RPC_time[digit]
108 ))
109 if digits[-1].identify().stationName() == "BIS":
110 digits.pop()
111 if len (digits): allDigits[evt] = digits
112 return allDigits
113
114def readSDOTree(in_file, treeName = "HitValidTree"):
115 allSDOS = {}
116 t_file = TFile.Open(in_file, "READ")
117 if not t_file:
118 print(f"Failed to open {in_file}")
119 exit(1)
120 tree = t_file.Get(treeName)
121 if not tree:
122 print("Failed to read tree {treeName} from {file}".format(treeName=treeName, file=t_file.GetName()))
123 exit(1)
124 allSDOS = {}
125 for entry in range(tree.GetEntries()):
126 tree.GetEntry(entry)
127 evt= tree.eventNumber
128
129 SDOs = []
130 for sdo in range(len(tree.SDO_RPC_stationIndex)):
131 SDOs.append(RpcSDO(stationIndex = ord(tree.SDO_RPC_stationIndex[sdo]),
132 stationEta = ord(tree.SDO_RPC_stationEta[sdo]),
133 stationPhi = ord(tree.SDO_RPC_stationPhi[sdo]),
134 doubletR = ord(tree.SDO_RPC_doubletR[sdo]),
135 doubletPhi = ord(tree.SDO_RPC_doubletPhi[sdo]),
136 gasGap = ord(tree.SDO_RPC_gasGap[sdo]),
137 measuresPhi=tree.SDO_RPC_measuresPhi[sdo],
138 strip = ord(tree.SDO_RPC_strip[sdo]),
139 globPosX = tree.SDO_RPC_globalPosX[sdo],
140 globPosY = tree.SDO_RPC_globalPosY[sdo],
141 globPosZ = tree.SDO_RPC_globalPosZ[sdo],
142
143 locPosX = tree.SDO_RPC_localPosX[sdo],
144 locPosY = tree.SDO_RPC_localPosY[sdo],
145 #time = tree.SDO_RPC_global_time[sdo],
146 barcode=tree.SDO_RPC_barcode[sdo]
147 ))
148
149 if len(SDOs):
150 allSDOS[evt] = SDOs
151
152 return allSDOS
153
154if __name__ == "__main__":
155
156 parser = ArgumentParser(prog="checkRpcDigits", description="Script comparing the Rpc digitization validation n-tuples")
157 parser.add_argument("--refFile", help="Reference file location", default = "/media/slowSSD/jojungge/ATLPHYSVAL-1018/SimulationTest/24.0.35/NSWPRDValAlg.digi.ntuple.root", type = str)
158 parser.add_argument("--testFile", help="Reference file location", default = "/media/slowSSD/jojungge/ATLPHYSVAL-1018/SimulationTest/25.0.5/NSWPRDValAlg.digi.ntuple.root", type = str)
159 parser.add_argument("--outFile", help="Location where the out file is stored", default="DigitComparison.txt")
160 args = parser.parse_args()
161
162 refDigits = readDigitTree(args.refFile)
163 testDigits = readDigitTree(args.testFile)
164
165 refSDOs = readSDOTree(args.refFile)
166 testSDOs = readSDOTree(args.testFile)
167
168 outFile = open(args.outFile, "w")
169
170
171 allGood = True
172 for event, refContent in refDigits.items():
173 if not event in testDigits:
174 print ("WARNING {event} is not part of the test file {testFile}".format(event = event, testFile=args.testFile))
175 continue
176 testContent = testDigits[event]
177
178 for refObj in refContent:
179 if refObj.identify().measuresPhi():
180 continue
181 if refObj not in testContent:
182 errorStr ="In Event {event}, {digit} cannot be found in the test sample. Potential candidates: \n".format(digit = str(refObj),
183 event = event)
184 for testObj in testContent:
185 if testObj.identify().gasGapID() == refObj.identify().gasGapID():
186 errorStr += " **** {digit} \n".format(digit = str(testObj))
187 print(errorStr)
188 outFile.write("{msg}\n".format(msg= errorStr))
189 allGood = False
190
191 exit(allGood == False)
192
void print(char *figname, TCanvas *c1)
Representation of a single RPC digit.
None __init__(self, stationIndex=-1, stationEta=-1, stationPhi=-1, doubletR=-1, doubletPhi=-1, doubletZ=-1, gasGap=-1, measuresPhi=False, strip=-1, globPosX=-1, globPosY=-1., globPosZ=-1, locPosX=-1, locPosY=-1, time=-1. ### Time of the digit signal)
bool __eq__(self, other)
None __init__(self, stationIndex=-1, stationEta=-1, stationPhi=-1, doubletR=-1, doubletPhi=-1, doubletZ=-1, gasGap=-1, measuresPhi=False, strip=-1, globPosX=-1, globPosY=-1, globPosZ=-1, locPosX=-1, locPosY=-1, time=-1, barcode=-1)
readSDOTree(in_file, treeName="HitValidTree")
readDigitTree(in_file, treeName="HitValidTree")