File indexing completed on 2024-04-06 12:21:48
0001 #ifndef L1Trigger_TrackFindingTMTT_L1fittedTrack_h
0002 #define L1Trigger_TrackFindingTMTT_L1fittedTrack_h
0003
0004 #include "FWCore/Utilities/interface/Exception.h"
0005 #include "DataFormats/Math/interface/deltaPhi.h"
0006 #include "L1Trigger/TrackFindingTMTT/interface/L1trackBase.h"
0007 #include "L1Trigger/TrackFindingTMTT/interface/L1track3D.h"
0008 #include "L1Trigger/TrackFindingTMTT/interface/Settings.h"
0009 #include "L1Trigger/TrackFindingTMTT/interface/Utility.h"
0010 #include "L1Trigger/TrackFindingTMTT/interface/TP.h"
0011 #include "L1Trigger/TrackFindingTMTT/interface/Stub.h"
0012 #include "L1Trigger/TrackFindingTMTT/interface/Sector.h"
0013 #include "L1Trigger/TrackFindingTMTT/interface/HTrphi.h"
0014 #include "L1Trigger/TrackFindingTMTT/interface/DigitalTrack.h"
0015 #include "L1Trigger/TrackFindingTMTT/interface/KFTrackletTrack.h"
0016
0017 #include <vector>
0018 #include <set>
0019 #include <utility>
0020 #include <string>
0021 #include <memory>
0022
0023
0024
0025
0026
0027
0028 namespace tmtt {
0029
0030 class L1fittedTrack : public L1trackBase {
0031 public:
0032
0033
0034
0035
0036
0037 L1fittedTrack(const Settings* settings,
0038 const L1track3D* l1track3D,
0039 const std::vector<Stub*>& stubs,
0040 unsigned int hitPattern,
0041 float qOverPt,
0042 float d0,
0043 float phi0,
0044 float z0,
0045 float tanLambda,
0046 float chi2rphi,
0047 float chi2rz,
0048 unsigned int nHelixParam,
0049 bool accepted = true)
0050 : L1trackBase(),
0051 settings_(settings),
0052 l1track3D_(l1track3D),
0053 stubs_(stubs),
0054 stubsConst_(stubs_.begin(), stubs_.end()),
0055 hitPattern_(hitPattern),
0056 qOverPt_(qOverPt),
0057 d0_(d0),
0058 phi0_(phi0),
0059 z0_(z0),
0060 tanLambda_(tanLambda),
0061 chi2rphi_(chi2rphi),
0062 chi2rz_(chi2rz),
0063 done_bcon_(false),
0064 qOverPt_bcon_(qOverPt),
0065 d0_bcon_(d0),
0066 phi0_bcon_(phi0),
0067 chi2rphi_bcon_(chi2rphi),
0068 nHelixParam_(nHelixParam),
0069 nSkippedLayers_(0),
0070 numUpdateCalls_(0),
0071 numIterations_(0),
0072 accepted_(accepted) {
0073 if (l1track3D != nullptr) {
0074 iPhiSec_ = l1track3D->iPhiSec();
0075 iEtaReg_ = l1track3D->iEtaReg();
0076 optoLinkID_ = l1track3D->optoLinkID();
0077 } else {
0078 iPhiSec_ = 0;
0079 iEtaReg_ = 0;
0080 optoLinkID_ = 0;
0081 }
0082 if (settings != nullptr) {
0083
0084 nLayers_ = Utility::countLayers(settings, stubs_);
0085
0086 matchedTP_ = Utility::matchingTP(settings, stubs_, nMatchedLayers_, matchedStubs_);
0087 } else {
0088 nLayers_ = 0;
0089 matchedTP_ = nullptr;
0090 }
0091
0092 if (nHelixParam == 4) {
0093 d0_ = 0.;
0094 d0_bcon_ = 0.;
0095 }
0096 if (settings != nullptr && not settings->hybrid()) {
0097
0098 secTmp_ = std::make_shared<Sector>(settings, iPhiSec_, iEtaReg_);
0099
0100 htRphiTmp_ = std::make_shared<HTrphi>(
0101 settings, iPhiSec_, iEtaReg_, secTmp_->etaMin(), secTmp_->etaMax(), secTmp_->phiCentre());
0102 this->setConsistentHTcell();
0103 } else {
0104 consistentCell_ = false;
0105 }
0106 }
0107
0108
0109 L1fittedTrack() : L1fittedTrack(nullptr, nullptr, noStubs_, 0, 0., 0., 0., 0., 0., 0., 0., 0, false) {}
0110
0111 ~L1fittedTrack() override = default;
0112
0113
0114 void setBeamConstr(float qOverPt_bcon, float phi0_bcon, float chi2rphi_bcon, bool accepted) {
0115 done_bcon_ = true;
0116 qOverPt_bcon_ = qOverPt_bcon;
0117 d0_bcon_ = 0.0, phi0_bcon_ = phi0_bcon;
0118 chi2rphi_bcon_ = chi2rphi_bcon;
0119 accepted_ = accepted;
0120 }
0121
0122
0123
0124
0125 void setInfoKF(unsigned int nSkippedLayers, unsigned int numUpdateCalls) {
0126 nSkippedLayers_ = nSkippedLayers;
0127 numUpdateCalls_ = numUpdateCalls;
0128 }
0129 void setInfoLR(int numIterations, std::string lostMatchingState, std::unordered_map<std::string, int> stateCalls) {
0130 numIterations_ = numIterations;
0131 lostMatchingState_ = lostMatchingState;
0132 stateCalls_ = stateCalls;
0133 }
0134 void setInfoCHI2() {}
0135
0136 void infoKF(unsigned int& nSkippedLayers, unsigned int& numUpdateCalls) const {
0137 nSkippedLayers = nSkippedLayers_;
0138 numUpdateCalls = numUpdateCalls_;
0139 }
0140 void infoLR(int& numIterations,
0141 std::string& lostMatchingState,
0142 std::unordered_map<std::string, int>& stateCalls) const {
0143 numIterations = numIterations_;
0144 lostMatchingState = lostMatchingState_;
0145 stateCalls = stateCalls_;
0146 }
0147 void infoCHI2() const {}
0148
0149
0150
0151 KFTrackletTrack returnKFTrackletTrack() {
0152 KFTrackletTrack trk_(l1track3D(),
0153 stubsConst(),
0154 hitPattern(),
0155 qOverPt(),
0156 d0(),
0157 phi0(),
0158 z0(),
0159 tanLambda(),
0160 chi2rphi(),
0161 chi2rz(),
0162 nHelixParam(),
0163 iPhiSec(),
0164 iEtaReg(),
0165 accepted(),
0166 done_bcon(),
0167 qOverPt_bcon(),
0168 d0_bcon(),
0169 phi0_bcon(),
0170 chi2rphi_bcon());
0171 return trk_;
0172 }
0173
0174
0175
0176
0177
0178 const L1track3D* l1track3D() const { return l1track3D_; }
0179
0180
0181 const std::vector<const Stub*>& stubsConst() const override { return stubsConst_; }
0182 const std::vector<Stub*>& stubs() const override { return stubs_; }
0183
0184 unsigned int numStubs() const override { return stubs_.size(); }
0185
0186 unsigned int numLayers() const override { return nLayers_; }
0187
0188 unsigned int numKilledStubs() const { return l1track3D_->numStubs() - this->numStubs(); }
0189
0190 unsigned int hitPattern() const { return hitPattern_; }
0191
0192
0193
0194
0195 std::pair<unsigned int, unsigned int> cellLocationFit() const { return htRphiTmp_->cell(this); }
0196
0197 std::pair<unsigned int, unsigned int> cellLocationHT() const override { return l1track3D_->cellLocationHT(); }
0198
0199
0200
0201
0202
0203 const TP* matchedTP() const override { return matchedTP_; }
0204
0205 const std::vector<const Stub*>& matchedStubs() const override { return matchedStubs_; }
0206
0207 unsigned int numMatchedStubs() const override { return matchedStubs_.size(); }
0208
0209 unsigned int numMatchedLayers() const override { return nMatchedLayers_; }
0210
0211 float purity() const { return numMatchedStubs() / float(numStubs()); }
0212
0213 unsigned int numKilledMatchedStubs() const {
0214 unsigned int nStubCount = l1track3D_->numMatchedStubs();
0215 if (nStubCount > 0) {
0216 const TP* tp = l1track3D_->matchedTP();
0217 for (const Stub* s : stubs_) {
0218 std::set<const TP*> assTPs = s->assocTPs();
0219 if (assTPs.find(tp) != assTPs.end())
0220 nStubCount--;
0221 }
0222 }
0223 return nStubCount;
0224 }
0225
0226
0227
0228 float qOverPt() const override { return qOverPt_; }
0229 float charge() const { return (qOverPt_ > 0 ? 1 : -1); }
0230 float invPt() const { return std::abs(qOverPt_); }
0231
0232 float pt() const {
0233 constexpr float small = 1.0e-6;
0234 return 1. / (small + this->invPt());
0235 }
0236 float d0() const { return d0_; }
0237 float phi0() const override { return phi0_; }
0238 float z0() const { return z0_; }
0239 float tanLambda() const { return tanLambda_; }
0240 float theta() const { return atan2(1., tanLambda_); }
0241 float eta() const { return -log(tan(0.5 * this->theta())); }
0242
0243
0244
0245
0246 bool done_bcon() const { return done_bcon_; }
0247 float qOverPt_bcon() const { return qOverPt_bcon_; }
0248 float charge_bcon() const { return (qOverPt_bcon_ > 0 ? 1 : -1); }
0249 float invPt_bcon() const { return std::abs(qOverPt_bcon_); }
0250
0251 float pt_bcon() const {
0252 constexpr float small = 1.0e-6;
0253 return 1. / (small + this->invPt_bcon());
0254 }
0255 float phi0_bcon() const { return phi0_bcon_; }
0256 float d0_bcon() const { return d0_bcon_; }
0257
0258
0259
0260 float phiAtChosenR(bool beamConstraint) const {
0261 if (beamConstraint) {
0262 return reco::deltaPhi(phi0_bcon_ - ((settings_->invPtToDphi() * settings_->chosenRofPhi()) * qOverPt_bcon_) -
0263 d0_bcon_ / (settings_->chosenRofPhi()),
0264 0.);
0265 } else {
0266 return reco::deltaPhi(phi0_ - ((settings_->invPtToDphi() * settings_->chosenRofPhi()) * qOverPt_) -
0267 d0_ / (settings_->chosenRofPhi()),
0268 0.);
0269 }
0270 }
0271 float zAtChosenR() const {
0272 return (z0_ + (settings_->chosenRofZ()) * tanLambda_);
0273 }
0274
0275
0276 float nHelixParam() const { return nHelixParam_; }
0277
0278
0279 unsigned int numDOF() const { return 2 * this->numStubs() - nHelixParam_; }
0280 unsigned int numDOFrphi() const { return this->numStubs() - (nHelixParam_ - 2); }
0281 unsigned int numDOFrz() const { return this->numStubs() - 2; }
0282 float chi2rphi() const { return chi2rphi_; }
0283 float chi2rz() const { return chi2rz_; }
0284 float chi2() const { return chi2rphi_ + chi2rz_; }
0285 float chi2dof() const { return (this->chi2()) / this->numDOF(); }
0286
0287
0288
0289 unsigned int numDOF_bcon() const { return (this->numDOF() - 1); }
0290 unsigned int numDOFrphi_bcon() const { return (this->numDOFrphi() - 1); }
0291 float chi2rphi_bcon() const { return chi2rphi_bcon_; }
0292 float chi2_bcon() const { return chi2rphi_bcon_ + chi2rz_; }
0293 float chi2dof_bcon() const { return (this->chi2_bcon()) / this->numDOF_bcon(); }
0294
0295
0296 unsigned int iPhiSec() const override { return iPhiSec_; }
0297 unsigned int iEtaReg() const override { return iEtaReg_; }
0298
0299
0300 unsigned int optoLinkID() const override { return optoLinkID_; }
0301
0302
0303
0304 bool accepted() const { return accepted_; }
0305
0306
0307
0308
0309 bool consistentHTcell() const { return consistentCell_; }
0310
0311
0312 void setConsistentHTcell() {
0313
0314
0315 std::pair<unsigned int, unsigned int> htCell = this->cellLocationHT();
0316 bool consistent = (htCell == this->cellLocationFit());
0317
0318 if (l1track3D_->mergedHTcell()) {
0319
0320 std::pair<unsigned int, unsigned int> htCell10(htCell.first + 1, htCell.second);
0321 std::pair<unsigned int, unsigned int> htCell01(htCell.first, htCell.second + 1);
0322 std::pair<unsigned int, unsigned int> htCell11(htCell.first + 1, htCell.second + 1);
0323 if (htCell10 == this->cellLocationFit())
0324 consistent = true;
0325 if (htCell01 == this->cellLocationFit())
0326 consistent = true;
0327 if (htCell11 == this->cellLocationFit())
0328 consistent = true;
0329 }
0330
0331 consistentCell_ = consistent;
0332 }
0333
0334
0335 bool consistentSector() const {
0336 if (settings_->hybrid()) {
0337 float phiCentre = 2. * M_PI * iPhiSec() / settings_->numPhiSectors();
0338 float sectorHalfWidth = M_PI / settings_->numPhiSectors();
0339 bool insidePhi = (std::abs(reco::deltaPhi(this->phiAtChosenR(done_bcon_), phiCentre)) < sectorHalfWidth);
0340 return insidePhi;
0341 } else {
0342 bool insidePhi = (std::abs(reco::deltaPhi(this->phiAtChosenR(done_bcon_), secTmp_->phiCentre())) <
0343 secTmp_->sectorHalfWidth());
0344 bool insideEta =
0345 (this->zAtChosenR() > secTmp_->zAtChosenR_Min() && this->zAtChosenR() < secTmp_->zAtChosenR_Max());
0346 return (insidePhi && insideEta);
0347 }
0348 }
0349
0350
0351 void digitizeTrack(const std::string& fitterName);
0352
0353
0354 const DigitalTrack* digitaltrack() const { return digitalTrack_.get(); }
0355
0356 private:
0357
0358 const Settings* settings_;
0359
0360
0361 const L1track3D* l1track3D_;
0362
0363
0364 std::vector<Stub*> stubs_;
0365 std::vector<const Stub*> stubsConst_;
0366 unsigned int nLayers_;
0367
0368
0369 unsigned int hitPattern_;
0370
0371
0372 float qOverPt_;
0373 float d0_;
0374 float phi0_;
0375 float z0_;
0376 float tanLambda_;
0377 float chi2rphi_;
0378 float chi2rz_;
0379
0380
0381 bool done_bcon_;
0382 float qOverPt_bcon_;
0383 float d0_bcon_;
0384 float phi0_bcon_;
0385 float chi2rphi_bcon_;
0386
0387
0388 unsigned int nHelixParam_;
0389
0390
0391 unsigned int iPhiSec_;
0392 unsigned int iEtaReg_;
0393
0394 unsigned int optoLinkID_;
0395
0396
0397 const TP* matchedTP_;
0398 std::vector<const Stub*> matchedStubs_;
0399 unsigned int nMatchedLayers_;
0400
0401
0402 std::shared_ptr<Sector> secTmp_;
0403
0404 std::shared_ptr<HTrphi> htRphiTmp_;
0405
0406
0407 unsigned int nSkippedLayers_;
0408 unsigned int numUpdateCalls_;
0409
0410 int numIterations_;
0411 std::string lostMatchingState_;
0412 std::unordered_map<std::string, int> stateCalls_;
0413
0414 std::shared_ptr<DigitalTrack> digitalTrack_;
0415
0416 static const std::vector<Stub*> noStubs_;
0417
0418 bool consistentCell_;
0419
0420
0421 bool accepted_;
0422 };
0423
0424 }
0425
0426 #endif