Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-16 02:43:03

0001 /*
0002 Kalman Filter L1 Muon algorithm
0003 Tyler Lam (UCLA)
0004 Sep. 2021
0005 */
0006 #ifndef L1Trigger_Phase2L1GMT_KMTFCore_h
0007 #define L1Trigger_Phase2L1GMT_KMTFCore_h
0008 #include "L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h"
0009 #include "DataFormats/L1TMuonPhase2/interface/KMTFTrack.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include <cstdlib>
0012 #include "ap_fixed.h"
0013 
0014 namespace Phase2L1GMT {
0015 
0016   class KMTFCore {
0017   public:
0018     typedef ROOT::Math::SVector<double, 2> Vector2;
0019     typedef ROOT::Math::SMatrix<double, 2, 2, ROOT::Math::MatRepSym<double, 2> > CovarianceMatrix2;
0020     typedef ROOT::Math::SMatrix<double, 3, 2> Matrix32;
0021     typedef ROOT::Math::SMatrix<double, 2, 3> Matrix23;
0022     typedef ROOT::Math::SMatrix<double, 1, 3> Matrix13;
0023     typedef ROOT::Math::SMatrix<double, 3, 1> Matrix31;
0024     typedef ROOT::Math::SMatrix<double, 3, 3> Matrix33;
0025 
0026     KMTFCore(const edm::ParameterSet& settings);
0027 
0028     std::pair<l1t::KMTFTrack, l1t::KMTFTrack> chain(const l1t::MuonStubRef& seed, const l1t::MuonStubRefVector& stubs);
0029 
0030     std::vector<l1t::KMTFTrack> clean(const std::vector<l1t::KMTFTrack>& tracks, uint seed, bool vertex);
0031 
0032   private:
0033     std::unique_ptr<KMTFLUTs> lutService_;
0034 
0035     std::pair<bool, uint> match(const l1t::MuonStubRef& seed, const l1t::MuonStubRefVector& stubs, int step);
0036 
0037     int correctedPhiB(const l1t::MuonStubRef& stub);
0038     void propagate(l1t::KMTFTrack& track);
0039     bool update(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, int mask, int seedQual);
0040     bool updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub);
0041     bool updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub);
0042     bool updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, int mask, int seedQual);
0043     void vertexConstraint(l1t::KMTFTrack& track);
0044     void vertexConstraintOffline(l1t::KMTFTrack& track);
0045     void vertexConstraintLUT(l1t::KMTFTrack& track);
0046     int hitPattern(const l1t::KMTFTrack& track);
0047     int customBitmask(unsigned int bit1, unsigned int bit2, unsigned int bit3, unsigned int bit4);
0048     bool getBit(int bitmask, int pos);
0049     void setFourVectors(l1t::KMTFTrack& track);
0050     bool estimateChiSquare(l1t::KMTFTrack& track, bool vertex);
0051     void setRank(l1t::KMTFTrack& track, bool vertex);
0052     int wrapAround(int value, int maximum);
0053     int encode(bool ownwheel, int sector, int tag);
0054     std::pair<bool, uint> getByCode(const std::vector<l1t::KMTFTrack>& tracks, int mask);
0055     uint twosCompToBits(int q);
0056     uint etaStubRank(const l1t::MuonStubRef& stub);
0057     void calculateEta(l1t::KMTFTrack& track);
0058     uint matchAbs(std::map<uint, uint>& info, uint i, uint j);
0059     int ptLUT(int K);
0060 
0061     bool verbose_;
0062 
0063     //Initial Curvature
0064     std::vector<double> initK_;
0065     std::vector<double> initK2_;
0066 
0067     //propagation coefficients
0068     std::vector<double> eLoss_;
0069     std::vector<double> aPhi_;
0070     std::vector<double> aPhiB_;
0071     std::vector<double> aPhiBNLO_;
0072     std::vector<double> bPhi_;
0073     std::vector<double> bPhiB_;
0074     double phiAt2_;
0075     std::vector<double> etaLUT0_;
0076     std::vector<double> etaLUT1_;
0077 
0078     //Chi Square estimator input
0079     uint globalChi2Cut_;
0080     uint globalChi2CutLimit_;
0081 
0082     std::vector<double> chiSquareDisp1_;
0083     std::vector<double> chiSquareDisp2_;
0084     std::vector<double> chiSquareDisp3_;
0085     std::vector<int> chiSquareErrADisp1_;
0086     std::vector<int> chiSquareErrADisp2_;
0087     std::vector<int> chiSquareErrADisp3_;
0088     std::vector<double> chiSquareErrBDisp1_;
0089     std::vector<double> chiSquareErrBDisp2_;
0090     std::vector<double> chiSquareErrBDisp3_;
0091 
0092     std::vector<double> chiSquarePrompt1_;
0093     std::vector<double> chiSquarePrompt2_;
0094     std::vector<double> chiSquarePrompt3_;
0095     std::vector<int> chiSquareErrAPrompt1_;
0096     std::vector<int> chiSquareErrAPrompt2_;
0097     std::vector<int> chiSquareErrAPrompt3_;
0098     std::vector<double> chiSquareErrBPrompt1_;
0099     std::vector<double> chiSquareErrBPrompt2_;
0100     std::vector<double> chiSquareErrBPrompt3_;
0101 
0102     std::vector<int> chiSquareCutDispPattern_;
0103     std::vector<int> chiSquareCutOffDisp_;
0104     std::vector<int> chiSquareCutDisp_;
0105     std::vector<int> chiSquareCutPromptPattern_;
0106     std::vector<int> chiSquareCutOffPrompt_;
0107     std::vector<int> chiSquareCutPrompt_;
0108 
0109     //bitmasks to run== diferent combinations for a given seed in a given station
0110     std::vector<int> combos4_;
0111     std::vector<int> combos3_;
0112     std::vector<int> combos2_;
0113     std::vector<int> combos1_;
0114 
0115     //bits for fixed point precision
0116     static const int PHIBSCALE = 16;
0117     static const int PHIBSCALE_INT = 5;
0118     static const int BITSCURV = 16;
0119     static const int BITSPHI = 18;
0120     static const int BITSPHIB = 17;  // 12 bits *28 (+5 bits)
0121     static const int BITSPARAM = 14;
0122     static const int GAIN_0 = 9;
0123     static const int GAIN_0INT = 6;
0124     static const int GAIN_4 = 9;
0125     static const int GAIN_4INT = 4;
0126     static const int GAIN_V0 = 9;
0127     static const int GAIN_V0INT = 0;
0128 
0129     static const int GAIN2_0 = 12;
0130     static const int GAIN2_0INT = 6;
0131     static const int GAIN2_1 = 12;
0132     static const int GAIN2_1INT = 3;
0133     static const int GAIN2_4 = 12;
0134     static const int GAIN2_4INT = 4;
0135     static const int GAIN2_5 = 12;
0136     static const int GAIN2_5INT = 0;
0137     //STUFF NOT USED IN THE FIRMWARE BUT ONLY FOR DEBUGGING
0138     ///////////////////////////////////////////////////////
0139 
0140     bool useOfflineAlgo_;
0141     std::vector<double> mScatteringPhi_;
0142     std::vector<double> mScatteringPhiB_;
0143     //point resolution for phi
0144     double pointResolutionPhi_;
0145     //point resolution for phiB
0146     double pointResolutionPhiB_;
0147     std::vector<double> pointResolutionPhiBH_;
0148     std::vector<double> pointResolutionPhiBL_;
0149     //double pointResolutionPhiB_;
0150     //point resolution for vertex
0151     double pointResolutionVertex_;
0152     std::vector<double> curvResolution1_;
0153     std::vector<double> curvResolution2_;
0154     //Sorter
0155     class StubSorter {
0156     public:
0157       StubSorter(uint sector) { sec_ = sector; }
0158 
0159       bool operator()(const l1t::MuonStubRef& a, const l1t::MuonStubRef& b) {
0160         if (a->coord1() < b->coord1())
0161           return true;
0162         return false;
0163       }
0164 
0165     private:
0166       int sec_;
0167     };
0168   };
0169 
0170 }  // namespace Phase2L1GMT
0171 #endif