Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:01

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 
0003 #include "L1Trigger/L1TMuonEndCapPhase2/interface/EMTFContext.h"
0004 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Utils/DataUtils.h"
0005 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Utils/DebugUtils.h"
0006 
0007 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Algo/DuplicateRemovalLayer.h"
0008 
0009 using namespace emtf::phase2;
0010 using namespace emtf::phase2::algo;
0011 
0012 DuplicateRemovalLayer::DuplicateRemovalLayer(const EMTFContext& context) : context_(context) {}
0013 
0014 void DuplicateRemovalLayer::apply(std::vector<track_t>& tracks) const {
0015   // ===========================================================================
0016   // Unpack model
0017   // ---------------------------------------------------------------------------
0018   const auto& model = context_.model_;
0019   const auto& model_reduced_sites = model.reduced_sites_;
0020 
0021   // ===========================================================================
0022   // Build reduced tracks
0023   // ---------------------------------------------------------------------------
0024   std::vector<reduced_track_t> reduced_tracks;
0025 
0026   for (const auto& track : tracks) {  // Begin loop tracks
0027     // Fetch reduced track
0028     auto& rtrk = reduced_tracks.emplace_back();
0029     auto& rtrk_valid = rtrk.valid;
0030 
0031     // Initialize valid state
0032     rtrk_valid = track.valid;
0033 
0034     // Fill reduced track with segments
0035     for (const auto& model_rsite : model_reduced_sites) {  // Begin loop reduced model sites
0036 
0037       // Get reduced site
0038       int model_rsite_id = static_cast<int>(model_rsite.id);
0039 
0040       auto& rsite_seg = rtrk.site_segs[model_rsite_id];
0041       auto& rsite_bit = rtrk.site_mask[model_rsite_id];
0042 
0043       // Init reduced site
0044       rsite_seg = 0;
0045       rsite_bit = 0;
0046 
0047       // Select the first segment available for the reduced site
0048       for (const auto& model_rs_ts : model_rsite.trk_sites) {  // Begin loop reduced site track sites
0049         int trk_site_id = static_cast<int>(model_rs_ts);
0050 
0051         const auto& trk_site_seg = track.site_segs[trk_site_id];
0052         const auto& trk_site_bit = track.site_mask[trk_site_id];
0053 
0054         if (trk_site_bit == 0) {
0055           continue;
0056         }
0057 
0058         // Attach segment
0059         // If even one segment is attached
0060         // the reduced track is considered valid
0061         rtrk_valid = 1;
0062         rsite_seg = trk_site_seg;
0063         rsite_bit = 1;
0064 
0065         break;
0066       }  // End loop reduced site track sites
0067     }    // End loop reduced model sites
0068   }      // End loop tracks
0069 
0070   // ===========================================================================
0071   // Find and invalidate duplicate tracks
0072   // ---------------------------------------------------------------------------
0073   for (unsigned int i_rtrk = 0; i_rtrk < reduced_tracks.size(); ++i_rtrk) {  // Begin loop reduced tracks i
0074 
0075     auto& trk_i = tracks[i_rtrk];
0076     const auto& rtrk_i = reduced_tracks[i_rtrk];
0077 
0078     if (rtrk_i.valid == 1) {
0079       for (unsigned int j_rtrk = (i_rtrk + 1); j_rtrk < reduced_tracks.size();
0080            ++j_rtrk) {  // Begin loop reduced tracks j
0081 
0082         auto& rtrk_j = reduced_tracks[j_rtrk];
0083 
0084         // If the reduced track is already invalid, move on
0085         if (rtrk_j.valid == 0)
0086           continue;
0087 
0088         // Compare reduced track sites
0089         for (unsigned int k_rsite = 0; k_rsite < v3::kNumTrackSitesRM; ++k_rsite) {  // Begin loop reduced sites k
0090           const auto& rtrk_site_mask_ik = rtrk_i.site_mask[k_rsite];
0091           const auto& rtrk_site_mask_jk = rtrk_j.site_mask[k_rsite];
0092 
0093           // If one or both of the sites are missing, move on
0094           if (!(rtrk_site_mask_ik & rtrk_site_mask_jk))
0095             continue;
0096 
0097           // Compare segment_ids
0098           const auto& rtrk_seg_id_ik = rtrk_i.site_segs[k_rsite];
0099           const auto& rtrk_seg_id_jk = rtrk_j.site_segs[k_rsite];
0100 
0101           // If segment ids are differente, move on
0102           if (rtrk_seg_id_ik != rtrk_seg_id_jk)
0103             continue;
0104 
0105           // If there's even one collision, invalidate the track
0106           rtrk_j.valid = 0;
0107         }  // End loop reduced sites k
0108       }    // End loop reduced tracks j
0109     }
0110 
0111     // Propagate invalidation
0112     trk_i.valid = rtrk_i.valid;
0113 
0114     // DEBUG
0115     if (this->context_.config_.verbosity_ > 1) {
0116       if (trk_i.valid) {
0117         edm::LogInfo("L1TEMTFpp") << "Unique Track"
0118                                   << " zone " << trk_i.zone << " col " << trk_i.col << " pat " << trk_i.pattern
0119                                   << " qual " << trk_i.quality << " phi " << trk_i.phi << " theta " << trk_i.theta
0120                                   << " valid " << trk_i.valid << std::endl;
0121       }
0122     }
0123   }  // End loop reduced tracks i
0124 }