Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-07 22:33:29

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     void setFitPars(double rinvfit,
0161                     double phi0fit,
0162                     double d0fit,
0163                     double tfit,
0164                     double z0fit,
0165                     double chisqrphifit,
0166                     double chisqrzfit,
0167                     double rinvfitexact,
0168                     double phi0fitexact,
0169                     double d0fitexact,
0170                     double tfitexact,
0171                     double z0fitexact,
0172                     double chisqrphifitexact,
0173                     double chisqrzfitexact,
0174                     int irinvfit,
0175                     int iphi0fit,
0176                     int id0fit,
0177                     int itfit,
0178                     int iz0fit,
0179                     int ichisqrphifit,
0180                     int ichisqrzfit,
0181                     int hitpattern,
0182                     const std::vector<const L1TStub*>& l1stubs = std::vector<const L1TStub*>());
0183 
0184     const std::string layerstubstr(const unsigned layer) const;
0185     const std::string diskstubstr(const unsigned disk) const;
0186     std::string trackfitstr() const;
0187 
0188     Track makeTrack(const std::vector<const L1TStub*>& l1stubs);
0189 
0190     Track* getTrack() {
0191       assert(fpgatrack_ != nullptr);
0192       return fpgatrack_.get();
0193     }
0194 
0195     bool fit() const { return ichisqrphifit_.value() != -1; }
0196 
0197     int layer() const;
0198     int disk() const;
0199 
0200     bool isBarrel() const { return barrel_; }
0201     bool isOverlap() const { return overlap_; }
0202     int isDisk() const { return disk_; }
0203 
0204     void setTrackletIndex(unsigned int index);
0205 
0206     int trackletIndex() const { return trackletIndex_; }
0207 
0208     void setTCIndex(int index) { TCIndex_ = index; }
0209 
0210     int TCIndex() const { return TCIndex_; }
0211 
0212     int TCID() const { return TCIndex_ * (1 << settings_.nbitstrackletindex()) + trackletIndex_; }
0213 
0214     int getISeed() const;
0215     int getITC() const;
0216 
0217     void setTrackIndex(int index);
0218     int trackIndex() const;
0219 
0220     unsigned int PSseed() const { return ((layer() == 1) || (layer() == 2) || (disk() != 0)) ? 1 : 0; }
0221 
0222     unsigned int seedIndex() const { return seedIndex_; }
0223 
0224   private:
0225     unsigned int seedIndex_;
0226 
0227     // three types of tracklets + one triplet
0228     bool barrel_;
0229     bool disk_;
0230     bool overlap_;
0231     bool triplet_;
0232 
0233     const Stub* innerFPGAStub_;
0234     const Stub* middleFPGAStub_;
0235     const Stub* outerFPGAStub_;
0236 
0237     int trackletIndex_;
0238     int TCIndex_;
0239     int trackIndex_;
0240 
0241     //Tracklet track parameters
0242     TrackPars<FPGAWord> fpgapars_;
0243 
0244     TrackPars<double> trackpars_;
0245     TrackPars<double> trackparsapprox_;
0246 
0247     // the layer/disk ids that we project to (never project to >4 barrel layers)
0248     int projlayer_[N_LAYER - 2];
0249     int projdisk_[N_DISK];
0250 
0251     //Track parameters from track fit
0252     TrackPars<FPGAWord> fpgafitpars_;
0253     FPGAWord ichisqrphifit_;
0254     FPGAWord ichisqrzfit_;
0255 
0256     TrackPars<double> fitpars_;
0257     double chisqrphifit_;
0258     double chisqrzfit_;
0259 
0260     TrackPars<double> fitparsexact_;
0261     double chisqrphifitexact_;
0262     double chisqrzfitexact_;
0263 
0264     int hitpattern_;
0265 
0266     std::unique_ptr<Track> fpgatrack_;
0267 
0268     Projection proj_[N_LAYER + N_DISK];
0269 
0270     Residual resid_[N_LAYER + N_DISK];
0271 
0272     Settings const& settings_;
0273   };
0274 };  // namespace trklet
0275 #endif