File indexing completed on 2024-04-06 12:09:43
0001
0002
0003
0004
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 DTTnPEfficiencyTask : public BaseTnPEfficiencyTask {
0015 public:
0016
0017 DTTnPEfficiencyTask(const edm::ParameterSet& config);
0018
0019
0020 ~DTTnPEfficiencyTask() 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
0028 void bookWheelHistos(DQMStore::IBooker& iBooker, int wheel, std::string folder = "");
0029
0030
0031 void analyze(const edm::Event& event, const edm::EventSetup& context) override;
0032 };
0033
0034 DTTnPEfficiencyTask::DTTnPEfficiencyTask(const edm::ParameterSet& config) : BaseTnPEfficiencyTask(config) {
0035 LogTrace("DQMOffline|MuonDPG|DTTnPEfficiencyTask") << "[DTTnPEfficiencyTask]: Constructor" << std::endl;
0036 }
0037
0038 DTTnPEfficiencyTask::~DTTnPEfficiencyTask() {
0039 LogTrace("DQMOffline|MuonDPG|DTTnPEfficiencyTask")
0040 << "[DTTnPEfficiencyTask]: analyzed " << m_nEvents << " events" << std::endl;
0041 }
0042
0043 void DTTnPEfficiencyTask::bookHistograms(DQMStore::IBooker& iBooker,
0044 edm::Run const& run,
0045 edm::EventSetup const& context) {
0046 BaseTnPEfficiencyTask::bookHistograms(iBooker, run, context);
0047
0048 LogTrace("DQMOffline|MuonDPG|DTTnPEfficiencyTask") << "[DTTnPEfficiencyTask]: bookHistograms" << std::endl;
0049
0050 for (int wheel = -2; wheel <= 2; ++wheel) {
0051 bookWheelHistos(iBooker, wheel, "Task");
0052 }
0053 auto baseDir = topFolder() + "Task/";
0054 iBooker.setCurrentFolder(baseDir);
0055
0056 MonitorElement* me_DT_pass_allCh = iBooker.book1D("DT_nPassingProbe_allCh", "DT_nPassingProbe_allCh", 20, 0.5, 20.5);
0057 MonitorElement* me_DT_fail_allCh = iBooker.book1D("DT_nFailingProbe_allCh", "DT_nFailingProbe_allCh", 20, 0.5, 20.5);
0058
0059 me_DT_pass_allCh->setBinLabel(1, "MB1/YB-2", 1);
0060 me_DT_pass_allCh->setBinLabel(2, "MB2/YB-2", 1);
0061 me_DT_pass_allCh->setBinLabel(3, "MB3/YB-2", 1);
0062 me_DT_pass_allCh->setBinLabel(4, "MB4/YB-2", 1);
0063 me_DT_pass_allCh->setBinLabel(5, "MB1/YB-1", 1);
0064 me_DT_pass_allCh->setBinLabel(6, "MB2/YB-1", 1);
0065 me_DT_pass_allCh->setBinLabel(7, "MB3/YB-1", 1);
0066 me_DT_pass_allCh->setBinLabel(8, "MB4/YB-1", 1);
0067 me_DT_pass_allCh->setBinLabel(9, "MB1/YB0", 1);
0068 me_DT_pass_allCh->setBinLabel(10, "MB2/YB0", 1);
0069 me_DT_pass_allCh->setBinLabel(11, "MB3/YB0", 1);
0070 me_DT_pass_allCh->setBinLabel(12, "MB4/YB0", 1);
0071 me_DT_pass_allCh->setBinLabel(13, "MB1/YB1", 1);
0072 me_DT_pass_allCh->setBinLabel(14, "MB2/YB1", 1);
0073 me_DT_pass_allCh->setBinLabel(15, "MB3/YB1", 1);
0074 me_DT_pass_allCh->setBinLabel(16, "MB4/YB1", 1);
0075 me_DT_pass_allCh->setBinLabel(17, "MB1/YB2", 1);
0076 me_DT_pass_allCh->setBinLabel(18, "MB2/YB2", 1);
0077 me_DT_pass_allCh->setBinLabel(19, "MB3/YB2", 1);
0078 me_DT_pass_allCh->setBinLabel(20, "MB4/YB2", 1);
0079 me_DT_pass_allCh->setAxisTitle("Number of passing probes", 2);
0080
0081 me_DT_fail_allCh->setBinLabel(1, "MB1/YB-2", 1);
0082 me_DT_fail_allCh->setBinLabel(2, "MB2/YB-2", 1);
0083 me_DT_fail_allCh->setBinLabel(3, "MB3/YB-2", 1);
0084 me_DT_fail_allCh->setBinLabel(4, "MB4/YB-2", 1);
0085 me_DT_fail_allCh->setBinLabel(5, "MB1/YB-1", 1);
0086 me_DT_fail_allCh->setBinLabel(6, "MB2/YB-1", 1);
0087 me_DT_fail_allCh->setBinLabel(7, "MB3/YB-1", 1);
0088 me_DT_fail_allCh->setBinLabel(8, "MB4/YB-1", 1);
0089 me_DT_fail_allCh->setBinLabel(9, "MB1/YB0", 1);
0090 me_DT_fail_allCh->setBinLabel(10, "MB2/YB0", 1);
0091 me_DT_fail_allCh->setBinLabel(11, "MB3/YB0", 1);
0092 me_DT_fail_allCh->setBinLabel(12, "MB4/YB0", 1);
0093 me_DT_fail_allCh->setBinLabel(13, "MB1/YB1", 1);
0094 me_DT_fail_allCh->setBinLabel(14, "MB2/YB1", 1);
0095 me_DT_fail_allCh->setBinLabel(15, "MB3/YB1", 1);
0096 me_DT_fail_allCh->setBinLabel(16, "MB4/YB1", 1);
0097 me_DT_fail_allCh->setBinLabel(17, "MB1/YB2", 1);
0098 me_DT_fail_allCh->setBinLabel(18, "MB2/YB2", 1);
0099 me_DT_fail_allCh->setBinLabel(19, "MB3/YB2", 1);
0100 me_DT_fail_allCh->setBinLabel(20, "MB4/YB2", 1);
0101 me_DT_fail_allCh->setAxisTitle("Number of failing probes", 2);
0102
0103 m_histos["DT_nPassingProbe_allCh"] = me_DT_pass_allCh;
0104 m_histos["DT_nFailingProbe_allCh"] = me_DT_fail_allCh;
0105 }
0106
0107 void DTTnPEfficiencyTask::analyze(const edm::Event& event, const edm::EventSetup& context) {
0108 BaseTnPEfficiencyTask::analyze(event, context);
0109
0110 edm::Handle<reco::MuonCollection> muons;
0111 event.getByToken(m_muToken, muons);
0112
0113
0114 std::vector<std::vector<int>> probe_coll_DT_wh;
0115 std::vector<std::vector<int>> probe_coll_DT_sec;
0116 std::vector<std::vector<int>> probe_coll_DT_sta;
0117 std::vector<std::vector<float>> probe_coll_DT_dx;
0118 std::vector<uint8_t> probe_coll_DT_staMatch;
0119
0120 std::vector<unsigned> probe_indices;
0121 if (!m_probeIndices.empty())
0122 probe_indices = m_probeIndices.back();
0123
0124
0125 for (const auto i : probe_indices) {
0126
0127 std::vector<int> probe_DT_wh;
0128 std::vector<int> probe_DT_sec;
0129 std::vector<int> probe_DT_sta;
0130 std::vector<float> probe_DT_dx;
0131 uint8_t DT_stationMatching = 0;
0132
0133 float dt_matched = false;
0134
0135 for (const auto& chambMatch : (*muons).at(i).matches()) {
0136
0137 if (chambMatch.detector() == MuonSubdetId::DT) {
0138 if (chambMatch.edgeX < m_borderCut && chambMatch.edgeY < m_borderCut) {
0139 dt_matched = true;
0140
0141 DTChamberId chId(chambMatch.id.rawId());
0142
0143 int wheel = chId.wheel();
0144 int sector = chId.sector();
0145 int station = chId.station();
0146
0147 reco::MuonSegmentMatch closest_matchedSegment;
0148 double smallestDx = 999.;
0149
0150 for (auto& seg : chambMatch.segmentMatches) {
0151 float dx = std::abs(chambMatch.x - seg.x);
0152 if (dx < smallestDx) {
0153 smallestDx = dx;
0154 closest_matchedSegment = seg;
0155 }
0156 }
0157
0158 DT_stationMatching = DT_stationMatching | (1 << (station - 1));
0159
0160 probe_DT_wh.push_back(wheel);
0161 probe_DT_sec.push_back(sector);
0162 probe_DT_sta.push_back(station);
0163 probe_DT_dx.push_back(smallestDx);
0164 }
0165 } else
0166 continue;
0167 }
0168
0169
0170 if (m_detailedAnalysis && dt_matched) {
0171 m_histos.find("probeEta")->second->Fill((*muons).at(i).eta());
0172 m_histos.find("probePhi")->second->Fill((*muons).at(i).phi());
0173 m_histos.find("probeNumberOfMatchedStations")->second->Fill((*muons).at(i).numberOfMatchedStations());
0174 m_histos.find("probePt")->second->Fill((*muons).at(i).pt());
0175 }
0176
0177
0178 probe_coll_DT_wh.push_back(probe_DT_wh);
0179 probe_coll_DT_sec.push_back(probe_DT_sec);
0180 probe_coll_DT_sta.push_back(probe_DT_sta);
0181 probe_coll_DT_dx.push_back(probe_DT_dx);
0182 probe_coll_DT_staMatch.push_back(DT_stationMatching);
0183 }
0184
0185
0186 for (unsigned i = 0; i < probe_indices.size(); ++i) {
0187 uint8_t DT_matchPatt = probe_coll_DT_staMatch.at(i);
0188
0189
0190 unsigned nDT_matches = probe_coll_DT_wh.at(i).size();
0191 for (unsigned j = 0; j < nDT_matches; ++j) {
0192
0193 int DT_wheel = probe_coll_DT_wh.at(i).at(j);
0194 int DT_station = probe_coll_DT_sta.at(i).at(j);
0195 int DT_sector = probe_coll_DT_sec.at(i).at(j);
0196 float DT_dx = probe_coll_DT_dx.at(i).at(j);
0197
0198
0199 if ((DT_matchPatt & (1 << (DT_station - 1))) != 0 &&
0200 (DT_matchPatt & (1 << (DT_station - 1))) !=
0201 DT_matchPatt)
0202 {
0203 if (DT_dx < m_dxCut) {
0204 std::string hName = std::string("DT_nPassingProbePerCh_W") + std::to_string(DT_wheel);
0205 m_histos.find(hName)->second->Fill(DT_sector, DT_station);
0206 m_histos.find("DT_nPassingProbe_allCh")->second->Fill((DT_station) + 4 * (DT_wheel + 2));
0207 } else {
0208 std::string hName = std::string("DT_nFailingProbePerCh_W") + std::to_string(DT_wheel);
0209 m_histos.find(hName)->second->Fill(DT_sector, DT_station);
0210 m_histos.find("DT_nFailingProbe_allCh")->second->Fill((DT_station) + 4 * (DT_wheel + 2));
0211 }
0212 }
0213 }
0214 }
0215 }
0216
0217 void DTTnPEfficiencyTask::bookWheelHistos(DQMStore::IBooker& iBooker, int wheel, std::string folder) {
0218 auto baseDir = topFolder() + folder + "/";
0219 iBooker.setCurrentFolder(baseDir);
0220
0221 LogTrace("DQMOffline|MuonDPG|DTTnPEfficiencyTask")
0222 << "[DTTnPEfficiencyTask]: booking histos in " << baseDir << std::endl;
0223
0224 auto hName_DT_pass = std::string("DT_nPassingProbePerCh_W") + std::to_string(wheel);
0225 auto hName_DT_fail = std::string("DT_nFailingProbePerCh_W") + std::to_string(wheel);
0226
0227 MonitorElement* me_DT_pass = iBooker.book2D(hName_DT_pass.c_str(), hName_DT_pass.c_str(), 14, 0.5, 14.5, 4, 0., 4.5);
0228 MonitorElement* me_DT_fail = iBooker.book2D(hName_DT_fail.c_str(), hName_DT_fail.c_str(), 14, 0.5, 14.5, 4, 0., 4.5);
0229
0230 me_DT_pass->setBinLabel(1, "MB1", 2);
0231 me_DT_pass->setBinLabel(2, "MB2", 2);
0232 me_DT_pass->setBinLabel(3, "MB3", 2);
0233 me_DT_pass->setBinLabel(4, "MB4", 2);
0234 for (int i = 1; i < 15; ++i) {
0235 me_DT_pass->setBinLabel(i, std::to_string(i), 1);
0236 }
0237 me_DT_pass->setAxisTitle("Sector", 1);
0238 me_DT_pass->setAxisTitle("Number of passing probes", 3);
0239
0240 me_DT_fail->setBinLabel(1, "MB1", 2);
0241 me_DT_fail->setBinLabel(2, "MB2", 2);
0242 me_DT_fail->setBinLabel(3, "MB3", 2);
0243 me_DT_fail->setBinLabel(4, "MB4", 2);
0244 for (int i = 1; i < 15; ++i) {
0245 me_DT_fail->setBinLabel(i, std::to_string(i), 1);
0246 }
0247 me_DT_fail->setAxisTitle("Sector", 1);
0248 me_DT_fail->setAxisTitle("Number of failing probes", 3);
0249
0250 m_histos[hName_DT_pass] = me_DT_pass;
0251 m_histos[hName_DT_fail] = me_DT_fail;
0252 }
0253
0254 std::string DTTnPEfficiencyTask::topFolder() const { return "DT/Segment_TnP/"; };
0255
0256 DEFINE_FWK_MODULE(DTTnPEfficiencyTask);