91 std::pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface> tsosPair
95 if ( chi2 > 0. && chi2 <
theChi2_2 )
return true;
98 if ( distance > 0. && distance <
theDeltaD_2 )
return true;
115 int surfaceOption)
const {
117 std::pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface> tsosPair;
120 if ( surfaceOption != 0 && surfaceOption != 1 )
return -1.0;
122 if ( matchOption == 0 ) {
124 return match_Chi2(tsosPair.first,tsosPair.second);
126 else if ( matchOption == 1 ) {
128 return match_d(tsosPair.first,tsosPair.second);
130 else if ( matchOption == 2 ) {
132 return match_Rpos(tsosPair.first,tsosPair.second);
134 else if ( matchOption == 3 ) {
135 return match_dist(tsosPair.first,tsosPair.second);
147 std::vector<GlobalMuonTrackMatcher::TrackCand>::const_iterator
149 const std::vector<TrackCand>&
tracks)
const {
151 if ( tracks.empty() )
return tracks.end();
154 vector<TrackCand>::const_iterator
result = tracks.end();
155 for (vector<TrackCand>::const_iterator is = tracks.begin(); is != tracks.end(); ++is) {
157 std::pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface> tsosPair
162 if ( chi2 > 0. && chi2 <= minChi2 ) {
180 vector<GlobalMuonTrackMatcher::TrackCand>
182 const vector<TrackCand>&
tracks)
const {
183 const string category =
"GlobalMuonTrackMatcher";
187 if ( tracks.empty() )
return result;
189 typedef std::pair<TrackCand, TrajectoryStateOnSurface> TrackCandWithTSOS;
190 vector<TrackCandWithTSOS>
cands;
194 LogTrace(category) <<
" ***" << endl <<
"STA Muon pT "<< sta.second->pt();
195 LogTrace(category) <<
" Tk in Region " << tracks.size() << endl;
197 for (vector<TrackCand>::const_iterator is = tracks.begin(); is != tracks.end(); ++is,iiTk++) {
199 std::pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface> tsosPair =
convertToTSOSMuHit(sta,*is);
200 LogTrace(category) <<
" Tk " << iiTk <<
" of " << tracks.size() <<
" ConvertToMuHitSurface muon isValid " << tsosPair.first.isValid() <<
" tk isValid " << tsosPair.second.isValid() << endl;
201 if(tsosPair.first.isValid()) muonTSOS = tsosPair.first;
202 cands.push_back(TrackCandWithTSOS(*is,tsosPair.second));
206 double min_chisq = 999999;
207 double min_d = 999999;
208 double min_de= 999999;
209 double min_r_pos = 999999;
210 std::vector<bool> passes(cands.size(),
false);
214 for (vector<TrackCandWithTSOS>::const_iterator
ii = cands.begin();
ii != cands.end(); ++
ii,jj++,iTkCand++) {
217 if(!muonTSOS.
isValid() || !(*ii).second.isValid())
continue;
222 double loc_chi2 =
match_dist(muonTSOS,(*ii).second);
225 LogTrace(category) <<
" iTk " << iTkCand <<
" of " << cands.size() <<
" eta " << (*ii).second.globalPosition().eta() <<
" phi " << (*ii).second.globalPosition().phi() << endl;
226 LogTrace(category) <<
" distance " << distance <<
" distance cut " <<
" " << endl;
227 LogTrace(category) <<
" chi2 " << chi2 <<
" chi2 cut " <<
" " << endl;
228 LogTrace(category) <<
" loc_chi2 " << loc_chi2 <<
" locChi2 cut " <<
" " << endl;
229 LogTrace(category) <<
" deltaR " << deltaR <<
" deltaR cut " <<
" " << endl;
232 LogTrace(category) <<
" Enters a1" << endl;
235 LogTrace(category) <<
" Passes a1" << endl;
236 result.push_back((*ii).first);
240 if( (passes[jj]==
false) && (*ii).second.globalMomentum().perp()<
thePt_threshold2){
241 LogTrace(category) <<
" Enters a2" << endl;
243 LogTrace(category) <<
" Passes a2" << endl;
244 result.push_back((*ii).first);
248 LogTrace(category) <<
" Enters a3" << endl;
249 if( distance>0 && distance<theDeltaD_3 && deltaR>0 && deltaR<
theDeltaR_1){
250 LogTrace(category) <<
" Passes a3" << endl;
251 result.push_back((*ii).first);
257 if(distance<min_d) min_d =
distance;
258 if(loc_chi2<min_de) min_de = loc_chi2;
259 if(deltaR<min_r_pos) min_r_pos =
deltaR;
260 if(chi2<min_chisq) min_chisq =
chi2;
268 if ( result.empty() ) {
269 LogTrace(category) <<
" Stage 1 returned 0 results";
270 for (vector<TrackCandWithTSOS>::const_iterator is = cands.begin(); is != cands.end(); ++is,jj++) {
273 if (muonTSOS.
isValid() && (*is).second.isValid()) {
279 result.push_back((*is).first);
287 double loc_chi2 =
match_dist(muonTSOS,(*is).second);
288 if(distance<min_d) min_d =
distance;
289 if(loc_chi2<min_de) min_de = loc_chi2;
290 if(deltaR<min_r_pos) min_r_pos =
deltaR;
291 if(chi2<min_chisq) min_chisq =
chi2;
299 for(vector<TrackCand>::const_iterator iTk=result.begin();
300 iTk != result.end(); ++iTk) {
301 LogTrace(category) <<
" -----" << endl
302 <<
"selected pt " << iTk->second->pt()
303 <<
" eta " << iTk->second->eta()
304 <<
" phi " << iTk->second->phi() << endl;
312 LogTrace(category) <<
" Cleaning matched candiates" << endl;
318 for (vector<TrackCandWithTSOS>::const_iterator is = cands.begin(); is != cands.end(); ++is,jj++) {
320 if(!passes[jj])
continue;
329 int qual = (
int)(chi2/min_chisq + distance/min_d + deltaR/min_r_pos);
330 int n_min = ((chi2/min_chisq==1)?1:0) + ((distance/min_d==1)?1:0) + ((deltaR/min_r_pos==1)?1:0);
333 result.push_back((*is).first);
337 result.push_back((*is).first);
341 result.push_back((*is).first);
345 result.push_back((*is).first);
350 for(vector<TrackCand>::const_iterator iTk=result.begin();
351 iTk != result.end(); ++iTk) {
352 LogTrace(category) <<
" -----" << endl
353 <<
"selected pt " << iTk->second->pt()
354 <<
" eta " << iTk->second->eta()
355 <<
" phi " << iTk->second->phi() << endl;
365 std::pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>
369 const string category =
"GlobalMuonTrackMatcher";
377 if (tkCand.second.isNonnull()) {
379 if ( !(tkCand.second->p() <
theMinP || tkCand.second->pt() <
theMinPt )) {
385 if ( !impactMuTSOS.isValid() || !outerTkTsos.
isValid() )
return pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>(empty,empty);
394 if ( !
samePlane(tkTsosFromMu,tkTsosFromTk) ) {
399 same1 =
samePlane(newTkTsosFromTk,tkTsosFromMu);
400 LogTrace(category) <<
"Propagating to same tracker surface (Mu):" << same1;
403 same2 =
samePlane(newTkTsosFromMu,tkTsosFromTk);
404 LogTrace(category) <<
"Propagating to same tracker surface (Tk):" << same2;
406 if (same1) tkTsosFromTk = newTkTsosFromTk;
407 else if (same2) tkTsosFromMu = newTkTsosFromMu;
409 LogTrace(category) <<
"Could not propagate Muon and Tracker track to the same tracker bound!";
410 return pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>(
empty,
empty);
414 return pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>(tkTsosFromMu, tkTsosFromTk);
422 std::pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>
426 const string category =
"GlobalMuonTrackMatcher";
431 if ( tkCand.second.isNonnull() ) {
433 if ( !(tkCand.second->p() <
theMinP || tkCand.second->pt() <
theMinPt ) ) {
439 if ( (innerMuTSOS.globalPosition() - outerTkTsos.
globalPosition()).
mag() > (innerMuTSOS.globalPosition() - innerTkTsos.globalPosition()).
mag() )
440 outerTkTsos = innerTkTsos;
445 if ( !innerMuTSOS.isValid() || !outerTkTsos.
isValid() ) {
446 LogTrace(category) <<
"A TSOS validity problem! MuTSOS " << innerMuTSOS.isValid() <<
" TkTSOS " << outerTkTsos.
isValid();
447 return pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>(
empty,
empty);
450 const Surface& refSurface = innerMuTSOS.surface();
454 LogTrace(category) <<
"Could not propagate Muon and Tracker track to the same muon hit surface!";
455 return pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>(
empty,
empty);
458 return pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>(innerMuTSOS, tkAtMu);
466 std::pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>
470 const string category =
"GlobalMuonTrackMatcher";
479 if ( tkCand.second.isNonnull() ) {
481 if ( !(tkCand.second->p() <
theMinP || tkCand.second->pt() <
theMinPt )) {
488 outerTkTsos = innerTkTsos;
493 if ( !impactMuTSOS.isValid() || !outerTkTsos.
isValid() ) {
494 LogTrace(category) <<
"A TSOS validity problem! MuTSOS " << impactMuTSOS.isValid() <<
" TkTSOS " << outerTkTsos.
isValid();
495 return pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>(
empty,
empty);
502 LogTrace(category) <<
"Could not propagate Muon and Tracker track to the same tracker hit surface!";
503 return pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>(
empty,
empty);
506 return pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>(muAtTk, outerTkTsos);
520 if ( fabs(
match_D(tsos1,tsos2) -
match_d(tsos1,tsos2)) > 0.1 )
return false;
522 const float maxtilt = 0.999;
523 const float maxdist = 0.01;
528 bool returnValue = ( (fabs(
p1->normalVector().dot(
p2->normalVector())) > maxtilt) || (fabs((
p1->toLocal(
p2->position())).z()) < maxdist) ) ?
true :
false;
542 const string category =
"GlobalMuonTrackMatcher";
551 bool ierr = !
m.Invert();
554 edm::LogInfo(category) <<
"Error inverting covariance matrix";
558 double est = ROOT::Math::Similarity(
v,
m);
575 if (tkCand.second.isNonnull()) {
576 dR = (deltaR<double>(staCand.second->eta(),staCand.second->phi(),
577 tkCand.second->eta(),tkCand.second->phi()));
647 const string category =
"GlobalMuonTrackMatcher";
661 LogTrace(category) <<
"Error inverting local matrix ";
665 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
T getParameter(std::string const &) const
GlobalMuonTrackMatcher(const edm::ParameterSet &, const MuonServiceProxy *)
constructor
virtual ConstReferenceCountingPointer< TangentPlane > tangentPlane(const GlobalPoint &) const =0
const LocalTrajectoryParameters & localParameters() const
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
double match_Rmom(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
double match_R_IP(const TrackCand &, const TrackCand &) const
LocalError positionError() const
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepStd< double, 2, 2 > > AlgebraicMatrix22
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > convertToTSOSMuHit(const TrackCand &, const TrackCand &) const
AlgebraicVector5 vector() const
const SurfaceType & surface() const
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > convertToTSOSTk(const TrackCand &, const TrackCand &) const
FreeTrajectoryState const * freeState(bool withErrors=true) const
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
double deltaR(double eta1, double eta2, double phi1, double phi2)
ROOT::Math::SVector< double, 5 > AlgebraicVector5
double match_dist(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
std::pair< const Trajectory *, reco::TrackRef > TrackCand
double match_Rpos(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
GlobalVector globalMomentum() const
bool samePlane(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
ROOT::Math::SVector< double, 2 > AlgebraicVector2
virtual ~GlobalMuonTrackMatcher()
destructor