Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync 74X heppy with vhbb developments #36

Merged
merged 3 commits into from
May 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def __init__(self, cfg_ana, cfg_comp, looperName):
self.lepSelCut = getattr(self.cfg_ana, 'lepSelCut', lambda lep : True)
self.jetGammaDR = getattr(self.cfg_ana, 'jetGammaDR', 0.4)
if(self.cfg_ana.doQG):
self.qglcalc = QGLikelihoodCalculator("%s/src/PhysicsTools/Heppy/data/pdfQG_AK4chs_antib_13TeV_v1.root" % os.environ['CMSSW_BASE'])
qgdefname="{CMSSW_BASE}/src/PhysicsTools/Heppy/data/pdfQG_AK4chs_antib_13TeV_v1.root"
self.qglcalc = QGLikelihoodCalculator(getattr(self.cfg_ana,"QGpath",qgdefname).format(CMSSW_BASE= os.environ['CMSSW_BASE']))
if not hasattr(self.cfg_ana ,"collectionPostFix"):self.cfg_ana.collectionPostFix=""

def declareHandles(self):
Expand Down
122 changes: 75 additions & 47 deletions PhysicsTools/Heppy/python/analyzers/objects/TauAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,54 +20,53 @@ def declareHandles(self):
super(TauAnalyzer, self).declareHandles()
self.handles['taus'] = AutoHandle( ('slimmedTaus',''),'std::vector<pat::Tau>')


def beginLoop(self, setup):
super(TauAnalyzer,self).beginLoop(setup)
self.counters.addCounter('events')
count = self.counters.counter('events')
count.register('all events')
count.register('has >=1 tau at preselection')
count.register('has >=1 selected taus')
count.register('has >=1 loose taus')
count.register('has >=1 inclusive taus')
count.register('has >=1 other taus')

#------------------
# MAKE LEPTON LISTS
#------------------
def makeTaus(self, event):
event.selectedTaus = []
event.looseTaus = []
event.inclusiveTaus = []
event.selectedTaus = []
event.otherTaus = []

#get all
alltaus = map( Tau, self.handles['taus'].product() )

foundTau = False
#make inclusive taus
for tau in alltaus:
tau.associatedVertex = event.goodVertices[0] if len(event.goodVertices)>0 else event.vertices[0]
tau.lepVeto = False
tau.idDecayMode = tau.tauID("decayModeFinding")
tau.idDecayModeNewDMs = tau.tauID("decayModeFindingNewDMs")
if hasattr(self.cfg_ana, 'decayModeID') and self.cfg_ana.decayModeID and not tau.tauID(self.cfg_ana.decayModeID):

if hasattr(self.cfg_ana, 'inclusive_decayModeID') and self.cfg_ana.inclusive_decayModeID and not tau.tauID(self.cfg_ana.inclusive_decayModeID):
continue

if self.cfg_ana.vetoLeptons:
tau.inclusive_lepVeto = False
if self.cfg_ana.inclusive_vetoLeptons:
for lep in event.selectedLeptons:
if deltaR(lep.eta(), lep.phi(), tau.eta(), tau.phi()) < self.cfg_ana.leptonVetoDR:
tau.lepVeto = True
if tau.lepVeto: continue
if self.cfg_ana.vetoLeptonsPOG:
if not tau.tauID(self.cfg_ana.tauAntiMuonID):
tau.lepVeto = True
if not tau.tauID(self.cfg_ana.tauAntiElectronID):
tau.lepVeto = True
if tau.lepVeto: continue

if tau.pt() < self.cfg_ana.ptMin: continue
if abs(tau.eta()) > self.cfg_ana.etaMax: continue
if abs(tau.dxy()) > self.cfg_ana.dxyMax or abs(tau.dz()) > self.cfg_ana.dzMax: continue

foundTau = True
if deltaR(lep.eta(), lep.phi(), tau.eta(), tau.phi()) < self.cfg_ana.inclusive_leptonVetoDR:
tau.inclusive_lepVeto = True
if tau.inclusive_lepVeto: continue
if self.cfg_ana.inclusive_vetoLeptonsPOG:
if not tau.tauID(self.cfg_ana.inclusive_tauAntiMuonID):
tau.inclusive_lepVeto = True
if not tau.tauID(self.cfg_ana.inclusive_tauAntiElectronID):
tau.inclusive_lepVeto = True
if tau.inclusive_lepVeto: continue

if tau.pt() < self.cfg_ana.inclusive_ptMin: continue
if abs(tau.eta()) > self.cfg_ana.inclusive_etaMax: continue
if abs(tau.dxy()) > self.cfg_ana.inclusive_dxyMax or abs(tau.dz()) > self.cfg_ana.inclusive_dzMax: continue

def id3(tau,X):
"""Create an integer equal to 1-2-3 for (loose,medium,tight)"""
return tau.tauID(X%"Loose") + tau.tauID(X%"Medium") + tau.tauID(X%"Tight")
Expand All @@ -86,28 +85,44 @@ def id6(tau,X):
tau.idAntiMu = tau.tauID("againstMuonLoose") + tau.tauID("againstMuonTight")
tau.idAntiE = id5(tau, "againstElectron%sMVA5")
#print "Tau pt %5.1f: idMVA2 %d, idCI3hit %d, %s, %s" % (tau.pt(), tau.idMVA2, tau.idCI3hit, tau.tauID(self.cfg_ana.tauID), tau.tauID(self.cfg_ana.tauLooseID))
if tau.tauID(self.cfg_ana.tauID):
event.selectedTaus.append(tau)
event.inclusiveTaus.append(tau)
elif tau.tauID(self.cfg_ana.tauLooseID):
event.looseTaus.append(tau)

if tau.tauID(self.cfg_ana.inclusive_tauID):
event.inclusiveTaus.append(tau)

for tau in event.inclusiveTaus:

tau.loose_lepVeto = False
if self.cfg_ana.loose_vetoLeptons:
for lep in event.selectedLeptons:
if deltaR(lep.eta(), lep.phi(), tau.eta(), tau.phi()) < self.cfg_ana.loose_leptonVetoDR:
tau.loose_lepVeto = True
if self.cfg_ana.loose_vetoLeptonsPOG:
if not tau.tauID(self.cfg_ana.loose_tauAntiMuonID):
tau.loose_lepVeto = True
if not tau.tauID(self.cfg_ana.loose_tauAntiElectronID):
tau.loose_lepVeto = True

if tau.tauID(self.cfg_ana.loose_decayModeID) and \
tau.pt() > self.cfg_ana.loose_ptMin and abs(tau.eta()) < self.cfg_ana.loose_etaMax and \
abs(tau.dxy()) < self.cfg_ana.loose_dxyMax and abs(tau.dz()) < self.cfg_ana.loose_dzMax and \
tau.tauID(self.cfg_ana.loose_tauID) and not tau.loose_lepVeto:
event.selectedTaus.append(tau)
else:
event.otherTaus.append(tau)

event.inclusiveTaus.sort(key = lambda l : l.pt(), reverse = True)
event.selectedTaus.sort(key = lambda l : l.pt(), reverse = True)
event.looseTaus.sort(key = lambda l : l.pt(), reverse = True)
event.otherTaus.sort(key = lambda l : l.pt(), reverse = True)
self.counters.counter('events').inc('all events')
if foundTau: self.counters.counter('events').inc('has >=1 tau at preselection')
if len(event.inclusiveTaus): self.counters.counter('events').inc('has >=1 tau at preselection')
if len(event.selectedTaus): self.counters.counter('events').inc('has >=1 selected taus')
if len(event.looseTaus): self.counters.counter('events').inc('has >=1 loose taus')
if len(event.inclusiveTaus): self.counters.counter('events').inc('has >=1 inclusive taus')

if len(event.otherTaus): self.counters.counter('events').inc('has >=1 other taus')

def matchTaus(self, event):
match = matchObjectCollection3(event.inclusiveTaus, event.gentaus, deltaRMax = 0.5)
for lep in event.inclusiveTaus:
gen = match[lep]
lep.mcMatchId = 1 if gen else 0
lep.mcTau = gen

def process(self, event):
self.readCollections( event.input )
Expand All @@ -126,18 +141,31 @@ def process(self, event):
# http://cmslxr.fnal.gov/lxr/source/PhysicsTools/PatAlgos/python/producersLayer1/tauProducer_cfi.py

setattr(TauAnalyzer,"defaultConfig",cfg.Analyzer(
class_object=TauAnalyzer,
ptMin = 20,
etaMax = 9999,
dxyMax = 1000.,
dzMax = 0.2,
vetoLeptons = True,
leptonVetoDR = 0.4,
decayModeID = "decayModeFindingNewDMs", # ignored if not set or ""
tauID = "byLooseCombinedIsolationDeltaBetaCorr3Hits",
vetoLeptonsPOG = False, # If True, the following two IDs are required
tauAntiMuonID = "againstMuonLoose3",
tauAntiElectronID = "againstElectronLooseMVA5",
tauLooseID = "decayModeFinding",
class_object = TauAnalyzer,
# inclusive very loose hadronic tau selection
inclusive_ptMin = 18,
inclusive_etaMax = 9999,
inclusive_dxyMax = 1000.,
inclusive_dzMax = 0.4,
inclusive_vetoLeptons = False,
inclusive_leptonVetoDR = 0.4,
inclusive_decayModeID = "decayModeFindingNewDMs", # ignored if not set or ""
inclusive_tauID = "decayModeFindingNewDMs",
inclusive_vetoLeptonsPOG = False, # If True, the following two IDs are required
inclusive_tauAntiMuonID = "",
inclusive_tauAntiElectronID = "",
# loose hadronic tau selection
loose_ptMin = 18,
loose_etaMax = 9999,
loose_dxyMax = 1000.,
loose_dzMax = 0.2,
loose_vetoLeptons = True,
loose_leptonVetoDR = 0.4,
loose_decayModeID = "decayModeFindingNewDMs", # ignored if not set or ""
loose_tauID = "byLooseCombinedIsolationDeltaBetaCorr3Hits",
loose_vetoLeptonsPOG = False, # If True, the following two IDs are required
loose_tauAntiMuonID = "againstMuonLoose3",
loose_tauAntiElectronID = "againstElectronLooseMVA5",
loose_tauLooseID = "decayModeFindingNewDMs"
)
)
5 changes: 4 additions & 1 deletion PhysicsTools/Heppy/python/utils/cmsswPreprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@ def run(self,component,wd,firstEvent,nEvents):
f.close()
runstring="%s %s >& %s/cmsRun.log" % (self.command,configfile,wd)
print "Running pre-processor: %s " %runstring
os.system(runstring)
ret=os.system(runstring)
if ret != 0:
print "CMSRUN failed"
exit(ret)
return component