50 : theService(service) {
81 std::pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface> tsosPair =
convertToTSOSMuHit(sta, track);
103 int surfaceOption)
const {
104 std::pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface> tsosPair;
105 if (surfaceOption == 0)
107 if (surfaceOption == 1)
109 if (surfaceOption != 0 && surfaceOption != 1)
112 if (matchOption == 0) {
114 return match_Chi2(tsosPair.first, tsosPair.second);
115 }
else if (matchOption == 1) {
117 return match_d(tsosPair.first, tsosPair.second);
118 }
else if (matchOption == 2) {
120 return match_Rpos(tsosPair.first, tsosPair.second);
121 }
else if (matchOption == 3) {
122 return match_dist(tsosPair.first, tsosPair.second);
137 double minChi2 = 1000.0;
138 vector<TrackCand>::const_iterator
result = tracks.end();
139 for (vector<TrackCand>::const_iterator is = tracks.begin(); is != tracks.end(); ++is) {
141 std::pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface> tsosPair =
convertToTSOSMuHit(sta, *is);
145 if (chi2 > 0. && chi2 <= minChi2) {
161 const vector<TrackCand>&
tracks)
const {
162 const string category =
"GlobalMuonTrackMatcher";
169 typedef std::pair<TrackCand, TrajectoryStateOnSurface> TrackCandWithTSOS;
170 vector<TrackCandWithTSOS>
cands;
174 LogTrace(category) <<
" ***" << endl <<
"STA Muon pT " << sta.second->pt();
175 LogTrace(category) <<
" Tk in Region " << tracks.size() << endl;
177 for (vector<TrackCand>::const_iterator is = tracks.begin(); is != tracks.end(); ++is, iiTk++) {
179 std::pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface> tsosPair =
convertToTSOSMuHit(sta, *is);
180 LogTrace(category) <<
" Tk " << iiTk <<
" of " << tracks.size() <<
" ConvertToMuHitSurface muon isValid "
181 << tsosPair.first.isValid() <<
" tk isValid " << tsosPair.second.isValid() << endl;
182 if (tsosPair.first.isValid())
183 muonTSOS = tsosPair.first;
184 cands.push_back(TrackCandWithTSOS(*is, tsosPair.second));
188 double min_chisq = 999999;
189 double min_d = 999999;
190 double min_de = 999999;
191 double min_r_pos = 999999;
192 std::vector<bool> passes(cands.size(),
false);
196 for (vector<TrackCandWithTSOS>::const_iterator
ii = cands.begin();
ii != cands.end(); ++
ii, jj++, iTkCand++) {
198 if (!muonTSOS.
isValid() || !(*ii).second.isValid())
204 double loc_chi2 =
match_dist(muonTSOS, (*ii).second);
207 LogTrace(category) <<
" iTk " << iTkCand <<
" of " << cands.size() <<
" eta "
208 << (*ii).second.globalPosition().eta() <<
" phi " << (*ii).second.globalPosition().phi() << endl;
209 LogTrace(category) <<
" distance " << distance <<
" distance cut "
211 LogTrace(category) <<
" chi2 " << chi2 <<
" chi2 cut "
213 LogTrace(category) <<
" loc_chi2 " << loc_chi2 <<
" locChi2 cut "
215 LogTrace(category) <<
" deltaR " << deltaR <<
" deltaR cut "
219 LogTrace(category) <<
" Enters a1" << endl;
222 (distance > 0 && distance / (*ii).first.second->pt() <
theDeltaD_1 && loc_chi2 > 0 &&
224 LogTrace(category) <<
" Passes a1" << endl;
225 result.push_back((*ii).first);
229 if ((passes[jj] ==
false) && (*ii).second.globalMomentum().perp() <
thePt_threshold2) {
230 LogTrace(category) <<
" Enters a2" << endl;
232 LogTrace(category) <<
" Passes a2" << endl;
233 result.push_back((*ii).first);
237 LogTrace(category) <<
" Enters a3" << endl;
238 if (distance > 0 && distance < theDeltaD_3 && deltaR > 0 && deltaR <
theDeltaR_1) {
239 LogTrace(category) <<
" Passes a3" << endl;
240 result.push_back((*ii).first);
246 if (distance < min_d)
248 if (loc_chi2 < min_de)
250 if (deltaR < min_r_pos)
252 if (chi2 < min_chisq)
260 if (result.empty()) {
261 LogTrace(category) <<
" Stage 1 returned 0 results";
262 for (vector<TrackCandWithTSOS>::const_iterator is = cands.begin(); is != cands.end(); ++is, jj++) {
265 if (muonTSOS.
isValid() && (*is).second.isValid()) {
267 LogTrace(category) <<
" Stage 2 deltaR " << deltaR <<
" deltaEta "
271 << (fabs(
deltaPhi((*is).second.globalPosition().barePhi(),
278 result.push_back((*is).first);
286 double loc_chi2 =
match_dist(muonTSOS, (*is).second);
287 if (distance < min_d)
289 if (loc_chi2 < min_de)
291 if (deltaR < min_r_pos)
293 if (chi2 < min_chisq)
299 for (vector<TrackCand>::const_iterator iTk = result.begin(); iTk != result.end(); ++iTk) {
300 LogTrace(category) <<
" -----" << endl
301 <<
"selected pt " << iTk->second->pt() <<
" eta " << iTk->second->eta() <<
" phi "
302 << iTk->second->phi() << endl;
305 if (result.size() < 2)
310 LogTrace(category) <<
" Cleaning matched candiates" << endl;
315 for (vector<TrackCandWithTSOS>::const_iterator is = cands.begin(); is != cands.end(); ++is, jj++) {
326 int qual = (int)(chi2 / min_chisq + distance / min_d + deltaR / min_r_pos);
328 ((chi2 / min_chisq == 1) ? 1 : 0) + ((distance / min_d == 1) ? 1 : 0) + ((deltaR / min_r_pos == 1) ? 1 : 0);
331 result.push_back((*is).first);
335 result.push_back((*is).first);
339 result.push_back((*is).first);
343 result.push_back((*is).first);
347 for (vector<TrackCand>::const_iterator iTk = result.begin(); iTk != result.end(); ++iTk) {
348 LogTrace(category) <<
" -----" << endl
349 <<
"selected pt " << iTk->second->pt() <<
" eta " << iTk->second->eta() <<
" phi "
350 << iTk->second->phi() << endl;
361 const string category =
"GlobalMuonTrackMatcher";
369 if (tkCand.second.isNonnull()) {
371 if (!(tkCand.second->p() <
theMinP || tkCand.second->pt() <
theMinPt)) {
377 if (!impactMuTSOS.isValid() || !outerTkTsos.
isValid())
378 return pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface>(empty, empty);
387 if (!
samePlane(tkTsosFromMu, tkTsosFromTk)) {
391 if (tkTsosFromMu.isValid())
393 same1 =
samePlane(newTkTsosFromTk, tkTsosFromMu);
394 LogTrace(category) <<
"Propagating to same tracker surface (Mu):" << same1;
398 same2 =
samePlane(newTkTsosFromMu, tkTsosFromTk);
399 LogTrace(category) <<
"Propagating to same tracker surface (Tk):" << same2;
402 tkTsosFromTk = newTkTsosFromTk;
404 tkTsosFromMu = newTkTsosFromMu;
406 LogTrace(category) <<
"Could not propagate Muon and Tracker track to the same tracker bound!";
407 return pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface>(
empty,
empty);
411 return pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface>(tkTsosFromMu, tkTsosFromTk);
419 const string category =
"GlobalMuonTrackMatcher";
424 if (tkCand.second.isNonnull()) {
426 if (!(tkCand.second->p() <
theMinP || tkCand.second->pt() <
theMinPt)) {
435 (innerMuTSOS.globalPosition() - innerTkTsos.globalPosition()).
mag())
436 outerTkTsos = innerTkTsos;
440 if (!innerMuTSOS.isValid() || !outerTkTsos.
isValid()) {
441 LogTrace(category) <<
"A TSOS validity problem! MuTSOS " << innerMuTSOS.isValid() <<
" TkTSOS "
443 return pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface>(
empty,
empty);
446 const Surface& refSurface = innerMuTSOS.surface();
451 LogTrace(category) <<
"Could not propagate Muon and Tracker track to the same muon hit surface!";
452 return pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface>(
empty,
empty);
455 return pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface>(innerMuTSOS, tkAtMu);
463 const string category =
"GlobalMuonTrackMatcher";
472 if (tkCand.second.isNonnull()) {
474 if (!(tkCand.second->p() <
theMinP || tkCand.second->pt() <
theMinPt)) {
483 outerTkTsos = innerTkTsos;
487 if (!impactMuTSOS.isValid() || !outerTkTsos.
isValid()) {
488 LogTrace(category) <<
"A TSOS validity problem! MuTSOS " << impactMuTSOS.isValid() <<
" TkTSOS "
490 return pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface>(
empty,
empty);
498 LogTrace(category) <<
"Could not propagate Muon and Tracker track to the same tracker hit surface!";
499 return pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface>(
empty,
empty);
502 return pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface>(muAtTk, outerTkTsos);
516 const float maxtilt = 0.999;
517 const float maxdist = 0.01;
522 bool returnValue = ((fabs(
p1->normalVector().dot(
p2->normalVector())) > maxtilt) ||
523 (fabs((
p1->toLocal(
p2->position())).z()) < maxdist))
535 const string category =
"GlobalMuonTrackMatcher";
545 bool ierr = !
m.Invert();
548 edm::LogInfo(category) <<
"Error inverting covariance matrix";
552 double est = ROOT::Math::Similarity(
v,
m);
564 if (tkCand.second.isNonnull()) {
565 dR = (deltaR<double>(staCand.second->eta(), staCand.second->phi(), tkCand.second->eta(), tkCand.second->phi()));
578 return (deltaR<double>(
589 return (deltaR<double>(
617 const string category =
"GlobalMuonTrackMatcher";
632 LogTrace(category) <<
"Error inverting local matrix ";
636 return ROOT::Math::Similarity(v, m);
std::vector< TrackCand >::const_iterator matchOne(const TrackCand &sta, const std::vector< TrackCand > &tracks) const
choose the one tracker track which best matches a muon track
std::pair< const Trajectory *, reco::TrackRef > TrackCand
GlobalMuonTrackMatcher(const edm::ParameterSet &, const MuonServiceProxy *)
constructor
virtual ConstReferenceCountingPointer< TangentPlane > tangentPlane(const GlobalPoint &) const =0
const LocalTrajectoryParameters & localParameters() const
static const char category[]
std::string theOutPropagatorName
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
LocalPoint localPosition() const
bool matchTight(const TrackCand &sta, const TrackCand &track) const
check if two tracks are compatible (less than Chi2Cut, DeltaDCut, DeltaRCut)
Geom::Phi< T > phi() const
GlobalPoint globalPosition() const
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > convertToTSOSTkHit(const TrackCand &, const TrackCand &) const
auto const & tracks
cannot be loose
double match_Rmom(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
double match_R_IP(const TrackCand &, const TrackCand &) const
LocalError positionError() const
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > convertToTSOSMuHit(const TrackCand &, const TrackCand &) const
AlgebraicVector5 vector() const
const SurfaceType & surface() const
ROOT::Math::SVector< double, 2 > AlgebraicVector2
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > convertToTSOSTk(const TrackCand &, const TrackCand &) const
FreeTrajectoryState const * freeState(bool withErrors=true) const
ROOT::Math::SVector< double, 5 > AlgebraicVector5
double match_d(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
double match_Chi2(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
const AlgebraicSymMatrix55 & matrix() const
const LocalTrajectoryError & localError() const
double match(const TrackCand &sta, const TrackCand &track, int matchOption=0, int surfaceOption=1) const
double match_D(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
const MuonServiceProxy * theService
Log< level::Info, false > LogInfo
T getParameter(std::string const &) const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
double match_dist(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
double match_Rpos(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
GlobalVector globalMomentum() const
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepStd< double, 2, 2 > > AlgebraicMatrix22
bool samePlane(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
virtual ~GlobalMuonTrackMatcher()
destructor