Skip to content

Commit

Permalink
Merge pull request #3 from konush/hiforest_ggAnalysis_muons
Browse files Browse the repository at this point in the history
Added reco muons to ggHiAnalysis
  • Loading branch information
R. Alex Barbieri committed Jan 23, 2015
2 parents 842a934 + 2ea9950 commit 3b58642
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 17 deletions.
30 changes: 29 additions & 1 deletion HeavyIonsAnalysis/PhotonAnalysis/interface/ggHiNtuplizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "DataFormats/HepMCCandidate/interface/GenParticle.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
#include "DataFormats/EgammaCandidates/interface/Photon.h"
#include "DataFormats/MuonReco/interface/Muon.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"

Expand All @@ -28,8 +29,9 @@ class ggHiNtuplizer : public edm::EDAnalyzer {

void fillGenParticles (const edm::Event&);
void fillGenPileupInfo(const edm::Event&);
void fillElectrons (const edm::Event&, const edm::EventSetup&);
void fillElectrons (const edm::Event&, const edm::EventSetup&, math::XYZPoint& pv);
void fillPhotons (const edm::Event&, const edm::EventSetup&);
void fillMuons (const edm::Event&, const edm::EventSetup&, math::XYZPoint& pv);

// Et and pT sums
float getGenCalIso(edm::Handle<vector<reco::GenParticle> >&, reco::GenParticleCollection::const_iterator, float dRMax, bool removeMu, bool removeNu);
Expand All @@ -44,6 +46,7 @@ class ggHiNtuplizer : public edm::EDAnalyzer {
edm::EDGetTokenT<vector<reco::GenParticle> > genParticlesCollection_;
edm::EDGetTokenT<edm::View<reco::GsfElectron> > gsfElectronsCollection_;
edm::EDGetTokenT<edm::View<reco::Photon> > recoPhotonsCollection_;
edm::EDGetTokenT<edm::View<reco::Muon> > recoMuonsCollection_;
edm::EDGetTokenT<EcalRecHitCollection> ebRecHitCollection_;
edm::EDGetTokenT<EcalRecHitCollection> eeRecHitCollection_;
edm::EDGetTokenT<vector<reco::Vertex> > vtxCollection_;
Expand Down Expand Up @@ -163,6 +166,31 @@ class ggHiNtuplizer : public edm::EDAnalyzer {
vector<float> phoBC1Eta_;
vector<float> phoBC2E_;
vector<float> phoBC2Eta_;

// reco::Muon
Int_t nMu_;
vector<float> muPt_;
vector<float> muEta_;
vector<float> muPhi_;
vector<int> muCharge_;
vector<int> muType_;
vector<int> muIsGood_;
vector<float> muD0_;
vector<float> muDz_;
vector<float> muChi2NDF_;
vector<float> muInnerD0_;
vector<float> muInnerDz_;
vector<int> muTrkLayers_;
vector<int> muPixelLayers_;
vector<int> muPixelHits_;
vector<int> muMuonHits_;
vector<int> muTrkQuality_;
vector<int> muStations_;
vector<float> muIsoTrk_;
vector<float> muPFChIso_;
vector<float> muPFPhoIso_;
vector<float> muPFNeuIso_;
vector<float> muPFPUIso_;
};

#endif
138 changes: 122 additions & 16 deletions HeavyIonsAnalysis/PhotonAnalysis/plugins/ggHiNtuplizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "CommonTools/UtilAlgos/interface/TFileService.h"
#include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h"
#include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
#include "DataFormats/MuonReco/interface/MuonSelectors.h"

#include "HeavyIonsAnalysis/PhotonAnalysis/interface/ggHiNtuplizer.h"
#include "HeavyIonsAnalysis/PhotonAnalysis/interface/GenParticleParentage.h"
Expand All @@ -19,6 +20,7 @@ ggHiNtuplizer::ggHiNtuplizer(const edm::ParameterSet& ps)
genParticlesCollection_ = consumes<vector<reco::GenParticle> > (ps.getParameter<edm::InputTag>("genParticleSrc"));
gsfElectronsCollection_ = consumes<edm::View<reco::GsfElectron> >(ps.getParameter<edm::InputTag>("gsfElectronLabel"));
recoPhotonsCollection_ = consumes<edm::View<reco::Photon> > (ps.getParameter<edm::InputTag>("recoPhotonSrc"));
recoMuonsCollection_ = consumes<edm::View<reco::Muon> > (ps.getParameter<edm::InputTag>("recoMuonSrc"));
ebRecHitCollection_ = consumes<EcalRecHitCollection> (ps.getParameter<edm::InputTag>("ebRecHitCollection"));
eeRecHitCollection_ = consumes<EcalRecHitCollection> (ps.getParameter<edm::InputTag>("eeRecHitCollection"));
vtxCollection_ = consumes<vector<reco::Vertex> > (ps.getParameter<edm::InputTag>("VtxLabel"));
Expand Down Expand Up @@ -137,6 +139,30 @@ ggHiNtuplizer::ggHiNtuplizer(const edm::ParameterSet& ps)
tree_->Branch("phoBC1Eta", &phoBC1Eta_);
tree_->Branch("phoBC2E", &phoBC2E_);
tree_->Branch("phoBC2Eta", &phoBC2Eta_);

tree_->Branch("nMu", &nMu_);
tree_->Branch("muPt", &muPt_);
tree_->Branch("muEta", &muEta_);
tree_->Branch("muPhi", &muPhi_);
tree_->Branch("muCharge", &muCharge_);
tree_->Branch("muType", &muType_);
tree_->Branch("muIsGood", &muIsGood_);
tree_->Branch("muD0", &muD0_);
tree_->Branch("muDz", &muDz_);
tree_->Branch("muChi2NDF", &muChi2NDF_);
tree_->Branch("muInnerD0", &muInnerD0_);
tree_->Branch("muInnerDz", &muInnerDz_);
tree_->Branch("muTrkLayers", &muTrkLayers_);
tree_->Branch("muPixelLayers", &muPixelLayers_);
tree_->Branch("muPixelHits", &muPixelHits_);
tree_->Branch("muMuonHits", &muMuonHits_);
tree_->Branch("muTrkQuality", &muTrkQuality_);
tree_->Branch("muStations", &muStations_);
tree_->Branch("muIsoTrk", &muIsoTrk_);
tree_->Branch("muPFChIso", &muPFChIso_);
tree_->Branch("muPFPhoIso", &muPFPhoIso_);
tree_->Branch("muPFNeuIso", &muPFNeuIso_);
tree_->Branch("muPFPUIso", &muPFPUIso_);
}

void ggHiNtuplizer::analyze(const edm::Event& e, const edm::EventSetup& es)
Expand All @@ -147,6 +173,7 @@ void ggHiNtuplizer::analyze(const edm::Event& e, const edm::EventSetup& es)
nMC_ = 0;
nEle_ = 0;
nPho_ = 0;
nMu_ = 0;

nPU_ .clear();
puBX_ .clear();
Expand Down Expand Up @@ -248,6 +275,29 @@ void ggHiNtuplizer::analyze(const edm::Event& e, const edm::EventSetup& es)
phoBC2E_ .clear();
phoBC2Eta_ .clear();

muPt_ .clear();
muEta_ .clear();
muPhi_ .clear();
muCharge_ .clear();
muType_ .clear();
muIsGood_ .clear();
muD0_ .clear();
muDz_ .clear();
muChi2NDF_ .clear();
muInnerD0_ .clear();
muInnerDz_ .clear();
muTrkLayers_ .clear();
muPixelLayers_ .clear();
muPixelHits_ .clear();
muMuonHits_ .clear();
muTrkQuality_ .clear();
muStations_ .clear();
muIsoTrk_ .clear();
muPFChIso_ .clear();
muPFPhoIso_ .clear();
muPFNeuIso_ .clear();
muPFPUIso_ .clear();

run_ = e.id().run();
event_ = e.id().event();
lumis_ = e.luminosityBlock();
Expand All @@ -259,8 +309,20 @@ void ggHiNtuplizer::analyze(const edm::Event& e, const edm::EventSetup& es)
fillGenParticles(e);
}

fillElectrons(e, es);
edm::Handle<vector<reco::Vertex> > vtxHandle;
e.getByToken(vtxCollection_, vtxHandle);

// best-known primary vertex coordinates
math::XYZPoint pv(0, 0, 0);
for (vector<reco::Vertex>::const_iterator v = vtxHandle->begin(); v != vtxHandle->end(); ++v)
if (!v->isFake()) {
pv.SetXYZ(v->x(), v->y(), v->z());
break;
}

fillElectrons(e, es, pv);
fillPhotons(e, es);
fillMuons(e, es, pv);

tree_->Fill();
}
Expand Down Expand Up @@ -439,27 +501,16 @@ float ggHiNtuplizer::getGenTrkIso(edm::Handle<vector<reco::GenParticle> > &handl
return ptSum;
}

void ggHiNtuplizer::fillElectrons(const edm::Event& e, const edm::EventSetup& es)
void ggHiNtuplizer::fillElectrons(const edm::Event& e, const edm::EventSetup& es, math::XYZPoint& pv)
{
// Fills tree branches with reco GSF electrons.

edm::Handle<edm::View<reco::GsfElectron> > gsfElectronsHandle;
e.getByToken(gsfElectronsCollection_, gsfElectronsHandle);

edm::Handle<vector<reco::Vertex> > vtxHandle;
e.getByToken(vtxCollection_, vtxHandle);

EcalClusterLazyTools lazyTool (e, es, ebRecHitCollection_, eeRecHitCollection_);
noZS::EcalClusterLazyTools lazyTool_noZS(e, es, ebRecHitCollection_, eeRecHitCollection_);

// best-known primary vertex coordinates
math::XYZPoint pv(0, 0, 0);
for (vector<reco::Vertex>::const_iterator v = vtxHandle->begin(); v != vtxHandle->end(); ++v)
if (!v->isFake()) {
pv.SetXYZ(v->x(), v->y(), v->z());
break;
}

// loop over electrons
for (edm::View<reco::GsfElectron>::const_iterator ele = gsfElectronsHandle->begin(); ele != gsfElectronsHandle->end(); ++ele) {
eleCharge_ .push_back(ele->charge());
Expand Down Expand Up @@ -527,9 +578,6 @@ void ggHiNtuplizer::fillPhotons(const edm::Event& e, const edm::EventSetup& es)
edm::Handle<edm::View<reco::Photon> > recoPhotonsHandle;
e.getByToken(recoPhotonsCollection_, recoPhotonsHandle);

edm::Handle<vector<reco::Vertex> > vtxHandle;
e.getByToken(vtxCollection_, vtxHandle);

EcalClusterLazyTools lazyTool (e, es, ebRecHitCollection_, eeRecHitCollection_);
noZS::EcalClusterLazyTools lazyTool_noZS(e, es, ebRecHitCollection_, eeRecHitCollection_);

Expand Down Expand Up @@ -593,4 +641,62 @@ void ggHiNtuplizer::fillPhotons(const edm::Event& e, const edm::EventSetup& es)
} // photons loop
}

void ggHiNtuplizer::fillMuons(const edm::Event& e, const edm::EventSetup& es, math::XYZPoint& pv)
{
// Fills tree branches with reco muons.

edm::Handle<edm::View<reco::Muon> > recoMuonsHandle;
e.getByToken(recoMuonsCollection_, recoMuonsHandle);

for (edm::View<reco::Muon>::const_iterator mu = recoMuonsHandle->begin(); mu != recoMuonsHandle->end(); ++mu) {
if (mu->pt() < 5) continue;
if (!(mu->isPFMuon() || mu->isGlobalMuon() || mu->isTrackerMuon())) continue;

muPt_ .push_back(mu->pt());
muEta_ .push_back(mu->eta());
muPhi_ .push_back(mu->phi());
muCharge_.push_back(mu->charge());
muType_ .push_back(mu->type());
muIsGood_.push_back((int) muon::isGoodMuon(*mu, muon::selectionTypeFromString("TMOneStationTight")));
muD0_ .push_back(mu->muonBestTrack()->dxy(pv));
muDz_ .push_back(mu->muonBestTrack()->dz(pv));

const reco::TrackRef glbMu = mu->globalTrack();
const reco::TrackRef innMu = mu->innerTrack();

if (glbMu.isNull()) {
muChi2NDF_ .push_back(-99);
muMuonHits_.push_back(-99);
} else {
muChi2NDF_.push_back(glbMu->normalizedChi2());
muMuonHits_.push_back(glbMu->hitPattern().numberOfValidMuonHits());
}

if (innMu.isNull()) {
muInnerD0_ .push_back(-99);
muInnerDz_ .push_back(-99);
muTrkLayers_ .push_back(-99);
muPixelLayers_ .push_back(-99);
muPixelHits_ .push_back(-99);
muTrkQuality_ .push_back(-99);
} else {
muInnerD0_ .push_back(innMu->dxy(pv));
muInnerDz_ .push_back(innMu->dz(pv));
muTrkLayers_ .push_back(innMu->hitPattern().trackerLayersWithMeasurement());
muPixelLayers_ .push_back(innMu->hitPattern().pixelLayersWithMeasurement());
muPixelHits_ .push_back(innMu->hitPattern().numberOfValidPixelHits());
muTrkQuality_ .push_back(innMu->quality(reco::TrackBase::highPurity));
}

muStations_ .push_back(mu->numberOfMatchedStations());
muIsoTrk_ .push_back(mu->isolationR03().sumPt);
muPFChIso_ .push_back(mu->pfIsolationR04().sumChargedHadronPt);
muPFPhoIso_ .push_back(mu->pfIsolationR04().sumPhotonEt);
muPFNeuIso_ .push_back(mu->pfIsolationR04().sumNeutralHadronEt);
muPFPUIso_ .push_back(mu->pfIsolationR04().sumPUPt);

nMu_++;
} // muons loop
}

DEFINE_FWK_MODULE(ggHiNtuplizer);
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
genParticleSrc = cms.InputTag("hiGenParticles"),
gsfElectronLabel = cms.InputTag("ecalDrivenGsfElectrons"),
recoPhotonSrc = cms.InputTag("photons"),
recoMuonSrc = cms.InputTag("muons"),
ebRecHitCollection = cms.InputTag("ecalRecHit", "EcalRecHitsEB"),
eeRecHitCollection = cms.InputTag("ecalRecHit", "EcalRecHitsEE"),
VtxLabel = cms.InputTag("hiSelectedVertex"),
Expand Down

0 comments on commit 3b58642

Please sign in to comment.