Skip to content

Commit

Permalink
Update KLepton
Browse files Browse the repository at this point in the history
This now includes isolation and IDs
  • Loading branch information
JoramBerger committed Nov 30, 2014
1 parent be117c2 commit 4e91541
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 30 deletions.
96 changes: 82 additions & 14 deletions DataFormats/interface/KTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,28 +160,96 @@ struct KMuonTriggerCandidate : public KTrack

typedef std::vector<KMuonTriggerCandidate> KMuonTriggerCandidates;

struct KTrackSummary
const unsigned char KLeptonFlavourMask = 3;
const unsigned char KLeptonChargeMask = 1 << 2;
const unsigned char KLeptonAlternativeTrackMask = 1 << 3;
const unsigned char KLeptonPFMask = 1 << 4;

namespace KLeptonFlavour { enum Type
{
NONE = 0,
ELECTRON = 1,
MUON = 2,
TAU = 3
};
}

namespace KLeptonId { enum Type
{
unsigned int nTracks;
unsigned int nTracksHQ;
ANY = 0, //< returns true if the information for any ID was filled
LOOSE = 1, //< e/mu/tau loose ID
MEDIUM = 2, //< e/tau medium ID
TIGHT = 3, //< e/mu tight ID
VETO = 4, //< e veto ID
SOFT = 5, //< mu soft ID
HIGHPT = 6, //< mu high pt ID
CUSTOM = 7, //< empty bit for any userdefined ID
LOOSEELECTRONREJECTION = 4, // tau discriminator
LOOSEMUONREJECTION = 5, // tau discriminator
TIGHTMUONREJECTION = 6 // tau discriminator
};
}

struct KLepton : public KLV
{
public:
enum Flavour
unsigned char leptonInfo; //< bitset containing the flavour, charge and user bits
unsigned char ids; //< most relevant IDs of the lepton
float sumChargedHadronPt; //< sum pt of charged hadrons for isolation
float sumNeutralHadronEt; //< sum Et of neutral hadrons for isolation
float sumPhotonEt; //< sum Et of photons for isolation
float sumPUPt; //< sum pt of pile-up for isolation
KTrack track; //< (main) track of the lepton (e: GSF, mu: inner, tau: lead. PF candidate)

// access functions for leptonInfo
/// lepton flavour according to KLeptonFlavour::Type
inline KLeptonFlavour::Type flavour() const { return KLeptonFlavour::Type(leptonInfo & KLeptonFlavourMask); };
/// lepton charge (+1 or -1)
inline char charge() const { return ((leptonInfo & KLeptonChargeMask) ? +1 : -1); };
/// whether the stored object is reconstructed using PF objects
inline bool isPF() const { return (leptonInfo & KLeptonPFMask); };
/// if the normal track is not available, the producer can fill the track information with a second option and set this flag
inline bool isAlternativeTrack() const { return (leptonInfo & KLeptonAlternativeTrackMask); };

/// access function for ID bitset ids
/// returns true if the ID is set and the flavour is correct
inline bool isAvailable() const { return (ids & (1 << KLeptonId::ANY)); }; // e, mu, tau
inline bool idLoose() const { return (ids & (1 << KLeptonId::LOOSE)); }; // e, mu, tau
inline bool idMedium() const { return (ids & (1 << KLeptonId::MEDIUM)); }; // e, (mu,) tau
inline bool idTight() const { return (ids & (1 << KLeptonId::TIGHT)); }; // e, mu, tau
inline bool idVeto() const { return (ids & (1 << KLeptonId::VETO) && (KLeptonFlavour::ELECTRON == (leptonInfo & KLeptonFlavourMask))); }; // e
inline bool idSoft() const { return (ids & (1 << KLeptonId::SOFT) && (KLeptonFlavour::MUON == (leptonInfo & KLeptonFlavourMask))); }; // mu
inline bool idHighPt() const { return (ids & (1 << KLeptonId::HIGHPT) && (KLeptonFlavour::MUON == (leptonInfo & KLeptonFlavourMask))); }; // mu
inline bool idLooseElectronRejection() const { return (ids & (1 << KLeptonId::LOOSEELECTRONREJECTION) && (KLeptonFlavour::TAU == (leptonInfo & KLeptonFlavourMask))); }; // tau
inline bool idLooseMuonRejection() const { return (ids & (1 << KLeptonId::LOOSEMUONREJECTION) && (KLeptonFlavour::TAU == (leptonInfo & KLeptonFlavourMask))); }; // tau
inline bool idTightMuonRejection() const { return (ids & (1 << KLeptonId::TIGHTMUONREJECTION) && (KLeptonFlavour::TAU == (leptonInfo & KLeptonFlavourMask))); }; // tau

/// PF isolation with delta beta corrections (default fraction of pile-up is 0.5)
inline double pfIso(const double puFraction=0.5) const
{
NONE = 0,
ELECTRON = 1,
MUON = 2,
TAU = 3
};
Flavour flavour;

char charge;
KTrack track;
return sumChargedHadronPt + std::max(0.0,
sumNeutralHadronEt + sumPhotonEt - puFraction * sumPUPt);
}

/// rho effective area isolation (approximation)
/** this is an alternative method for pile-up subtraction:
PFIso = PF(ChHad PFNoPU) + Max(PF(Nh+Ph) - rho’EA), 0.0) with rho'=max(rho,0)
approximation: effective area as a circle area
rho is usually provided by a KPileupDensity object
*/
double pfIsoRho(const double rho = 0.0, const double radius = 0.4) const
{
double area = radius * radius * 3.14159;
return std::max(0.0, pfIso(0.0) - std::max(rho * area, 0.0));
}
};

typedef std::vector<KLepton> KLeptons;


struct KTrackSummary
{
unsigned int nTracks; //< number of tracks in the event
unsigned int nTracksHQ; //< number of high quality tracks in the event
};

#endif
2 changes: 1 addition & 1 deletion DataFormats/test/KDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ std::ostream &operator<<(std::ostream &os, const KJet &jet)

std::ostream &operator<<(std::ostream &os, const KBasicTau &tau)
{
return os << static_cast<const KLV>(tau) << " charge=" << tau.charge;
return os << static_cast<const KLV>(tau) << " charge=" << tau.charge();
}

std::ostream &operator<<(std::ostream &os, const KGenTau &tau)
Expand Down
24 changes: 19 additions & 5 deletions Producers/interface/KBasicTauProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,27 @@ class KBasicTauProducer : public KBaseMultiLVProducer<std::vector<TTau>, TProduc
const typename KBaseMultiLVProducer<std::vector<TTau>, TProduct>::SingleInputType &in,
typename KBaseMultiLVProducer<std::vector<TTau>, TProduct>::SingleOutputType &out)
{
out.flavour = KLepton::MUON;

// Momentum:
// momentum:
copyP4(in, out.p4);

// Charge:
out.charge = in.charge();
// charge and flavour (lepton type)
out.leptonInfo = KLeptonFlavour::TAU;
assert(in.charge() == 1 || in.charge() == -1);
if (in.charge() > 0)
out.leptonInfo |= KLeptonChargeMask;
out.leptonInfo |= KLeptonPFMask;

if (in.leadPFChargedHadrCand().isNonnull())
{
if (in.leadPFChargedHadrCand()->trackRef().isNonnull())
KTrackProducer::fillTrack(*in.leadPFChargedHadrCand()->trackRef(), out.track);
else if (in.leadPFChargedHadrCand()->gsfTrackRef().isNonnull())
{
KTrackProducer::fillTrack(*in.leadPFChargedHadrCand()->gsfTrackRef(), out.track);
out.leptonInfo |= KLeptonAlternativeTrackMask;
}
}

out.emFraction = in.emFraction();
out.decayMode = in.decayMode();

Expand Down
23 changes: 16 additions & 7 deletions Producers/interface/KElectronProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,26 @@ if (!trh.isValid())
}

virtual void fillSingle(const SingleInputType &in, SingleOutputType &out)
{
out.flavour = KLepton::ELECTRON;

// Momentum:
{
// momentum:
copyP4(in, out.p4);

// Charge, ...
out.charge = in.charge();
// charge and flavour (lepton type)
assert(in.charge() == 1 || in.charge() == -1);
out.leptonInfo = KLeptonFlavour::ELECTRON;
if (in.charge() > 0)
out.leptonInfo |= KLeptonChargeMask;
if (in.isPF())
out.leptonInfo |= KLeptonPFMask;

// electron track
KTrackProducer::fillTrack(*in.gsfTrack(), out.track);
if (in.gsfTrack().isNonnull())
KTrackProducer::fillTrack(*in.gsfTrack(), out.track);
else if (in.gsfTrack().isNonnull())
{
KTrackProducer::fillTrack(*in.gsfTrack(), out.track);
out.leptonInfo |= KLeptonAlternativeTrackMask;
}

// ECAL region: bits are set according to reco::GsfElectron::FiducialFlags
// the last bit is set to show that this bitset is filled.
Expand Down
6 changes: 3 additions & 3 deletions Producers/interface/KMuonProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ class KMuonProducer : public KBaseMultiLVProducer<edm::View<reco::Muon>, KMuons>
/// fill muon from DataFormats/MuonReco/interface/Muon.h
virtual void fillSingle(const SingleInputType &in, SingleOutputType &out)
{
out.flavour = KLepton::MUON;
out.leptonInfo = KLeptonFlavour::MUON;

// Momentum:
/// momentum:
copyP4(in, out.p4);

// Tracks
/// Tracks and track extracted information
if (in.track().isNonnull())
KTrackProducer::fillTrack(*in.track(), out.track);
if (in.globalTrack().isNonnull())
Expand Down

0 comments on commit 4e91541

Please sign in to comment.