Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-10-14 01:44:01

0001 #ifndef L1Trigger_TrackFindingTracklet_interface_Tracklet_h
0002 #define L1Trigger_TrackFindingTracklet_interface_Tracklet_h
0003 
0004 #include <iostream>
0005 #include <fstream>
0006 #include <cassert>
0007 #include <cmath>
0008 #include <vector>
0009 #include <memory>
0010 #include <set>
0011 
0012 #include "L1Trigger/TrackFindingTracklet/interface/Settings.h"
0013 #include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h"
0014 #include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h"
0015 #include "L1Trigger/TrackFindingTracklet/interface/Track.h"
0016 #include "L1Trigger/TrackFindingTracklet/interface/TrackPars.h"
0017 #include "L1Trigger/TrackFindingTracklet/interface/Projection.h"
0018 #include "L1Trigger/TrackFindingTracklet/interface/Residual.h"
0019 #include "L1Trigger/TrackFindingTracklet/interface/Util.h"
0020 
0021 namespace trklet {
0022 
0023   class Settings;
0024   class Stub;
0025   class Track;
0026 
0027   class Tracklet {
0028   public:
0029     Tracklet(Settings const& settings,
0030              unsigned int iSeed,
0031              const Stub* innerFPGAStub,
0032              const Stub* middleFPGAStub,
0033              const Stub* outerFPGAStub,
0034              double rinv,
0035              double phi0,
0036              double d0,
0037              double z0,
0038              double t,
0039              double rinvapprox,
0040              double phi0approx,
0041              double d0approx,
0042              double z0approx,
0043              double tapprox,
0044              int irinv,
0045              int iphi0,
0046              int id0,
0047              int iz0,
0048              int it,
0049              Projection projs[N_LAYER + N_DISK],
0050              bool disk,
0051              bool overlap = false);
0052 
0053     ~Tracklet() = default;
0054 
0055     //Find tp corresponding to seed.
0056     //Will require 'tight match' such that tp is part of each of the four clustes returns 0 if no tp matches
0057     int tpseed();
0058 
0059     bool stubtruthmatch(const L1TStub* stub);
0060 
0061     const Stub* innerFPGAStub() { return innerFPGAStub_; }
0062 
0063     const Stub* middleFPGAStub() { return middleFPGAStub_; }
0064 
0065     const Stub* outerFPGAStub() { return outerFPGAStub_; }
0066 
0067     std::string addressstr();
0068 
0069     //Tracklet parameters print out
0070     std::string trackletparstr();
0071 
0072     std::string vmstrlayer(int layer, unsigned int allstubindex);
0073 
0074     std::string vmstrdisk(int disk, unsigned int allstubindex);
0075 
0076     std::string trackletprojstr(int layer) const;
0077     std::string trackletprojstrD(int disk) const;
0078 
0079     std::string trackletprojstrlayer(int layer) const { return trackletprojstr(layer); }
0080     std::string trackletprojstrdisk(int disk) const { return trackletprojstrD(disk); }
0081 
0082     bool validProj(int layerdisk) const {
0083       assert(layerdisk >= 0 && layerdisk < N_LAYER + N_DISK);
0084       return proj_[layerdisk].valid();
0085     }
0086 
0087     Projection& proj(int layerdisk) {
0088       assert(validProj(layerdisk));
0089       return proj_[layerdisk];
0090     }
0091 
0092     void addMatch(unsigned int layerdisk,
0093                   int ideltaphi,
0094                   int ideltarz,
0095                   double dphi,
0096                   double drz,
0097                   double dphiapprox,
0098                   double drzapprox,
0099                   int stubid,
0100                   const trklet::Stub* stubptr);
0101 
0102     std::string fullmatchstr(int layer);
0103     std::string fullmatchdiskstr(int disk);
0104 
0105     bool match(unsigned int layerdisk) {
0106       assert(layerdisk < N_LAYER + N_DISK);
0107       return resid_[layerdisk].valid();
0108     }
0109 
0110     const Residual& resid(unsigned int layerdisk) {
0111       assert(layerdisk < N_LAYER + N_DISK);
0112       assert(resid_[layerdisk].valid());
0113       return resid_[layerdisk];
0114     }
0115 
0116     std::vector<const L1TStub*> getL1Stubs();
0117 
0118     std::map<int, int> getStubIDs();
0119 
0120     double rinv() const { return trackpars_.rinv(); }
0121     double phi0() const { return trackpars_.phi0(); }
0122     double d0() const { return trackpars_.d0(); }
0123     double t() const { return trackpars_.t(); }
0124     double z0() const { return trackpars_.z0(); }
0125 
0126     double rinvapprox() const { return trackparsapprox_.rinv(); }
0127     double phi0approx() const { return trackparsapprox_.phi0(); }
0128     double d0approx() const { return trackparsapprox_.d0(); }
0129     double tapprox() const { return trackparsapprox_.t(); }
0130     double z0approx() const { return trackparsapprox_.z0(); }
0131 
0132     const FPGAWord& fpgarinv() const { return fpgapars_.rinv(); }
0133     const FPGAWord& fpgaphi0() const { return fpgapars_.phi0(); }
0134     const FPGAWord& fpgad0() const { return fpgapars_.d0(); }
0135     const FPGAWord& fpgat() const { return fpgapars_.t(); }
0136     const FPGAWord& fpgaz0() const { return fpgapars_.z0(); }
0137 
0138     double rinvfit() const { return fitpars_.rinv(); }
0139     double phi0fit() const { return fitpars_.phi0(); }
0140     double d0fit() const { return fitpars_.d0(); }
0141     double tfit() const { return fitpars_.t(); }
0142     double z0fit() const { return fitpars_.z0(); }
0143     double chiSqfit() const { return chisqrphifit_ + chisqrzfit_; }
0144 
0145     double rinvfitexact() const { return fitparsexact_.rinv(); }
0146     double phi0fitexact() const { return fitparsexact_.phi0(); }
0147     double d0fitexact() const { return fitparsexact_.d0(); }
0148     double tfitexact() const { return fitparsexact_.t(); }
0149     double z0fitexact() const { return fitparsexact_.z0(); }
0150 
0151     const FPGAWord& irinvfit() const { return fpgafitpars_.rinv(); }
0152     const FPGAWord& iphi0fit() const { return fpgafitpars_.phi0(); }
0153     const FPGAWord& id0fit() const { return fpgafitpars_.d0(); }
0154     const FPGAWord& itfit() const { return fpgafitpars_.t(); }
0155     const FPGAWord& iz0fit() const { return fpgafitpars_.z0(); }
0156     FPGAWord ichiSqfit() const {
0157       return FPGAWord(ichisqrphifit_.value() + ichisqrzfit_.value(), ichisqrphifit_.nbits());
0158     }
0159 
0160     // Note floating & digitized helix params after track fit.
0161     void setFitPars(double rinvfit,
0162                     double phi0fit,
0163                     double d0fit,
0164                     double tfit,
0165                     double z0fit,
0166                     double chisqrphifit,
0167                     double chisqrzfit,
0168                     double rinvfitexact,
0169                     double phi0fitexact,
0170                     double d0fitexact,
0171                     double tfitexact,
0172                     double z0fitexact,
0173                     double chisqrphifitexact,
0174                     double chisqrzfitexact,
0175                     int irinvfit,
0176                     int iphi0fit,
0177                     int id0fit,
0178                     int itfit,
0179                     int iz0fit,
0180                     int ichisqrphifit,
0181                     int ichisqrzfit,
0182                     int hitpattern,
0183                     const std::vector<const L1TStub*>& l1stubs = std::vector<const L1TStub*>());
0184 
0185     const std::string layerstubstr(const unsigned layer) const;
0186     const std::string diskstubstr(const unsigned disk) const;
0187     std::string trackfitstr() const;
0188 
0189     // Create a Track object from stubs & digitized track helix params
0190     Track makeTrack(const std::vector<const L1TStub*>& l1stubs);
0191 
0192     Track* getTrack() {
0193       assert(fpgatrack_ != nullptr);
0194       return fpgatrack_.get();
0195     }
0196 
0197     bool fit() const { return ichisqrphifit_.value() != -1; }
0198 
0199     int layer() const;
0200     int disk() const;
0201 
0202     bool isBarrel() const { return barrel_; }
0203     bool isOverlap() const { return overlap_; }
0204     int isDisk() const { return disk_; }
0205 
0206     void setTrackletIndex(unsigned int index);
0207 
0208     int trackletIndex() const { return trackletIndex_; }
0209 
0210     void setTCIndex(int index) { TCIndex_ = index; }
0211 
0212     int TCIndex() const { return TCIndex_; }
0213 
0214     int TCID() const { return TCIndex_ * (1 << settings_.nbitstrackletindex()) + trackletIndex_; }
0215 
0216     int getISeed() const;
0217     int getITC() const;
0218 
0219     void setTrackIndex(int index);
0220     int trackIndex() const;
0221 
0222     unsigned int PSseed() const { return ((layer() == 1) || (layer() == 2) || (disk() != 0)) ? 1 : 0; }
0223 
0224     unsigned int seedIndex() const { return seedIndex_; }
0225 
0226   private:
0227     unsigned int seedIndex_;
0228 
0229     // three types of tracklets + one triplet
0230     bool barrel_;
0231     bool disk_;
0232     bool overlap_;
0233     bool triplet_;
0234 
0235     const Stub* innerFPGAStub_;
0236     const Stub* middleFPGAStub_;
0237     const Stub* outerFPGAStub_;
0238 
0239     int trackletIndex_;
0240     int TCIndex_;
0241     int trackIndex_;
0242 
0243     //Tracklet track parameters
0244     TrackPars<FPGAWord> fpgapars_;
0245 
0246     TrackPars<double> trackpars_;
0247     TrackPars<double> trackparsapprox_;
0248 
0249     // the layer/disk ids that we project to (never project to >4 barrel layers)
0250     int projlayer_[N_LAYER - 2];
0251     int projdisk_[N_DISK];
0252 
0253     //Track parameters from track fit
0254     TrackPars<FPGAWord> fpgafitpars_;
0255     FPGAWord ichisqrphifit_;
0256     FPGAWord ichisqrzfit_;
0257 
0258     TrackPars<double> fitpars_;
0259     double chisqrphifit_;
0260     double chisqrzfit_;
0261 
0262     TrackPars<double> fitparsexact_;
0263     double chisqrphifitexact_;
0264     double chisqrzfitexact_;
0265 
0266     int hitpattern_;
0267 
0268     std::unique_ptr<Track> fpgatrack_;
0269 
0270     Projection proj_[N_LAYER + N_DISK];
0271 
0272     Residual resid_[N_LAYER + N_DISK];
0273 
0274     Settings const& settings_;
0275   };
0276 };  // namespace trklet
0277 #endif