Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:36:46

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 // Constructors and destructor
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 // Main methods (initialise, run, finish)
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;  // Needed for t0 (TDC) calculation, taken from main algo
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 ///  OTHER METHODS
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 = 0;
0062     if (slId.superLayer() != 2)
0063       PhiMP = 1;
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 = 0;
0097 
0098       for (auto &mp2 : allMPs) {
0099         DTChamberId chId2(mp2.rawId);
0100         DTSuperLayerId slId2(mp2.rawId);
0101 
0102         bool PhiMP2 = 0;
0103         if (slId2.superLayer() != 2)
0104           PhiMP2 = 1;
0105 
0106         int qcut = co_quality;  // Tested for 0,1,5
0107         if (mp.quality > qcut)
0108           qcut = 0;  // Filter High Quality WRT any Quality
0109         if (PhiMP2 == 0 && qcut > 2)
0110           qcut = 2;  // For Th TP max quality is 3 (4-hit)
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 = 0;
0124         if (sector2 == sector || sector2 == sector_p1 || sector2 == sector_m1)
0125           SectorSearch = 1;
0126         if (SectorSearch != 1)
0127           continue;
0128 
0129         bool WheelSearch = 0;
0130         if (wheel2 == wheel || wheel2 == wheel - 1 || wheel2 == wheel + 1)
0131           WheelSearch = 1;
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 = 0;
0151         if (station2 == station && sector2 == sector && wheel2 == wheel)
0152           SameCh = 1;
0153 
0154         bool Wh2Exc = 0;
0155         if (abs(wheel) == 2 && station < 3 && SameCh == 1)
0156           Wh2Exc = 1;  // exception for WH2 MB1/2
0157 
0158         if (Wh2Exc == 1 && PhiMP != PhiMP2) {  // pass if Phi-Th(large k) pair in same chamber
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 = 1;
0167             break;
0168           } else if (wheel == -2 && k < -0.9) {
0169             co_found = 1;
0170             break;
0171           }
0172         }
0173 
0174         if (co_option == 1 && PhiMP2 == 0)
0175           continue;  // Phi Only
0176         else if (co_option == 2 && PhiMP2 == 1)
0177           continue;  // Theta Only
0178 
0179         if (station2 == station)
0180           continue;  // Different chambers + not adjacent chambers (standard)
0181 
0182         if (abs(t02 - t0) < thres) {
0183           co_found = 1;
0184           break;
0185         }
0186       }  // loop over all MPs and look for co
0187 
0188       if (co_found == 1)
0189         outMPs.push_back(mp);
0190 
0191     }  // co check decision
0192   }  // input MP iterator
0193 
0194   return outMPs;
0195 }