ATLAS Offline Software
checkRpcDigits.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 from HitIdentifier import RpcIdentifier
4 from ROOT import TVector3, TVector2, TFile
5 from argparse import ArgumentParser
6 
7 
8 class RpcDigit(object):
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 
77 def readDigitTree(in_file, treeName = "NSWValTree"):
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 
114 def readSDOTree(in_file, treeName = "NSWValTree"):
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 
154 if __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 
checkRpcDigits.RpcDigit.identify
def identify(self)
Definition: checkRpcDigits.py:25
xAOD::identify
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx:61
vtune_athena.format
format
Definition: vtune_athena.py:14
dumpTgcDigiDeadChambers.stationName
dictionary stationName
Definition: dumpTgcDigiDeadChambers.py:30
checkRpcDigits.RpcDigit.__str__
str __str__(self)
Definition: checkRpcDigits.py:37
checkRpcDigits.readSDOTree
def readSDOTree(in_file, treeName="NSWValTree")
Definition: checkRpcDigits.py:114
Monitored::X
@ X
Definition: HistogramFillerUtils.h:24
checkRpcDigits.RpcDigit.globalPosition
def globalPosition(self)
Definition: checkRpcDigits.py:28
checkRpcDigits.RpcDigit.__globPos
__globPos
Definition: checkRpcDigits.py:14
checkRpcDigits.RpcDigit
Representation of a single RPC digit.
Definition: checkRpcDigits.py:8
checkRpcDigits.RpcSDO.__barcode
__barcode
Definition: checkRpcDigits.py:58
checkRpcDigits.RpcSDO.__init__
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)
Definition: checkRpcDigits.py:51
checkRpcDigits.RpcSDO.__str__
str __str__(self)
Definition: checkRpcDigits.py:67
checkRpcDigits.RpcDigit.__time
__time
Definition: checkRpcDigits.py:16
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
checkRpcDigits.RpcDigit.__id
__id
Definition: checkRpcDigits.py:10
calibdata.exit
exit
Definition: calibdata.py:236
checkRpcDigits.RpcDigit.localPosition
def localPosition(self)
Definition: checkRpcDigits.py:31
checkRpcDigits.RpcDigit.__init__
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)
Definition: checkRpcDigits.py:9
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
Monitored::Y
@ Y
Definition: HistogramFillerUtils.h:24
checkRpcDigits.RpcDigit.__eq__
bool __eq__(self, other)
Definition: checkRpcDigits.py:45
checkRpcDigits.RpcDigit.__locPos
__locPos
Definition: checkRpcDigits.py:15
Trk::open
@ open
Definition: BinningType.h:40
HitIdentifier.RpcIdentifier
Definition: HitIdentifier.py:51
pickleTool.object
object
Definition: pickleTool.py:30
str
Definition: BTagTrackIpAccessor.cxx:11
checkRpcDigits.RpcSDO.barcode
def barcode(self)
Definition: checkRpcDigits.py:64
checkRpcDigits.RpcDigit.time
def time(self)
Definition: checkRpcDigits.py:34
checkRpcDigits.RpcSDO
Definition: checkRpcDigits.py:50
checkRpcDigits.readDigitTree
def readDigitTree(in_file, treeName="NSWValTree")
Definition: checkRpcDigits.py:77