Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:54

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