File indexing completed on 2025-04-15 22:41:37
0001 #include "L1Trigger/DTTriggerPhase2/interface/MPCoincidenceFilter.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include "L1Trigger/DTTriggerPhase2/interface/constants.h"
0004
0005 using namespace edm;
0006 using namespace std;
0007 using namespace cmsdt;
0008
0009
0010
0011
0012 MPCoincidenceFilter::MPCoincidenceFilter(const ParameterSet &pset)
0013 : MPFilter(pset),
0014 debug_(pset.getUntrackedParameter<bool>("debug")),
0015 co_option_(pset.getParameter<int>("co_option")),
0016 co_quality_(pset.getParameter<int>("co_quality")),
0017 co_wh2option_(pset.getParameter<int>("co_wh2option")),
0018 scenario_(pset.getParameter<int>("scenario")) {}
0019
0020
0021
0022
0023 void MPCoincidenceFilter::initialise(const edm::EventSetup &iEventSetup) {}
0024
0025 void MPCoincidenceFilter::run(edm::Event &iEvent,
0026 const edm::EventSetup &iEventSetup,
0027 std::vector<metaPrimitive> &allMPaths,
0028 std::vector<metaPrimitive> &inMPaths,
0029 std::vector<metaPrimitive> &outMPaths) {
0030 if (debug_)
0031 LogDebug("MPCoincidenceFilter") << "MPCoincidenceFilter: run";
0032
0033 double shift_back = 0;
0034 if (scenario_ == MC)
0035 shift_back = 400;
0036 else if (scenario_ == DATA)
0037 shift_back = 0;
0038 else if (scenario_ == SLICE_TEST)
0039 shift_back = 400;
0040
0041 auto filteredMPs = filter(inMPaths, allMPaths, co_option_, co_quality_, co_wh2option_, shift_back);
0042 for (auto &mp : filteredMPs)
0043 outMPaths.push_back(mp);
0044 }
0045
0046 void MPCoincidenceFilter::finish() {}
0047
0048
0049
0050
0051 std::vector<metaPrimitive> MPCoincidenceFilter::filter(std::vector<metaPrimitive> inMPs,
0052 std::vector<metaPrimitive> allMPs,
0053 int co_option,
0054 int co_quality,
0055 int co_wh2option,
0056 double shift_back) {
0057 std::vector<metaPrimitive> outMPs;
0058
0059 for (auto &mp : inMPs) {
0060 DTChamberId chId(mp.rawId);
0061 DTSuperLayerId slId(mp.rawId);
0062
0063 bool PhiMP = false;
0064 if (slId.superLayer() != 2)
0065 PhiMP = true;
0066
0067 int sector = chId.sector();
0068 int wheel = chId.wheel();
0069 int station = chId.station();
0070 if (sector == 13)
0071 sector = 4;
0072 if (sector == 14)
0073 sector = 10;
0074
0075 bool wh2pass = false;
0076 if (abs(wheel) == 2 && station == 1 && co_wh2option == 1)
0077 wh2pass = true;
0078 if (abs(wheel) == 2 && station < 3 && co_wh2option == 2)
0079 wh2pass = true;
0080
0081 if (co_option == -1 || mp.quality > 5 || wh2pass == 1)
0082 outMPs.push_back(mp);
0083 else {
0084 int sector_p1 = sector + 1;
0085 int sector_m1 = sector - 1;
0086 if (sector_p1 == 13)
0087 sector_p1 = 1;
0088 if (sector_m1 == 0)
0089 sector_m1 = 12;
0090
0091 string whch = "wh" + std::to_string(wheel) + "ch" + std::to_string(station) + "";
0092 float t0_mean, t0_width;
0093 if (PhiMP == 1) {
0094 t0_mean = mphi_mean.find("" + whch + "")->second;
0095 t0_width = mphi_width.find("" + whch + "")->second;
0096 } else {
0097 t0_mean = mth_mean.find("" + whch + "")->second;
0098 t0_width = mth_width.find("" + whch + "")->second;
0099 }
0100
0101 float t0 = (mp.t0 - shift_back * LHC_CLK_FREQ) * ((float)TIME_TO_TDC_COUNTS / (float)LHC_CLK_FREQ);
0102 t0 = t0 - t0_mean;
0103
0104 bool co_found = false;
0105
0106 for (auto &mp2 : allMPs) {
0107 DTChamberId chId2(mp2.rawId);
0108 DTSuperLayerId slId2(mp2.rawId);
0109
0110 bool PhiMP2 = false;
0111 if (slId2.superLayer() != 2)
0112 PhiMP2 = true;
0113
0114 int qcut = co_quality;
0115 if (mp.quality > qcut)
0116 qcut = 0;
0117 if (PhiMP2 == 0 && qcut > 2)
0118 qcut = 2;
0119
0120 if (!(mp2.quality > qcut))
0121 continue;
0122
0123 int sector2 = chId2.sector();
0124 int wheel2 = chId2.wheel();
0125 int station2 = chId2.station();
0126 if (sector2 == 13)
0127 sector2 = 4;
0128 if (sector2 == 14)
0129 sector2 = 10;
0130
0131 bool SectorSearch = false;
0132 if (sector2 == sector || sector2 == sector_p1 || sector2 == sector_m1)
0133 SectorSearch = true;
0134 if (SectorSearch != 1)
0135 continue;
0136
0137 bool WheelSearch = false;
0138 if (wheel2 == wheel || wheel2 == wheel - 1 || wheel2 == wheel + 1)
0139 WheelSearch = true;
0140 if (WheelSearch != 1)
0141 continue;
0142
0143 string whch2 = "wh" + std::to_string(wheel2) + "ch" + std::to_string(station2) + "";
0144 float t0_mean2, t0_width2;
0145 if (PhiMP2 == 1) {
0146 t0_mean2 = mphi_mean.find("" + whch2 + "")->second;
0147 t0_width2 = mphi_width.find("" + whch2 + "")->second;
0148 } else {
0149 t0_mean2 = mth_mean.find("" + whch2 + "")->second;
0150 t0_width2 = mth_width.find("" + whch2 + "")->second;
0151 }
0152
0153 float t02 = (mp2.t0 - shift_back * LHC_CLK_FREQ) * ((float)TIME_TO_TDC_COUNTS / (float)LHC_CLK_FREQ);
0154 t02 = t02 - t0_mean2;
0155
0156 float thres = t0_width + t0_width2;
0157
0158 bool SameCh = false;
0159 if (station2 == station && sector2 == sector && wheel2 == wheel)
0160 SameCh = true;
0161
0162 bool Wh2Exc = false;
0163 if (abs(wheel) == 2 && station < 3 && SameCh == 1)
0164 Wh2Exc = true;
0165
0166 if (Wh2Exc == 1 && PhiMP != PhiMP2) {
0167 float k = 0;
0168 if (PhiMP == 0)
0169 k = mp.phiB;
0170 else
0171 k = mp2.phiB;
0172
0173 if (wheel == 2 && k > 0.9) {
0174 co_found = true;
0175 break;
0176 } else if (wheel == -2 && k < -0.9) {
0177 co_found = true;
0178 break;
0179 }
0180 }
0181
0182 if (co_option == 1 && PhiMP2 == 0)
0183 continue;
0184 else if (co_option == 2 && PhiMP2 == 1)
0185 continue;
0186
0187 if (station2 == station)
0188 continue;
0189
0190 if (abs(t02 - t0) < thres) {
0191 co_found = true;
0192 break;
0193 }
0194 }
0195
0196 if (co_found == 1)
0197 outMPs.push_back(mp);
0198
0199 }
0200 }
0201
0202 return outMPs;
0203 }