Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-26 02:34:21

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