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

Heppy 7 4 4 patch4 #9544

Merged
merged 51 commits into from
Jun 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
8ee798b
Merged heppy_7_4_1_patch1 from repository cbernet
arizzi May 11, 2015
405a386
add error if cmsRun fail in preprocessor and make QGL path configurable
arizzi May 12, 2015
ed1d0be
add developments of tauAnalyzer from VHbb @veelken
arizzi May 12, 2015
4f93653
Merge pull request #36 from arizzi/sync74XheppyWithVHBB
cbernet May 21, 2015
405518c
added empty event generator for heppy.
cbernet May 27, 2015
141cddb
Merge remote-tracking branch 'my-cmssw/heppy_7_4_1_patch1' into heppy…
cbernet May 27, 2015
b40cf56
HeppyCore DataComponent: properly propagate the triggers kwarg
gpetruc Apr 14, 2015
6ff88a1
Heppy: switch to pf b-tagging, but make the thing backwards compatibl…
gpetruc Apr 15, 2015
4bc1732
Heppy Add collection of LHE weights to the event. Add flag makeLHEwei…
jmvizan Mar 31, 2015
6254f4f
Heppy add type for WeightsInfo object (for reading LHE information)
jmvizan Mar 31, 2015
93e4d03
Heppy putting back some additional variables that were left out in th…
jmvizan Mar 31, 2015
f6d4257
Add flag <<lazy>> (to True by default). If set to False, ReallyLoad i…
jmvizan Apr 13, 2015
8d010a5
use lazy = False for LHE AutoHandle
jmvizan Apr 13, 2015
14983e7
Heppy Declare only the LHEweights handle if the flag makeLHEweights i…
jmvizan Apr 14, 2015
4dd4625
Don't move the medium Id in this PR
gpetruc May 22, 2015
9cd51b6
Heppy electron: add a looser WP for the Phys14 MVA
gpetruc May 4, 2015
f83b9f3
forward port of the PR 337
mariadalfonso May 25, 2015
b373e1c
Normalize spaces
gpetruc May 28, 2015
b360243
Merge pull request #37 from gpetruc/heppy_743
cbernet May 28, 2015
8199dc4
Heppy: mod in heppy script so that current working dir is added to sy…
cbernet Jun 2, 2015
243565f
Merge remote-tracking branch 'my-cmssw/heppy_7_4_3' into merge_attempt
cbernet Jun 2, 2015
453ed03
Heppy: can now copy analysers and securely change instance_label
cbernet Jun 3, 2015
ef74d59
simplified imports for easier sync with FCC
cbernet Jun 3, 2015
f32fa34
event can now be initialized without input (generation in heppy)
cbernet Jun 3, 2015
1a1eefb
bug fix
cbernet Jun 3, 2015
46b69b6
Merged heppy_7_4_3 from repository cbernet
cbernet Jun 3, 2015
3fc2fac
added unittest for diclist, and secured add function against integer …
cbernet Jun 3, 2015
741bed2
added unittest and doc for counter
cbernet Jun 3, 2015
297b631
removed obsolete main section (now we have unittest)
cbernet Jun 3, 2015
7645cb5
unittest for value
cbernet Jun 3, 2015
4a87a51
removed obsolete main section
cbernet Jun 3, 2015
3875059
documentation and unittest for services
cbernet Jun 3, 2015
4930e8c
unittest for eventstfile
cbernet Jun 3, 2015
e280ae9
looper main section removed.
cbernet Jun 3, 2015
aea3fa7
put script part of heppy.py in scripts
cbernet Jun 3, 2015
1538087
Heppy: heppy_check is now working (number of events processed written…
cbernet Jun 8, 2015
02477e9
removed option not supported in recent versions of ipython
cbernet Jun 9, 2015
7ab02c3
Merge remote-tracking branch 'my-cmssw/heppy_7_4_3' into heppy_7_4_4_…
cbernet Jun 9, 2015
5f24d78
bug fix
cbernet Jun 9, 2015
275c519
removed noconfirm_exit, not supported in ipython 3.1
cbernet Jun 10, 2015
96d9735
updated batchmanager and added cmsBatch in Heppy
cbernet Jun 11, 2015
21efbaf
dataset is working
cbernet Jun 11, 2015
2b7d227
added eosdataset
cbernet Jun 11, 2015
2bb036e
added protection against non-exising dir
cbernet Jun 11, 2015
0e9f2c6
bug fix: eostools imported from HeppyCore
cbernet Jun 13, 2015
31f4f02
744
jpata Jun 13, 2015
30f730f
fixed pfn check
jpata Jun 13, 2015
0b7515c
added test for loading lfn/rootfn
jpata Jun 13, 2015
e27e97f
rename
jpata Jun 13, 2015
3a3ea5a
Merge pull request #39 from jpata/heppy-chain-744p4
cbernet Jun 13, 2015
2394eb4
Heppy: added missing modules for cmsBatch
cbernet Jun 15, 2015
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
16 changes: 9 additions & 7 deletions PhysicsTools/Heppy/python/analyzers/core/AutoHandle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@ class AutoHandle( Handle, object ):

handles = {}

def __init__(self, label, type, mayFail=False, fallbackLabel=None):
def __init__(self, label, type, mayFail=False, fallbackLabel=None, lazy=True):
'''Note: label can be a tuple : (module_label, collection_label, process)'''
self.label = label
self.fallbackLabel = fallbackLabel
self.type = type
self.mayFail = mayFail
self.lazy = lazy
Handle.__init__(self, self.type)
def product(self):
if not self.isLoaded :
self.ReallyLoad(self.event)
self.isLoaded=True
return super(AutoHandle,self).product()
if not self.isLoaded :
self.ReallyLoad(self.event)
self.isLoaded=True
return super(AutoHandle,self).product()

def Load(self, event): #is actually a reset state
self.event=event
self.isLoaded=False
self.event=event
self.isLoaded=False
if self.lazy==False: self.ReallyLoad(self.event)

def ReallyLoad(self, event):
'''Load self from a given event.
Expand Down
15 changes: 15 additions & 0 deletions PhysicsTools/Heppy/python/analyzers/gen/GeneratorAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class GeneratorAnalyzer( Analyzer ):
event.genwzquarks and event.genbquarks, might have overlaps
event.genbquarksFromTop and event.genbquarksFromH are all contained in event.genbquarks

In addition to genParticles, if makeLHEweights is set to True, the list WeightsInfo objects of the LHE branch
is stored in event.LHE_weights

"""

def __init__(self, cfg_ana, cfg_comp, looperName ):
Expand All @@ -54,10 +57,13 @@ def __init__(self, cfg_ana, cfg_comp, looperName ):
self.makeAllGenParticles = cfg_ana.makeAllGenParticles
self.makeSplittedGenLists = cfg_ana.makeSplittedGenLists
self.allGenTaus = cfg_ana.allGenTaus if self.makeSplittedGenLists else False
self.makeLHEweights = cfg_ana.makeLHEweights

def declareHandles(self):
super(GeneratorAnalyzer, self).declareHandles()
self.mchandles['genParticles'] = AutoHandle( 'prunedGenParticles', 'std::vector<reco::GenParticle>' )
if self.makeLHEweights:
self.mchandles['LHEweights'] = AutoHandle( 'source', 'LHEEventProduct', mayFail = True, lazy = False )

def beginLoop(self,setup):
super(GeneratorAnalyzer,self).beginLoop(setup)
Expand Down Expand Up @@ -239,6 +245,13 @@ def makeMCInfo(self, event):
if id <= 5 and any([abs(m.pdgId()) in {23,24} for m in realGenMothers(p)]):
event.genwzquarks.append(p)

#Add LHE weight info
event.LHE_weights = []
if self.makeLHEweights:
if self.mchandles['LHEweights'].isValid():
for w in self.mchandles['LHEweights'].product().weights():
event.LHE_weights.append(w)

def process(self, event):
self.readCollections( event.input )

Expand All @@ -263,6 +276,8 @@ def process(self, event):
# Make also the splitted lists
makeSplittedGenLists = True,
allGenTaus = False,
# Save LHE weights in LHEEventProduct
makeLHEweights = True,
# Print out debug information
verbose = False,
)
Expand Down
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
12 changes: 10 additions & 2 deletions PhysicsTools/Heppy/python/analyzers/objects/LeptonAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ def makeAllElectrons(self, event):
ele.tightIdResult = ele.electronID("POG_MVA_ID_Trig_full5x5")
elif self.cfg_ana.ele_tightId=="Cuts_2012" :
ele.tightIdResult = -1 + 1*ele.electronID("POG_Cuts_ID_2012_Veto_full5x5") + 1*ele.electronID("POG_Cuts_ID_2012_Loose_full5x5") + 1*ele.electronID("POG_Cuts_ID_2012_Medium_full5x5") + 1*ele.electronID("POG_Cuts_ID_2012_Tight_full5x5")
elif self.cfg_ana.ele_tightId=="Cuts_PHYS14_25ns_v1_ConvVetoDxyDz" :
ele.tightIdResult = -1 + 1*ele.electronID("POG_Cuts_ID_PHYS14_25ns_v1_ConvVetoDxyDz_Veto_full5x5") + 1*ele.electronID("POG_Cuts_ID_PHYS14_25ns_v1_ConvVetoDxyDz_Loose_full5x5") + 1*ele.electronID("POG_Cuts_ID_PHYS14_25ns_v1_ConvVetoDxyDz_Medium_full5x5") + 1*ele.electronID("POG_Cuts_ID_PHYS14_25ns_v1_ConvVetoDxyDz_Tight_full5x5")

else :
try:
ele.tightIdResult = ele.electronID(self.cfg_ana.ele_tightId)
Expand All @@ -349,7 +352,10 @@ def attachMiniIsolation(self, mu):
# -- version with increasing cone at low pT, gives slightly better performance for tight cuts and low pt leptons
# mu.miniIsoR = 10.0/min(max(mu.pt(), 50),200) if mu.pt() > 20 else 4.0/min(max(mu.pt(),10),20)
what = "mu" if (abs(mu.pdgId()) == 13) else ("eleB" if mu.isEB() else "eleE")
mu.miniAbsIsoCharged = self.IsolationComputer.chargedAbsIso(mu.physObj, mu.miniIsoR, {"mu":0.0001,"eleB":0,"eleE":0.015}[what], 0.0);
if what == "mu":
mu.miniAbsIsoCharged = self.IsolationComputer.chargedAbsIso(mu.physObj, mu.miniIsoR, {"mu":0.0001,"eleB":0,"eleE":0.015}[what], 0.0);
else:
mu.miniAbsIsoCharged = self.IsolationComputer.chargedAbsIso(mu.physObj, mu.miniIsoR, {"mu":0.0001,"eleB":0,"eleE":0.015}[what], 0.0,self.IsolationComputer.selfVetoNone);
if self.miniIsolationPUCorr == "weights":
if what == "mu":
mu.miniAbsIsoNeutral = self.IsolationComputer.neutralAbsIsoWeighted(mu.physObj, mu.miniIsoR, 0.01, 0.5);
Expand All @@ -373,7 +379,7 @@ def attachMiniIsolation(self, mu):
if what == "mu":
mu.miniAbsIsoPU = self.IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.01, 0.5);
else:
mu.miniAbsIsoPU = self.IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.015 if what == "eleE" else 0.0, 0.0);
mu.miniAbsIsoPU = self.IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.015 if what == "eleE" else 0.0, 0.0,self.IsolationComputer.selfVetoNone);
mu.miniAbsIsoNeutral = max(0.0, mu.miniAbsIsoNeutral - 0.5*mu.miniAbsIsoPU)
elif self.miniIsolationPUCorr != 'raw':
raise RuntimeError, "Unsupported miniIsolationCorr name '" + str(self.cfg_ana.miniIsolationCorr) + "'! For now only 'rhoArea', 'deltaBeta', 'raw', 'weights' are supported (and 'weights' is not tested)."
Expand Down Expand Up @@ -473,6 +479,7 @@ def process(self, event):
loose_muon_dxy = 0.05,
loose_muon_dz = 0.2,
loose_muon_relIso = 0.4,
# loose_muon_isoCut = lambda muon :muon.miniRelIso < 0.2
# inclusive very loose electron selection
inclusive_electron_id = "",
inclusive_electron_pt = 5,
Expand All @@ -487,6 +494,7 @@ def process(self, event):
loose_electron_dxy = 0.05,
loose_electron_dz = 0.2,
loose_electron_relIso = 0.4,
# loose_electron_isoCut = lambda electron : electron.miniRelIso < 0.1
loose_electron_lostHits = 1.0,
# muon isolation correction method (can be "rhoArea" or "deltaBeta")
mu_isoCorr = "rhoArea" ,
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"
)
)
Loading