Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-03 04:18:05

0001 import argparse
0002 import ROOT
0003 from DataFormats.FWLite import Events, Handle
0004 from L1Trigger.Phase2L1GT.l1tGTScales import scale_parameter
0005 
0006 
0007 def object_name(object_type):
0008     if not hasattr(ROOT, "getObjectName"):
0009         ROOT.gInterpreter.Declare("""
0010 #include "DataFormats/L1Trigger/interface/P2GTCandidate.h"
0011 const char* getObjectName(l1t::P2GTCandidate::ObjectType objectType){
0012     switch(objectType) {
0013         case l1t::P2GTCandidate::GCTNonIsoEg: return "GCTNonIsoEg";
0014         case l1t::P2GTCandidate::GCTIsoEg: return "GCTIsoEg";
0015         case l1t::P2GTCandidate::GCTJets: return "GCTJet";
0016         case l1t::P2GTCandidate::GCTTaus: return "GCTTau";
0017         case l1t::P2GTCandidate::GCTHtSum: return "GCTHtSum";
0018         case l1t::P2GTCandidate::GCTEtSum: return "GCTEtSum";
0019         case l1t::P2GTCandidate::GMTSaPromptMuons: return "GMTSaPromptMuon";
0020         case l1t::P2GTCandidate::GMTSaDisplacedMuons: return "GMTSaDisplacedMuon";
0021         case l1t::P2GTCandidate::GMTTkMuons: return "GMTTkMuon";
0022         case l1t::P2GTCandidate::GMTTopo: return "GMTTopo";
0023         case l1t::P2GTCandidate::GTTPromptJets: return "GTTPromptJet";
0024         case l1t::P2GTCandidate::GTTDisplacedJets: return "GTTDisplacedJet";
0025         case l1t::P2GTCandidate::GTTPhiCandidates: return "GTTPhiCandidate";
0026         case l1t::P2GTCandidate::GTTRhoCandidates: return "GTTRhoCandidate";
0027         case l1t::P2GTCandidate::GTTBsCandidates: return "GTTBsCandidate";
0028         case l1t::P2GTCandidate::GTTHadronicTaus: return "GTTHadronicTau";
0029         case l1t::P2GTCandidate::GTTPrimaryVert: return "GTTPrimaryVert";
0030         case l1t::P2GTCandidate::GTTPromptHtSum: return "GTTPromptHtSum";
0031         case l1t::P2GTCandidate::GTTDisplacedHtSum: return "GTTDisplacedHtSum";
0032         case l1t::P2GTCandidate::GTTEtSum: return "GTTEtSum";
0033         case l1t::P2GTCandidate::CL2JetsSC4: return "CL2JetSc4";
0034         case l1t::P2GTCandidate::CL2JetsSC8: return "CL2JetSc8";
0035         case l1t::P2GTCandidate::CL2Taus: return "CL2Tau";
0036         case l1t::P2GTCandidate::CL2Electrons: return "CL2Electron";
0037         case l1t::P2GTCandidate::CL2Photons: return "CL2Photon";
0038         case l1t::P2GTCandidate::CL2HtSum: return "CL2HtSum";
0039         case l1t::P2GTCandidate::CL2EtSum: return "CL2EtSum"; 
0040         default: return "Undefined";
0041     }
0042 }
0043 """)
0044     return ROOT.getObjectName(object_type)
0045 
0046 
0047 if __name__ == "__main__":
0048 
0049     parser = argparse.ArgumentParser(description='L1GT analyzer')
0050     parser.add_argument('in_filename', nargs="+", help='input filename')
0051     parser.add_argument('--prefix', '-p', default='file:', help='file prefix')
0052     parser.add_argument('--process', '-P', default='', help='Process to analyze')
0053 
0054     args = parser.parse_args()
0055 
0056     in_filenames_with_prefix = ['{}{}'.format(args.prefix, x) for x in args.in_filename]
0057     events = Events(in_filenames_with_prefix)
0058 
0059     print("number of events", events.size())
0060     print('*' * 80)
0061 
0062     for idx, event in enumerate(events):
0063         print('Event:', idx)
0064 
0065         algo_blocks = Handle('l1t::P2GTAlgoBlockMap')
0066         event.getByLabel('l1tGTAlgoBlockProducer', '', args.process, algo_blocks)
0067 
0068         for name, algo_blk in algo_blocks.product():
0069             print(name, algo_blk.decisionBeforeBxMaskAndPrescale())
0070 
0071             for obj in algo_blk.trigObjects():
0072                 if object_name(obj.objectType()) in ["CL2Electron", "CL2Photon"]:
0073                     print(" {}: pt {:3.1f} eta {:3.2f} phi {:3.2f} iso: {:3.2f} relIso: {:3.2f}".format(
0074                         object_name(obj.objectType()), obj.pt(), obj.eta(), obj.phi(),
0075                         obj.hwIso() * scale_parameter.isolationPT_lsb.value(),
0076                         obj.hwIso() * scale_parameter.isolationPT_lsb.value()/(obj.hwPT() * scale_parameter.pT_lsb.value())))
0077                 elif "Sum" not in object_name(obj.objectType()):
0078                     print(" {}: pt {:3.1f} eta {:3.2f} phi {:3.2f}".format(
0079                         object_name(obj.objectType()), obj.pt(), obj.eta(), obj.phi()))
0080                 else:
0081                     print(" {}: pt {:3.1f} phi {:3.2f}".format(
0082                         object_name(obj.objectType()), obj.pt(), obj.phi()))
0083 
0084         print('*' * 80)