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 = rinvfit / settings_.krinvpars();
216  int iphi0fit = phi0fit / settings_.kphi0pars();
217  int itanlfit = trk.tanLambda() / settings_.ktpars();
218  int iz0fit = trk.z0() / settings_.kz0pars();
219  int id0fit = 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
tmtt::Settings::houghMinPt
double houghMinPt() const
Definition: Settings.h:135
tmtt::KFTrackletTrack::chi2
float chi2() const
Definition: KFTrackletTrack.h:160
L1TStub.h
trklet::Tracklet::PSseed
unsigned int PSseed() const
Definition: Tracklet.h:220
MessageLogger.h
trklet::Tracklet::z0approx
double z0approx() const
Definition: Tracklet.h:130
tmtt::KFTrackletTrack::stubs
const std::vector< const Stub * > & stubs() const
Definition: KFTrackletTrack.h:94
trklet::Tracklet::fpgat
const FPGAWord & fpgat() const
Definition: Tracklet.h:135
trklet::Settings::ktpars
double ktpars() const
Definition: Settings.h:389
trklet::L1TStub::layer
unsigned int layer() const
Definition: L1TStub.h:41
trklet::Settings::krinvpars
double krinvpars() const
Definition: Settings.h:384
trklet::Tracklet::phi0
double phi0() const
Definition: Tracklet.h:121
min
T min(T a, T b)
Definition: MathUtil.h:58
deltaPhi.h
trklet::Tracklet::d0approx
double d0approx() const
Definition: Tracklet.h:128
tmtt::KFTrackletTrack::chi2rphi_bcon
float chi2rphi_bcon() const
Definition: KFTrackletTrack.h:167
tmtt::KFTrackletTrack::hitPattern
unsigned int hitPattern() const
Definition: KFTrackletTrack.h:103
trklet::N_SECTOR
constexpr unsigned int N_SECTOR
Definition: Settings.h:19
trklet::Settings
Definition: Settings.h:52
trklet::L1TStub::bend
double bend() const
Definition: L1TStub.h:61
trklet::L1TStub
Definition: L1TStub.h:14
trklet::L1TStub::z
double z() const
Definition: L1TStub.h:57
tmtt::L1fittedTrack::accepted
bool accepted() const
Definition: L1fittedTrack.h:304
trklet::Tracklet::getISeed
int getISeed() const
Definition: Tracklet.cc:798
alpha
float alpha
Definition: AMPTWrapper.h:105
trklet::Tracklet::fpgad0
const FPGAWord & fpgad0() const
Definition: Tracklet.h:134
tmtt::KFTrackletTrack::phi0_bcon
float phi0_bcon() const
Definition: KFTrackletTrack.h:130
trklet::Settings::dphisector
double dphisector() const
Definition: Settings.h:290
trklet::Tracklet::rinvapprox
double rinvapprox() const
Definition: Tracklet.h:126
trklet::Globals
Definition: Globals.h:30
trklet::L1TStub::isTilted
bool isTilted() const
Definition: L1TStub.cc:126
trklet::Settings::kz0pars
double kz0pars() const
Definition: Settings.h:390
trklet::Settings::bfield
double bfield() const
Definition: Settings.h:253
trklet::Tracklet
Definition: Tracklet.h:27
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
alignCSCRings.s
s
Definition: alignCSCRings.py:92
tmtt::KFTrackletTrack::phi0
float phi0() const
Definition: KFTrackletTrack.h:116
tmtt::KFbase::fit
L1fittedTrack fit(const L1track3D &l1track3D) override
Definition: KFbase.cc:38
trklet::Settings::dphisectorHG
double dphisectorHG() const
Definition: Settings.h:281
tmtt::KFTrackletTrack::chi2rphi
float chi2rphi() const
Definition: KFTrackletTrack.h:158
trklet::L1TStub::isPSmodule
unsigned int isPSmodule() const
Definition: L1TStub.h:94
trklet::Settings::fakefit
bool fakefit() const
Definition: Settings.h:242
trklet::Settings::printDebugKF
bool printDebugKF() const
Definition: Settings.h:181
trklet::Tracklet::phi0approx
double phi0approx() const
Definition: Tracklet.h:127
tmtt::KFTrackletTrack::d0_bcon
float d0_bcon() const
Definition: KFTrackletTrack.h:131
trklet::N_LAYER
constexpr int N_LAYER
Definition: Settings.h:21
tmtt::KFTrackletTrack::tanLambda
float tanLambda() const
Definition: KFTrackletTrack.h:118
trklet::Settings::kd0pars
double kd0pars() const
Definition: Settings.h:391
dqmdumpme.k
k
Definition: dqmdumpme.py:60
HybridFit.h
PixelPluginsPhase0_cfi.isBarrel
isBarrel
Definition: PixelPluginsPhase0_cfi.py:17
tmtt::L1fittedTrack
Definition: L1fittedTrack.h:30
trklet::HybridFit::iSector_
unsigned int iSector_
Definition: HybridFit.h:39
trklet::Settings::kphi0pars
double kphi0pars() const
Definition: Settings.h:388
trklet::L1TStub::allStubIndex
unsigned int allStubIndex() const
Definition: L1TStub.h:83
trklet::Settings::nHelixPar
unsigned int nHelixPar() const
Definition: Settings.h:245
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
trklet::HybridFit::settings_
Settings const & settings_
Definition: HybridFit.h:41
tmtt::Settings
Definition: Settings.h:17
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
tmtt::Settings::chosenRofZ
double chosenRofZ() const
Definition: Settings.h:127
trklet::Tracklet::tapprox
double tapprox() const
Definition: Tracklet.h:129
trklet::L1TStub::disk
int disk() const
Definition: L1TStub.h:42
trklet::HybridFit::Fit
void Fit(Tracklet *tracklet, std::vector< const Stub * > &trackstublist)
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
tmtt::KFTrackletTrack
Definition: KFTrackletTrack.h:27
tmtt::KFTrackletTrack::d0
float d0() const
Definition: KFTrackletTrack.h:115
trklet::Tracklet::fpgaz0
const FPGAWord & fpgaz0() const
Definition: Tracklet.h:136
trklet::L1TStub::alpha
double alpha(double pitch) const
Definition: L1TStub.cc:73
trklet
Definition: AllInnerStubsMemory.h:10
trklet::FPGAWord::value
int value() const
Definition: FPGAWord.h:24
trklet::HybridFit::globals_
Globals * globals_
Definition: HybridFit.h:42
trklet::Settings::stripPitch
double stripPitch(bool isPSmodule) const
Definition: Settings.h:260
me0TriggerPseudoDigis_cff.nStrips
nStrips
1.2 is to make the matching window safely the two nearest strips 0.35 is the size of an ME0 chamber i...
Definition: me0TriggerPseudoDigis_cff.py:26
tmtt::KFTrackletTrack::pt
float pt() const
Definition: KFTrackletTrack.h:111
trklet::Tracklet::z0
double z0() const
Definition: Tracklet.h:124
trklet::Tracklet::rinv
double rinv() const
Definition: Tracklet.h:120
trklet::Settings::nStrips
unsigned int nStrips(bool isPSmodule) const
Definition: Settings.h:256
tmtt::Settings::houghNbinsPt
unsigned int houghNbinsPt() const
Definition: Settings.h:137
trklet::Tracklet::d0
double d0() const
Definition: Tracklet.h:122
tmtt::KFTrackletTrack::done_bcon
bool done_bcon() const
Definition: KFTrackletTrack.h:125
std
Definition: JetResolutionObject.h:76
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
l1s
Definition: L1Scalers.h:16
tmtt::L1fittedTrack::returnKFTrackletTrack
KFTrackletTrack returnKFTrackletTrack()
Definition: L1fittedTrack.h:151
tmtt::KFParamsComb
Definition: KFParamsComb.h:13
trklet::Tracklet::setFitPars
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
trklet::Settings::stripLength
double stripLength(bool isPSmodule) const
Definition: Settings.h:264
ALCARECOTkAlBeamHalo_cff.etaMax
etaMax
Definition: ALCARECOTkAlBeamHalo_cff.py:33
tmtt::KFTrackletTrack::chi2rz
float chi2rz() const
Definition: KFTrackletTrack.h:159
tmtt::KFTrackletTrack::qOverPt_bcon
float qOverPt_bcon() const
Definition: KFTrackletTrack.h:126
trklet::L1TStub::iphi
unsigned int iphi() const
Definition: L1TStub.h:65
trklet::Tracklet::fpgarinv
const FPGAWord & fpgarinv() const
Definition: Tracklet.h:132
trklet::L1TStub::r
double r() const
Definition: L1TStub.h:58
tmtt::KFTrackletTrack::z0
float z0() const
Definition: KFTrackletTrack.h:117
tmtt::KFTrackletTrack::qOverPt
float qOverPt() const
Definition: KFTrackletTrack.h:107
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
tmtt::KFTrackletTrack::accepted
bool accepted() const
Definition: KFTrackletTrack.h:180
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
Phase1L1TJetProducer_cfi.etaRegions
etaRegions
Definition: Phase1L1TJetProducer_cfi.py:36
tmtt::Stub
Definition: Stub.h:43
trklet::Tracklet::t
double t() const
Definition: Tracklet.h:123
trklet::Settings::c
double c() const
Definition: Settings.h:212
trklet::Tracklet::fpgaphi0
const FPGAWord & fpgaphi0() const
Definition: Tracklet.h:133
d0
static constexpr float d0
Definition: L1EGammaCrystalsEmulatorProducer.cc:85
tmtt::KFTrackletTrack::eta
float eta() const
Definition: KFTrackletTrack.h:120
edm::Log
Definition: MessageLogger.h:70
tmtt::L1track3D
Definition: L1track3D.h:24
Stub.h
Tracklet.h
tmtt::Settings::etaRegions
const std::vector< double > & etaRegions() const
Definition: Settings.h:124
trklet::L1TStub::phi
double phi() const
Definition: L1TStub.h:63
reco::reduceRange
constexpr T reduceRange(T x)
Definition: deltaPhi.h:18