Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30:35

0001 // Include files
0002 
0003 // local
0004 #include "L1Trigger/RPCTechnicalTrigger/interface/TTUTrackingAlg.h"
0005 #include <algorithm>
0006 
0007 //-----------------------------------------------------------------------------
0008 // Implementation file for class : TTUTrackingAlg
0009 //
0010 // 2008-10-18 : Andres Osorio
0011 //-----------------------------------------------------------------------------
0012 
0013 //=============================================================================
0014 // Standard constructor, initializes variables
0015 //=============================================================================
0016 TTUTrackingAlg::TTUTrackingAlg() {
0017   int StOrder[6] = {6, 5, 4, 3, 2, 1};
0018   int SeOrder[12] = {4, 5, 3, 6, 2, 7, 1, 8, 12, 9, 11, 10};
0019 
0020   for (int i = 0; i < 6; ++i) {
0021     m_STscanorder[i] = StOrder[i];
0022     m_SEscanorder[i * 2] = SeOrder[i * 2];
0023     m_SEscanorder[(i * 2) + 1] = SeOrder[(i * 2) + 1];
0024   }
0025 
0026   m_triggersignal = false;
0027   m_mintrklength = 4;
0028 
0029   m_debug = false;
0030 }
0031 
0032 //=============================================================================
0033 // Destructor
0034 //=============================================================================
0035 TTUTrackingAlg::~TTUTrackingAlg() {}
0036 
0037 //=============================================================================
0038 void TTUTrackingAlg::setBoardSpecs(const TTUBoardSpecs::TTUBoardConfig& boardspecs) {
0039   m_mintrklength = boardspecs.m_TrackLength;
0040 }
0041 
0042 bool TTUTrackingAlg::process(const TTUInput& inmap) {
0043   if (m_debug)
0044     std::cout << "TTUTrackingAlg>process() starts + bx= " << inmap.m_bx << std::endl;
0045 
0046   m_triggersignal = false;
0047 
0048   auto initTrk = std::make_unique<Track>();
0049 
0050   //.
0051   runSeedBuster(inmap);
0052 
0053   if (!m_initialseeds.empty() && m_initialseeds.size() < 20)  // if too much hits, then cannot process
0054     initTrk->add(m_initialseeds[0].get());
0055   else {
0056     initTrk->addnone();
0057     if (m_debug)
0058       std::cout << "TTUTrackingAlg>process() ends: no initialseeds" << std::endl;
0059     return false;
0060   }
0061 
0062   auto trk = m_tracks.emplace_back(std::move(initTrk)).get();
0063 
0064   //..
0065   auto _seed = m_initialseeds.begin();
0066   std::vector<Seed*> neighbors;
0067 
0068   while (_seed != m_initialseeds.end()) {
0069     findNeighbors((*_seed).get(), neighbors);
0070     filter(trk, neighbors);
0071     executeTracker(trk, neighbors);
0072     ghostBuster(trk);
0073 
0074     ++_seed;
0075 
0076     if (_seed != m_initialseeds.end()) {
0077       auto initTrk = std::make_unique<Track>();
0078       initTrk->add((*_seed).get());
0079       m_tracks.emplace_back(std::move(initTrk));
0080     }
0081   }
0082 
0083   if (m_debug) {
0084     std::cout << "Total tracks: " << m_tracks.size() << std::endl;
0085     for (auto& tr : m_tracks)
0086       std::cout << "length: " << tr->length() << '\t';
0087     std::cout << std::endl;
0088   }
0089 
0090   //...
0091   alignTracks();
0092 
0093   //.... Look at the first track and compare its track length
0094 
0095   int tracklen(0);
0096   auto itr = m_tracks.begin();
0097   if (itr != m_tracks.end())
0098     tracklen = (*itr)->length();
0099 
0100   if (tracklen >= m_mintrklength)
0101     m_triggersignal = true;
0102 
0103   if (m_debug) {
0104     std::cout << "TTUTrackingAlg> trk len= " << tracklen << '\t' << "triggered: " << m_triggersignal << std::endl;
0105   }
0106 
0107   //..... Clean up for next run
0108 
0109   cleanUp();
0110 
0111   //.......................................................
0112 
0113   if (m_debug)
0114     std::cout << "TTUTrackingAlg>process ends" << std::endl;
0115 
0116   return true;
0117 }
0118 
0119 void TTUTrackingAlg::runSeedBuster(const TTUInput& inmap) {
0120   int idx(0);
0121   int idy(0);
0122 
0123   for (int i = 0; i < 12; ++i) {
0124     idx = (m_SEscanorder[i] - 1);
0125     std::bitset<6> station = inmap.input_sec[idx];
0126 
0127     if (!station.any())
0128       continue;
0129 
0130     for (int k = 0; k < 6; ++k) {
0131       idy = (m_STscanorder[k] - 1);
0132       bool _hit = station[idy];
0133 
0134       if (_hit) {
0135         m_initialseeds.emplace_back(std::make_unique<Seed>(idx, idy, 0));
0136       }
0137     }
0138   }
0139 
0140   //...
0141   if (m_debug)
0142     std::cout << "SeedBuster: " << m_initialseeds.size() << std::endl;
0143 }
0144 
0145 int TTUTrackingAlg::executeTracker(Track* _trk, std::vector<Seed*>& neighbors) {
0146   if (m_debug)
0147     std::cout << "executeTracker: " << neighbors.size() << std::endl;
0148 
0149   //...
0150 
0151   auto _itr = neighbors.begin();
0152 
0153   while (_itr != neighbors.end()) {
0154     _trk->add((*_itr));
0155 
0156     std::vector<Seed*> _nextneighbors;
0157 
0158     findNeighbors((*_itr), _nextneighbors);
0159 
0160     filter(_trk, _nextneighbors);
0161 
0162     if (_nextneighbors.size() == 1)
0163       executeTracker(_trk, _nextneighbors);
0164 
0165     //... bifurcation not considered at the moment
0166 
0167     ++_itr;
0168   }
0169 
0170   //...
0171 
0172   return 1;
0173 }
0174 
0175 void TTUTrackingAlg::findNeighbors(Seed* _seed, std::vector<Seed*>& neighbors) {
0176   neighbors.clear();
0177 
0178   int _xo = _seed->m_sectorId;
0179   int _yo = _seed->m_stationId;
0180 
0181   if (m_debug)
0182     std::cout << "X: " << _xo + 1 << " Y: " << _yo + 1 << std::endl;
0183 
0184   auto _itr = m_initialseeds.begin();
0185 
0186   while (_itr != m_initialseeds.end()) {
0187     int _difx = std::abs(_xo - (*_itr)->m_sectorId);
0188     int _dify = std::abs(_yo - (*_itr)->m_stationId);
0189 
0190     if (m_debug)
0191       std::cout << "difference (x,y): " << _difx << "," << _dify << "\t";
0192 
0193     if (_difx == 11)
0194       _difx = 1;
0195 
0196     if (((_difx == 1) && (_dify == 1)) || ((_difx == 1) && (_dify == 0)) || ((_difx == 0) && (_dify == 1)))
0197 
0198       neighbors.push_back((*_itr).get());
0199 
0200     ++_itr;
0201   }
0202 
0203   if (m_debug)
0204     std::cout << std::endl;
0205 }
0206 
0207 void TTUTrackingAlg::filter(Track* _trk, std::vector<Seed*>& _nbrs) {
0208   //... filter: removes from neighbors list, seeds already present
0209   //...    in tracks
0210 
0211   for (auto _itr = _trk->m_seeds.begin(); _itr != _trk->m_seeds.end(); ++_itr) {
0212     auto _isalready = std::find(_nbrs.begin(), _nbrs.end(), (*_itr));
0213 
0214     if (_isalready != _nbrs.end()) {
0215       _nbrs.erase(_isalready);
0216       if (m_debug)
0217         std::cout << "removing ..." << std::endl;
0218     }
0219   }
0220 }
0221 
0222 void TTUTrackingAlg::ghostBuster(Track* currentTrk) {
0223   //...do a final check to make sure there are no repeated seeds in track
0224 
0225   std::vector<Seed*>::iterator seedItr;
0226 
0227   std::sort(currentTrk->m_seeds.begin(), currentTrk->m_seeds.end(), [](const Seed* a, const Seed* b) {
0228     if (a->m_sectorId == b->m_sectorId) {
0229       return a->m_stationId < b->m_stationId;
0230     }
0231     return a->m_sectorId < b->m_sectorId;
0232   });
0233 
0234   seedItr = std::unique(currentTrk->m_seeds.begin(), currentTrk->m_seeds.end(), [](const Seed* a, const Seed* b) {
0235     return a->m_sectorId == b->m_sectorId and a->m_stationId == b->m_stationId;
0236   });
0237 
0238   currentTrk->m_seeds.resize(seedItr - currentTrk->m_seeds.begin());
0239 
0240   currentTrk->updateTrkLength();
0241 }
0242 
0243 void TTUTrackingAlg::alignTracks() {
0244   CompareMechanism<std::unique_ptr<Track>> compare;
0245 
0246   std::sort(m_tracks.begin(), m_tracks.end(), compare);
0247   std::reverse(m_tracks.begin(), m_tracks.end());
0248 
0249   if (m_debug) {
0250     for (auto& tr : m_tracks)
0251       std::cout << "Align tracks> trk len: " << tr->length() << " ";
0252     std::cout << std::endl;
0253   }
0254 }
0255 
0256 void TTUTrackingAlg::cleanUp() {
0257   m_tracks.clear();
0258   m_initialseeds.clear();
0259 }