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