Skip to content

Commit

Permalink
Update KMuon
Browse files Browse the repository at this point in the history
- Isolation and cutbased ID variables moved to KLepton
- Reduced amount of isolation variables
  • Loading branch information
JoramBerger committed Nov 30, 2014
1 parent b33bbd2 commit 4173b91
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 94 deletions.
95 changes: 46 additions & 49 deletions DataFormats/interface/KMuon.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,72 +50,69 @@ struct KMuonMetadata

struct KMuon : public KLepton
{
/*
virtual ~KMuon() {};
virtual bool isMuon() {
return true;
};
*/

/// global track in addition to KLepton track == innerTrack, no outer or best track
KTrack globalTrack;
KTrack innerTrack;
KTrack outerTrack;
KTrack bestTrack;

/// type of the muon: bits are set according to reco::Muon::type_;
unsigned char type;

inline bool isTrackerMuon() const { return (type & (1 << 2)); };
inline bool isCaloMuon() const { return (type & (1 << 4)); };
inline bool isStandAloneMuon() const { return (type & (1 << 3)); };
inline bool isGlobalMuon() const { return (type & (1 << 1)); };
inline bool isPFMuon() const { return (type & (1 << 5)); };

float hcalIso03; ///< hcal isolation as given by muon.isolationR03().hadEt
float ecalIso03; ///< ecal isolation as given by muon.isolationR03().emEt
float trackIso03; ///< tracker isolation as given by muon.isolationR03().sumPt

float pfIso04; ///< PF isolation

float hcalIso05;
float ecalIso05;
float trackIso05;
/// ID variables
unsigned long isGoodMuonBits; //< isGoodMuon bitmask, used by soft ID
unsigned char type; //< type of the muon: bits are set according to reco::Muon::type_ (used by various IDs)

unsigned int isGoodMuon; ///< bitmask
/// ID var from track: nValidPixelHits, nTrackerLayers
/// ID var from globalTrack: normalizedChi2=chi2/nDOF, nValidMuonHits
/// ID var from the bestTrack which is not saved entirely:
float dxy; //< dxy from vertex using IPTools like PAT
float dz; //< dz from vertex using bestTrack->dz(vtx)

float caloComp, segComp;
/// muon system information
short nMatchedStations;
// unused variables
short nChambers, nMatches;
float caloCompatibility, segmentCompatibility;

int nChambers;
int nMatches;
/// isolation results
float trackIso03; ///< tracker isolation as given by muon.isolationR03().sumPt
float pfIso03; ///< PF isolation R = 0.3
// deleted: hcalIso03, ecalIso03 and all 05

unsigned long long hltMatch;
/// additional isolation variables for PF isolation which are not stored in a KLepton
/// DataFormats/MuonReco/interface/MuonPFIsolation.h
float sumChargedParticlePt;
float sumNeutralHadronEtHighThreshold;
float sumPhotonEtHighThreshold;

/// \f$\eta\f$ and \f$\phi\f$ after the propagation to the muon system, this quantity
/// is necessary for the matching to L1 trigger objects
float eta_propagated, phi_propagated;

unsigned long long hltMatch;

/// accessor functions to CMSSW muon bitsets
inline bool isGoodMuon(KGoodMuon::KGoodMuonType bit) const { return (isGoodMuonBits & (1 << bit)); };
inline bool isGlobalMuon() const { return (type & (1 << 1)); };
inline bool isTrackerMuon() const { return (type & (1 << 2)); };
inline bool isStandAloneMuon() const { return (type & (1 << 3)); };
inline bool isCaloMuon() const { return (type & (1 << 4)); };
inline bool isPFMuon() const { return (type & (1 << 5)); };
inline bool isRPCMuon() const { return (type & (1 << 6)); };

double pfIso04high(const double puFraction=0.5) const
{
return sumChargedHadronPt + std::max(0.0,
sumNeutralHadronEtHighThreshold + sumPhotonEtHighThreshold - puFraction * sumPUPt);
}

/// returns whether a given HLT fired
/** the information is read from the metadata
@param name Name of the HLT
@param muonMetadata reference to the meta data object
@param hltName Name of the HLT
@param meta reference to the muon meta data object
*/
bool hltFired(const std::string& name, const KMuonMetadata* muonMetadata) const
bool hltFired(const std::string& hltName, const KMuonMetadata* meta) const
{
std::vector<std::string>::const_iterator itSearch = std::lower_bound(muonMetadata->hltNames.begin(), muonMetadata->hltNames.end(), name);
if (itSearch != muonMetadata->hltNames.end())
return (hltMatch & (1ull << (itSearch - muonMetadata->hltNames.begin()))) != 0;
std::vector<std::string>::const_iterator itSearch = std::lower_bound(meta->hltNames.begin(), meta->hltNames.end(), hltName);
if (itSearch != meta->hltNames.end())
return (hltMatch & (1ull << (itSearch - meta->hltNames.begin()))) != 0;
return false; // given HLT does not exist
}

double puSubtractedPFIso04(const KPileupDensity* puRho) const
{
// jetArea == NULL --> no PU subtraction
if(puRho == NULL) return pfIso04;

static const double coneSize = 0.4;
return std::max(0.0, pfIso04 - puRho->rho * coneSize * coneSize * 3.14159);
}
};
typedef std::vector<KMuon> KMuons;

Expand Down
127 changes: 82 additions & 45 deletions Producers/interface/KMuonProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class KMuonProducer : public KBaseMultiLVProducer<edm::View<reco::Muon>, KMuons>
propagatorToMuonSystem(cfg)
{
std::sort(selectedMuonTriggerObjects.begin(), selectedMuonTriggerObjects.end());
std::vector<std::string>::iterator tempIt = std::unique (selectedMuonTriggerObjects.begin(), selectedMuonTriggerObjects.end());
std::vector<std::string>::iterator tempIt = std::unique(
selectedMuonTriggerObjects.begin(), selectedMuonTriggerObjects.end());
selectedMuonTriggerObjects.resize(tempIt - selectedMuonTriggerObjects.begin());

muonMetadata = new KMuonMetadata();
Expand Down Expand Up @@ -98,10 +99,14 @@ class KMuonProducer : public KBaseMultiLVProducer<edm::View<reco::Muon>, KMuons>
pfIsoVetoCone = pset.getParameter<double>("pfIsoVetoCone");
pfIsoVetoMinPt = pset.getParameter<double>("pfIsoVetoMinPt");

edm::InputTag VertexCollectionSource = pset.getParameter<edm::InputTag>("vertexcollection");
cEvent->getByLabel(VertexCollectionSource, VertexHandle);

// Continue normally
KBaseMultiLVProducer<edm::View<reco::Muon>, KMuons>::fillProduct(in, out, name, tag, pset);
}

/// fill muon from DataFormats/MuonReco/interface/Muon.h
virtual void fillSingle(const SingleInputType &in, SingleOutputType &out)
{
out.flavour = KLepton::MUON;
Expand All @@ -114,35 +119,51 @@ class KMuonProducer : public KBaseMultiLVProducer<edm::View<reco::Muon>, KMuons>
KTrackProducer::fillTrack(*in.track(), out.track);
if (in.globalTrack().isNonnull())
KTrackProducer::fillTrack(*in.globalTrack(), out.globalTrack);
if (in.innerTrack().isNonnull())
KTrackProducer::fillTrack(*in.innerTrack(), out.innerTrack);
if (in.outerTrack().isNonnull())
KTrackProducer::fillTrack(*in.outerTrack(), out.outerTrack);
if (in.bestTrack())
KTrackProducer::fillTrack(*in.bestTrack(), out.bestTrack);

edm::View<reco::Vertex> vertices = *VertexHandle;
reco::Vertex vtx = vertices.at(0);
if (in.muonBestTrack().isNonnull()) // && &vtx != NULL) TODO
{
/// ID var from the bestTrack which is not saved entirely
out.dxy = 0; //dxy from vertex using IPTools like PAT
out.dz = in.bestTrack()->dz(vtx.position());
}
// propagated values of eta and phi
out.eta_propagated = -1000.;
out.phi_propagated = -1000.;
if (in.innerTrack().isNonnull() && !noPropagation)
{
TrajectoryStateOnSurface prop = propagatorToMuonSystem.extrapolate(in);
if (prop.isValid())
{
out.eta_propagated = prop.globalPosition().eta();
out.phi_propagated = prop.globalPosition().phi();
}
}

// Charge, ...
out.charge = in.charge();
// Charge, muon system information
assert(in.charge() == 1 || in.charge() == -1);
out.leptonInfo |= (in.charge() > 0) ? KLeptonChargeMask : 0;
out.nChambers = in.numberOfChambers();
out.nMatches = in.numberOfMatches();
out.caloComp = in.caloCompatibility();
out.segComp = muon::segmentCompatibility(in);
out.nMatchedStations = in.numberOfMatchedStations();
out.caloCompatibility = muon::caloCompatibility(in);
out.segmentCompatibility = muon::segmentCompatibility(in);

assert(in.type() <= 255);
assert(in.type() < 256);
out.type = in.type();

// muon ID selection, described in AN-2008/098
// http://cms-service-sdtweb.web.cern.ch/cms-service-sdtweb/doxygen/CMSSW_3_3_6/doc/html/dd/de0/MuonSelectors_8cc-source.html#l00005
// muon ID selection
// DataFormats/MuonReco/src/MuonSelectors.cc
std::bitset<32> tmpBits;
for (size_t i = 0; i < 16; ++i)
tmpBits.set(i, muon::isGoodMuon(in, (muon::SelectionType)i));
out.isGoodMuon = (unsigned int)tmpBits.to_ulong();
tmpBits.set(i, muon::isGoodMuon(in, (muon::SelectionType) i));
out.isGoodMuonBits = (unsigned int) tmpBits.to_ulong();

// Isolation
/// Isolation
// source?
edm::RefToBase<reco::Muon> muonref(edm::Ref<edm::View<reco::Muon> >(handle, this->nCursor));
reco::IsoDeposit muonIsoDepositPF = (*isoDepsPF)[muonref];

reco::isodeposit::Direction dir = reco::isodeposit::Direction(in.eta(), in.phi());
reco::isodeposit::ConeVeto pf_cone_veto(dir, pfIsoVetoCone);
reco::isodeposit::ThresholdVeto pf_threshold_veto(pfIsoVetoMinPt);
Expand All @@ -151,31 +172,48 @@ class KMuonProducer : public KBaseMultiLVProducer<edm::View<reco::Muon>, KMuons>
vetosPF.push_back(&pf_cone_veto);
vetosPF.push_back(&pf_threshold_veto);

out.ecalIso03 = in.isolationR03().emEt;
out.hcalIso03 = in.isolationR03().hadEt;
out.trackIso03 = in.isolationR03().sumPt;

out.pfIso04 = muonIsoDepositPF.depositWithin(0.4, vetosPF);

out.ecalIso05 = in.isolationR05().emEt;
out.hcalIso05 = in.isolationR05().hadEt;
out.trackIso05 = in.isolationR05().sumPt;

out.eta_propagated = -1000.;
out.phi_propagated = -1000.;

// propagated values
if (in.innerTrack().isNonnull() && !noPropagation)
{
TrajectoryStateOnSurface prop = propagatorToMuonSystem.extrapolate(in);
if (prop.isValid())
{
out.eta_propagated = prop.globalPosition().eta();
out.phi_propagated = prop.globalPosition().phi();
}
}
/// isolation results
out.trackIso03 = in.isolationR03().sumPt;
out.pfIso03 = muonIsoDepositPF.depositWithin(0.3, vetosPF);
//out.pfIso04 = muonIsoDepositPF.depositWithin(0.4, vetosPF);

/// isolation variables for pfIso04
/// DataFormats/MuonReco/interface/MuonPFIsolation.h
out.sumChargedHadronPt = in.pfIsolationR04().sumChargedHadronPt;
out.sumChargedParticlePt = in.pfIsolationR04().sumChargedParticlePt;
out.sumNeutralHadronEt = in.pfIsolationR04().sumNeutralHadronEt;
out.sumPhotonEt = in.pfIsolationR04().sumPhotonEt;
out.sumPUPt = in.pfIsolationR04().sumPUPt;
out.sumNeutralHadronEtHighThreshold = in.pfIsolationR04().sumNeutralHadronEtHighThreshold;
out.sumPhotonEtHighThreshold = in.pfIsolationR04().sumPhotonEtHighThreshold;

/// highpt ID variables
/** needed variables according to
https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideMuonId#New_HighPT_Version_recommended
not in new CMSSW versions
reco::TrackRef cktTrack = muon::improvedMuonBestTrack(const reco::Muon & recoMu, muon::improvedTuneP);
dxy_high = cktTrack->db...
dz_high = 0;
pt_high = cktTrack->pt();
pte_high = cktTrack->ptError();
*/

out.hltMatch = getHLTInfo(out.p4);

/// precomputed muon IDs
/** https://hypernews.cern.ch/HyperNews/CMS/get/muon/868.html
https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideMuonId#Baseline_muon_selections_for_201
DataFormats/MuonReco/src/MuonSelectors.cc
automatically use muon::improvedTuneP default as in CMSSW
last update: 2014-10-03
*/
out.ids = KLeptonId::ANY;
out.ids |= (muon::isLooseMuon(in) << KLeptonId::LOOSE);
out.ids |= (muon::isTightMuon(in, vtx) << KLeptonId::TIGHT);
out.ids |= (muon::isSoftMuon(in, vtx) << KLeptonId::SOFT);
out.ids |= (muon::isHighPtMuon(in, vtx, reco::improvedTuneP) << KLeptonId::HIGHPT); // a
assert((out.ids & 148) == 0); // 148 = 0b10010100, these bits should be zero
}

private:
Expand All @@ -185,10 +223,9 @@ class KMuonProducer : public KBaseMultiLVProducer<edm::View<reco::Muon>, KMuons>
std::vector<std::string> selectedMuonTriggerObjects;
bool noPropagation;
PropagateToMuon propagatorToMuonSystem;
edm::Handle< edm::ValueMap<reco::IsoDeposit> > isoDepsPF;

edm::Handle< trigger::TriggerEvent > triggerEventHandle;

edm::Handle<edm::ValueMap<reco::IsoDeposit> > isoDepsPF;
edm::Handle<trigger::TriggerEvent> triggerEventHandle;
edm::Handle<edm::View<reco::Vertex> > VertexHandle;
KMuonMetadata *muonMetadata;

std::map<std::string, int> muonTriggerObjectBitMap;
Expand Down

0 comments on commit 4173b91

Please sign in to comment.