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  tracklet->setFitPars(tracklet->rinvapprox(),
21  tracklet->phi0approx(),
22  tracklet->d0approx(),
23  tracklet->tapprox(),
24  tracklet->z0approx(),
25  0.,
26  0.,
27  tracklet->rinv(),
28  tracklet->phi0(),
29  tracklet->d0(),
30  tracklet->t(),
31  tracklet->z0(),
32  0.,
33  0.,
34  tracklet->fpgarinv().value(),
35  tracklet->fpgaphi0().value(),
36  tracklet->fpgad0().value(),
37  tracklet->fpgat().value(),
38  tracklet->fpgaz0().value(),
39  0,
40  0,
41  0);
42  return;
43  }
44 
45  std::vector<tmtt::Stub*> TMTTstubs;
46  std::map<unsigned int, const L1TStub*> L1StubIndices;
47  unsigned int L1stubID = 0;
48 
49  if (globals_->tmttSettings() == nullptr) {
50  if (settings_.printDebugKF())
51  edm::LogVerbatim("L1track") << "Creating TMTT::Settings in HybridFit::Fit";
52  globals_->tmttSettings() = make_unique<tmtt::Settings>();
53  globals_->tmttSettings()->setMagneticField(settings_.bfield());
54  }
55 
56  const tmtt::Settings& TMTTsettings = *globals_->tmttSettings();
57 
58  int kf_phi_sec = iSector_;
59 
60  for (unsigned int k = 0; k < trackstublist.size(); k++) {
61  const L1TStub* L1stubptr = trackstublist[k]->l1tstub();
62 
63  double kfphi = L1stubptr->phi();
64  double kfr = L1stubptr->r();
65  double kfz = L1stubptr->z();
66  double kfbend = L1stubptr->bend();
67  bool psmodule = L1stubptr->isPSmodule();
68  unsigned int iphi = L1stubptr->iphi();
69  double alpha = L1stubptr->alpha(settings_.stripPitch(psmodule));
70  bool isTilted = L1stubptr->isTilted();
71 
72  bool isBarrel = trackstublist[k]->isBarrel();
73  int kflayer;
74 
75  if (isBarrel) { // Barrel-specific
76  kflayer = L1stubptr->layer() + 1;
77  if (settings_.printDebugKF())
78  edm::LogVerbatim("L1track") << "Will create layer stub with : ";
79  } else { // Disk-specific
80  kflayer = abs(L1stubptr->disk());
81  if (kfz > 0) {
82  kflayer += 10;
83  } else {
84  kflayer += 20;
85  }
86  if (settings_.printDebugKF())
87  edm::LogVerbatim("L1track") << "Will create disk stub with : ";
88  }
89 
90  float stripPitch = settings_.stripPitch(psmodule);
91  float stripLength = settings_.stripLength(psmodule);
92  unsigned int nStrips = settings_.nStrips(psmodule);
93 
94  if (settings_.printDebugKF()) {
95  edm::LogVerbatim("L1track") << kfphi << " " << kfr << " " << kfz << " " << kfbend << " " << kflayer << " "
96  << isBarrel << " " << psmodule << " " << isTilted << " \n"
97  << stripPitch << " " << stripLength << " " << nStrips;
98  }
99 
100  unsigned int uniqueStubIndex = 1000 * L1stubID + L1stubptr->allStubIndex();
101  tmtt::Stub* TMTTstubptr = new tmtt::Stub(&TMTTsettings,
102  uniqueStubIndex,
103  kfphi,
104  kfr,
105  kfz,
106  kfbend,
107  iphi,
108  -alpha,
109  kflayer,
110  kf_phi_sec,
111  psmodule,
112  isBarrel,
113  isTilted,
114  stripPitch,
115  stripLength,
116  nStrips);
117  TMTTstubs.push_back(TMTTstubptr);
118  L1StubIndices[uniqueStubIndex] = L1stubptr;
119  L1stubID++;
120  }
121 
122  if (settings_.printDebugKF()) {
123  edm::LogVerbatim("L1track") << "Made TMTTstubs: trackstublist.size() = " << trackstublist.size();
124  }
125 
126  double kfrinv = tracklet->rinvapprox();
127  double kfphi0 = tracklet->phi0approx();
128  double kfz0 = tracklet->z0approx();
129  double kft = tracklet->tapprox();
130  double kfd0 = tracklet->d0approx();
131 
132  if (settings_.printDebugKF()) {
133  edm::LogVerbatim("L1track") << "tracklet phi0 = " << kfphi0 << "\n"
134  << "iSector = " << iSector_ << "\n"
135  << "dphisectorHG = " << settings_.dphisectorHG();
136  }
137 
138  // KF wants global phi0, not phi0 measured with respect to lower edge of sector (Tracklet convention).
139  kfphi0 = reco::reduceRange(kfphi0 + iSector_ * settings_.dphisector() - 0.5 * settings_.dphisectorHG());
140 
141  std::pair<float, float> helixrphi(kfrinv / (0.01 * settings_.c() * settings_.bfield()), kfphi0);
142  std::pair<float, float> helixrz(kfz0, kft);
143 
144  // KF HLS uses HT mbin (which is binned q/Pt) to allow for scattering. So estimate it from tracklet.
145  double chargeOverPt = helixrphi.first;
146  int mBin = std::floor(TMTTsettings.houghNbinsPt() / 2) +
147  std::floor((TMTTsettings.houghNbinsPt() / 2) * chargeOverPt / (1. / TMTTsettings.houghMinPt()));
148  mBin = max(min(mBin, int(TMTTsettings.houghNbinsPt() - 1)), 0); // protect precision issues.
149  std::pair<unsigned int, unsigned int> celllocation(mBin, 1);
150 
151  // Get range in z of tracks covered by this sector at chosen radius from beam-line
152  const vector<double> etaRegions = TMTTsettings.etaRegions();
153  const float chosenRofZ = TMTTsettings.chosenRofZ();
154 
155  float kfzRef = kfz0 + chosenRofZ * kft;
156 
157  unsigned int kf_eta_reg = 0;
158  for (unsigned int iEtaSec = 1; iEtaSec < etaRegions.size() - 1; iEtaSec++) { // Doesn't apply eta < 2.4 cut.
159  const float etaMax = etaRegions[iEtaSec];
160  const float zRefMax = chosenRofZ / tan(2. * atan(exp(-etaMax)));
161  if (kfzRef > zRefMax)
162  kf_eta_reg = iEtaSec;
163  }
164 
165  tmtt::L1track3D l1track3d(
166  &TMTTsettings, TMTTstubs, celllocation, helixrphi, helixrz, kfd0, kf_phi_sec, kf_eta_reg, 1, false);
167  unsigned int seedType = tracklet->getISeed();
168  unsigned int numPS = tracklet->PSseed(); // Function PSseed() is out of date!
169  l1track3d.setSeedLayerType(seedType);
170  l1track3d.setSeedPS(numPS);
171 
172  if (globals_->tmttKFParamsComb() == nullptr) {
173  if (settings_.printDebugKF())
174  edm::LogVerbatim("L1track") << "Will make KFParamsComb for " << settings_.nHelixPar() << " param fit";
175  globals_->tmttKFParamsComb() = make_unique<tmtt::KFParamsComb>(&TMTTsettings, settings_.nHelixPar(), "KFfitter");
176  }
177 
178  tmtt::KFParamsComb& fitterKF = *globals_->tmttKFParamsComb();
179 
180  // Call Kalman fit
181  tmtt::L1fittedTrack fittedTrk = fitterKF.fit(l1track3d);
182 
183  if (fittedTrk.accepted()) {
185 
186  if (settings_.printDebugKF())
187  edm::LogVerbatim("L1track") << "Done with Kalman fit. Pars: pt = " << trk.pt()
188  << ", 1/2R = " << settings_.bfield() * 3 * trk.qOverPt() / 2000
189  << ", phi0 = " << trk.phi0() << ", eta = " << trk.eta() << ", z0 = " << trk.z0()
190  << ", chi2 = " << trk.chi2() << ", accepted = " << trk.accepted();
191 
192  // Tracklet wants phi0 with respect to lower edge of sector, not global phi0.
193  double phi0fit = reco::reduceRange(trk.phi0() - iSector_ * 2 * M_PI / N_SECTOR + 0.5 * settings_.dphisectorHG());
194 
195  double rinvfit = 0.01 * settings_.c() * settings_.bfield() * trk.qOverPt();
196 
197  int irinvfit = rinvfit / settings_.krinvpars();
198  int iphi0fit = phi0fit / settings_.kphi0pars();
199  int itanlfit = trk.tanLambda() / settings_.ktpars();
200  int iz0fit = trk.z0() / settings_.kz0pars();
201  int id0fit = trk.d0() / settings_.kd0pars();
202  int ichi2rphifit = trk.chi2rphi() / 16;
203  int ichi2rzfit = trk.chi2rz() / 16;
204 
205  const vector<const tmtt::Stub*>& stubsFromFit = trk.stubs();
206  vector<const L1TStub*> l1stubsFromFit;
207  for (const tmtt::Stub* s : stubsFromFit) {
208  unsigned int IDf = s->index();
209  const L1TStub* l1s = L1StubIndices.at(IDf);
210  l1stubsFromFit.push_back(l1s);
211  }
212 
213  if (settings_.printDebugKF()) {
214  edm::LogVerbatim("L1track") << "#stubs before/after KF fit = " << TMTTstubs.size() << "/"
215  << l1stubsFromFit.size();
216  }
217 
218  tracklet->setFitPars(rinvfit,
219  phi0fit,
220  trk.d0(),
221  trk.tanLambda(),
222  trk.z0(),
223  trk.chi2rphi(),
224  trk.chi2rz(),
225  rinvfit,
226  phi0fit,
227  trk.d0(),
228  trk.tanLambda(),
229  trk.z0(),
230  trk.chi2rphi(),
231  trk.chi2rz(),
232  irinvfit,
233  iphi0fit,
234  id0fit,
235  itanlfit,
236  iz0fit,
237  ichi2rphifit,
238  ichi2rzfit,
239  trk.hitPattern(),
240  l1stubsFromFit);
241  } else {
242  if (settings_.printDebugKF()) {
243  edm::LogVerbatim("L1track") << "FitTrack:KF rejected track";
244  }
245  }
246 
247  for (const tmtt::Stub* s : TMTTstubs) {
248  delete s;
249  }
250 }
251 #endif
tmtt::Settings::houghMinPt
double houghMinPt() const
Definition: Settings.h:135
tmtt::KFTrackletTrack::chi2
float chi2() const
Definition: KFTrackletTrack.h:162
L1TStub.h
trklet::Tracklet::PSseed
unsigned int PSseed() const
Definition: Tracklet.h:505
MessageLogger.h
trklet::Tracklet::z0approx
double z0approx() const
Definition: Tracklet.h:419
tmtt::KFTrackletTrack::stubs
const std::vector< const Stub * > & stubs() const
Definition: KFTrackletTrack.h:97
trklet::Tracklet::fpgat
const FPGAWord & fpgat() const
Definition: Tracklet.h:424
trklet::Settings::ktpars
double ktpars() const
Definition: Settings.h:332
trklet::L1TStub::layer
unsigned int layer() const
Definition: L1TStub.h:44
trklet::Settings::krinvpars
double krinvpars() const
Definition: Settings.h:327
trklet::Tracklet::phi0
double phi0() const
Definition: Tracklet.h:410
min
T min(T a, T b)
Definition: MathUtil.h:58
zMuMuMuonUserData.alpha
alpha
zGenParticlesMatch = cms.InputTag(""),
Definition: zMuMuMuonUserData.py:9
deltaPhi.h
trklet::Tracklet::d0approx
double d0approx() const
Definition: Tracklet.h:417
tmtt::KFTrackletTrack::hitPattern
unsigned int hitPattern() const
Definition: KFTrackletTrack.h:106
trklet::N_SECTOR
constexpr unsigned int N_SECTOR
Definition: Settings.h:17
trklet::Settings
Definition: Settings.h:26
trklet::L1TStub::bend
double bend() const
Definition: L1TStub.h:60
trklet::L1TStub
Definition: L1TStub.h:12
trklet::L1TStub::z
double z() const
Definition: L1TStub.h:56
tmtt::L1fittedTrack::accepted
bool accepted() const
Definition: L1fittedTrack.h:297
trklet::Tracklet::getISeed
int getISeed() const
Definition: Tracklet.cc:849
trklet::Tracklet::fpgad0
const FPGAWord & fpgad0() const
Definition: Tracklet.h:423
trklet::Settings::dphisector
double dphisector() const
Definition: Settings.h:238
trklet::Tracklet::rinvapprox
double rinvapprox() const
Definition: Tracklet.h:415
trklet::Globals
Definition: Globals.h:32
trklet::L1TStub::isTilted
bool isTilted() const
Definition: L1TStub.cc:117
trklet::Settings::kz0pars
double kz0pars() const
Definition: Settings.h:333
trklet::Settings::bfield
double bfield() const
Definition: Settings.h:212
trklet::Tracklet
Definition: Tracklet.h:28
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
alignCSCRings.s
s
Definition: alignCSCRings.py:92
tmtt::KFTrackletTrack::phi0
float phi0() const
Definition: KFTrackletTrack.h:119
tmtt::KFbase::fit
L1fittedTrack fit(const L1track3D &l1track3D) override
Definition: KFbase.cc:38
trklet::Settings::dphisectorHG
double dphisectorHG() const
Definition: Settings.h:230
tmtt::KFTrackletTrack::chi2rphi
float chi2rphi() const
Definition: KFTrackletTrack.h:160
trklet::L1TStub::isPSmodule
unsigned int isPSmodule() const
Definition: L1TStub.h:93
trklet::Settings::fakefit
bool fakefit() const
Definition: Settings.h:201
trklet::Settings::printDebugKF
bool printDebugKF() const
Definition: Settings.h:145
trklet::Tracklet::phi0approx
double phi0approx() const
Definition: Tracklet.h:416
tmtt::KFTrackletTrack::tanLambda
float tanLambda() const
Definition: KFTrackletTrack.h:121
trklet::Settings::kd0pars
double kd0pars() const
Definition: Settings.h:334
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:331
trklet::L1TStub::allStubIndex
unsigned int allStubIndex() const
Definition: L1TStub.h:82
trklet::Settings::nHelixPar
unsigned int nHelixPar() const
Definition: Settings.h:204
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:418
trklet::L1TStub::disk
int disk() const
Definition: L1TStub.h:45
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:118
trklet::Tracklet::fpgaz0
const FPGAWord & fpgaz0() const
Definition: Tracklet.h:425
trklet::L1TStub::alpha
double alpha(double pitch) const
Definition: L1TStub.cc:79
trklet
Definition: AllProjectionsMemory.h:9
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:219
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:114
trklet::Tracklet::z0
double z0() const
Definition: Tracklet.h:413
trklet::Tracklet::rinv
double rinv() const
Definition: Tracklet.h:409
trklet::Settings::nStrips
unsigned int nStrips(bool isPSmodule) const
Definition: Settings.h:215
tmtt::Settings::houghNbinsPt
unsigned int houghNbinsPt() const
Definition: Settings.h:137
trklet::Tracklet::d0
double d0() const
Definition: Tracklet.h:411
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:150
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:590
trklet::Settings::stripLength
double stripLength(bool isPSmodule) const
Definition: Settings.h:223
ALCARECOTkAlBeamHalo_cff.etaMax
etaMax
Definition: ALCARECOTkAlBeamHalo_cff.py:33
tmtt::KFTrackletTrack::chi2rz
float chi2rz() const
Definition: KFTrackletTrack.h:161
trklet::L1TStub::iphi
unsigned int iphi() const
Definition: L1TStub.h:64
trklet::Tracklet::fpgarinv
const FPGAWord & fpgarinv() const
Definition: Tracklet.h:421
trklet::L1TStub::r
double r() const
Definition: L1TStub.h:57
tmtt::KFTrackletTrack::z0
float z0() const
Definition: KFTrackletTrack.h:120
tmtt::KFTrackletTrack::qOverPt
float qOverPt() const
Definition: KFTrackletTrack.h:110
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
tmtt::KFTrackletTrack::accepted
bool accepted() const
Definition: KFTrackletTrack.h:182
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
tmtt::Stub
Definition: Stub.h:43
trklet::Tracklet::t
double t() const
Definition: Tracklet.h:412
trklet::Settings::c
double c() const
Definition: Settings.h:171
trklet::Tracklet::fpgaphi0
const FPGAWord & fpgaphi0() const
Definition: Tracklet.h:422
tmtt::KFTrackletTrack::eta
float eta() const
Definition: KFTrackletTrack.h:123
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:62
reco::reduceRange
constexpr T reduceRange(T x)
Definition: deltaPhi.h:18