CMS 3D CMS Logo

HybridFit.cc
Go to the documentation of this file.
5 
6 #ifdef USEHYBRID
9 
10 using namespace std;
11 using namespace trklet;
12 
13 HybridFit::HybridFit(unsigned int iSector, Settings const& settings, Globals* globals) : settings_(settings) {
14  iSector_ = iSector;
15  globals_ = globals;
16 }
17 
18 void HybridFit::Fit(Tracklet* tracklet, std::vector<const Stub*>& trackstublist) {
19  if (settings_.fakefit()) {
20  vector<const L1TStub*> l1stubsFromFitTrack;
21  for (unsigned int k = 0; k < trackstublist.size(); k++) {
22  const L1TStub* L1stub = trackstublist[k]->l1tstub();
23  l1stubsFromFitTrack.push_back(L1stub);
24  }
25  tracklet->setFitPars(tracklet->rinvapprox(),
26  tracklet->phi0approx(),
27  tracklet->d0approx(),
28  tracklet->tapprox(),
29  tracklet->z0approx(),
30  0.,
31  0.,
32  tracklet->rinv(),
33  tracklet->phi0(),
34  tracklet->d0(),
35  tracklet->t(),
36  tracklet->z0(),
37  0.,
38  0.,
39  tracklet->fpgarinv().value(),
40  tracklet->fpgaphi0().value(),
41  tracklet->fpgad0().value(),
42  tracklet->fpgat().value(),
43  tracklet->fpgaz0().value(),
44  0,
45  0,
46  0,
47  l1stubsFromFitTrack);
48  return;
49  }
50 
51  std::vector<tmtt::Stub*> TMTTstubs;
52  std::map<unsigned int, const L1TStub*> L1StubIndices;
53  unsigned int L1stubID = 0;
54 
55  if (globals_->tmttSettings() == nullptr) {
56  if (settings_.printDebugKF())
57  edm::LogVerbatim("L1track") << "Creating TMTT::Settings in HybridFit::Fit";
58  globals_->tmttSettings() = make_unique<tmtt::Settings>();
59  globals_->tmttSettings()->setMagneticField(settings_.bfield());
60  }
61 
62  const tmtt::Settings& TMTTsettings = *globals_->tmttSettings();
63 
64  int kf_phi_sec = iSector_;
65 
66  for (unsigned int k = 0; k < trackstublist.size(); k++) {
67  const L1TStub* L1stubptr = trackstublist[k]->l1tstub();
68 
69  double kfphi = L1stubptr->phi();
70  double kfr = L1stubptr->r();
71  double kfz = L1stubptr->z();
72  double kfbend = L1stubptr->bend();
73  bool psmodule = L1stubptr->isPSmodule();
74  unsigned int iphi = L1stubptr->iphi();
75  double alpha = L1stubptr->alpha(settings_.stripPitch(psmodule));
76  bool isTilted = L1stubptr->isTilted();
77 
78  bool isBarrel = trackstublist[k]->layerdisk() < N_LAYER;
79  int kflayer;
80 
81  if (isBarrel) { // Barrel-specific
82  kflayer = L1stubptr->layer() + 1;
83  if (settings_.printDebugKF())
84  edm::LogVerbatim("L1track") << "Will create layer stub with : ";
85  } else { // Disk-specific
86  kflayer = abs(L1stubptr->disk());
87  if (kfz > 0) {
88  kflayer += 10;
89  } else {
90  kflayer += 20;
91  }
92  if (settings_.printDebugKF())
93  edm::LogVerbatim("L1track") << "Will create disk stub with : ";
94  }
95 
96  float stripPitch = settings_.stripPitch(psmodule);
97  float stripLength = settings_.stripLength(psmodule);
98  unsigned int nStrips = settings_.nStrips(psmodule);
99 
100  if (settings_.printDebugKF()) {
101  edm::LogVerbatim("L1track") << kfphi << " " << kfr << " " << kfz << " " << kfbend << " " << kflayer << " "
102  << isBarrel << " " << psmodule << " " << isTilted << " \n"
103  << stripPitch << " " << stripLength << " " << nStrips;
104  }
105 
106  unsigned int uniqueStubIndex = 1000 * L1stubID + L1stubptr->allStubIndex();
107  tmtt::Stub* TMTTstubptr = new tmtt::Stub(&TMTTsettings,
108  uniqueStubIndex,
109  kfphi,
110  kfr,
111  kfz,
112  kfbend,
113  iphi,
114  -alpha,
115  kflayer,
116  kf_phi_sec,
117  psmodule,
118  isBarrel,
119  isTilted,
120  stripPitch,
121  stripLength,
122  nStrips);
123  TMTTstubs.push_back(TMTTstubptr);
124  L1StubIndices[uniqueStubIndex] = L1stubptr;
125  L1stubID++;
126  }
127 
128  if (settings_.printDebugKF()) {
129  edm::LogVerbatim("L1track") << "Made TMTTstubs: trackstublist.size() = " << trackstublist.size();
130  }
131 
132  double kfrinv = tracklet->rinvapprox();
133  double kfphi0 = tracklet->phi0approx();
134  double kfz0 = tracklet->z0approx();
135  double kft = tracklet->tapprox();
136  double kfd0 = tracklet->d0approx();
137 
138  if (settings_.printDebugKF()) {
139  edm::LogVerbatim("L1track") << "tracklet phi0 = " << kfphi0 << "\n"
140  << "iSector = " << iSector_ << "\n"
141  << "dphisectorHG = " << settings_.dphisectorHG();
142  }
143 
144  // KF wants global phi0, not phi0 measured with respect to lower edge of sector (Tracklet convention).
145  kfphi0 = reco::reduceRange(kfphi0 + iSector_ * settings_.dphisector() - 0.5 * settings_.dphisectorHG());
146 
147  std::pair<float, float> helixrphi(kfrinv / (0.01 * settings_.c() * settings_.bfield()), kfphi0);
148  std::pair<float, float> helixrz(kfz0, kft);
149 
150  // KF HLS uses HT mbin (which is binned q/Pt) to allow for scattering. So estimate it from tracklet.
151  double chargeOverPt = helixrphi.first;
152  int mBin = std::floor(TMTTsettings.houghNbinsPt() / 2) +
153  std::floor((TMTTsettings.houghNbinsPt() / 2) * chargeOverPt / (1. / TMTTsettings.houghMinPt()));
154  mBin = max(min(mBin, int(TMTTsettings.houghNbinsPt() - 1)), 0); // protect precision issues.
155  std::pair<unsigned int, unsigned int> celllocation(mBin, 1);
156 
157  // Get range in z of tracks covered by this sector at chosen radius from beam-line
158  const vector<double> etaRegions = TMTTsettings.etaRegions();
159  const float chosenRofZ = TMTTsettings.chosenRofZ();
160 
161  float kfzRef = kfz0 + chosenRofZ * kft;
162 
163  unsigned int kf_eta_reg = 0;
164  for (unsigned int iEtaSec = 1; iEtaSec < etaRegions.size() - 1; iEtaSec++) { // Doesn't apply eta < 2.4 cut.
165  const float etaMax = etaRegions[iEtaSec];
166  const float zRefMax = chosenRofZ / tan(2. * atan(exp(-etaMax)));
167  if (kfzRef > zRefMax)
168  kf_eta_reg = iEtaSec;
169  }
170 
171  tmtt::L1track3D l1track3d(
172  &TMTTsettings, TMTTstubs, celllocation, helixrphi, helixrz, kfd0, kf_phi_sec, kf_eta_reg, 1, false);
173  unsigned int seedType = tracklet->getISeed();
174  unsigned int numPS = tracklet->PSseed(); // Function PSseed() is out of date!
175  l1track3d.setSeedLayerType(seedType);
176  l1track3d.setSeedPS(numPS);
177 
178  if (globals_->tmttKFParamsComb() == nullptr) {
179  if (settings_.printDebugKF())
180  edm::LogVerbatim("L1track") << "Will make KFParamsComb for " << settings_.nHelixPar() << " param fit";
181  globals_->tmttKFParamsComb() = make_unique<tmtt::KFParamsComb>(&TMTTsettings, settings_.nHelixPar(), "KFfitter");
182  }
183 
184  tmtt::KFParamsComb& fitterKF = *globals_->tmttKFParamsComb();
185 
186  // Call Kalman fit
187  tmtt::L1fittedTrack fittedTrk = fitterKF.fit(l1track3d);
188 
189  if (fittedTrk.accepted()) {
191 
192  if (settings_.printDebugKF())
193  edm::LogVerbatim("L1track") << "Done with Kalman fit. Pars: pt = " << trk.pt()
194  << ", 1/2R = " << settings_.bfield() * 3 * trk.qOverPt() / 2000
195  << ", phi0 = " << trk.phi0() << ", eta = " << trk.eta() << ", z0 = " << trk.z0()
196  << ", chi2 = " << trk.chi2() << ", accepted = " << trk.accepted();
197 
198  double d0, chi2rphi, phi0, qoverpt = -999;
199  if (trk.done_bcon()) {
200  d0 = trk.d0_bcon();
201  chi2rphi = trk.chi2rphi_bcon();
202  phi0 = trk.phi0_bcon();
203  qoverpt = trk.qOverPt_bcon();
204  } else {
205  d0 = trk.d0();
206  chi2rphi = trk.chi2rphi();
207  phi0 = trk.phi0();
208  qoverpt = trk.qOverPt();
209  }
210 
211  // Tracklet wants phi0 with respect to lower edge of sector, not global phi0.
212  double phi0fit = reco::reduceRange(phi0 - iSector_ * 2 * M_PI / N_SECTOR + 0.5 * settings_.dphisectorHG());
213  double rinvfit = 0.01 * settings_.c() * settings_.bfield() * qoverpt;
214 
215  int irinvfit = floor(rinvfit / settings_.krinvpars());
216  int iphi0fit = floor(phi0fit / settings_.kphi0pars());
217  int itanlfit = floor(trk.tanLambda() / settings_.ktpars());
218  int iz0fit = floor(trk.z0() / settings_.kz0pars());
219  int id0fit = floor(d0 / settings_.kd0pars());
220  int ichi2rphifit = chi2rphi / 16;
221  int ichi2rzfit = trk.chi2rz() / 16;
222 
223  const vector<const tmtt::Stub*>& stubsFromFit = trk.stubs();
224  vector<const L1TStub*> l1stubsFromFit;
225  for (const tmtt::Stub* s : stubsFromFit) {
226  unsigned int IDf = s->index();
227  const L1TStub* l1s = L1StubIndices.at(IDf);
228  l1stubsFromFit.push_back(l1s);
229  }
230 
231  tracklet->setFitPars(rinvfit,
232  phi0fit,
233  d0,
234  trk.tanLambda(),
235  trk.z0(),
236  chi2rphi,
237  trk.chi2rz(),
238  rinvfit,
239  phi0fit,
240  d0,
241  trk.tanLambda(),
242  trk.z0(),
243  chi2rphi,
244  trk.chi2rz(),
245  irinvfit,
246  iphi0fit,
247  id0fit,
248  itanlfit,
249  iz0fit,
250  ichi2rphifit,
251  ichi2rzfit,
252  trk.hitPattern(),
253  l1stubsFromFit);
254  } else {
255  if (settings_.printDebugKF()) {
256  edm::LogVerbatim("L1track") << "FitTrack:KF rejected track";
257  }
258  }
259 
260  for (const tmtt::Stub* s : TMTTstubs) {
261  delete s;
262  }
263 }
264 #endif
Log< level::Info, true > LogVerbatim
double stripLength(bool isPSmodule) const
Definition: Settings.h:274
double phi() const
Definition: L1TStub.h:65
const FPGAWord & fpgarinv() const
Definition: Tracklet.h:132
const std::vector< const Stub * > & stubs() const
unsigned int iSector_
Definition: HybridFit.h:37
double t() const
Definition: Tracklet.h:123
Definition: L1Scalers.h:16
float alpha
Definition: AMPTWrapper.h:105
unsigned int layer() const
Definition: L1TStub.h:45
Settings const & settings_
Definition: HybridFit.h:39
unsigned int hitPattern() const
constexpr T reduceRange(T x)
Definition: deltaPhi.h:18
double kz0pars() const
Definition: Settings.h:403
double bend() const
Definition: L1TStub.h:63
double dphisectorHG() const
Definition: Settings.h:292
void Fit(Tracklet *tracklet, std::vector< const Stub *> &trackstublist)
const FPGAWord & fpgaz0() const
Definition: Tracklet.h:136
const FPGAWord & fpgaphi0() const
Definition: Tracklet.h:133
L1fittedTrack fit(const L1track3D &l1track3D) override
Definition: KFbase.cc:38
double phi0() const
Definition: Tracklet.h:121
double z() const
Definition: L1TStub.h:59
double kd0pars() const
Definition: Settings.h:404
double ktpars() const
Definition: Settings.h:402
bool printDebugKF() const
Definition: Settings.h:181
double krinvpars() const
Definition: Settings.h:397
const FPGAWord & fpgat() const
Definition: Tracklet.h:135
nStrips
1.2 is to make the matching window safely the two nearest strips 0.35 is the size of an ME0 chamber i...
double chosenRofZ() const
Definition: Settings.h:127
double kphi0pars() const
Definition: Settings.h:401
unsigned int isPSmodule() const
Definition: L1TStub.h:96
KFTrackletTrack returnKFTrackletTrack()
unsigned int houghNbinsPt() const
Definition: Settings.h:137
double phi0approx() const
Definition: Tracklet.h:127
double dphisector() const
Definition: Settings.h:301
double rinv() const
Definition: Tracklet.h:120
double bfield() const
Definition: Settings.h:263
double stripPitch(bool isPSmodule) const
Definition: Settings.h:270
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int value() const
Definition: FPGAWord.h:24
unsigned int nStrips(bool isPSmodule) const
Definition: Settings.h:266
double tapprox() const
Definition: Tracklet.h:129
bool fakefit() const
Definition: Settings.h:243
int disk() const
Definition: L1TStub.h:46
const FPGAWord & fpgad0() const
Definition: Tracklet.h:134
unsigned int allStubIndex() const
Definition: L1TStub.h:85
#define M_PI
double alpha(double pitch) const
Definition: L1TStub.cc:78
constexpr unsigned int N_SECTOR
Definition: Settings.h:19
double rinvapprox() const
Definition: Tracklet.h:126
double d0() const
Definition: Tracklet.h:122
bool isTilted() const
Definition: L1TStub.h:99
static constexpr float d0
double z0approx() const
Definition: Tracklet.h:130
unsigned int nHelixPar() const
Definition: Settings.h:253
int getISeed() const
Definition: Tracklet.cc:801
double houghMinPt() const
Definition: Settings.h:135
double d0approx() const
Definition: Tracklet.h:128
double c() const
Definition: Settings.h:212
double z0() const
Definition: Tracklet.h:124
double r() const
Definition: L1TStub.h:60
bool accepted() const
void setFitPars(double rinvfit, double phi0fit, double d0fit, double tfit, double z0fit, double chisqrphifit, double chisqrzfit, double rinvfitexact, double phi0fitexact, double d0fitexact, double tfitexact, double z0fitexact, double chisqrphifitexact, double chisqrzfitexact, int irinvfit, int iphi0fit, int id0fit, int itfit, int iz0fit, int ichisqrphifit, int ichisqrzfit, int hitpattern, const std::vector< const L1TStub *> &l1stubs=std::vector< const L1TStub *>())
Definition: Tracklet.cc:515
unsigned int iphi() const
Definition: L1TStub.h:67
unsigned int PSseed() const
Definition: Tracklet.h:222
Globals * globals_
Definition: HybridFit.h:40
const std::vector< double > & etaRegions() const
Definition: Settings.h:124
float chi2rphi_bcon() const
constexpr int N_LAYER
Definition: Settings.h:21
float qOverPt_bcon() const