diff --git a/CMGTools/RootTools/python/physicsobjects/Photon.py b/CMGTools/RootTools/python/physicsobjects/Photon.py index 2b4dee0a82f4d..92920db4e45a8 100644 --- a/CMGTools/RootTools/python/physicsobjects/Photon.py +++ b/CMGTools/RootTools/python/physicsobjects/Photon.py @@ -1,4 +1,25 @@ -from CMGTools.RootTools.physicsobjects.Lepton import Lepton +from CMGTools.RootTools.physicsobjects.PhysicsObject import * + +class Photon(PhysicsObject ): + + ''' return object from the photon + ''' + def hOVERe(self): + return self.physObj.full5x5_hadTowOverEm() + + def r9(self): + return self.physObj.full5x5_r9() + + def sigmaIetaIeta(self): + return self.physObj.full5x5_sigmaIetaIeta() + + def chargedHadronIso(self): + return self.physObj.chargedHadronIso() + + def neutralHadronIso(self): + return self.physObj.neutralHadronIso() + + def photonIso(self): + return self.physObj.photonIso() -class Photon(Lepton): pass diff --git a/CMGTools/TTHAnalysis/python/analyzers/ntupleTypes.py b/CMGTools/TTHAnalysis/python/analyzers/ntupleTypes.py index 3a7cd2c0fc2c0..95cce7e593562 100644 --- a/CMGTools/TTHAnalysis/python/analyzers/ntupleTypes.py +++ b/CMGTools/TTHAnalysis/python/analyzers/ntupleTypes.py @@ -20,6 +20,11 @@ particleType = NTupleObjectType("particle", baseObjectTypes = [ fourVectorType ], variables = [ NTupleVariable("pdgId", lambda x : x.pdgId(), int), ]) + +##------------------------------------------ +## LEPTON +##------------------------------------------ + leptonType = NTupleObjectType("lepton", baseObjectTypes = [ particleType ], variables = [ NTupleVariable("charge", lambda x : x.charge(), int), NTupleVariable("dxy", lambda x : x.dxy(), help="d_{xy} with respect to PV, in cm (with sign)"), @@ -100,6 +105,10 @@ ]) +##------------------------------------------ +## TAU +##------------------------------------------ + tauType = NTupleObjectType("tau", baseObjectTypes = [ particleType ], variables = [ NTupleVariable("charge", lambda x : x.charge(), int), NTupleVariable("dxy", lambda x : x.dxy(), help="d_{xy} of lead track with respect to PV, in cm (with sign)"), @@ -116,6 +125,10 @@ NTupleVariable("mcMatchId", lambda x : x.mcMatchId, int, mcOnly=True, help="Match to source from hard scatter (25 for H, 6 for t, 23/24 for W/Z)"), ]) +##------------------------------------------ +## ISOTRACK +##------------------------------------------ + isoTrackType = NTupleObjectType("isoTrack", baseObjectTypes = [ particleType ], variables = [ NTupleVariable("charge", lambda x : x.charge(), int), NTupleVariable("dz", lambda x : x.dz() , help="d_{z} of lead track with respect to PV, in cm (with sign)"), @@ -124,10 +137,25 @@ ]) -photonTypeSusy = NTupleObjectType("photon", baseObjectTypes = [ particleType ], variables = [ +##------------------------------------------ +## PHOTON +##------------------------------------------ + +photonTypeSusy = NTupleObjectType("gamma", baseObjectTypes = [ particleType ], variables = [ + NTupleVariable("idCutBased", lambda x : x.idCutBased, int, help="1,2,3 if the gamma passes the loose, medium, tight WP of PhotonCutBasedID"), + NTupleVariable("hOverE", lambda x : x.hOVERe(), float, help="hoverE for photons"), + NTupleVariable("r9", lambda x : x.r9(), float, help="r9 for photons"), + NTupleVariable("sigmaIetaIeta", lambda x : x.sigmaIetaIeta(), float, help="sigmaIetaIeta for photons"), + NTupleVariable("chHadIso", lambda x : x.chargedHadronIso(), float, help="chargedHadronIsolation for photons"), + NTupleVariable("neuHadIso", lambda x : x.neutralHadronIso(), float, help="neutralHadronIsolation for photons"), + NTupleVariable("phIso", lambda x : x.photonIso(), float, help="gammaIsolation for photons"), NTupleVariable("mcMatchId", lambda x : x.mcMatchId, int, mcOnly=True, help="Match to source from hard scatter (25 for H, 6 for t, 23/24 for W/Z)"), ]) +##------------------------------------------ +## JET +##------------------------------------------ + jetType = NTupleObjectType("jet", baseObjectTypes = [ fourVectorType ], variables = [ NTupleVariable("btagCSV", lambda x : x.btag('combinedSecondaryVertexBJetTags'), help="CSV discriminator"), NTupleVariable("rawPt", lambda x : x.pt() * x.rawFactor(), help="p_{T} before JEC"), @@ -149,15 +177,22 @@ NTupleVariable("Id", lambda x : x.jetID("POG_PFID_Loose") , int, mcOnly=False,help="POG Loose jet ID"), ]) - + +##------------------------------------------ +## MET +##------------------------------------------ + metType = NTupleObjectType("met", baseObjectTypes = [ fourVectorType ], variables = [ NTupleVariable("sumEt", lambda x : x.sumEt() ), NTupleVariable("genPt", lambda x : x.genMET().pt() , mcOnly=True ), NTupleVariable("genPhi", lambda x : x.genMET().phi(), mcOnly=True ), NTupleVariable("genEta", lambda x : x.genMET().eta(), mcOnly=True ), - ]) +##------------------------------------------ +## GENPARTICLE +##------------------------------------------ + genParticleType = NTupleObjectType("genParticle", baseObjectTypes = [ particleType ], mcOnly=True, variables = [ NTupleVariable("charge", lambda x : x.threeCharge()/3.0, float), ]) diff --git a/CMGTools/TTHAnalysis/python/analyzers/susyCore_modules_cff.py b/CMGTools/TTHAnalysis/python/analyzers/susyCore_modules_cff.py index 473afc7409b00..7c94a55f43390 100644 --- a/CMGTools/TTHAnalysis/python/analyzers/susyCore_modules_cff.py +++ b/CMGTools/TTHAnalysis/python/analyzers/susyCore_modules_cff.py @@ -132,6 +132,8 @@ 'ttHPhotonAnalyzerSusy', photons='slimmedPhotons', ptMin = 20, + etaMax = 2.5, + gammaID = "PhotonCutBasedIDLoose", ) # Tau Analyzer (generic) diff --git a/CMGTools/TTHAnalysis/python/analyzers/treeProducerSusyFullHad.py b/CMGTools/TTHAnalysis/python/analyzers/treeProducerSusyFullHad.py index 03d7e6df251fd..b768f9ca3361e 100644 --- a/CMGTools/TTHAnalysis/python/analyzers/treeProducerSusyFullHad.py +++ b/CMGTools/TTHAnalysis/python/analyzers/treeProducerSusyFullHad.py @@ -54,7 +54,7 @@ def __init__(self, cfg_ana, cfg_comp, looperName): "inclusiveLeptons" : NTupleCollection("lep", leptonTypeSusy, 8, help="Leptons after the preselection", filter=lambda l : l.pt()>10 ), #"inclusiveLeptonsCuts" : NTupleCollection("lep", leptonTypeSusy, 8, help="Leptons after the preselection", filter=lambda l : l.pt()>10 ), "cleanJetsAll" : NTupleCollection("jet", jetTypeSusy, 8, help="all jets after full selection and cleaning, sorted by pt"), - "allphotons" : NTupleCollection("gamma", photonTypeSusy, 5, help="all photons"), + "selectedPhotons" : NTupleCollection("gamma", photonTypeSusy, 5, help="photons with pt>20 and loose cut based ID"), "selectedIsoTrack" : NTupleCollection("isoTrack", isoTrackType, 3, help="isoTrack, sorted by pt"), }) diff --git a/CMGTools/TTHAnalysis/python/analyzers/ttHPhotonAnalyzerSusy.py b/CMGTools/TTHAnalysis/python/analyzers/ttHPhotonAnalyzerSusy.py index 0e8bc1015854c..d22d3d4a18537 100644 --- a/CMGTools/TTHAnalysis/python/analyzers/ttHPhotonAnalyzerSusy.py +++ b/CMGTools/TTHAnalysis/python/analyzers/ttHPhotonAnalyzerSusy.py @@ -1,9 +1,18 @@ +import operator +import itertools +import copy +import types + +from ROOT import TLorentzVector + from CMGTools.RootTools.fwlite.Analyzer import Analyzer +from CMGTools.RootTools.fwlite.Event import Event +from CMGTools.RootTools.statistics.Counter import Counter, Counters from CMGTools.RootTools.fwlite.AutoHandle import AutoHandle from CMGTools.RootTools.physicsobjects.Photon import Photon from CMGTools.TTHAnalysis.analyzers.ttHLepMCMatchAnalyzer import matchObjectCollection3 -from CMGTools.RootTools.utils.DeltaR import bestMatch +from CMGTools.RootTools.utils.DeltaR import deltaR, deltaPhi, bestMatch class ttHPhotonAnalyzerSusy( Analyzer ): @@ -26,6 +35,10 @@ def beginLoop(self): self.counters.addCounter('events') count = self.counters.counter('events') count.register('all events') + count.register('has >=1 gamma at preselection') + count.register('has >=1 selected gamma') + +## tauID = "PhotonCutBasedID", def makePhotons(self, event): event.allphotons = map( Photon, self.handles['photons'].product() ) @@ -37,11 +50,33 @@ def makePhotons(self, event): foundPhoton = False for gamma in event.allphotons: if gamma.pt() < self.cfg_ana.ptMin: continue + if gamma.eta() > self.cfg_ana.etaMax: continue foundPhoton = True - event.selectedPhotons.append(gamma) + + def idWP(gamma,X): + """Create an integer equal to 1-2-3 for (loose,medium,tight)""" + +## medium not stored +## return gamma.photonID(X%"Loose") + gamma.photonID(X%"Medium") + gamma.photonID(X%"Tight") + + id=-1 + if gamma.photonID(X%"Loose"): + id=0 + if gamma.photonID(X%"Tight"): + id=2 + return id + + gamma.idCutBased = idWP(gamma, "PhotonCutBasedID%s") + + if gamma.photonID(self.cfg_ana.gammaID): + event.selectedPhotons.append(gamma) +## event.selectedPhotons.append(gamma) event.selectedPhotons.sort(key = lambda l : l.pt(), reverse = True) + self.counters.counter('events').inc('all events') + if foundPhoton: self.counters.counter('events').inc('has >=1 gamma at preselection') + if len(event.selectedPhotons): self.counters.counter('events').inc('has >=1 selected gamma') def matchPhotons(self, event): event.genPhotons = [ x for x in event.genParticles if x.status() == 3 and abs(x.pdgId()) == 22 ] @@ -50,13 +85,30 @@ def matchPhotons(self, event): gen = match[gamma] gamma.mcMatchId = 1 if gen else 0 + def printInfo(self, event): + print '----------------' + if len(event.selectedPhotons)>0: + print 'lenght: ',len(event.selectedPhotons) + print 'gamma candidate pt: ',event.selectedPhotons[0].pt() + print 'gamma candidate eta: ',event.selectedPhotons[0].eta() + print 'gamma candidate phi: ',event.selectedPhotons[0].phi() + print 'gamma candidate mass: ',event.selectedPhotons[0].mass() + print 'gamma candidate HoE: ',event.selectedPhotons[0].hOVERe() + print 'gamma candidate r9: ',event.selectedPhotons[0].r9() + print 'gamma candidate sigmaIetaIeta: ',event.selectedPhotons[0].sigmaIetaIeta() + print 'gamma candidate had iso: ',event.selectedPhotons[0].chargedHadronIso() + print 'gamma candidate neu iso: ',event.selectedPhotons[0].neutralHadronIso() + print 'gamma candidate gamma iso: ',event.selectedPhotons[0].photonIso() + print 'gamma idCutBased',event.selectedPhotons[0].idCutBased + + def process(self, iEvent, event): self.readCollections( iEvent ) - self.counters.counter('events').inc('all events') - #call the photons functions self.makePhotons(event) +# self.printInfo(event) + ## ===> do matching if not self.cfg_comp.isMC: return True