Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-01 23:54:06

0001 #ifndef PHASE2GMT_NODE
0002 #define PHASE2GMT_NODE
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "L1Trigger/Phase2L1GMT/interface/TrackConverter.h"
0005 #include "L1Trigger/Phase2L1GMT/interface/ROITempAssociator.h"
0006 #include "L1Trigger/Phase2L1GMT/interface/TrackMuonMatchAlgorithm.h"
0007 #include "L1Trigger/Phase2L1GMT/interface/Isolation.h"
0008 #include "L1Trigger/Phase2L1GMT/interface/Tauto3Mu.h"
0009 #include "DataFormats/L1TMuonPhase2/interface/TrackerMuon.h"
0010 
0011 namespace Phase2L1GMT {
0012 
0013   class Node {
0014   public:
0015     Node(const edm::ParameterSet& iConfig)
0016         : verbose_(iConfig.getParameter<int>("verbose")),
0017           tt_track_converter_(new TrackConverter(iConfig.getParameter<edm::ParameterSet>("trackConverter"))),
0018           roi_assoc_(new ROITempAssociator(iConfig.getParameter<edm::ParameterSet>("roiTrackAssociator"))),
0019           track_mu_match_(new TrackMuonMatchAlgorithm(iConfig.getParameter<edm::ParameterSet>("trackMatching"))),
0020           isolation_(new Isolation(iConfig.getParameter<edm::ParameterSet>("isolation"))),
0021           tauto3mu_(new Tauto3Mu(iConfig.getParameter<edm::ParameterSet>("tauto3mu"))) {}
0022 
0023     ~Node() {}
0024 
0025     std::vector<l1t::TrackerMuon> processEvent(const std::vector<edm::Ptr<l1t::TrackerMuon::L1TTTrackType> >& tracks,
0026                                                const l1t::ObjectRefBxCollection<l1t::RegionalMuonCand>& muonTracks,
0027                                                const l1t::MuonStubRefVector& stubs) {
0028       //Split tracks to the links as they come
0029       std::vector<edm::Ptr<l1t::TrackerMuon::L1TTTrackType> > tracks0 = associateTracksWithNonant(tracks, 0);
0030       std::vector<edm::Ptr<l1t::TrackerMuon::L1TTTrackType> > tracks1 = associateTracksWithNonant(tracks, 1);
0031       std::vector<edm::Ptr<l1t::TrackerMuon::L1TTTrackType> > tracks2 = associateTracksWithNonant(tracks, 2);
0032       std::vector<edm::Ptr<l1t::TrackerMuon::L1TTTrackType> > tracks3 = associateTracksWithNonant(tracks, 3);
0033       std::vector<edm::Ptr<l1t::TrackerMuon::L1TTTrackType> > tracks4 = associateTracksWithNonant(tracks, 4);
0034       std::vector<edm::Ptr<l1t::TrackerMuon::L1TTTrackType> > tracks5 = associateTracksWithNonant(tracks, 5);
0035       std::vector<edm::Ptr<l1t::TrackerMuon::L1TTTrackType> > tracks6 = associateTracksWithNonant(tracks, 6);
0036       std::vector<edm::Ptr<l1t::TrackerMuon::L1TTTrackType> > tracks7 = associateTracksWithNonant(tracks, 7);
0037       std::vector<edm::Ptr<l1t::TrackerMuon::L1TTTrackType> > tracks8 = associateTracksWithNonant(tracks, 8);
0038 
0039       //Transition stubs to different nonants with overlap
0040       l1t::MuonStubRefVector stubs0 = associateStubsWithNonant(stubs, 0);
0041       l1t::MuonStubRefVector stubs1 = associateStubsWithNonant(stubs, 1);
0042       l1t::MuonStubRefVector stubs2 = associateStubsWithNonant(stubs, 2);
0043       l1t::MuonStubRefVector stubs3 = associateStubsWithNonant(stubs, 3);
0044       l1t::MuonStubRefVector stubs4 = associateStubsWithNonant(stubs, 4);
0045       l1t::MuonStubRefVector stubs5 = associateStubsWithNonant(stubs, 5);
0046       l1t::MuonStubRefVector stubs6 = associateStubsWithNonant(stubs, 6);
0047       l1t::MuonStubRefVector stubs7 = associateStubsWithNonant(stubs, 7);
0048       l1t::MuonStubRefVector stubs8 = associateStubsWithNonant(stubs, 8);
0049 
0050       //Convert TT tracks to our internal tracking format
0051       std::vector<ConvertedTTTrack> convertedTracks0 = tt_track_converter_->convertTracks(tracks0);
0052       std::vector<ConvertedTTTrack> convertedTracks1 = tt_track_converter_->convertTracks(tracks1);
0053       std::vector<ConvertedTTTrack> convertedTracks2 = tt_track_converter_->convertTracks(tracks2);
0054       std::vector<ConvertedTTTrack> convertedTracks3 = tt_track_converter_->convertTracks(tracks3);
0055       std::vector<ConvertedTTTrack> convertedTracks4 = tt_track_converter_->convertTracks(tracks4);
0056       std::vector<ConvertedTTTrack> convertedTracks5 = tt_track_converter_->convertTracks(tracks5);
0057       std::vector<ConvertedTTTrack> convertedTracks6 = tt_track_converter_->convertTracks(tracks6);
0058       std::vector<ConvertedTTTrack> convertedTracks7 = tt_track_converter_->convertTracks(tracks7);
0059       std::vector<ConvertedTTTrack> convertedTracks8 = tt_track_converter_->convertTracks(tracks8);
0060 
0061       //Build ROIs per nonant
0062       std::vector<MuonROI> rois0 = roi_assoc_->associate(0, muonTracks, stubs0);
0063       std::vector<MuonROI> rois1 = roi_assoc_->associate(0, muonTracks, stubs1);
0064       std::vector<MuonROI> rois2 = roi_assoc_->associate(0, muonTracks, stubs2);
0065       std::vector<MuonROI> rois3 = roi_assoc_->associate(0, muonTracks, stubs3);
0066       std::vector<MuonROI> rois4 = roi_assoc_->associate(0, muonTracks, stubs4);
0067       std::vector<MuonROI> rois5 = roi_assoc_->associate(0, muonTracks, stubs5);
0068       std::vector<MuonROI> rois6 = roi_assoc_->associate(0, muonTracks, stubs6);
0069       std::vector<MuonROI> rois7 = roi_assoc_->associate(0, muonTracks, stubs7);
0070       std::vector<MuonROI> rois8 = roi_assoc_->associate(0, muonTracks, stubs8);
0071 
0072       //run track - muon matching per nonant
0073       std::vector<PreTrackMatchedMuon> mu0 = track_mu_match_->processNonant(convertedTracks0, rois0);
0074       std::vector<PreTrackMatchedMuon> mu1 = track_mu_match_->processNonant(convertedTracks1, rois1);
0075       std::vector<PreTrackMatchedMuon> mu2 = track_mu_match_->processNonant(convertedTracks2, rois2);
0076       std::vector<PreTrackMatchedMuon> mu3 = track_mu_match_->processNonant(convertedTracks3, rois3);
0077       std::vector<PreTrackMatchedMuon> mu4 = track_mu_match_->processNonant(convertedTracks4, rois4);
0078       std::vector<PreTrackMatchedMuon> mu5 = track_mu_match_->processNonant(convertedTracks5, rois5);
0079       std::vector<PreTrackMatchedMuon> mu6 = track_mu_match_->processNonant(convertedTracks6, rois6);
0080       std::vector<PreTrackMatchedMuon> mu7 = track_mu_match_->processNonant(convertedTracks7, rois7);
0081       std::vector<PreTrackMatchedMuon> mu8 = track_mu_match_->processNonant(convertedTracks8, rois8);
0082       if (verbose_)
0083         printf("Matching Nonant 5 with %zu tracks and %zu rois and %zu stubs\n",
0084                convertedTracks5.size(),
0085                rois5.size(),
0086                stubs5.size());
0087 
0088       //clean neighboring nonants
0089       std::vector<PreTrackMatchedMuon> muCleaned = track_mu_match_->cleanNeighbor(mu0, mu8, mu1, true);
0090       std::vector<PreTrackMatchedMuon> muCleaned1 = track_mu_match_->cleanNeighbor(mu1, mu0, mu2, false);
0091       std::vector<PreTrackMatchedMuon> muCleaned2 = track_mu_match_->cleanNeighbor(mu2, mu1, mu3, true);
0092       std::vector<PreTrackMatchedMuon> muCleaned3 = track_mu_match_->cleanNeighbor(mu3, mu2, mu4, false);
0093       std::vector<PreTrackMatchedMuon> muCleaned4 = track_mu_match_->cleanNeighbor(mu4, mu3, mu5, true);
0094       std::vector<PreTrackMatchedMuon> muCleaned5 = track_mu_match_->cleanNeighbor(mu5, mu4, mu6, false);
0095       std::vector<PreTrackMatchedMuon> muCleaned6 = track_mu_match_->cleanNeighbor(mu6, mu5, mu7, true);
0096       std::vector<PreTrackMatchedMuon> muCleaned7 = track_mu_match_->cleanNeighbor(mu7, mu6, mu8, false);
0097       std::vector<PreTrackMatchedMuon> muCleaned8 =
0098           track_mu_match_->cleanNeighbor(mu8, mu7, mu0, false);  //ARGH! 9 sectors - so some duplicates very rarely
0099 
0100       //merge all the collections
0101       std::copy(muCleaned1.begin(), muCleaned1.end(), std::back_inserter(muCleaned));
0102       std::copy(muCleaned2.begin(), muCleaned2.end(), std::back_inserter(muCleaned));
0103       std::copy(muCleaned3.begin(), muCleaned3.end(), std::back_inserter(muCleaned));
0104       std::copy(muCleaned4.begin(), muCleaned4.end(), std::back_inserter(muCleaned));
0105       std::copy(muCleaned5.begin(), muCleaned5.end(), std::back_inserter(muCleaned));
0106       std::copy(muCleaned6.begin(), muCleaned6.end(), std::back_inserter(muCleaned));
0107       std::copy(muCleaned7.begin(), muCleaned7.end(), std::back_inserter(muCleaned));
0108       std::copy(muCleaned8.begin(), muCleaned8.end(), std::back_inserter(muCleaned));
0109 
0110       std::vector<l1t::TrackerMuon> trackMatchedMuonsNoIso = track_mu_match_->convert(muCleaned, 32);
0111 
0112       //Isolation and tau3mu will read those muons and all 9 collections of convertedTracks*
0113       std::vector<ConvertedTTTrack> convertedTracks = convertedTracks0;
0114       std::copy(convertedTracks1.begin(), convertedTracks1.end(), std::back_inserter(convertedTracks));
0115       std::copy(convertedTracks2.begin(), convertedTracks2.end(), std::back_inserter(convertedTracks));
0116       std::copy(convertedTracks3.begin(), convertedTracks3.end(), std::back_inserter(convertedTracks));
0117       std::copy(convertedTracks4.begin(), convertedTracks4.end(), std::back_inserter(convertedTracks));
0118       std::copy(convertedTracks5.begin(), convertedTracks5.end(), std::back_inserter(convertedTracks));
0119       std::copy(convertedTracks6.begin(), convertedTracks6.end(), std::back_inserter(convertedTracks));
0120       std::copy(convertedTracks7.begin(), convertedTracks7.end(), std::back_inserter(convertedTracks));
0121       std::copy(convertedTracks8.begin(), convertedTracks8.end(), std::back_inserter(convertedTracks));
0122 
0123       //sorter here:
0124       std::vector<l1t::TrackerMuon> sortedTrackMuonsNoIso = track_mu_match_->sort(trackMatchedMuonsNoIso, 12);
0125 
0126       isolation_->isolation_allmu_alltrk(sortedTrackMuonsNoIso, convertedTracks);
0127 
0128       //tauto3mu_->GetTau3Mu(sortedTrackMuonsNoIso, convertedTracks);
0129 
0130       track_mu_match_->outputGT(sortedTrackMuonsNoIso);
0131 
0132       return sortedTrackMuonsNoIso;  //when we add more collections like tau3mu etc we change that
0133     }
0134 
0135   private:
0136     int verbose_;
0137     std::unique_ptr<TrackConverter> tt_track_converter_;
0138     std::unique_ptr<ROITempAssociator> roi_assoc_;
0139     std::unique_ptr<TrackMuonMatchAlgorithm> track_mu_match_;
0140     std::unique_ptr<Isolation> isolation_;
0141     std::unique_ptr<Tauto3Mu> tauto3mu_;
0142 
0143     std::vector<edm::Ptr<l1t::TrackerMuon::L1TTTrackType> > associateTracksWithNonant(
0144         const std::vector<edm::Ptr<l1t::TrackerMuon::L1TTTrackType> >& tracks, uint processor) {
0145       std::vector<edm::Ptr<l1t::TrackerMuon::L1TTTrackType> > out;
0146       for (const auto& track : tracks) {
0147         if (track->phiSector() == processor) {
0148           out.push_back(track);
0149         }
0150       }
0151       return out;
0152     }
0153 
0154     l1t::MuonStubRefVector associateStubsWithNonant(const l1t::MuonStubRefVector& allStubs, uint processor) {
0155       l1t::MuonStubRefVector out;
0156 
0157       ap_int<BITSSTUBCOORD> center = ap_int<BITSSTUBCOORD>((processor * 910) / 32);
0158 
0159       for (const auto& s : allStubs) {
0160         ap_int<BITSSTUBCOORD> phi = 0;
0161         if (s->quality() & 0x1)
0162           phi = s->coord1();
0163         else
0164           phi = s->coord2();
0165 
0166         ap_int<BITSSTUBCOORD> deltaPhi = phi - center;
0167         ap_uint<BITSSTUBCOORD - 1> absDeltaPhi =
0168             (deltaPhi < 0) ? ap_uint<BITSSTUBCOORD - 1>(-deltaPhi) : ap_uint<BITSSTUBCOORD - 1>(deltaPhi);
0169         if (absDeltaPhi < 42)
0170           out.push_back(s);
0171 
0172         /* if (processor==0 && phi>=-3000/32 && phi<=3000/32 ) */
0173         /*   out.push_back(s); */
0174         /* else if (processor==1 && (phi>=-1000/32 && phi<=5000/32) ) */
0175         /*   out.push_back(s); */
0176         /* else if (processor==2 && (phi>=500/32 && phi<=6500/32) ) */
0177         /*   out.push_back(s); */
0178         /* else if (processor==3 && (phi>=2000/32 || phi<=-8000/32) ) */
0179         /*   out.push_back(s); */
0180         /* else if (processor==4 && (phi>=4500/32 || phi<=-6000/32) ) */
0181         /*   out.push_back(s); */
0182         /* else if (processor==5 && (phi>=6000/32 || phi<=-4500/32) ) */
0183         /*   out.push_back(s); */
0184         /* else if (processor==6 && (phi>=8000/32 || phi<=-2000/32) ) */
0185         /*   out.push_back(s); */
0186         /* else if (processor==7 && (phi>=-7000/32 && phi<=0) ) */
0187         /*   out.push_back(s); */
0188         /* else if (processor==8 && (phi>=-4500/32 && phi<=1000/32) ) */
0189         /*   out.push_back(s); */
0190       }
0191       return out;
0192     }
0193   };
0194 }  // namespace Phase2L1GMT
0195 
0196 #endif