Skip to content

Commit

Permalink
Merge pull request cms-sw#87 from mariadalfonso/maria_7X_photons
Browse files Browse the repository at this point in the history
added photons in 7X
  • Loading branch information
gpetruc committed Jul 14, 2014
2 parents 4728074 + 5d787dc commit 2b238d9
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 10 deletions.
25 changes: 23 additions & 2 deletions CMGTools/RootTools/python/physicsobjects/Photon.py
Original file line number Diff line number Diff line change
@@ -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
41 changes: 38 additions & 3 deletions CMGTools/TTHAnalysis/python/analyzers/ntupleTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"),
Expand Down Expand Up @@ -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)"),
Expand All @@ -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)"),
Expand All @@ -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"),
Expand All @@ -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),
])
Expand Down
2 changes: 2 additions & 0 deletions CMGTools/TTHAnalysis/python/analyzers/susyCore_modules_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
'ttHPhotonAnalyzerSusy',
photons='slimmedPhotons',
ptMin = 20,
etaMax = 2.5,
gammaID = "PhotonCutBasedIDLoose",
)

# Tau Analyzer (generic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
})

Expand Down
60 changes: 56 additions & 4 deletions CMGTools/TTHAnalysis/python/analyzers/ttHPhotonAnalyzerSusy.py
Original file line number Diff line number Diff line change
@@ -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 ):

Expand All @@ -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() )
Expand All @@ -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 ]
Expand All @@ -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
Expand Down

0 comments on commit 2b238d9

Please sign in to comment.