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()) {
190  if (fittedTrk.consistentSector()) {
192 
193  if (settings_.printDebugKF())
194  edm::LogVerbatim("L1track") << "Done with Kalman fit. Pars: pt = " << trk.pt()
195  << ", 1/2R = " << settings_.bfield() * 3 * trk.qOverPt() / 2000
196  << ", phi0 = " << trk.phi0() << ", eta = " << trk.eta() << ", z0 = " << trk.z0()
197  << ", chi2 = " << trk.chi2() << ", accepted = " << trk.accepted();
198 
199  double d0, chi2rphi, phi0, qoverpt = -999;
200  if (trk.done_bcon()) {
201  d0 = trk.d0_bcon();
202  chi2rphi = trk.chi2rphi_bcon();
203  phi0 = trk.phi0_bcon();
204  qoverpt = trk.qOverPt_bcon();
205  } else {
206  d0 = trk.d0();
207  chi2rphi = trk.chi2rphi();
208  phi0 = trk.phi0();
209  qoverpt = trk.qOverPt();
210  }
211 
212  // Tracklet wants phi0 with respect to lower edge of sector, not global phi0.
213  double phi0fit = reco::reduceRange(phi0 - iSector_ * 2 * M_PI / N_SECTOR + 0.5 * settings_.dphisectorHG());
214  double rinvfit = 0.01 * settings_.c() * settings_.bfield() * qoverpt;
215 
216  int irinvfit = floor(rinvfit / settings_.krinvpars());
217  int iphi0fit = floor(phi0fit / settings_.kphi0pars());
218  int itanlfit = floor(trk.tanLambda() / settings_.ktpars());
219  int iz0fit = floor(trk.z0() / settings_.kz0pars());
220  int id0fit = floor(d0 / settings_.kd0pars());
221  int ichi2rphifit = chi2rphi / 16;
222  int ichi2rzfit = trk.chi2rz() / 16;
223 
224  const vector<const tmtt::Stub*>& stubsFromFit = trk.stubs();
225  vector<const L1TStub*> l1stubsFromFit;
226  for (const tmtt::Stub* s : stubsFromFit) {
227  unsigned int IDf = s->index();
228  const L1TStub* l1s = L1StubIndices.at(IDf);
229  l1stubsFromFit.push_back(l1s);
230  }
231 
232  tracklet->setFitPars(rinvfit,
233  phi0fit,
234  d0,
235  trk.tanLambda(),
236  trk.z0(),
237  chi2rphi,
238  trk.chi2rz(),
239  rinvfit,
240  phi0fit,
241  d0,
242  trk.tanLambda(),
243  trk.z0(),
244  chi2rphi,
245  trk.chi2rz(),
246  irinvfit,
247  iphi0fit,
248  id0fit,
249  itanlfit,
250  iz0fit,
251  ichi2rphifit,
252  ichi2rzfit,
253  trk.hitPattern(),
254  l1stubsFromFit);
255  } else {
256  if (settings_.printDebugKF()) {
257  edm::LogVerbatim("L1track") << "FitTrack:KF rejected track";
258  }
259  }
260  } else {
261  if (settings_.printDebugKF()) {
262  edm::LogVerbatim("L1track") << "FitTrack:KF rejected track";
263  }
264  }
265 
266  for (const tmtt::Stub* s : TMTTstubs) {
267  delete s;
268  }
269 }
270 #endif
Log< level::Info, true > LogVerbatim
double stripLength(bool isPSmodule) const
Definition: Settings.h:290
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
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:431
double bend() const
Definition: L1TStub.h:63
double dphisectorHG() const
Definition: Settings.h:320
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:432
double ktpars() const
Definition: Settings.h:430
bool printDebugKF() const
Definition: Settings.h:193
double krinvpars() const
Definition: Settings.h:425
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:429
unsigned int isPSmodule() const
Definition: L1TStub.h:103
KFTrackletTrack returnKFTrackletTrack()
unsigned int houghNbinsPt() const
Definition: Settings.h:137
double phi0approx() const
Definition: Tracklet.h:127
double dphisector() const
Definition: Settings.h:329
double rinv() const
Definition: Tracklet.h:120
double bfield() const
Definition: Settings.h:277
double stripPitch(bool isPSmodule) const
Definition: Settings.h:284
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:280
double tapprox() const
Definition: Tracklet.h:129
bool fakefit() const
Definition: Settings.h:255
int disk() const
Definition: L1TStub.h:46
const FPGAWord & fpgad0() const
Definition: Tracklet.h:134
unsigned int allStubIndex() const
Definition: L1TStub.h:91
#define M_PI
double alpha(double pitch) const
Definition: L1TStub.cc:79
constexpr unsigned int N_SECTOR
Definition: Settings.h:23
double rinvapprox() const
Definition: Tracklet.h:126
double d0() const
Definition: Tracklet.h:122
bool isTilted() const
Definition: L1TStub.h:106
static constexpr float d0
bool consistentSector() const
double z0approx() const
Definition: Tracklet.h:130
unsigned int nHelixPar() const
Definition: Settings.h:265
int getISeed() const
Definition: Tracklet.cc:820
double houghMinPt() const
Definition: Settings.h:135
double d0approx() const
Definition: Tracklet.h:128
double c() const
Definition: Settings.h:224
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:523
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:25
float qOverPt_bcon() const