Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:43

0001 //-------------------------------------------------
0002 //
0003 //   Class: L1MuDTWedgeSorter
0004 //
0005 //   Description: Wedge Sorter
0006 //                find the 2 highest rank candidates per wedge
0007 //
0008 //
0009 //
0010 //   Author :
0011 //   N. Neumeister            CERN EP
0012 //   J. Troconiz              UAM Madrid
0013 //
0014 //--------------------------------------------------
0015 
0016 //-----------------------
0017 // This Class's Header --
0018 //-----------------------
0019 
0020 #include "L1Trigger/DTTrackFinder/src/L1MuDTWedgeSorter.h"
0021 
0022 //---------------
0023 // C++ Headers --
0024 //---------------
0025 
0026 #include <iostream>
0027 #include <algorithm>
0028 
0029 //-------------------------------
0030 // Collaborating Class Headers --
0031 //-------------------------------
0032 
0033 #include "L1Trigger/DTTrackFinder/interface/L1MuDTTFConfig.h"
0034 #include "L1Trigger/DTTrackFinder/interface/L1MuDTTrackFinder.h"
0035 #include "L1Trigger/DTTrackFinder/interface/L1MuDTTrack.h"
0036 #include "L1Trigger/DTTrackFinder/interface/L1MuDTSecProcId.h"
0037 #include "L1Trigger/DTTrackFinder/src/L1MuDTSectorProcessor.h"
0038 #include "L1Trigger/DTTrackFinder/src/L1MuDTEtaProcessor.h"
0039 
0040 using namespace std;
0041 
0042 // --------------------------------
0043 //       class L1MuDTWedgeSorter
0044 //---------------------------------
0045 
0046 //----------------
0047 // Constructors --
0048 //----------------
0049 
0050 L1MuDTWedgeSorter::L1MuDTWedgeSorter(const L1MuDTTrackFinder& tf, int id) : m_tf(tf), m_wsid(id), m_TrackCands(2) {
0051   m_TrackCands.reserve(2);
0052 }
0053 
0054 //--------------
0055 // Destructor --
0056 //--------------
0057 
0058 L1MuDTWedgeSorter::~L1MuDTWedgeSorter() {}
0059 
0060 //--------------
0061 // Operations --
0062 //--------------
0063 
0064 //
0065 // run Wedge Sorter
0066 //
0067 void L1MuDTWedgeSorter::run() {
0068   // get track candidates from Sector Processors
0069   vector<L1MuDTTrack*> wedgecands;
0070   wedgecands.reserve(12);
0071 
0072   int sector = m_wsid;
0073   for (int wheel = -3; wheel <= 3; wheel++) {
0074     if (wheel == 0)
0075       continue;
0076     L1MuDTSecProcId tmpspid(wheel, sector);
0077     for (int number = 0; number < 2; number++) {
0078       const L1MuDTTrack* cand = m_tf.sp(tmpspid)->track(number);
0079       if (cand && !cand->empty()) {
0080         // remove tracks which where found in wheel 0 and
0081         // which didn't cross wheel boundaries (SP -1)
0082         bool reject = false;
0083         if (wheel == -1) {
0084           reject = true;
0085           for (int stat = 2; stat <= 4; stat++) {
0086             int adr = cand->address(stat);
0087             // check addresses : 0,1,4,5,8,9 (own wheel)
0088             if (adr != 15)
0089               reject &= ((adr / 2) % 2 == 0);
0090           }
0091         }
0092         if (!reject)
0093           wedgecands.push_back(const_cast<L1MuDTTrack*>(cand));
0094       }
0095     }
0096   }
0097 
0098   // print input data
0099   if (L1MuDTTFConfig::Debug(5)) {
0100     cout << "Wedge Sorter " << m_wsid << " input: " << wedgecands.size() << endl;
0101     vector<L1MuDTTrack*>::const_iterator iter;
0102     for (iter = wedgecands.begin(); iter != wedgecands.end(); iter++) {
0103       if (*iter)
0104         (*iter)->print();
0105     }
0106   }
0107 
0108   // print input data
0109   runCOL(wedgecands);
0110 
0111   // remove disabled candidates
0112   vector<L1MuDTTrack*>::iterator it = wedgecands.begin();
0113   while (it != wedgecands.end()) {
0114     if (*it && (*it)->empty()) {
0115       wedgecands.erase(it);
0116       it = wedgecands.begin();
0117       continue;
0118     }
0119     it++;
0120   }
0121 
0122   // sort candidates by pt and quality and copy the 2 best candidates
0123   partial_sort_copy(wedgecands.begin(), wedgecands.end(), m_TrackCands.begin(), m_TrackCands.end(), L1MuDTTrack::rank);
0124 
0125   if (L1MuDTTFConfig::Debug(4)) {
0126     cout << "Wedge Sorter " << m_wsid << " output: " << endl;
0127     vector<const L1MuDTTrack*>::const_iterator iter;
0128     for (iter = m_TrackCands.begin(); iter != m_TrackCands.end(); iter++) {
0129       if (*iter)
0130         (*iter)->print();
0131     }
0132   }
0133 }
0134 
0135 //
0136 // reset Wedge Sorter
0137 //
0138 void L1MuDTWedgeSorter::reset() {
0139   vector<const L1MuDTTrack*>::iterator iter;
0140   for (iter = m_TrackCands.begin(); iter != m_TrackCands.end(); iter++) {
0141     *iter = nullptr;
0142   }
0143 }
0144 
0145 //
0146 // print candidates found in  Wedge Sorter
0147 //
0148 void L1MuDTWedgeSorter::print() const {
0149   if (anyTrack()) {
0150     cout << "Muon candidates found in Wedge Sorter " << m_wsid << " : " << endl;
0151     vector<const L1MuDTTrack*>::const_iterator iter = m_TrackCands.begin();
0152     while (iter != m_TrackCands.end()) {
0153       if (*iter)
0154         cout << *(*iter) << " found in " << (*iter)->spid() << endl;
0155       iter++;
0156     }
0157   }
0158 }
0159 
0160 //
0161 // are there any muon candidates?
0162 //
0163 bool L1MuDTWedgeSorter::anyTrack() const {
0164   vector<const L1MuDTTrack*>::const_iterator iter = m_TrackCands.begin();
0165   while (iter != m_TrackCands.end()) {
0166     if (*iter && !(*iter)->empty())
0167       return true;
0168     iter++;
0169   }
0170 
0171   return false;
0172 }
0173 
0174 //
0175 // Cancel Out Logic for Wedge Muon Sorter
0176 //
0177 void L1MuDTWedgeSorter::runCOL(vector<L1MuDTTrack*>& cands) const {
0178   // compare candidates which were found in nearby wheels:
0179   // if 2 candidates have at least one track segment in common
0180   // disable the one with lower quality;
0181   // compare addresses from stations 2, 3 and 4
0182 
0183   typedef vector<L1MuDTTrack*>::iterator TI;
0184   for (TI iter1 = cands.begin(); iter1 != cands.end(); iter1++) {
0185     if (*iter1 == nullptr)
0186       continue;
0187     if ((*iter1)->empty())
0188       continue;
0189     L1MuDTSecProcId sp1 = (*iter1)->spid();
0190     int qual1 = (*iter1)->quality();
0191     for (TI iter2 = cands.begin(); iter2 != cands.end(); iter2++) {
0192       if (*iter2 == nullptr)
0193         continue;
0194       if (*iter1 == *iter2)
0195         continue;
0196       if ((*iter2)->empty())
0197         continue;
0198       L1MuDTSecProcId sp2 = (*iter2)->spid();
0199       int qual2 = (*iter2)->quality();
0200       if (sp1 == sp2)
0201         continue;
0202       if (!neighbour(sp1, sp2))
0203         continue;
0204       int adr_shift = (sp2.wheel() == -1) ? 0 : 2;
0205       int countTS = 0;
0206       for (int stat = 2; stat <= 4; stat++) {
0207         int adr1 = (*iter1)->address(stat);
0208         int adr2 = (*iter2)->address(stat);
0209         if (adr1 == 15 || adr2 == 15)
0210           continue;
0211         if ((adr2 / 2) % 2 == 1)
0212           continue;
0213         if (adr1 == adr2 + adr_shift)
0214           countTS++;
0215       }
0216       if (countTS > 0) {
0217         if (qual1 < qual2) {
0218           if (L1MuDTTFConfig::Debug(5)) {
0219             cout << "Wedge Sorter cancel : ";
0220             (*iter1)->print();
0221           }
0222           (*iter1)->disable();
0223           break;
0224         } else {
0225           if (L1MuDTTFConfig::Debug(5)) {
0226             cout << "Wedge Sorter cancel : ";
0227             (*iter2)->print();
0228           }
0229           (*iter2)->disable();
0230         }
0231       }
0232     }
0233   }
0234 }
0235 
0236 //
0237 // find out if two Sector Processors are neighbours in the same wedge
0238 //
0239 bool L1MuDTWedgeSorter::neighbour(const L1MuDTSecProcId& spid1, const L1MuDTSecProcId& spid2) {
0240   // neighbour definition:
0241   // wheel 1 :  -2,  -1,  +1,  +1,  +2
0242   // wheel 2 :  -3,  -2,  -1,  +2,  +3
0243 
0244   bool neigh = false;
0245 
0246   int sector1 = spid1.sector();
0247   int wheel1 = spid1.wheel();
0248 
0249   int sector2 = spid2.sector();
0250   int wheel2 = spid2.wheel();
0251 
0252   if (sector1 == sector2) {
0253     if ((wheel1 == -2 && wheel2 == -3) || (wheel1 == -1 && wheel2 == -2) || (wheel1 == +1 && wheel2 == -1) ||
0254         (wheel1 == +1 && wheel2 == +2) || (wheel1 == +2 && wheel2 == +3))
0255       neigh = true;
0256   }
0257 
0258   return neigh;
0259 }