Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:14

0001 #include "DQM/RPCMonitorDigi/interface/RPCRecHitProbability.h"
0002 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0003 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0004 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHit.h"
0007 
0008 #include <TMath.h>
0009 
0010 RPCRecHitProbability::RPCRecHitProbability(const edm::ParameterSet& pset) : counter(0) {
0011   saveRootFile = pset.getUntrackedParameter<bool>("SaveRootFile", false);
0012   RootFileName = pset.getUntrackedParameter<std::string>("RootFileName", "RPCRecHitProbabilityDQM.root");
0013 
0014   muonLabel_ = consumes<reco::CandidateView>(pset.getParameter<edm::InputTag>("MuonLabel"));
0015   muPtCut_ = pset.getUntrackedParameter<double>("MuonPtCut", 3.0);
0016   muEtaCut_ = pset.getUntrackedParameter<double>("MuonEtaCut", 1.9);
0017   scalersRawToDigiLabel_ = consumes<DcsStatusCollection>(pset.getParameter<edm::InputTag>("ScalersRawToDigiLabel"));
0018 
0019   subsystemFolder_ = pset.getUntrackedParameter<std::string>("RPCFolder", "RPC");
0020   globalFolder_ = pset.getUntrackedParameter<std::string>("GlobalFolder", "SummaryHistograms");
0021   muonFolder_ = pset.getUntrackedParameter<std::string>("MuonFolder", "Muon");
0022 }
0023 
0024 void RPCRecHitProbability::bookHistograms(DQMStore::IBooker& ibooker,
0025                                           edm::Run const& r,
0026                                           edm::EventSetup const& iSetup) {
0027   edm::LogInfo("rpcrechitprobability") << "[RPCRecHitProbability]: Begin Run ";
0028 
0029   const std::string currentFolder = subsystemFolder_ + "/" + muonFolder_ + "/" + globalFolder_;
0030   ibooker.setCurrentFolder(currentFolder);
0031 
0032   const int ptBins = 100 - (int)muPtCut_;
0033 
0034   //General part
0035   NumberOfMuonEta_ = ibooker.book1D("NumberOfMuonEta", "Muons vs Eta", 20 * muEtaCut_, -muEtaCut_, muEtaCut_);
0036   NumberOfMuonPt_B_ = ibooker.book1D("NumberOfMuonPt_Barrel", "Muons vs Pt - Barrel", ptBins, muPtCut_, 100);
0037   NumberOfMuonPt_EP_ = ibooker.book1D("NumberOfMuonPt_EndcapP", "Muons vs Pt - Endcap+", ptBins, muPtCut_, 100);
0038   NumberOfMuonPt_EM_ = ibooker.book1D("NumberOfMuonPt_EndcapM", "Muons vs Pt - Endcap-", ptBins, muPtCut_, 100);
0039   NumberOfMuonPhi_B_ =
0040       ibooker.book1D("NumberOfMuonPhi_Barrel", "Muons vs Phi - Barrel", 144, -TMath::Pi(), TMath::Pi());
0041   NumberOfMuonPhi_EP_ =
0042       ibooker.book1D("NumberOfMuonPhi_EndcapP", "Muons vs Phi - Endcap+", 144, -TMath::Pi(), TMath::Pi());
0043   NumberOfMuonPhi_EM_ =
0044       ibooker.book1D("NumberOfMuonPhi_EndcapM", "Muons vs Phi - Endcap-", 144, -TMath::Pi(), TMath::Pi());
0045 
0046   //RPC part
0047   RPCRecHitMuonEta_ = ibooker.book2D(
0048       "RPCRecHitMuonEta", "Number Of RecHits per Muons vs Eta", 20 * muEtaCut_, -muEtaCut_, muEtaCut_, 7, 0.5, 7.5);
0049 
0050   std::stringstream name, title;
0051   for (int i = 0; i < 6; i++) {
0052     name.str("");
0053     title.str("");
0054     name << (i + 1) << "RecHitMuonEta";
0055     title << "At least " << (i + 1) << " Cluster vs Eta";
0056     recHitEta_[i] = ibooker.book1D(name.str(), title.str(), 20 * muEtaCut_, -muEtaCut_, muEtaCut_);
0057 
0058     name.str("");
0059     title.str("");
0060     name << (i + 1) << "RecHitMuonPhiB";
0061     title << "At least " << (i + 1) << " Cluster vs Phi-Barrel";
0062     recHitPhi_B_[i] = ibooker.book1D(name.str(), title.str(), 144, -TMath::Pi(), TMath::Pi());
0063 
0064     name.str("");
0065     title.str("");
0066     name << (i + 1) << "RecHitMuonPtB";
0067     title << "At least " << (i + 1) << " Cluster vs Pt-Barrel";
0068     recHitPt_B_[i] = ibooker.book1D(name.str(), title.str(), ptBins, muPtCut_, 100);
0069 
0070     name.str("");
0071     title.str("");
0072     name << (i + 1) << "RecHitMuonPhiEP";
0073     title << "At least " << (i + 1) << " Cluster vs Phi-Endcap+";
0074     recHitPhi_EP_[i] = ibooker.book1D(name.str(), title.str(), 144, -TMath::Pi(), TMath::Pi());
0075 
0076     name.str("");
0077     title.str("");
0078     name << (i + 1) << "RecHitMuonPtEP";
0079     title << "At least " << (i + 1) << " Cluster vs Pt-Endcap+";
0080     recHitPt_EP_[i] = ibooker.book1D(name.str(), title.str(), ptBins, muPtCut_, 100);
0081 
0082     name.str("");
0083     title.str("");
0084     name << (i + 1) << "RecHitMuonPhiEM";
0085     title << "At least " << (i + 1) << " Cluster vs Phi-Endcap-";
0086     recHitPhi_EM_[i] = ibooker.book1D(name.str(), title.str(), 144, -TMath::Pi(), TMath::Pi());
0087 
0088     name.str("");
0089     title.str("");
0090     name << (i + 1) << "RecHitMuonPtEM";
0091     title << "At least " << (i + 1) << " Cluster vs Pt-Endcap-";
0092     recHitPt_EM_[i] = ibooker.book1D(name.str(), title.str(), ptBins, muPtCut_, 100);
0093   }
0094 
0095   dcs_ = true;
0096 }
0097 
0098 void RPCRecHitProbability::analyze(const edm::Event& event, const edm::EventSetup& setup) {
0099   dcs_ = true;
0100   //Check HV status
0101   this->makeDcsInfo(event);
0102   if (!dcs_) {
0103     edm::LogWarning("rpcrechitprobability") << "[RPCRecHitProbability]: DCS bit OFF";
0104     return;  //if RPC not ON there's no need to continue
0105   }
0106 
0107   counter++;
0108   edm::LogInfo("rpcrechitprobability") << "[RPCRecHitProbability]: Beginning analyzing event " << counter;
0109 
0110   //Muons
0111   edm::Handle<reco::CandidateView> muonCands;
0112   event.getByToken(muonLabel_, muonCands);
0113   std::map<RPCDetId, std::vector<RPCRecHit> > rechitMuon;
0114 
0115   if (muonCands.isValid()) {
0116     int nStaMuons = muonCands->size();
0117 
0118     for (int i = 0; i < nStaMuons; i++) {
0119       const reco::Candidate& goodMuon = (*muonCands)[i];
0120       const reco::Muon* muCand = dynamic_cast<const reco::Muon*>(&goodMuon);
0121 
0122       if (!muCand->isGlobalMuon())
0123         continue;
0124       float eta = muCand->eta();
0125       float pt = muCand->pt();
0126       if (pt < muPtCut_ || fabs(eta) > muEtaCut_)
0127         continue;
0128 
0129       float phi = muCand->phi();
0130 
0131       NumberOfMuonEta_->Fill(eta);
0132 
0133       if (eta > 0.8) {
0134         NumberOfMuonPt_EP_->Fill(pt);
0135         NumberOfMuonPhi_EP_->Fill(phi);
0136       } else if (eta < -0.8) {
0137         NumberOfMuonPt_EM_->Fill(pt);
0138         NumberOfMuonPhi_EM_->Fill(phi);
0139       } else {
0140         NumberOfMuonPt_B_->Fill(pt);
0141         NumberOfMuonPhi_B_->Fill(phi);
0142       }
0143 
0144       reco::Track muTrack = (*(muCand->outerTrack()));
0145       std::vector<TrackingRecHitRef> rpcTrackRecHits;
0146 
0147       //loop on mu rechits
0148 
0149       int recHitCounter = 0;
0150       for (trackingRecHit_iterator it = muTrack.recHitsBegin(); it != muTrack.recHitsEnd(); it++) {
0151         if (!(*it)->isValid())
0152           continue;
0153         int muSubDetId = (*it)->geographicalId().subdetId();
0154         if (muSubDetId == MuonSubdetId::RPC) {
0155           recHitCounter++;
0156         }
0157       }  // end loop on mu rechits
0158 
0159       RPCRecHitMuonEta_->Fill(eta, recHitCounter);
0160 
0161       int j = 0;
0162       while (recHitCounter >= j + 1 && j < 6) {
0163         if (recHitEta_[j])
0164           recHitEta_[j]->Fill(eta);
0165         if (eta > 0.8) {
0166           recHitPt_EP_[j]->Fill(pt);
0167           recHitPhi_EP_[j]->Fill(phi);
0168         } else if (eta < -0.8) {
0169           recHitPt_EM_[j]->Fill(pt);
0170           recHitPhi_EM_[j]->Fill(phi);
0171         } else {
0172           recHitPt_B_[j]->Fill(pt);
0173           recHitPhi_B_[j]->Fill(phi);
0174         }
0175 
0176         j++;
0177       }
0178     }
0179   } else {
0180     edm::LogError("rpcrechitprobability") << "[RPCRecHitProbability]: Muons - Product not valid for event" << counter;
0181   }
0182 }
0183 
0184 void RPCRecHitProbability::makeDcsInfo(const edm::Event& e) {
0185   edm::Handle<DcsStatusCollection> dcsStatus;
0186 
0187   if (!e.getByToken(scalersRawToDigiLabel_, dcsStatus)) {
0188     dcs_ = true;
0189     return;
0190   }
0191 
0192   if (!dcsStatus.isValid()) {
0193     edm::LogWarning("RPCDcsInfo") << "scalersRawToDigi not found";
0194     dcs_ = true;  // info not available: set to true
0195     return;
0196   }
0197 
0198   for (auto& dcsStat : *dcsStatus) {
0199     if (!dcsStat.ready(DcsStatus::RPC))
0200       dcs_ = false;
0201   }
0202 
0203   return;
0204 }