Skip to content

Commit

Permalink
Merge pull request #13 from MT2Analysis/revert-10-boris_toMergeHeppyW…
Browse files Browse the repository at this point in the history
…ithCMG

Revert "Update also our Heppy branch with what is in cmg/heppy central r...
  • Loading branch information
mangano committed Mar 12, 2015
2 parents aee9d96 + de6c098 commit c495ea4
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 182 deletions.
14 changes: 0 additions & 14 deletions PhysicsTools/Heppy/interface/ReclusterJets.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,13 @@ class ReclusterJets {

/// get grouping (exclusive jets, until n are left)
std::vector<LorentzVector> getGroupingExclusive(int njets);

/// get grouping (exclusive jets, up to cut dcut)
std::vector<LorentzVector> getGroupingExclusive(double dcut);

/// get pruned 4-vector
LorentzVector getPruned(double zcut, double rcutFactor) ;

/// get pruned 4-vector for a given subject (must be called after getGroupingExclusive)
LorentzVector getPrunedSubjetExclusive(unsigned int isubjet, double zcut, double rcutFactor) ;

/// get pruned 4-vector for a given subject (must be called after getGroupingInclusive)
LorentzVector getPrunedSubjetInclusive(unsigned int isubjet, double zcut, double rcutFactor) ;


private:
// pack the returns in a fwlite-friendly way
std::vector<LorentzVector> makeP4s(const std::vector<fastjet::PseudoJet> &jets) ;

// prune and return in fa fwlite-friendly way
LorentzVector getPruned(const fastjet::PseudoJet & jet, double zcut, double rcutFactor) ;

// used to handle the inputs
std::vector<fastjet::PseudoJet> fjInputs_; // fastjet inputs

Expand Down
36 changes: 13 additions & 23 deletions PhysicsTools/Heppy/python/analyzers/objects/METAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ def declareHandles(self):
super(METAnalyzer, self).declareHandles()
self.handles['met'] = AutoHandle( 'slimmedMETs', 'std::vector<pat::MET>' )
self.handles['nopumet'] = AutoHandle( 'slimmedMETs', 'std::vector<pat::MET>' )
self.handles['cmgCand'] = AutoHandle( self.cfg_ana.candidates, self.cfg_ana.candidatesTypes )
self.handles['cmgCand1'] = AutoHandle( self.cfg_ana.candidates, self.cfg_ana.candidatesTypes )
self.handles['cmgCand2'] = AutoHandle( self.cfg_ana.candidates, self.cfg_ana.candidatesTypes )
self.handles['cmgCand3'] = AutoHandle( self.cfg_ana.candidates, self.cfg_ana.candidatesTypes )
self.handles['cmgCand4'] = AutoHandle( self.cfg_ana.candidates, self.cfg_ana.candidatesTypes )
self.handles['cmgCand5'] = AutoHandle( self.cfg_ana.candidates, self.cfg_ana.candidatesTypes )
self.handles['cmgCand6'] = AutoHandle( self.cfg_ana.candidates, self.cfg_ana.candidatesTypes )
self.handles['cmgCand7'] = AutoHandle( self.cfg_ana.candidates, self.cfg_ana.candidatesTypes )
self.handles['cmgCand8'] = AutoHandle( self.cfg_ana.candidates, self.cfg_ana.candidatesTypes )
self.handles['vertices'] = AutoHandle( "offlineSlimmedPrimaryVertices", 'std::vector<reco::Vertex>', fallbackLabel="offlinePrimaryVertices" )

def beginLoop(self, setup):
Expand All @@ -37,35 +44,18 @@ def makeTkMETs(self, event):
event.tkMet = 0

charged = []
chargedchs = []
chargedPVLoose = []
chargedPVTight = []

pfcands = self.handles['cmgCand'].product()

for i in xrange(pfcands.size()):

## ===> require the Track Candidate charge and with a minimum dz

if (pfcands.at(i).charge()!=0):

if abs(pfcands.at(i).dz())<=self.cfg_ana.dzMax:
charged.append(pfcands.at(i))

if pfcands.at(i).fromPV()>0:
chargedchs.append(pfcands.at(i))

if pfcands.at(i).fromPV()>1:
chargedPVLoose.append(pfcands.at(i))

if pfcands.at(i).fromPV()>2:
chargedPVTight.append(pfcands.at(i))

if (pfcands.at(i).charge()!=0 and (abs(pfcands.at(i).dz())<=self.cfg_ana.dzMax )):

charged.append(pfcands.at(i))

import ROOT
event.tkMet = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in charged])) , -1.*(sum([x.py() for x in charged])), 0, math.hypot((sum([x.px() for x in charged])),(sum([x.py() for x in charged]))) )
event.tkMetchs = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in chargedchs])) , -1.*(sum([x.py() for x in chargedchs])), 0, math.hypot((sum([x.px() for x in chargedchs])),(sum([x.py() for x in chargedchs]))) )
event.tkMetPVLoose = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in chargedPVLoose])) , -1.*(sum([x.py() for x in chargedPVLoose])), 0, math.hypot((sum([x.px() for x in chargedPVLoose])),(sum([x.py() for x in chargedPVLoose]))) )
event.tkMetPVTight = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in chargedPVTight])) , -1.*(sum([x.py() for x in chargedPVTight])), 0, math.hypot((sum([x.px() for x in chargedPVTight])),(sum([x.py() for x in chargedPVTight]))) )
event.tkMet = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px() for x in charged])) , -1.*(sum([x.py() for x in charged])), 0, 0 )
## print 'tkmet',event.tkMet.pt(),'tkmetphi',event.tkMet.phi()


Expand Down
126 changes: 14 additions & 112 deletions PhysicsTools/Heppy/python/analyzers/objects/PhotonAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ def declareHandles(self):
# DECLARATION OF HANDLES OF PHOTONS STUFF
#----------------------------------------

#photons
self.handles['photons'] = AutoHandle( self.cfg_ana.photons,'std::vector<pat::Photon>')
self.mchandles['packedGen'] = AutoHandle( 'packedGenParticles', 'std::vector<pat::PackedGenParticle>' )
self.handles['packedCandidates'] = AutoHandle( 'packedPFCandidates', 'std::vector<pat::PackedCandidate>')
self.handles['jets'] = AutoHandle( "slimmedJets", 'std::vector<pat::Jet>' )


def beginLoop(self, setup):
super(PhotonAnalyzer,self).beginLoop(setup)
Expand Down Expand Up @@ -115,126 +113,35 @@ def matchPhotons(self, event):
gen = match[gamma]
if gen and gen.pt()>=0.5*gamma.pt() and gen.pt()<=2.*gamma.pt():
gamma.mcMatchId = 22
sumPt03 = 0.;
sumPt04 = 0.;
sumPt = 0.;
for part in packedGenParts:
if abs(part.pdgId())==12: continue # exclude neutrinos
if abs(part.pdgId())==14: continue
if abs(part.pdgId())==16: continue
if abs(part.pdgId())==18: continue
deltar = deltaR(gen.eta(), gen.phi(), part.eta(), part.phi())
if deltar <= 0.3:
sumPt03 += part.pt()
if deltar <= 0.4:
sumPt04 += part.pt()
sumPt03 -= gen.pt()
sumPt04 -= gen.pt()
if sumPt03<0. : sumPt03=0.
if sumPt04<0. : sumPt04=0.
gamma.genIso03 = sumPt03
gamma.genIso04 = sumPt04
if deltaR(gen.eta(), gen.phi(), part.eta(), part.phi()) > 0.4: continue
sumPt += part.pt()
sumPt -= gen.pt()
if sumPt<0. : sumPt=0.
gamma.genIso = sumPt
else:
genNoMom = matchNoMom[gamma]
if genNoMom:
gamma.mcMatchId = 7
sumPt03 = 0.;
sumPt04 = 0.;
sumPt = 0.;
for part in packedGenParts:
if abs(part.pdgId())==12: continue # exclude neutrinos
if abs(part.pdgId())==14: continue
if abs(part.pdgId())==16: continue
if abs(part.pdgId())==18: continue
deltar = deltaR(genNoMom.eta(), genNoMom.phi(), part.eta(), part.phi());
if deltar <= 0.3:
sumPt03 += part.pt()
if deltar <= 0.4:
sumPt04 += part.pt()
sumPt03 -= genNoMom.pt()
sumPt04 -= genNoMom.pt()
if sumPt03<0. : sumPt03=0.
if sumPt04<0. : sumPt04=0.
gamma.genIso03 = sumPt03
gamma.genIso04 = sumPt04
if deltaR(genNoMom.eta(), genNoMom.phi(), part.eta(), part.phi()) > 0.4: continue
sumPt += part.pt()
sumPt -= genNoMom.pt()
if sumPt<0. : sumPt=0.
gamma.genIso = sumPt
else:
gamma.mcMatchId = 0
gamma.genIso03 = -1.
gamma.genIso04 = -1.





def checkMatch( self, eta, phi, particles, deltar ):

for part in particles:
if deltaR(eta, phi, part.eta(), part.phi()) < deltar:
return True

return False





def computeRandomCone( self, event, eta, phi, deltarmax, charged, jets, photons ):

if self.checkMatch( eta, phi, jets, 2.*deltarmax ):
return -1.

if self.checkMatch( eta, phi, photons, 2.*deltarmax ):
return -1.

if self.checkMatch( eta, phi, event.selectedLeptons, deltarmax ):
return -1.

iso = 0.

for part in charged:
if deltaR(eta, phi, part.eta(), part.phi()) > deltarmax : continue
#if deltaR(eta, phi, part.eta(), part.phi()) < 0.02: continue
iso += part.pt()

return iso






def randomCone( self, event ):

patcands = self.handles['packedCandidates'].product()
jets = self.handles['jets'].product()

charged = [ p for p in patcands if ( p.charge() != 0 and abs(p.pdgId())>20 and abs(p.dz())<=0.1 and p.fromPV()>1 and p.trackHighPurity() ) ]
photons10 = [ p for p in patcands if ( p.pdgId() == 22 and p.pt()>10. ) ]
jets20 = [ j for j in jets if j.pt() > 20 and abs(j.eta())<2.5 ]

for gamma in event.allphotons:

etaPhot = gamma.eta()
phiPhot = gamma.eta()
pi = 3.14159
phiRC = phiPhot + 0.5*pi
while phiRC>pi:
phiRC -= 2.*pi

gamma.chHadIsoRC03 = self.computeRandomCone( event, etaPhot, phiRC, 0.3, charged, jets20, photons10 )
gamma.chHadIsoRC = self.computeRandomCone( event, etaPhot, phiRC, 0.4, charged, jets20, photons10 )

if gamma.chHadIsoRC>=0. : continue #good to go

#if not, try other side:
phiRC = phiPhot - 0.5*pi
while phiRC<-pi:
phiRC += 2.*pi

gamma.chHadIsoRC03 = self.computeRandomCone( event, etaPhot, phiRC, 0.3, charged, jets20, photons10 )
gamma.chHadIsoRC = self.computeRandomCone( event, etaPhot, phiRC, 0.4, charged, jets20, photons10 )




gamma.genIso = -1.

def printInfo(self, event):
print '----------------'
Expand All @@ -258,16 +165,12 @@ def process(self, event):
self.makePhotons(event)
# self.printInfo(event)

if self.cfg_ana.do_randomCone:
self.randomCone(event)

if not self.cfg_comp.isMC:
return True

if self.cfg_ana.do_mc_match and hasattr(event, 'genParticles'):
self.matchPhotons(event)


return True


Expand All @@ -278,6 +181,5 @@ def process(self, event):
etaMax = 2.5,
gammaID = "PhotonCutBasedIDLoose",
do_mc_match = True,
do_randomCone = False,
)
)
3 changes: 1 addition & 2 deletions PhysicsTools/Heppy/python/analyzers/objects/autophobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@
#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("chHadIso", lambda x : x.recoChargedHadronIso(), float, help="chargedHadronIsolation for photons (reco::Photon method, deltaR = 0.3)"),
NTupleVariable("chHadIso04", lambda x : x.chargedHadronIso(), float, help="chargedHadronIsolation for photons (PAT method, deltaR = 0.4)"),
NTupleVariable("chHadIso", lambda x : x.recoChargedHadronIso(), float, help="chargedHadronIsolation for photons"),
NTupleVariable("neuHadIso", lambda x : x.recoNeutralHadronIso(), float, help="neutralHadronIsolation for photons"),
NTupleVariable("phIso", lambda x : x.recoPhotonIso(), float, help="gammaIsolation for photons"),
NTupleVariable("mcMatchId", lambda x : x.mcMatchId, int, mcOnly=True, help="Match to source from hard scatter (pdgId of heaviest particle in chain, 25 for H, 6 for t, 23/24 for W/Z), zero if non-prompt or fake"),
Expand Down
2 changes: 1 addition & 1 deletion PhysicsTools/Heppy/python/physicsobjects/Photon.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def photonIDCSA14(self, name):
keepThisPhoton = True
if name == "PhotonCutBasedIDLoose_CSA14":
if abs(self.physObj.eta())<1.479 :
if self.full5x5_sigmaIetaIeta() > 0.015 : keepThisPhoton = False
if self.full5x5_sigmaIetaIeta() > 0.012 : keepThisPhoton = False
if self.hOVERe() > 0.0559 : keepThisPhoton = False
else :
if self.full5x5_sigmaIetaIeta() > 0.035 : keepThisPhoton = False
Expand Down
30 changes: 0 additions & 30 deletions PhysicsTools/Heppy/src/ReclusterJets.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "PhysicsTools/Heppy/interface/ReclusterJets.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "fastjet/tools/Pruner.hh"

using namespace std;

Expand Down Expand Up @@ -69,33 +68,4 @@ std::vector<math::XYZTLorentzVector> ReclusterJets::getGroupingExclusive(int nje
// return
return makeP4s(exclusiveJets_);
}

math::XYZTLorentzVector ReclusterJets::getPruned(double zcut, double rcutFactor) {
// cluster everything first
exclusiveJets_ = fastjet::sorted_by_pt(fjClusterSeq_->exclusive_jets(1));
// get pruned exclusive
return getPrunedSubjetExclusive(0, zcut, rcutFactor);
}

math::XYZTLorentzVector ReclusterJets::getPrunedSubjetExclusive(unsigned int isubjet, double zcut, double rcutFactor) {
if (isubjet >= exclusiveJets_.size()) {
throw cms::Exception("InvalidArgument", "getPrunedSubjetExclusive called for non-existing exclusive subjet");
}
return getPruned(exclusiveJets_[isubjet], zcut, rcutFactor);
}
math::XYZTLorentzVector ReclusterJets::getPrunedSubjetInclusive(unsigned int isubjet, double zcut, double rcutFactor) {
if (isubjet >= inclusiveJets_.size()) {
throw cms::Exception("InvalidArgument", "getPrunedSubjetInclusive called for non-existing inclusive subjet");
}
return getPruned(inclusiveJets_[isubjet], zcut, rcutFactor);
}

math::XYZTLorentzVector ReclusterJets::getPruned(const fastjet::PseudoJet & jet, double zcut, double rcutFactor) {
// create pruner
fastjet::Pruner pruner(fastjet::cambridge_algorithm, zcut, rcutFactor);
// Prune the jet
fastjet::PseudoJet pruned_jet = pruner(jet);
return LorentzVector( pruned_jet.px(), pruned_jet.py(), pruned_jet.pz(), pruned_jet.e() );
}

}

0 comments on commit c495ea4

Please sign in to comment.