Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-23 02:30:04

0001 #include "FWCore/Framework/interface/Frameworkfwd.h"
0002 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0003 
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/Utilities/interface/InputTag.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "DataFormats/Common/interface/Handle.h"
0008 
0009 #include "FWCore/ServiceRegistry/interface/Service.h"
0010 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0011 
0012 //#include "DataFormats/TrackReco/interface/Track.h"
0013 //#include "Geometry/Records/interface/MuonGeometryRecord.h"
0014 //#include "Geometry/CommonDetUnit/interface/GeomDet.h"
0015 #include "DataFormats/MuonReco/interface/Muon.h"
0016 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0017 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
0018 
0019 #include "DataFormats/Provenance/interface/RunLumiEventNumber.h"
0020 
0021 #include "TTree.h"
0022 #include "TH1F.h"
0023 #include "TH2F.h"
0024 
0025 #include <iostream>
0026 #include <cmath>
0027 #include <vector>
0028 
0029 using namespace std;
0030 using namespace edm;
0031 using namespace reco;
0032 
0033 class RPCMuonAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0034 public:
0035   RPCMuonAnalyzer(const edm::ParameterSet& pset);
0036   ~RPCMuonAnalyzer() override{};
0037 
0038   void analyze(const edm::Event& event, const edm::EventSetup& eventSetup) override;
0039   void beginJob() override{};
0040   void endJob() override{};
0041 
0042 private:
0043   edm::InputTag muonLabel_;
0044   edm::EDGetTokenT<edm::View<reco::Muon>> muonToken_;
0045   double minPtTrk_;
0046   double maxEtaTrk_;
0047 
0048   edm::RunNumber_t runNumber;
0049   edm::EventNumber_t eventNumber;
0050   Int_t nMuon;
0051   Int_t nGlbMuon, nStaMuon, nTrkMuon;
0052   Int_t nRPCMuon, nRPCMuTight;
0053   Int_t nTrkMuTight, nTrkMuTight2;
0054   Int_t nGlbMuTight, nGlbMuTight2, nGlbMuTighter, nGlbMuTighter2;
0055 
0056   TH1F* hNMuon_;
0057   TH1F* hNRPCMuon_;
0058   TH1F* hNRPCMuTight_;
0059   TH1F* hNTrkMuTight_;
0060   TH1F* hNTrkMuTight2_;
0061   TH1F* hNGlbMuTight_;
0062   TH1F* hNGlbMuTight2_;
0063   TH1F* hNGlbMuTighter_;
0064   TH1F* hNGlbMuTighter2_;
0065 
0066   TH2F* hIdCorrelation_;
0067   TH2F* hIdCorrelationB_;
0068   TH2F* hIdCorrelationO_;
0069   TH2F* hIdCorrelationE_;
0070 };
0071 
0072 RPCMuonAnalyzer::RPCMuonAnalyzer(const edm::ParameterSet& pset) {
0073   muonLabel_ = pset.getUntrackedParameter<edm::InputTag>("muon");
0074   muonToken_ = consumes(muonLabel_);
0075   minPtTrk_ = pset.getUntrackedParameter<double>("minPtTrk");
0076   maxEtaTrk_ = pset.getUntrackedParameter<double>("maxEtaTrk");
0077 
0078   edm::Service<TFileService> fs;
0079   usesResource(TFileService::kSharedResource);
0080 
0081   hNMuon_ = fs->make<TH1F>("hNMuon", "Number of muons;Number of muons", 10, 0, 10);
0082   hNRPCMuon_ = fs->make<TH1F>("hNRPCMuon", "Number of RPC muons;Number of muons", 10, 0, 10);
0083   hNRPCMuTight_ = fs->make<TH1F>("hNRPCMuTight", "Number of RPCMuTight;Number of muons", 10, 0, 10);
0084   hNTrkMuTight_ = fs->make<TH1F>("hNTrkMuTight", "Number of TrkMuTight muons;Number of muons", 10, 0, 10);
0085   hNTrkMuTight2_ = fs->make<TH1F>("hNTrkMuTight2", "Number of TrkMuTight muons;Number of muons", 10, 0, 10);
0086   hNGlbMuTight_ = fs->make<TH1F>("hNGlbMuTight", "Number of GlobalMuPromptTight muons;Number of muons", 10, 0, 10);
0087   hNGlbMuTight2_ = fs->make<TH1F>("hNGlbMuTight2", "Number of GlobalMuPromptTight muons;Number of muons", 10, 0, 10);
0088   hNGlbMuTighter_ = fs->make<TH1F>("hNGlbMuTighter", "Number of GlobalMuPromptTight muons;Number of muons", 10, 0, 10);
0089   hNGlbMuTighter2_ =
0090       fs->make<TH1F>("hNGlbMuTighter2", "Number of GlobalMuPromptTight muons;Number of muons", 10, 0, 10);
0091 
0092   const char* idNames[] = {"All",
0093                            "AllGlbMu",
0094                            "AllStaMu",
0095                            "AllTrkMu",
0096                            "AllRPCMu",
0097                            "RPCMuTight",
0098                            "TMOneStationTight",
0099                            "TMOneStationTight+",
0100                            "GlbPromptTight",
0101                            "GlbPromptTight+",
0102                            "GlbPromptTighter",
0103                            "GlbPromptTighter+"};
0104   const int nId = sizeof(idNames) / sizeof(const char*);
0105   hIdCorrelation_ = fs->make<TH2F>("hIdCorrelation", "ID correlation", nId, 0, nId, nId, 0, nId);
0106   hIdCorrelationB_ = fs->make<TH2F>("hIdCorrelationBarrel", "ID correlation (Barrel)", nId, 0, nId, nId, 0, nId);
0107   hIdCorrelationO_ = fs->make<TH2F>("hIdCorrelationOverlap", "ID correlation (Overlap)", nId, 0, nId, nId, 0, nId);
0108   hIdCorrelationE_ = fs->make<TH2F>("hIdCorrelationEndcap", "ID correlation (Endcap)", nId, 0, nId, nId, 0, nId);
0109   for (int i = 0; i < nId; ++i) {
0110     hIdCorrelation_->GetXaxis()->SetBinLabel(i + 1, idNames[i]);
0111     hIdCorrelation_->GetYaxis()->SetBinLabel(i + 1, idNames[i]);
0112     hIdCorrelationB_->GetXaxis()->SetBinLabel(i + 1, idNames[i]);
0113     hIdCorrelationB_->GetYaxis()->SetBinLabel(i + 1, idNames[i]);
0114     hIdCorrelationO_->GetXaxis()->SetBinLabel(i + 1, idNames[i]);
0115     hIdCorrelationO_->GetYaxis()->SetBinLabel(i + 1, idNames[i]);
0116     hIdCorrelationE_->GetXaxis()->SetBinLabel(i + 1, idNames[i]);
0117     hIdCorrelationE_->GetYaxis()->SetBinLabel(i + 1, idNames[i]);
0118   }
0119   hIdCorrelation_->SetOption("COLZ");
0120   hIdCorrelationB_->SetOption("COLZ");
0121   hIdCorrelationO_->SetOption("COLZ");
0122   hIdCorrelationE_->SetOption("COLZ");
0123 }
0124 
0125 void RPCMuonAnalyzer::analyze(const edm::Event& event, const edm::EventSetup& eventSetup) {
0126   // select the event
0127   runNumber = event.id().run();
0128   eventNumber = event.id().event();
0129 
0130   edm::Handle<edm::View<reco::Muon>> muonHandle = event.getHandle(muonToken_);
0131 
0132   //nMuon = muonHandle->size();
0133   nMuon = 0;
0134   nGlbMuon = 0, nStaMuon = 0, nTrkMuon = 0;
0135   nRPCMuon = 0, nRPCMuTight = 0;
0136   nTrkMuTight = 0, nTrkMuTight2 = 0;
0137   nGlbMuTight = 0, nGlbMuTight2 = 0, nGlbMuTighter = 0, nGlbMuTighter2 = 0;
0138   for (edm::View<reco::Muon>::const_iterator muon = muonHandle->begin(); muon != muonHandle->end(); ++muon) {
0139     if (muon->pt() < minPtTrk_)
0140       continue;
0141     const double abseta = abs(muon->eta());
0142     if (abseta > maxEtaTrk_)
0143       continue;
0144 
0145     const bool idFlags[] = {true,
0146                             muon->isGlobalMuon(),
0147                             muon->isStandAloneMuon(),
0148                             muon->isTrackerMuon(),
0149                             muon->isRPCMuon(),
0150                             muon::isGoodMuon(*muon, muon::RPCMuLoose) &&
0151                                 muon->numberOfMatchedStations(reco::Muon::RPCHitAndTrackArbitration) > 1 &&
0152                                 muon->numberOfMatchedRPCLayers(reco::Muon::RPCHitAndTrackArbitration) > 2,
0153                             muon::isGoodMuon(*muon, muon::TMOneStationTight),
0154                             muon::isGoodMuon(*muon, muon::TMOneStationTight) ||
0155                                 (muon::isGoodMuon(*muon, muon::RPCMuLoose) &&
0156                                  muon->numberOfMatchedStations(reco::Muon::RPCHitAndTrackArbitration) > 1 &&
0157                                  muon->numberOfMatchedRPCLayers(reco::Muon::RPCHitAndTrackArbitration) > 2),
0158                             muon::isGoodMuon(*muon, muon::GlobalMuonPromptTight),
0159                             muon::isGoodMuon(*muon, muon::GlobalMuonPromptTight) ||
0160                                 (muon::isGoodMuon(*muon, muon::RPCMuLoose) &&
0161                                  muon->numberOfMatchedStations(reco::Muon::RPCHitAndTrackArbitration) > 1 &&
0162                                  muon->numberOfMatchedRPCLayers(reco::Muon::RPCHitAndTrackArbitration) > 2),
0163                             muon::isGoodMuon(*muon, muon::GlobalMuonPromptTight) &&
0164                                 muon->numberOfMatchedStations(reco::Muon::SegmentAndTrackArbitration) > 1,
0165                             (muon::isGoodMuon(*muon, muon::GlobalMuonPromptTight) &&
0166                              muon->numberOfMatchedStations(reco::Muon::SegmentAndTrackArbitration) > 1) ||
0167                                 (muon::isGoodMuon(*muon, muon::RPCMuLoose) &&
0168                                  muon->numberOfMatchedStations(reco::Muon::RPCHitAndTrackArbitration) > 1 &&
0169                                  muon->numberOfMatchedRPCLayers(reco::Muon::RPCHitAndTrackArbitration) > 2)};
0170 
0171     ++nMuon;
0172     if (idFlags[1])
0173       ++nGlbMuon;
0174     if (idFlags[2])
0175       ++nStaMuon;
0176     if (idFlags[3])
0177       ++nTrkMuon;
0178 
0179     if (idFlags[4])
0180       ++nRPCMuon;
0181     if (idFlags[5])
0182       ++nRPCMuTight;
0183     if (idFlags[6])
0184       ++nTrkMuTight;
0185     if (idFlags[7])
0186       ++nTrkMuTight2;
0187 
0188     if (idFlags[8])
0189       ++nGlbMuTight;
0190     if (idFlags[9])
0191       ++nGlbMuTight2;
0192     if (idFlags[10])
0193       ++nGlbMuTighter;
0194     if (idFlags[11])
0195       ++nGlbMuTighter2;
0196 
0197     // Fill correlation matrix
0198     for (int i = 0, n = sizeof(idFlags) / sizeof(const bool); i < n; ++i) {
0199       for (int j = i; j < n; ++j) {
0200         if (idFlags[i] and idFlags[j]) {
0201           hIdCorrelation_->Fill(i, j);
0202           if (abseta < 0.8)
0203             hIdCorrelationB_->Fill(i, j);
0204           else if (abseta < 1.2)
0205             hIdCorrelationO_->Fill(i, j);
0206           else
0207             hIdCorrelationE_->Fill(i, j);
0208         }
0209       }
0210     }
0211   }
0212 
0213   hNMuon_->Fill(nMuon);
0214   hNRPCMuon_->Fill(nRPCMuon);
0215   hNRPCMuTight_->Fill(nRPCMuTight);
0216   hNTrkMuTight_->Fill(nTrkMuTight);
0217   hNTrkMuTight2_->Fill(nTrkMuTight2);
0218   hNGlbMuTight_->Fill(nGlbMuTight);
0219   hNGlbMuTight2_->Fill(nGlbMuTight2);
0220   hNGlbMuTighter_->Fill(nGlbMuTighter);
0221   hNGlbMuTighter2_->Fill(nGlbMuTighter2);
0222 }
0223 
0224 #include "FWCore/Framework/interface/MakerMacros.h"
0225 DEFINE_FWK_MODULE(RPCMuonAnalyzer);