Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-16 23:25:33

0001 /*
0002  * \file CSCTnPEfficiencyTask.cc
0003  *
0004  * \author L. Lunerti - INFN Bologna
0005  *
0006  */
0007 
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 
0010 #include "DataFormats/MuonReco/interface/MuonSegmentMatch.h"
0011 
0012 #include "DQMOffline/MuonDPG/interface/BaseTnPEfficiencyTask.h"
0013 
0014 class CSCTnPEfficiencyTask : public BaseTnPEfficiencyTask {
0015 public:
0016   /// Constructor
0017   CSCTnPEfficiencyTask(const edm::ParameterSet& config);
0018 
0019   /// Destructor
0020   ~CSCTnPEfficiencyTask() override;
0021 
0022 protected:
0023   std::string topFolder() const override;
0024 
0025   void bookHistograms(DQMStore::IBooker& iBooker, edm::Run const& run, edm::EventSetup const& context) override;
0026 
0027   /// Analyze
0028   void analyze(const edm::Event& event, const edm::EventSetup& context) override;
0029 };
0030 
0031 CSCTnPEfficiencyTask::CSCTnPEfficiencyTask(const edm::ParameterSet& config) : BaseTnPEfficiencyTask(config) {
0032   LogTrace("DQMOffline|MuonDPG|CSCTnPEfficiencyTask") << "[CSCTnPEfficiencyTask]: Constructor" << std::endl;
0033 }
0034 
0035 CSCTnPEfficiencyTask::~CSCTnPEfficiencyTask() {
0036   LogTrace("DQMOffline|MuonDPG|CSCTnPEfficiencyTask")
0037       << "[CSCTnPEfficiencyTask]: analyzed " << m_nEvents << " events" << std::endl;
0038 }
0039 
0040 void CSCTnPEfficiencyTask::bookHistograms(DQMStore::IBooker& iBooker,
0041                                           edm::Run const& run,
0042                                           edm::EventSetup const& context) {
0043   BaseTnPEfficiencyTask::bookHistograms(iBooker, run, context);
0044 
0045   LogTrace("DQMOffline|MuonDPG|CSCTnPEfficiencyTask") << "[CSCTnPEfficiencyTask]: bookHistograms" << std::endl;
0046 
0047   auto baseDir = topFolder() + "Task/";
0048   iBooker.setCurrentFolder(baseDir);
0049 
0050   MonitorElement* me_CSC_pass_allCh =
0051       iBooker.book2D("CSC_nPassingProbe_allCh", "CSC_nPassingProbe_allCh", 9, -4., 5., 4, 0., 4.5);
0052   MonitorElement* me_CSC_fail_allCh =
0053       iBooker.book2D("CSC_nFailingProbe_allCh", "CSC_nFailingProbe_allCh", 9, -4., 5., 4, 0., 4.5);
0054 
0055   MonitorElement* me_CSC_pass_allCh_1D =
0056       iBooker.book1D("CSC_nPassingProbe_allCh_1D", "CSC_nPassingProbe_allCh_1D", 9, -4., 5.);
0057   MonitorElement* me_CSC_fail_allCh_1D =
0058       iBooker.book1D("CSC_nFailingProbe_allCh_1D", "CSC_nFailingProbe_allCh_1D", 9, -4., 5.);
0059 
0060   me_CSC_pass_allCh->setBinLabel(1, "ME-4", 1);
0061   me_CSC_pass_allCh->setBinLabel(2, "ME-3", 1);
0062   me_CSC_pass_allCh->setBinLabel(3, "ME-2", 1);
0063   me_CSC_pass_allCh->setBinLabel(4, "ME-1", 1);
0064   me_CSC_pass_allCh->setBinLabel(6, "ME1", 1);
0065   me_CSC_pass_allCh->setBinLabel(7, "ME2", 1);
0066   me_CSC_pass_allCh->setBinLabel(8, "ME3", 1);
0067   me_CSC_pass_allCh->setBinLabel(9, "ME4", 1);
0068   for (int i = 1; i < 5; ++i) {
0069     me_CSC_pass_allCh->setBinLabel(i, std::to_string(i), 2);
0070   }
0071   me_CSC_pass_allCh->setAxisTitle("Ring", 2);
0072   me_CSC_pass_allCh->setAxisTitle("Number of passing probes", 3);
0073 
0074   me_CSC_fail_allCh->setBinLabel(1, "ME-4", 1);
0075   me_CSC_fail_allCh->setBinLabel(2, "ME-3", 1);
0076   me_CSC_fail_allCh->setBinLabel(3, "ME-2", 1);
0077   me_CSC_fail_allCh->setBinLabel(4, "ME-1", 1);
0078   me_CSC_fail_allCh->setBinLabel(6, "ME1", 1);
0079   me_CSC_fail_allCh->setBinLabel(7, "ME2", 1);
0080   me_CSC_fail_allCh->setBinLabel(8, "ME3", 1);
0081   me_CSC_fail_allCh->setBinLabel(9, "ME4", 1);
0082   for (int i = 1; i < 5; ++i) {
0083     me_CSC_fail_allCh->setBinLabel(i, std::to_string(i), 2);
0084   }
0085   me_CSC_fail_allCh->setAxisTitle("Ring", 2);
0086   me_CSC_fail_allCh->setAxisTitle("Number of failing probes", 3);
0087 
0088   me_CSC_pass_allCh_1D->setBinLabel(1, "ME-4", 1);
0089   me_CSC_pass_allCh_1D->setBinLabel(2, "ME-3", 1);
0090   me_CSC_pass_allCh_1D->setBinLabel(3, "ME-2", 1);
0091   me_CSC_pass_allCh_1D->setBinLabel(4, "ME-1", 1);
0092   me_CSC_pass_allCh_1D->setBinLabel(6, "ME1", 1);
0093   me_CSC_pass_allCh_1D->setBinLabel(7, "ME2", 1);
0094   me_CSC_pass_allCh_1D->setBinLabel(8, "ME3", 1);
0095   me_CSC_pass_allCh_1D->setBinLabel(9, "ME4", 1);
0096   me_CSC_pass_allCh_1D->setAxisTitle("Number of passing probes", 2);
0097 
0098   me_CSC_fail_allCh_1D->setBinLabel(1, "ME-4", 1);
0099   me_CSC_fail_allCh_1D->setBinLabel(2, "ME-3", 1);
0100   me_CSC_fail_allCh_1D->setBinLabel(3, "ME-2", 1);
0101   me_CSC_fail_allCh_1D->setBinLabel(4, "ME-1", 1);
0102   me_CSC_fail_allCh_1D->setBinLabel(6, "ME1", 1);
0103   me_CSC_fail_allCh_1D->setBinLabel(7, "ME2", 1);
0104   me_CSC_fail_allCh_1D->setBinLabel(8, "ME3", 1);
0105   me_CSC_fail_allCh_1D->setBinLabel(9, "ME4", 1);
0106   me_CSC_fail_allCh_1D->setAxisTitle("Number of failing probes", 2);
0107 
0108   m_histos["CSC_nPassingProbe_allCh"] = me_CSC_pass_allCh;
0109   m_histos["CSC_nFailingProbe_allCh"] = me_CSC_fail_allCh;
0110 
0111   m_histos["CSC_nPassingProbe_allCh_1D"] = me_CSC_pass_allCh_1D;
0112   m_histos["CSC_nFailingProbe_allCh_1D"] = me_CSC_fail_allCh_1D;
0113 }
0114 
0115 void CSCTnPEfficiencyTask::analyze(const edm::Event& event, const edm::EventSetup& context) {
0116   BaseTnPEfficiencyTask::analyze(event, context);
0117 
0118   edm::Handle<reco::MuonCollection> muons;
0119   event.getByToken(m_muToken, muons);
0120 
0121   //CSC variables
0122   std::vector<std::vector<int>> probe_coll_CSC_zend;
0123   std::vector<std::vector<int>> probe_coll_CSC_ring;
0124   std::vector<std::vector<int>> probe_coll_CSC_sta;
0125   std::vector<std::vector<float>> probe_coll_CSC_dx;
0126   std::vector<uint8_t> probe_coll_CSC_staMatch;
0127 
0128   std::vector<unsigned> probe_indices;
0129   if (!m_probeIndices.empty())
0130     probe_indices = m_probeIndices.back();
0131 
0132   //Fill probe dx + subdetector coordinates
0133   for (const auto i : probe_indices) {
0134     //CSC variables
0135     std::vector<int> probe_CSC_zend;
0136     std::vector<int> probe_CSC_ring;
0137     std::vector<int> probe_CSC_sta;
0138     std::vector<float> probe_CSC_dx;
0139     uint8_t CSC_stationMatching = 0;
0140 
0141     float csc_matched = false;  // fill detailed plots only for probes matching CSC
0142 
0143     for (const auto& chambMatch : (*muons).at(i).matches()) {
0144       // look in CSCs
0145       if (chambMatch.detector() == MuonSubdetId::CSC) {
0146         if (chambMatch.edgeX < m_borderCut && chambMatch.edgeY < m_borderCut) {
0147           csc_matched = true;  //fill detailed plots if at least one CSC match
0148 
0149           CSCDetId chId(chambMatch.id.rawId());
0150 
0151           int zendcap = chId.zendcap();
0152           int ring = chId.ring();
0153           int station = chId.station();
0154 
0155           reco::MuonSegmentMatch closest_matchedSegment;
0156           double smallestDx = 99999.;
0157           for (auto& seg : chambMatch.segmentMatches) {
0158             float dx = std::abs(chambMatch.x - seg.x);
0159             if (dx < smallestDx) {
0160               smallestDx = dx;
0161               closest_matchedSegment = seg;
0162             }
0163           }
0164 
0165           CSC_stationMatching = CSC_stationMatching | (1 << (station - 1));
0166 
0167           if (station == 1 && ring == 4 && chambMatch.y < -31.5) {
0168             probe_CSC_zend.push_back(zendcap);
0169             probe_CSC_ring.push_back(ring);
0170             probe_CSC_sta.push_back(station);
0171             probe_CSC_dx.push_back(smallestDx);
0172           } else if (station == 1 && ring == 1 && chambMatch.y > -31.5) {
0173             probe_CSC_zend.push_back(zendcap);
0174             probe_CSC_ring.push_back(ring);
0175             probe_CSC_sta.push_back(station);
0176             probe_CSC_dx.push_back(smallestDx);
0177           } else if (station > 1 || ring == 2 || ring == 3) {
0178             probe_CSC_zend.push_back(zendcap);
0179             probe_CSC_ring.push_back(ring);
0180             probe_CSC_sta.push_back(station);
0181             probe_CSC_dx.push_back(smallestDx);
0182           }
0183         }
0184       } else
0185         continue;
0186     }  //loop over chamber matches
0187 
0188     //Fill detailed plots
0189     if (m_detailedAnalysis && csc_matched) {
0190       m_histos.find("probeEta")->second->Fill((*muons).at(i).eta());
0191       m_histos.find("probePhi")->second->Fill((*muons).at(i).phi());
0192       m_histos.find("probeNumberOfMatchedStations")->second->Fill((*muons).at(i).numberOfMatchedStations());
0193       m_histos.find("probePt")->second->Fill((*muons).at(i).pt());
0194     }
0195 
0196     //Fill CSC variables
0197     probe_coll_CSC_zend.push_back(probe_CSC_zend);
0198     probe_coll_CSC_ring.push_back(probe_CSC_ring);
0199     probe_coll_CSC_sta.push_back(probe_CSC_sta);
0200     probe_coll_CSC_dx.push_back(probe_CSC_dx);
0201     probe_coll_CSC_staMatch.push_back(CSC_stationMatching);
0202   }  //loop over probe collection
0203 
0204   //Loop over probes
0205   for (unsigned i = 0; i < probe_indices.size(); ++i) {
0206     uint8_t CSC_matchPatt = probe_coll_CSC_staMatch.at(i);
0207 
0208     //Loop over CSC matches
0209     unsigned nCSC_matches = probe_coll_CSC_zend.at(i).size();
0210     for (unsigned j = 0; j < nCSC_matches; ++j) {
0211       int CSC_zendcap = probe_coll_CSC_zend.at(i).at(j);
0212       int CSC_sta = probe_coll_CSC_sta.at(i).at(j);
0213       int CSC_ring = probe_coll_CSC_ring.at(i).at(j);
0214       float CSC_dx = probe_coll_CSC_dx.at(i).at(j);
0215 
0216       //Fill CSC plots
0217       if ((CSC_matchPatt & (1 << (CSC_sta - 1))) != 0 &&  //avoids 0 station matching
0218           (CSC_matchPatt & (1 << (CSC_sta - 1))) !=
0219               CSC_matchPatt)  //avoids matching with the station under consideration only
0220       {
0221         if (CSC_dx < m_dxCut) {
0222           m_histos.find("CSC_nPassingProbe_allCh")->second->Fill(CSC_zendcap * CSC_sta, CSC_ring);
0223           m_histos.find("CSC_nPassingProbe_allCh_1D")->second->Fill(CSC_zendcap * CSC_sta);
0224         } else {
0225           m_histos.find("CSC_nFailingProbe_allCh")->second->Fill(CSC_zendcap * CSC_sta, CSC_ring);
0226           m_histos.find("CSC_nFailingProbe_allCh_1D")->second->Fill(CSC_zendcap * CSC_sta);
0227         }
0228       }
0229     }
0230   }
0231 }
0232 
0233 std::string CSCTnPEfficiencyTask::topFolder() const { return "CSC/Segment_TnP/"; };
0234 
0235 DEFINE_FWK_MODULE(CSCTnPEfficiencyTask);