Skip to content

Commit

Permalink
Merge pull request cms-sw#29 from gpetruc/76X-metmt
Browse files Browse the repository at this point in the history
Compute MET and MT for tags and probes
  • Loading branch information
gpetruc committed May 25, 2016
2 parents 34ad0da + 8eccf9d commit 7b49ce0
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 2 deletions.
97 changes: 97 additions & 0 deletions plugins/MuonMetMT.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// system include files
#include <memory>
#include <cmath>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDProducer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/ESHandle.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/Service.h"

#include "DataFormats/Math/interface/deltaR.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/MuonReco/interface/Muon.h"
#include "DataFormats/METReco/interface/MET.h"

//
// class declaration
//

class MuonMetMT : public edm::EDProducer {
public:

typedef edm::View<reco::MET> METColl;

explicit MuonMetMT(const edm::ParameterSet&);
~MuonMetMT();

private:
virtual void produce(edm::Event&, const edm::EventSetup&);

const edm::EDGetTokenT<edm::View<reco::Muon>> probes_;
const edm::EDGetTokenT<METColl> pfMet_;

template<typename Hand, typename T>
void storeMap(edm::Event &iEvent, const Hand & handle, const std::vector<T> & values, const std::string & label) const ;
};

MuonMetMT::MuonMetMT(const edm::ParameterSet& iConfig):
probes_(consumes<edm::View<reco::Muon>>(iConfig.getParameter<edm::InputTag>("probes"))),
pfMet_(consumes<METColl>(iConfig.getParameter<edm::InputTag>("met")))
{
produces<edm::ValueMap<float> >("met");
produces<edm::ValueMap<float> >("mt");
}


MuonMetMT::~MuonMetMT()
{
}

void
MuonMetMT::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
{
using namespace edm;

Handle<View<reco::Muon> > probes;
iEvent.getByToken(probes_, probes);

Handle<METColl> mets;
iEvent.getByToken(pfMet_, mets);
const auto & met = mets->front();

unsigned int n = probes->size();
std::vector<float> vmet(n,met.pt());
std::vector<float> vmt(n,0);

unsigned int imu = 0;
for (auto probe = probes->begin(); imu < n; ++probe, ++imu) {
const reco::Muon &mu = *probe;
vmt[imu] = std::sqrt(2 * mu.pt() * met.pt() * ( 1 - std::cos(mu.phi()-met.phi()) ) );
}

storeMap(iEvent, probes, vmet, "met");
storeMap(iEvent, probes, vmt, "mt");
}

template<typename Hand, typename T>
void
MuonMetMT::storeMap(edm::Event &iEvent,
const Hand & handle,
const std::vector<T> & values,
const std::string & label) const {
using namespace edm; using namespace std;
auto_ptr<ValueMap<T> > valMap(new ValueMap<T>());
typename edm::ValueMap<T>::Filler filler(*valMap);
filler.insert(handle, values.begin(), values.end());
filler.fill();
iEvent.put(valMap, label);
}

//define this as a plug-in
DEFINE_FWK_MODULE(MuonMetMT);
11 changes: 11 additions & 0 deletions python/common_modules_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,14 @@
cut = cms.string("abs(pdgId) == 13 && pt > 3 && abs(eta) < 2.4 && status == 1 && isPromptFinalState")
)

##############
## MET & MT
#############
tagMetMt = cms.EDProducer("MuonMetMT",
probes = cms.InputTag("tagMuons"),
met = cms.InputTag("pfMet"),
)
probeMetMt = cms.EDProducer("MuonMetMT",
probes = cms.InputTag("probeMuons"),
met = cms.InputTag("pfMet"),
)
5 changes: 3 additions & 2 deletions test/treeSync.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <Rtypes.h>

/// utility: deltaPhi (unsigned)
inline float dphi(float phi1, float phi2) {
Expand All @@ -52,7 +53,7 @@ struct Item {
tag_pt(tagpt), tag_eta(tageta), tag_phi(tagphi), probe_pt(probept), probe_eta(probeeta), probe_phi(probephi),
count(1) {}

unsigned int event;
ULong64_t event;
float tag_pt, tag_eta, tag_phi, probe_pt, probe_eta, probe_phi;
mutable unsigned int count;

Expand Down Expand Up @@ -379,7 +380,7 @@ int main(int argc, char **argv) {

if (nshared1 == nshared2) break;

std::cout << "Swaping trees before repeating." << std::endl;
std::cout << "Swapping trees before repeating." << std::endl;
std::swap(t1,t2);
std::swap(f1,f2);
std::swap(ok1,ok2);
Expand Down
4 changes: 4 additions & 0 deletions test/zmumu/tp_from_aod_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
miniIsoPhotons = cms.InputTag("muonMiniIsoPhotons","miniIso"),
activity_miniIsoPhotons = cms.InputTag("muonMiniIsoPhotons","activity"),
nSplitTk = cms.InputTag("splitTrackTagger"),
mt = cms.InputTag("probeMetMt","mt"),
),
flags = cms.PSet(
TrackQualityFlags,
Expand Down Expand Up @@ -240,6 +241,8 @@
#mu17ps = cms.InputTag("l1hltprescale","HLTMu17TotalPrescale"),
#mu8ps = cms.InputTag("l1hltprescale","HLTMu8TotalPrescale"),
instLumi = cms.InputTag("addEventInfo", "instLumi"),
met = cms.InputTag("tagMetMt","met"),
mt = cms.InputTag("tagMetMt","mt"),
),
tagFlags = cms.PSet(HighPtTriggerFlags,HighPtTriggerFlagsDebug),
pairVariables = cms.PSet(
Expand Down Expand Up @@ -288,6 +291,7 @@
process.mvaIsoVariablesSeq * process.mvaIsoVariablesTag * process.radialIso +
process.splitTrackTagger +
process.muonDxyPVdzmin +
process.probeMetMt + process.tagMetMt +
process.miniIsoSeq +
# process.ak4PFCHSJetsL1L2L3 +
process.ak4PFCHSL1FastL2L3CorrectorChain * process.jetAwareCleaner +
Expand Down
4 changes: 4 additions & 0 deletions test/zmumu/tp_from_aod_MC.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
miniIsoPhotons = cms.InputTag("muonMiniIsoPhotons","miniIso"),
activity_miniIsoPhotons = cms.InputTag("muonMiniIsoPhotons","activity"),
nSplitTk = cms.InputTag("splitTrackTagger"),
mt = cms.InputTag("probeMetMt","mt"),
),
flags = cms.PSet(
TrackQualityFlags,
Expand Down Expand Up @@ -192,6 +193,8 @@
dzPV = cms.InputTag("muonDxyPVdzminTags","dzPV"),
radialIso = cms.InputTag("radialIso"),
nSplitTk = cms.InputTag("splitTrackTagger"),
met = cms.InputTag("tagMetMt","met"),
mt = cms.InputTag("tagMetMt","mt"),
),
tagFlags = cms.PSet(HighPtTriggerFlags,HighPtTriggerFlagsDebug),
pairVariables = cms.PSet(
Expand Down Expand Up @@ -248,6 +251,7 @@
process.mvaIsoVariablesSeq * process.mvaIsoVariablesTag * process.radialIso +
process.splitTrackTagger +
process.muonDxyPVdzmin +
process.probeMetMt + process.tagMetMt +
process.miniIsoSeq +
# process.ak4PFCHSJetsL1L2L3 +
process.ak4PFCHSL1FastL2L3CorrectorChain * process.jetAwareCleaner +
Expand Down

0 comments on commit 7b49ce0

Please sign in to comment.