Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:20:54

0001 #!/usr/bin/env python
0002 #
0003 # Example of how to analyse HLT objects using FWLite and pyROOT.
0004 # 
0005 
0006 # adapted from PhysicsTools/PatExamples/bin/PatBasicFWLiteAnalyzer.py
0007 
0008 from __future__ import print_function
0009 import ROOT
0010 import sys
0011 from DataFormats.FWLite import Events, Handle
0012 
0013 #----------------------------------------------------------------------
0014 # main
0015 #----------------------------------------------------------------------
0016 
0017 
0018 events = Events (["input.root"])
0019 handle = Handle ("trigger::TriggerFilterObjectWithRefs")
0020 
0021 # declare a variable 'electrons' to get them from the trigger objects
0022 ROOT.gROOT.ProcessLine("std::vector<reco::ElectronRef> electrons;")
0023 
0024 # copied from DataFormats/HLTReco/interface/TriggerTypeDefs.h
0025 TriggerElectron       = +82
0026 
0027 # note that for this collection there is only one (not two for L1Iso and L1NonIso)
0028 label = ("hltL1NonIsoHLTNonIsoSingleElectronEt22TighterEleIdOneOEMinusOneOPFilter")
0029 
0030 numElectronsSeen = 0
0031 numEventsWithElectron = 0
0032 
0033 # loop over events
0034 for event in events:
0035     # use getByLabel, just like in cmsRun
0036     event.getByLabel (label, handle)
0037     # get the product
0038     trigobjs = handle.product()
0039 
0040     trigobjs.getObjects(TriggerElectron, ROOT.electrons)
0041     print("number of electrons in this event:",len(ROOT.electrons))
0042 
0043     bestOneOverEminusOneOverP = None
0044 
0045     numElectronsSeen += len(ROOT.electrons)
0046 
0047     if len(ROOT.electrons) > 0:
0048         numEventsWithElectron += 1
0049     else:
0050         continue
0051 
0052     for eleindex, electron in enumerate(ROOT.electrons):
0053 
0054         print("electron",eleindex)
0055         # see HLTrigger/Egamma/src/HLTElectronOneOEMinusOneOPFilterRegional.cc
0056         # how 1/E-1/p is calculated 
0057         tracks = electron.track().product()
0058 
0059         superClusters = electron.superCluster().product()
0060 
0061         print("  number of tracks:",len(tracks))
0062         print("  number of superclusters:",len(superClusters))
0063 
0064         for track in tracks:
0065             momentum = track.p()
0066 
0067             for superCluster in superClusters:
0068                 energy = superCluster.energy()
0069 
0070                 thisOneOverEminusOneOverP = abs(1/energy - 1/momentum)
0071                 
0072                 print("    momentum=",momentum,"energy=",energy,"E/P=",energy/momentum,"1/E-1/p=",thisOneOverEminusOneOverP)
0073 
0074 
0075                 if bestOneOverEminusOneOverP == None or thisOneOverEminusOneOverP < bestOneOverEminusOneOverP:
0076                     bestOneOverEminusOneOverP = thisOneOverEminusOneOverP
0077 
0078             # loop over clusters
0079 
0080         # loop over tracks
0081 
0082     # loop over electron trigger objects
0083 
0084     print("best value:",bestOneOverEminusOneOverP)
0085 
0086     
0087 
0088 print("total number of electrons:",numElectronsSeen)
0089 print("events with at least one electron:",numEventsWithElectron)