Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:13:42

0001 #include "L1Trigger/TrackFindingTMTT/interface/Make3Dtracks.h"
0002 #include "L1Trigger/TrackFindingTMTT/interface/L1track2D.h"
0003 #include "L1Trigger/TrackFindingTMTT/interface/Settings.h"
0004 
0005 #include <iostream>
0006 #include <unordered_set>
0007 
0008 using namespace std;
0009 
0010 namespace tmtt {
0011 
0012   class Settings;
0013 
0014   //=== Initialization
0015 
0016   Make3Dtracks::Make3Dtracks(const Settings* settings,
0017                              unsigned int iPhiSec,
0018                              unsigned int iEtaReg,
0019                              float etaMinSector,
0020                              float etaMaxSector,
0021                              float phiCentreSector)
0022       :  // Store config params & arguments.
0023         settings_(settings),
0024         iPhiSec_(iPhiSec),  // Sector number
0025         iEtaReg_(iEtaReg),
0026         etaMinSector_(etaMinSector),        // Range of eta sector
0027         etaMaxSector_(etaMaxSector),        // Range of eta sector
0028         phiCentreSector_(phiCentreSector),  // Centre of phi sector
0029 
0030         // Note if any fitters require an r-z track filter to be run.
0031         runRZfilter_(not settings->useRZfilter().empty()) {
0032     // Initialize any track filters (e.g. r-z) run after the r-phi Hough transform.
0033     if (runRZfilter_)
0034       rzFilter_ =
0035           std::make_unique<TrkRZfilter>(settings_, iPhiSec_, iEtaReg_, etaMinSector_, etaMaxSector_, phiCentreSector_);
0036   }
0037 
0038   //=== Convert 2D tracks found by HT within the current sector to 3D tracks, without running any r-z track filter.
0039   //=== by adding a rough estimate of their r-z helix parameters.
0040 
0041   void Make3Dtracks::makeUnfilteredTrks(const list<L1track2D>& vecTracksRphi) {
0042     vecTracks3D_unfiltered_.clear();
0043 
0044     for (const L1track2D& trkRphi : vecTracksRphi) {
0045       const vector<Stub*>& stubsOnTrkRphi = trkRphi.stubs();  // stubs assigned to track
0046 
0047       float qOverPt = trkRphi.helix2D().first;
0048       float phi0 = trkRphi.helix2D().second;
0049 
0050       if (settings_->enableDigitize()) {
0051         // Centre of HT bin lies on boundary of two fitted track digi bins, so nudge slightly +ve (like FW)
0052         // to remove ambiguity.
0053         const float small = 0.1;
0054         const unsigned int nHelixBits = 18;  // Bits used internally in KF HLS to represent helix params.
0055         qOverPt += (2. / settings_->invPtToInvR()) * small * settings_->kf_oneOver2rRange() / pow(2., nHelixBits);
0056         phi0 += small * settings_->kf_phi0Range() / pow(2., nHelixBits);
0057       }
0058       pair<float, float> helixRphi(qOverPt, phi0);
0059 
0060       // Estimate r-z track helix parameters from centre of eta sector.
0061       float z0 = 0.;
0062       float tan_lambda = 0.5 * (1 / tan(2 * atan(exp(-etaMinSector_))) + 1 / tan(2 * atan(exp(-etaMaxSector_))));
0063 
0064       pair<float, float> helixRz(z0, tan_lambda);
0065 
0066       // Create 3D track, by adding r-z helix params to 2D track
0067       L1track3D trk3D(settings_,
0068                       stubsOnTrkRphi,
0069                       trkRphi.cellLocationHT(),
0070                       helixRphi,
0071                       helixRz,
0072                       iPhiSec_,
0073                       iEtaReg_,
0074                       trkRphi.optoLinkID(),
0075                       trkRphi.mergedHTcell());
0076 
0077       // Optionally use MC truth to eliminate all fake tracks & all incorrect stubs assigned to tracks
0078       // before doing fit (for debugging).
0079       bool cheat_keep = true;
0080       if (settings_->trackFitCheat())
0081         cheat_keep = trk3D.cheat();
0082 
0083       // Add to list of stored 3D tracks.
0084       if (cheat_keep)
0085         vecTracks3D_unfiltered_.push_back(trk3D);
0086     }
0087   }
0088 
0089   //=== Make 3D tracks from the 2D tracks found by the HT within the current sector, by running the r-z track filter.
0090   //=== The r-z filter also adds an estimate of the r-z helix parameters to each track.
0091 
0092   void Make3Dtracks::makeRZfilteredTrks(const list<L1track2D>& vecTracksRphi) {
0093     vecTracks3D_rzFiltered_ = rzFilter_->filterTracks(vecTracksRphi);
0094 
0095     // Optionally use MC truth to eliminate all fake tracks & all incorrect stubs assigned to tracks
0096     // before doing fit (for debugging).
0097     if (settings_->trackFitCheat()) {
0098       list<L1track3D> vecTracks3D_tmp;
0099       for (const L1track3D& trk : vecTracks3D_rzFiltered_) {
0100         L1track3D trk_tmp = trk;
0101         bool cheat_keep = trk_tmp.cheat();
0102         if (cheat_keep)
0103           vecTracks3D_tmp.push_back(trk_tmp);
0104       }
0105       vecTracks3D_rzFiltered_ = vecTracks3D_tmp;
0106     }
0107   }
0108 
0109   //=== Get all 3D track candidates (either r-z filtered on unfiltered, depending on the boolean),
0110   //=== that are associated to the given tracking particle.
0111   //=== (If the vector is empty, then the tracking particle was not reconstructed in this sector).
0112 
0113   vector<const L1track3D*> Make3Dtracks::assocTrackCands3D(const TP& tp, bool rzFiltered) const {
0114     const list<L1track3D>& allTracks3D = (rzFiltered) ? vecTracks3D_rzFiltered_ : vecTracks3D_unfiltered_;
0115 
0116     vector<const L1track3D*> assocRecoTrk;
0117 
0118     // Loop over track candidates, looking for those associated to given TP.
0119     for (const L1track3D& trk : allTracks3D) {
0120       if (trk.matchedTP() != nullptr) {
0121         if (trk.matchedTP()->index() == tp.index())
0122           assocRecoTrk.push_back(&trk);
0123       }
0124     }
0125 
0126     return assocRecoTrk;
0127   }
0128 
0129 }  // namespace tmtt