File indexing completed on 2024-04-06 12:27:04
0001 #ifndef RecoMuon_MuonIdentification_TestMuon_H
0002 #define RecoMuon_MuonIdentification_TestMuon_H
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include "FWCore/Framework/interface/Frameworkfwd.h"
0013 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/EventSetup.h"
0016 #include "FWCore/Framework/interface/MakerMacros.h"
0017 #include "DataFormats/Common/interface/Handle.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "DataFormats/Common/interface/View.h"
0020
0021 #include "DataFormats/MuonReco/interface/Muon.h"
0022 #include "DataFormats/MuonReco/interface/MuonTimeExtra.h"
0023 #include "DataFormats/MuonReco/interface/MuonTimeExtraMap.h"
0024
0025 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0026 #include "DataFormats/TrackReco/interface/Track.h"
0027
0028 class TestMuons : public edm::one::EDAnalyzer<> {
0029 public:
0030 explicit TestMuons(const edm::ParameterSet&);
0031 virtual ~TestMuons() {}
0032
0033 virtual void analyze(const edm::Event&, const edm::EventSetup&);
0034 void printMuonCollections(const edm::Handle<edm::View<reco::Muon>>& muons);
0035 void checkTimeMaps(const edm::Event& iEvent, const edm::Handle<reco::MuonCollection>& muons);
0036 void checkPFMap(const edm::Event& iEvent, const edm::Handle<reco::MuonCollection>& muons);
0037
0038 private:
0039 edm::InputTag theInput;
0040 edm::EDGetTokenT<edm::View<reco::Muon>> theMuonsVToken;
0041 edm::EDGetTokenT<reco::MuonCollection> theMuonsToken;
0042 };
0043 #endif
0044
0045 TestMuons::TestMuons(const edm::ParameterSet& iConfig) {
0046 theInput = iConfig.getParameter<edm::InputTag>("InputCollection");
0047 theMuonsVToken = consumes(theInput);
0048 theMuonsToken = consumes(theInput);
0049 }
0050
0051 void TestMuons::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0052 edm::Handle<edm::View<reco::Muon>> muonsV = iEvent.getHandle(theMuonsVToken);
0053 printMuonCollections(muonsV);
0054
0055 edm::Handle<reco::MuonCollection> muons = iEvent.getHandle(theMuonsToken);
0056
0057 checkTimeMaps(iEvent, muons);
0058 checkPFMap(iEvent, muons);
0059 }
0060
0061 void TestMuons::checkTimeMaps(const edm::Event& iEvent, const edm::Handle<reco::MuonCollection>& muons) {
0062 std::cout << "checkTimeMaps" << std::endl;
0063
0064 edm::Handle<reco::MuonTimeExtraMap> timeMapCmb;
0065 edm::Handle<reco::MuonTimeExtraMap> timeMapDT;
0066 edm::Handle<reco::MuonTimeExtraMap> timeMapCSC;
0067
0068 iEvent.getByLabel(theInput.label(), "combined", timeMapCmb);
0069 iEvent.getByLabel(theInput.label(), "dt", timeMapDT);
0070 iEvent.getByLabel(theInput.label(), "csc", timeMapCSC);
0071
0072 for (unsigned int imucount = 0; imucount < muons->size(); ++imucount) {
0073 reco::MuonRef muonR(muons, imucount);
0074 std::cout << "Ref: " << muonR.id() << " " << muonR.key() << " Time CMB " << (*timeMapCmb)[muonR].timeAtIpInOut()
0075 << " time DT " << (*timeMapDT)[muonR].timeAtIpInOut() << " time CSC "
0076 << (*timeMapCSC)[muonR].timeAtIpInOut() << std::endl;
0077 }
0078 }
0079
0080 void TestMuons::printMuonCollections(const edm::Handle<edm::View<reco::Muon>>& muons) {
0081 for (edm::View<reco::Muon>::const_iterator muon = muons->begin(); muon != muons->end(); ++muon) {
0082 std::cout << "\n----------------------------------------------------" << std::endl;
0083 std::cout << "Muon (pt,eta,phi): " << muon->pt() << ", " << muon->eta() << ", " << muon->phi() << std::endl;
0084 std::cout << "\t energy (ecal, hcal, ho): " << muon->calEnergy().em << ", " << muon->calEnergy().had << ", "
0085 << muon->calEnergy().ho << std::endl;
0086 std::cout << "\t isolation dR=0.3 (sumPt, emEt, hadEt, hoEt, nTracks, nJets): " << muon->isolationR03().sumPt
0087 << ", " << muon->isolationR03().emEt << ", " << muon->isolationR03().hadEt << ", "
0088 << muon->isolationR03().hoEt << ", " << muon->isolationR03().nTracks << ", " << muon->isolationR03().nJets
0089 << std::endl;
0090 std::cout << "\t isolation dR=0.5 (sumPt, emEt, hadEt, hoEt, nTracks, nJets): " << muon->isolationR05().sumPt
0091 << ", " << muon->isolationR05().emEt << ", " << muon->isolationR05().hadEt << ", "
0092 << muon->isolationR05().hoEt << ", " << muon->isolationR05().nTracks << ", " << muon->isolationR05().nJets
0093 << std::endl;
0094 std::cout << "\t # matches: " << muon->numberOfMatches() << std::endl;
0095 std::cout << "\t # caloCompatibility: " << muon->caloCompatibility() << std::endl;
0096
0097 if (muon->isAValidMuonTrack(reco::Muon::TPFMS))
0098 std::cout << "TPFMS pt: " << muon->tpfmsTrack()->pt() << std::endl;
0099
0100 if (muon->isAValidMuonTrack(reco::Muon::Picky))
0101 std::cout << "Picky pt: " << muon->pickyTrack()->pt() << std::endl;
0102
0103 if (muon->isAValidMuonTrack(reco::Muon::DYT))
0104 std::cout << "DYT pt: " << muon->dytTrack()->pt() << std::endl;
0105
0106 if (muon->isPFIsolationValid()) {
0107 std::cout << "PF Isolation is Valid." << std::endl
0108 << "Iso 0.3, (sumChargedHadronPt, sumChargedParticlePt, sumNeutralHadronEt, sumPhotonEt, "
0109 "sumNeutralHadronEtHighThreshold, sumPhotonEtHighThreshold, sumPUPt): "
0110 << muon->pfIsolationR03().sumChargedHadronPt << ", " << muon->pfIsolationR03().sumChargedParticlePt
0111 << ", " << muon->pfIsolationR03().sumNeutralHadronEt << ", " << muon->pfIsolationR03().sumPhotonEt
0112 << ", " << muon->pfIsolationR03().sumNeutralHadronEtHighThreshold << ", "
0113 << muon->pfIsolationR03().sumPhotonEtHighThreshold << ", " << muon->pfIsolationR03().sumPUPt
0114 << std::endl;
0115 std::cout << "Iso 0.4, (sumChargedHadronPt, sumChargedParticlePt, sumNeutralHadronEt, sumPhotonEt, "
0116 "sumNeutralHadronEtHighThreshold, sumPhotonEtHighThreshold, sumPUPt): "
0117 << muon->pfIsolationR04().sumChargedHadronPt << ", " << muon->pfIsolationR04().sumChargedParticlePt
0118 << ", " << muon->pfIsolationR04().sumNeutralHadronEt << ", " << muon->pfIsolationR04().sumPhotonEt
0119 << ", " << muon->pfIsolationR04().sumNeutralHadronEtHighThreshold << ", "
0120 << muon->pfIsolationR04().sumPhotonEtHighThreshold << ", " << muon->pfIsolationR04().sumPUPt
0121 << std::endl;
0122 }
0123 }
0124 }
0125
0126 void TestMuons::checkPFMap(const edm::Event& iEvent, const edm::Handle<reco::MuonCollection>& muons) {
0127 std::cout << "checkPFMaps" << std::endl;
0128
0129 edm::Handle<edm::ValueMap<reco::PFCandidatePtr>> pfMap;
0130 iEvent.getByLabel("particleFlow", theInput.label(), pfMap);
0131
0132 for (unsigned int imucount = 0; imucount < muons->size(); ++imucount) {
0133 reco::MuonRef muonR(muons, imucount);
0134 if ((*pfMap)[muonR].isNonnull())
0135 std::cout << "PfCand muon pT: " << (*pfMap)[muonR]->muonRef()->pt() << " Muon pT: " << muonR->pt() << std::endl;
0136 }
0137 }
0138
0139
0140 DEFINE_FWK_MODULE(TestMuons);