Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:18

0001 #! /usr/bin/env python
0002 
0003 # import ROOT in batch mode
0004 from __future__ import print_function
0005 import sys
0006 oldargv = sys.argv[:]
0007 sys.argv = [ '-b-' ]
0008 import ROOT
0009 ROOT.gROOT.SetBatch(True)
0010 sys.argv = oldargv
0011 
0012 # load FWLite C++ libraries
0013 ROOT.gSystem.Load("libFWCoreFWLite.so");
0014 ROOT.gSystem.Load("libDataFormatsFWLite.so");
0015 ROOT.FWLiteEnabler.enable()
0016 
0017 #cms python data types
0018 import FWCore.ParameterSet.Config as cms
0019 
0020 # load FWlite python libraries
0021 from DataFormats.FWLite import Handle, Events
0022 from RecoEgamma.ElectronIdentification.VIDElectronSelector import VIDElectronSelector
0023 
0024 
0025 from RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_PHYS14_PU20bx25_V2_cff import cutBasedElectronID_PHYS14_PU20bx25_V2_standalone_tight
0026 
0027 selectElectron = VIDElectronSelector(cutBasedElectronID_PHYS14_PU20bx25_V2_standalone_tight)
0028 print('Initialized VID Selector for Electrons')
0029 print(selectElectron)
0030 
0031 from PhysicsTools.SelectorUtils.trivialCutFlow_cff import trivialCutFlow
0032 testExprEval = VIDElectronSelector(trivialCutFlow)
0033 print('test expression evaluator')
0034 print(testExprEval)
0035 
0036 #photon MVA (only works on reMiniAOD)
0037 print('Initialized VID Photon MVA Selector')
0038 from RecoEgamma.PhotonIdentification.VIDPhotonSelector import VIDPhotonSelector
0039 from RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring15_50ns_nonTrig_V0_cff import mvaPhoID_Spring15_50ns_nonTrig_V0_wp90
0040 selectPhoton = VIDPhotonSelector(mvaPhoID_Spring15_50ns_nonTrig_V0_wp90)
0041 print(selectPhoton)
0042 
0043 # try muons!
0044 from RecoMuon.MuonIdentification.VIDMuonSelector import VIDMuonSelector
0045 from RecoMuon.MuonIdentification.Identification.globalMuonPromptTight_V0_cff import globalMuonPromptTight_V0
0046 from RecoMuon.MuonIdentification.Identification.cutBasedMuonId_MuonPOG_V0_cff import *
0047 
0048 selectMuons = [VIDMuonSelector(globalMuonPromptTight_V0)]
0049 for selectMuon in [cutBasedMuonId_MuonPOG_V0_loose, cutBasedMuonId_MuonPOG_V0_medium, cutBasedMuonId_MuonPOG_V0_tight,
0050                    cutBasedMuonId_MuonPOG_V0_soft, cutBasedMuonId_MuonPOG_V0_highpt]:
0051     for cf in selectMuon.cutFlow:
0052         cf.vertexSrc = "offlineSlimmedPrimaryVertices"
0053     selectMuons.append(VIDMuonSelector(selectMuon))
0054     print('Initialized VID Selector for Muons')
0055     print(selectMuon)
0056 
0057 # open file (you can use 'edmFileUtil -d /store/whatever.root' to get the physical file name)
0058 events = Events("root://eoscms//eos/cms/store/relval/CMSSW_7_4_0_pre9_ROOT6/DoubleMu/MINIAOD/GR_R_74_V8A_RelVal_zMu2011A-v1/00000/06961B48-CFD1-E411-8B87-002618943971.root")
0059 
0060 muons, muonLabel = Handle("std::vector<pat::Muon>"), "slimmedMuons::".split(":")
0061 electrons, electronLabel = Handle("std::vector<pat::Electron>"), "slimmedElectrons::".split(":")
0062 photons, photonLabel = Handle("std::vector<pat::Photon>"), "slimmedPhotons::".split(":")
0063 
0064 for iev,event in enumerate(events):
0065     
0066     if iev > 10: break
0067     event.getByLabel(muonLabel[0],muonLabel[1],muonLabel[2], muons)
0068     event.getByLabel(electronLabel[0],electronLabel[1],electronLabel[2], electrons)
0069     event.getByLabel(photonLabel[0],photonLabel[1],photonLabel[2],photons)
0070     
0071     print("\nEvent %d: run %6d, lumi %4d, event %12d" % (iev,event.eventAuxiliary().run(), 
0072                                                          event.eventAuxiliary().luminosityBlock(),
0073                                                          event.eventAuxiliary().event()))
0074 
0075     # Muons
0076     for i,mu in enumerate(muons.product()): 
0077         if mu.pt() < 5 or not mu.isLooseMuon(): continue
0078         print("muon %2d: pt %4.1f, POG loose id %d." % (
0079             i, mu.pt(), mu.isLooseMuon()))
0080         for selectMuon in selectMuons:
0081             selectMuon(muons.product(),i,event)
0082             print(selectMuon)
0083 
0084     # Electrons
0085     for i,el in enumerate(electrons.product()):
0086         if el.pt() < 5: continue
0087         print("elec %2d: pt %4.1f, supercluster eta %+5.3f, sigmaIetaIeta %.3f (%.3f with full5x5 shower shapes), pass conv veto %d" % (
0088                     i, el.pt(), el.superCluster().eta(), el.sigmaIetaIeta(), el.full5x5_sigmaIetaIeta(), el.passConversionVeto()))
0089         passfail_byvalue = selectElectron(el,event)
0090         passfail = selectElectron(electrons.product(),i,event)       
0091         print(selectElectron)
0092         testExprEval(electrons.product(),i,event)
0093         print(testExprEval)
0094 
0095         cf_result = selectElectron.cutFlowResult()
0096         for i in range(cf_result.cutFlowSize()):
0097             print('%d : %s : %d'%(i,cf_result.getNameAtIndex(i),cf_result.getCutResultByName(cf_result.getNameAtIndex(i))))
0098         print(passfail, passfail_byvalue)
0099         print(cf_result.cutFlowPassed())
0100         print("{0:b}".format(selectElectron.bitMap()))
0101         masked_cf_ints = cf_result.getCutFlowResultMasking([2,3,4,9])
0102         masked_cf_strs = cf_result.getCutFlowResultMasking(['GsfEleDEtaInCut_0',
0103                                                             'GsfEleDPhiInCut_0',
0104                                                             'GsfEleFull5x5SigmaIEtaIEtaCut_0',
0105                                                             'GsfEleEffAreaPFIsoCut_0'])
0106         print(masked_cf_ints.cutFlowPassed(), masked_cf_strs.cutFlowPassed())
0107 
0108     for i,ph in enumerate(photons.product()):
0109         print("pho %2d: pt %4.1f, supercluster eta %+5.3f, sigmaIetaIeta %.3f (%.3f with full5x5 shower shapes)" % (
0110             i, ph.pt(), ph.superCluster().eta(), ph.sigmaIetaIeta(), ph.full5x5_sigmaIetaIeta()))
0111         passfail_byvalue = selectPhoton(ph,event)
0112         for uf in ph.userFloatNames():
0113             print(uf)
0114         for ui in ph.userIntNames():
0115             print(ui)
0116         print(passfail_byvalue)
0117         print(selectPhoton)
0118 
0119 #test the validator framework
0120 
0121 print('test validation framework') 
0122 
0123 selectElectronValid = VIDElectronSelector(cutBasedElectronID_PHYS14_PU20bx25_V2_standalone_tight)
0124 selectMuonValid = VIDMuonSelector(globalMuonPromptTight_V0)
0125 
0126 from  PhysicsTools.SelectorUtils.VIDSelectorValidator import VIDSelectorValidator
0127 electron_validator = VIDSelectorValidator(selectElectronValid,'std::vector<pat::Electron>','slimmedElectrons')
0128 muon_validator = VIDSelectorValidator(selectMuonValid,'std::vector<pat::Muon>','slimmedMuons')
0129 
0130 signal_files     = []
0131 background_files = []
0132 mix_files        = ['root://eoscms//eos/cms/store/relval/CMSSW_7_4_0_pre9_ROOT6/DoubleMu/MINIAOD/GR_R_74_V8A_RelVal_zMu2011A-v1/00000/06961B48-CFD1-E411-8B87-002618943971.root']
0133 
0134 electron_validator.setMixFiles(mix_files)
0135 muon_validator.setMixFiles(mix_files)
0136 
0137 electron_validator.runValidation()
0138 muon_validator.runValidation()
0139