Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-02 03:45:30

0001 ////////
0002 //
0003 // class to store the 96-bit track word produced by the L1 Track Trigger.  Intended to be inherited by L1 TTTrack.
0004 // packing scheme given below.
0005 //
0006 // author: Mike Hildreth
0007 // modified by: Alexx Perloff
0008 // created:     April 9, 2019
0009 // modified:    March 9, 2021
0010 //
0011 ///////
0012 
0013 #include "DataFormats/L1TrackTrigger/interface/TTTrack_TrackWord.h"
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015 
0016 void tttrack_trackword::infoTestDigitizationScheme(const unsigned int nBits,
0017                                                    const double lsb,
0018                                                    const double floatingPointValue,
0019                                                    const unsigned int digitizedSignedValue,
0020                                                    const double undigitizedSignedValue,
0021                                                    const unsigned int redigitizedSignedValue) {
0022   edm::LogInfo("TTTrack_TrackWord") << "testDigitizationScheme: (nBits, lsb) = (" << nBits << ", " << lsb << ")\n"
0023                                     << "Floating point value = " << floatingPointValue
0024                                     << "\tDigitized value = " << digitizedSignedValue
0025                                     << "\tUn-digitized value = " << undigitizedSignedValue
0026                                     << "\tRe-digitized value = " << redigitizedSignedValue;
0027 }
0028 
0029 //Constructor - turn track parameters into 96-bit word
0030 TTTrack_TrackWord::TTTrack_TrackWord(unsigned int valid,
0031                                      const GlobalVector& momentum,
0032                                      const GlobalPoint& POCA,
0033                                      double rInv,
0034                                      double chi2RPhi,  // would be xy chisq if chi2Z is non-zero
0035                                      double chi2RZ,
0036                                      double bendChi2,
0037                                      unsigned int hitPattern,
0038                                      unsigned int mvaQuality,
0039                                      unsigned int mvaOther,
0040                                      unsigned int sector) {
0041   setTrackWord(valid, momentum, POCA, rInv, chi2RPhi, chi2RZ, bendChi2, hitPattern, mvaQuality, mvaOther, sector);
0042 }
0043 
0044 TTTrack_TrackWord::TTTrack_TrackWord(unsigned int valid,
0045                                      unsigned int rInv,
0046                                      unsigned int phi0,
0047                                      unsigned int tanl,
0048                                      unsigned int z0,
0049                                      unsigned int d0,
0050                                      unsigned int chi2RPhi,  // would be total chisq if chi2Z is zero
0051                                      unsigned int chi2RZ,
0052                                      unsigned int bendChi2,
0053                                      unsigned int hitPattern,
0054                                      unsigned int mvaQuality,
0055                                      unsigned int mvaOther) {
0056   setTrackWord(valid, rInv, phi0, tanl, z0, d0, chi2RPhi, chi2RZ, bendChi2, hitPattern, mvaQuality, mvaOther);
0057 }
0058 
0059 // A setter for the floating point values
0060 void TTTrack_TrackWord::setTrackWord(unsigned int valid,
0061                                      const GlobalVector& momentum,
0062                                      const GlobalPoint& POCA,
0063                                      double rInv,
0064                                      double chi2RPhi,  // would be total chisq if chi2Z is zero
0065                                      double chi2RZ,
0066                                      double bendChi2,
0067                                      unsigned int hitPattern,
0068                                      unsigned int mvaQuality,
0069                                      unsigned int mvaOther,
0070                                      unsigned int sector) {
0071   // first, derive quantities to be packed
0072   float rPhi = localPhi(momentum.phi(), sector);  // this needs to be phi relative to the center of the sector
0073   float rTanl = momentum.z() / momentum.perp();
0074   float rZ0 = POCA.z();
0075   float rD0 = POCA.perp();
0076 
0077   // bin and convert to integers
0078   valid_t valid_ = valid;
0079   rinv_t rInv_ = digitizeSignedValue(rInv, TrackBitWidths::kRinvSize, stepRinv);
0080   phi_t phi0_ = digitizeSignedValue(rPhi, TrackBitWidths::kPhiSize, stepPhi0);
0081   tanl_t tanl_ = digitizeSignedValue(rTanl, TrackBitWidths::kTanlSize, stepTanL);
0082   z0_t z0_ = digitizeSignedValue(rZ0, TrackBitWidths::kZ0Size, stepZ0);
0083   d0_t d0_ = digitizeSignedValue(rD0, TrackBitWidths::kD0Size, stepD0);
0084   chi2rphi_t chi2RPhi_ = getBin(chi2RPhi, chi2RPhiBins);
0085   chi2rz_t chi2RZ_ = getBin(chi2RZ, chi2RZBins);
0086   bendChi2_t bendChi2_ = getBin(bendChi2, bendChi2Bins);
0087   hit_t hitPattern_ = hitPattern;
0088   qualityMVA_t mvaQuality_ = mvaQuality;
0089   otherMVA_t mvaOther_ = mvaOther;
0090 
0091   // pack the track word
0092   //trackWord = ( mvaOther_, mvaQuality_, hitPattern_, bendChi2_, chi2RZ_, chi2RPhi_, d0_, z0_, tanl_, phi0_, rInv_, valid_ );
0093   setTrackWord(
0094       valid_, rInv_, phi0_, tanl_, z0_, d0_, chi2RPhi_, chi2RZ_, bendChi2_, hitPattern_, mvaQuality_, mvaOther_);
0095 }
0096 
0097 // A setter for already-digitized values
0098 void TTTrack_TrackWord::setTrackWord(unsigned int valid,
0099                                      unsigned int rInv,
0100                                      unsigned int phi0,
0101                                      unsigned int tanl,
0102                                      unsigned int z0,
0103                                      unsigned int d0,
0104                                      unsigned int chi2RPhi,  // would be total chisq if chi2Z is zero
0105                                      unsigned int chi2RZ,
0106                                      unsigned int bendChi2,
0107                                      unsigned int hitPattern,
0108                                      unsigned int mvaQuality,
0109                                      unsigned int mvaOther) {
0110   // bin and convert to integers
0111   valid_t valid_ = valid;
0112   rinv_t rInv_ = rInv;
0113   phi_t phi0_ = phi0;
0114   tanl_t tanl_ = tanl;
0115   z0_t z0_ = z0;
0116   d0_t d0_ = d0;
0117   chi2rphi_t chi2RPhi_ = chi2RPhi;
0118   chi2rz_t chi2RZ_ = chi2RZ;
0119   bendChi2_t bendChi2_ = bendChi2;
0120   hit_t hitPattern_ = hitPattern;
0121   qualityMVA_t mvaQuality_ = mvaQuality;
0122   otherMVA_t mvaOther_ = mvaOther;
0123 
0124   // pack the track word
0125   //trackWord = ( otherMVA_t(mvaOther), qualityMVA_t(mvaQuality), hit_t(hitPattern),
0126   //              bendChi2_t(bendChi2), chi2rz_t(chi2RZ), chi2rphi_t(chi2RPhi),
0127   //              d0_t(d0), z0_t(z0), tanl_t(tanl), phi_t(phi0), rinv_t(rInv), valid_t(valid) );
0128   setTrackWord(
0129       valid_, rInv_, phi0_, tanl_, z0_, d0_, chi2RPhi_, chi2RZ_, bendChi2_, hitPattern_, mvaQuality_, mvaOther_);
0130 }
0131 
0132 void TTTrack_TrackWord::setTrackWord(
0133     ap_uint<TrackBitWidths::kValidSize> valid,
0134     ap_uint<TrackBitWidths::kRinvSize> rInv,
0135     ap_uint<TrackBitWidths::kPhiSize> phi0,
0136     ap_uint<TrackBitWidths::kTanlSize> tanl,
0137     ap_uint<TrackBitWidths::kZ0Size> z0,
0138     ap_uint<TrackBitWidths::kD0Size> d0,
0139     ap_uint<TrackBitWidths::kChi2RPhiSize> chi2RPhi,  // would be total chisq if chi2Z is zero
0140     ap_uint<TrackBitWidths::kChi2RZSize> chi2RZ,
0141     ap_uint<TrackBitWidths::kBendChi2Size> bendChi2,
0142     ap_uint<TrackBitWidths::kHitPatternSize> hitPattern,
0143     ap_uint<TrackBitWidths::kMVAQualitySize> mvaQuality,
0144     ap_uint<TrackBitWidths::kMVAOtherSize> mvaOther) {
0145   // pack the track word
0146   unsigned int offset = 0;
0147   for (unsigned int b = offset; b < (offset + TrackBitWidths::kMVAOtherSize); b++) {
0148     trackWord_.set(b, mvaOther[b - offset]);
0149   }
0150   offset += TrackBitWidths::kMVAOtherSize;
0151   for (unsigned int b = offset; b < (offset + TrackBitWidths::kMVAQualitySize); b++) {
0152     trackWord_.set(b, mvaQuality[b - offset]);
0153   }
0154   offset += TrackBitWidths::kMVAQualitySize;
0155   for (unsigned int b = offset; b < (offset + TrackBitWidths::kHitPatternSize); b++) {
0156     trackWord_.set(b, hitPattern[b - offset]);
0157   }
0158   offset += TrackBitWidths::kHitPatternSize;
0159   for (unsigned int b = offset; b < (offset + TrackBitWidths::kBendChi2Size); b++) {
0160     trackWord_.set(b, bendChi2[b - offset]);
0161   }
0162   offset += TrackBitWidths::kBendChi2Size;
0163   for (unsigned int b = offset; b < (offset + TrackBitWidths::kD0Size); b++) {
0164     trackWord_.set(b, d0[b - offset]);
0165   }
0166   offset += TrackBitWidths::kD0Size;
0167   for (unsigned int b = offset; b < (offset + TrackBitWidths::kChi2RZSize); b++) {
0168     trackWord_.set(b, chi2RZ[b - offset]);
0169   }
0170   offset += TrackBitWidths::kChi2RZSize;
0171   for (unsigned int b = offset; b < (offset + TrackBitWidths::kZ0Size); b++) {
0172     trackWord_.set(b, z0[b - offset]);
0173   }
0174   offset += TrackBitWidths::kZ0Size;
0175   for (unsigned int b = offset; b < (offset + TrackBitWidths::kTanlSize); b++) {
0176     trackWord_.set(b, tanl[b - offset]);
0177   }
0178   offset += TrackBitWidths::kTanlSize;
0179   for (unsigned int b = offset; b < (offset + TrackBitWidths::kChi2RPhiSize); b++) {
0180     trackWord_.set(b, chi2RPhi[b - offset]);
0181   }
0182   offset += TrackBitWidths::kChi2RPhiSize;
0183   for (unsigned int b = offset; b < (offset + TrackBitWidths::kPhiSize); b++) {
0184     trackWord_.set(b, phi0[b - offset]);
0185   }
0186   offset += TrackBitWidths::kPhiSize;
0187   for (unsigned int b = offset; b < (offset + TrackBitWidths::kRinvSize); b++) {
0188     trackWord_.set(b, rInv[b - offset]);
0189   }
0190   offset += TrackBitWidths::kRinvSize;
0191   for (unsigned int b = offset; b < offset + TrackBitWidths::kValidSize; b++) {
0192     trackWord_.set(b, valid[b - offset]);
0193   }
0194 }
0195 
0196 bool TTTrack_TrackWord::singleDigitizationSchemeTest(const double floatingPointValue,
0197                                                      const unsigned int nBits,
0198                                                      const double lsb) const {
0199   unsigned int digitizedSignedValue = digitizeSignedValue(floatingPointValue, nBits, lsb);
0200   double undigitizedSignedValue = undigitizeSignedValue(digitizedSignedValue, nBits, lsb);
0201   unsigned int redigitizedSignedValue = digitizeSignedValue(undigitizedSignedValue, nBits, lsb);
0202   tttrack_trackword::infoTestDigitizationScheme(
0203       nBits, lsb, floatingPointValue, digitizedSignedValue, undigitizedSignedValue, redigitizedSignedValue);
0204   return (std::abs(floatingPointValue - undigitizedSignedValue) <= (lsb / 2.0)) &&
0205          (digitizedSignedValue == redigitizedSignedValue);
0206 }
0207 
0208 void TTTrack_TrackWord::testDigitizationScheme() const {
0209   /*
0210   Expected output:
0211     testDigitizationScheme: Floating point value = -4 Digitized value = 4  Un-digitized value = -3.5
0212     testDigitizationScheme: Floating point value = 3  Digitized value = 3  Un-digitized value = 3.5
0213     testDigitizationScheme: Floating point value = -3.5 Digitized value = 9  Un-digitized value = -3.25
0214     testDigitizationScheme: Floating point value = 3.5  Digitized value = 7  Un-digitized value = 3.75
0215   */
0216   assert(singleDigitizationSchemeTest(-4.0, 3, 1.0));
0217   assert(singleDigitizationSchemeTest(3.0, 3, 1.0));
0218   assert(singleDigitizationSchemeTest(-3.5, 4, 0.5));
0219   assert(singleDigitizationSchemeTest(3.5, 4, 0.5));
0220 }