Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-27 03:17:45

0001 import ROOT
0002 import sys
0003 
0004 from DataFormats.FWLite import Events, Handle
0005 
0006 ROOT.gROOT.SetBatch()
0007 
0008 def compare_bx_vector(xs, ys):
0009     x_total_size = xs.getLastBX() - xs.getFirstBX() + 1
0010     y_total_size = ys.getLastBX() - ys.getLastBX() + 1
0011 
0012     if x_total_size != y_total_size:
0013         print("> BX count mismatch:", x_total_size, "vs", y_total_size)
0014         print(">", xs.getFirstBX(), ",", ys.getFirstBX())
0015         print(">", xs.getLastBX(), ",", ys.getLastBX())
0016         return
0017 
0018     for bx in range(xs.getFirstBX(), xs.getLastBX() + 1):
0019         x_size = xs.size(bx)
0020         y_size = ys.size(bx)
0021 
0022         if x_size != y_size:
0023             print(">> BX size mismatch:", x_size, "vs", y_size, "@", bx)
0024 
0025         for i in range(min(x_size, y_size)):
0026             x = xs.at(bx, i)
0027             y = ys.at(bx, i)
0028 
0029             if x.hwPt() != y.hwPt():
0030                 print(">>> Pt mismatch:", x.hwPt(), "vs", y.hwPt())
0031             if x.hwEta() != y.hwEta():
0032                 print(">>> Eta mismatch:", x.hwEta(), "vs", y.hwEta())
0033             if x.hwPhi() != y.hwPhi():
0034                 print(">>> Phi mismatch:", x.hwPhi(), "vs", y.hwPhi())
0035             #if ((x.hwQual()>>0)&0x1) != ((y.hwQual()>>0)&0x1):
0036             #    print ">>> Qual bit 0 mismatch:", ((x.hwQual()>>0)&0x1), "vs", ((y.hwQual()>>0)&0x1)
0037             if ((x.hwQual()>>1)&0x1) != ((y.hwQual()>>1)&0x1):
0038                 print(">>> Qual bit 1 mismatch:", ((x.hwQual()>>1)&0x1), "vs", ((y.hwQual()>>1)&0x1))
0039             if x.hwIso() != y.hwIso():
0040                 print(">>> Iso mismatch:", x.hwIso(), "vs", y.hwIso())
0041 
0042             yield x, y
0043 
0044         # for j in range(min(x_size, 0), min(x_size, y_size)):
0045         #     x = xs.at(bx, j)
0046         #     y = ys.at(bx, j)
0047         #     print ">>>> ({0} @ {1}, {2} : {3}, {4} - {5}) vs ({6} @ {7}, {8} : {9}, {10} - {11})".format(
0048         #             x.hwPt(), x.hwEta(), x.hwPhi(), ((x.hwQual()>>0)&0x1), ((x.hwQual()>>1)&0x1), x.hwIso(),
0049         #             y.hwPt(), y.hwEta(), y.hwPhi(), ((y.hwQual()>>0)&0x1), ((y.hwQual()>>1)&0x1), y.hwIso())
0050 
0051         print("<< Compared", x_size, "quantities")
0052 
0053 class Test(object):
0054     def __init__(self, msg, type, inlabel, outlabel, tests):
0055         self.msg = msg
0056         self.inhandle = Handle(type)
0057         self.outhandle = Handle(type)
0058         self.inlabel = inlabel
0059         self.outlabel = outlabel,
0060         self.tests = tests or []
0061 
0062     def __call__(self, event):
0063         event.getByLabel(*(list(self.inlabel) + [self.inhandle]))
0064         event.getByLabel(*(list(self.outlabel) + [self.outhandle]))
0065 
0066         print(self.msg)
0067         for a, b in compare_bx_vector(self.inhandle.product(), self.outhandle.product()):
0068             for t in self.tests:
0069                 t(a, b)
0070 
0071 def test_type(a, b):
0072     if a.getType() != b.getType():
0073         print(">>> Type different:", a.getType(), "vs", b.getType())
0074 
0075 events = Events(sys.argv[1])
0076 
0077 run = [
0078         Test(
0079             'Checking spare rings',
0080             'BXVector<l1t::CaloSpare>',
0081             ('simCaloStage1FinalDigis', 'HFRingSums'),
0082             ('l1tRawToDigi', 'HFRingSums'),
0083             [test_type]
0084         ),
0085         Test(
0086             'Checking spare bits',
0087             'BXVector<l1t::CaloSpare>',
0088             ('simCaloStage1FinalDigis', 'HFBitCounts'),
0089             ('l1tRawToDigi', 'HFBitCounts'),
0090             [test_type]
0091         ),
0092         Test(
0093             'Checking EG',
0094             'BXVector<l1t::EGamma>',
0095             ('simCaloStage1FinalDigis',),
0096             ('l1tRawToDigi',),
0097             []
0098         ),
0099         Test(
0100             'Checking EtSum',
0101             'BXVector<l1t::EtSum>',
0102             ('simCaloStage1FinalDigis',),
0103             ('l1tRawToDigi',),
0104             []
0105         ),
0106         Test(
0107             'Checking Jets',
0108             'BXVector<l1t::Jet>',
0109             ('simCaloStage1FinalDigis',),
0110             ('l1tRawToDigi',),
0111             []
0112         ),
0113         Test(
0114             'Checking Taus',
0115             'BXVector<l1t::Tau>',
0116             ('simCaloStage1FinalDigis', 'rlxTaus'),
0117             ('l1tRawToDigi', 'rlxTaus'),
0118             []
0119         ),
0120         Test(
0121             'Checking Iso Taus',
0122             'BXVector<l1t::Tau>',
0123             ('simCaloStage1FinalDigis', 'isoTaus'),
0124             ('l1tRawToDigi', 'isoTaus'),
0125             []
0126         )
0127 ]
0128 
0129 for event in events:
0130     print("< New event")
0131     for test in run:
0132         test(event)