93 std::pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface> tsosPair
96 double chi2 =
match_Chi2(tsosPair.first,tsosPair.second);
97 if ( chi2 > 0. && chi2 <
theChi2_2 )
return true;
99 double distance =
match_d(tsosPair.first,tsosPair.second);
100 if ( distance > 0. && distance <
theDeltaD_2 )
return true;
117 int surfaceOption)
const {
119 std::pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface> tsosPair;
122 if ( surfaceOption != 0 && surfaceOption != 1 )
return -1.0;
124 if ( matchOption == 0 ) {
126 return match_Chi2(tsosPair.first,tsosPair.second);
128 else if ( matchOption == 1 ) {
130 return match_d(tsosPair.first,tsosPair.second);
132 else if ( matchOption == 2 ) {
134 return match_Rpos(tsosPair.first,tsosPair.second);
136 else if ( matchOption == 3 ) {
137 return match_dist(tsosPair.first,tsosPair.second);
149 std::vector<GlobalMuonTrackMatcher::TrackCand>::const_iterator
151 const std::vector<TrackCand>&
tracks)
const {
153 if ( tracks.empty() )
return tracks.end();
156 vector<TrackCand>::const_iterator
result = tracks.end();
157 for (vector<TrackCand>::const_iterator is = tracks.begin(); is != tracks.end(); ++is) {
159 std::pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface> tsosPair
163 double chi2 =
match_Chi2(tsosPair.first,tsosPair.second);
164 if ( chi2 > 0. && chi2 <= minChi2 ) {
182 vector<GlobalMuonTrackMatcher::TrackCand>
184 const vector<TrackCand>&
tracks)
const {
185 const string category =
"GlobalMuonTrackMatcher";
189 if ( tracks.empty() )
return result;
191 typedef std::pair<TrackCand, TrajectoryStateOnSurface> TrackCandWithTSOS;
192 vector<TrackCandWithTSOS> cands;
196 LogTrace(category) <<
" ***" << endl <<
"STA Muon pT "<< sta.second->pt();
197 LogTrace(category) <<
" Tk in Region " << tracks.size() << endl;
199 for (vector<TrackCand>::const_iterator is = tracks.begin(); is != tracks.end(); ++is,iiTk++) {
201 std::pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface> tsosPair =
convertToTSOSMuHit(sta,*is);
202 LogTrace(category) <<
" Tk " << iiTk <<
" of " << tracks.size() <<
" ConvertToMuHitSurface muon isValid " << tsosPair.first.isValid() <<
" tk isValid " << tsosPair.second.isValid() << endl;
203 if(tsosPair.first.isValid()) muonTSOS = tsosPair.first;
204 cands.push_back(TrackCandWithTSOS(*is,tsosPair.second));
208 double min_chisq = 999999;
209 double min_d = 999999;
210 double min_de= 999999;
211 double min_r_pos = 999999;
212 std::vector<bool> passes(cands.size(),
false);
216 for (vector<TrackCandWithTSOS>::const_iterator
ii = cands.begin();
ii != cands.end(); ++
ii,jj++,iTkCand++) {
219 if(!muonTSOS.
isValid() || !(*ii).second.isValid())
continue;
222 double distance =
match_d(muonTSOS,(*ii).second);
223 double chi2 =
match_Chi2(muonTSOS,(*ii).second);
224 double loc_chi2 =
match_dist(muonTSOS,(*ii).second);
227 LogTrace(category) <<
" iTk " << iTkCand <<
" of " << cands.size() <<
" eta " << (*ii).second.globalPosition().eta() <<
" phi " << (*ii).second.globalPosition().phi() << endl;
228 LogTrace(category) <<
" distance " << distance <<
" distance cut " <<
" " << endl;
229 LogTrace(category) <<
" chi2 " << chi2 <<
" chi2 cut " <<
" " << endl;
230 LogTrace(category) <<
" loc_chi2 " << loc_chi2 <<
" locChi2 cut " <<
" " << endl;
231 LogTrace(category) <<
" deltaR " << deltaR <<
" deltaR cut " <<
" " << endl;
234 LogTrace(category) <<
" Enters a1" << endl;
237 LogTrace(category) <<
" Passes a1" << endl;
238 result.push_back((*ii).first);
242 if( (passes[jj]==
false) && (*ii).second.globalMomentum().perp()<
thePt_threshold2){
243 LogTrace(category) <<
" Enters a2" << endl;
245 LogTrace(category) <<
" Passes a2" << endl;
246 result.push_back((*ii).first);
250 LogTrace(category) <<
" Enters a3" << endl;
251 if( distance>0 && distance<theDeltaD_3 && deltaR>0 && deltaR<
theDeltaR_1){
252 LogTrace(category) <<
" Passes a3" << endl;
253 result.push_back((*ii).first);
259 if(distance<min_d) min_d = distance;
260 if(loc_chi2<min_de) min_de = loc_chi2;
261 if(deltaR<min_r_pos) min_r_pos =
deltaR;
262 if(chi2<min_chisq) min_chisq = chi2;
270 if ( result.empty() ) {
271 LogTrace(category) <<
" Stage 1 returned 0 results";
272 for (vector<TrackCandWithTSOS>::const_iterator is = cands.begin(); is != cands.end(); ++is,jj++) {
275 if (muonTSOS.
isValid() && (*is).second.isValid()) {
281 result.push_back((*is).first);
287 double distance =
match_d(muonTSOS,(*is).second);
288 double chi2 =
match_Chi2(muonTSOS,(*is).second);
289 double loc_chi2 =
match_dist(muonTSOS,(*is).second);
290 if(distance<min_d) min_d = distance;
291 if(loc_chi2<min_de) min_de = loc_chi2;
292 if(deltaR<min_r_pos) min_r_pos =
deltaR;
293 if(chi2<min_chisq) min_chisq = chi2;
301 for(vector<TrackCand>::const_iterator iTk=result.begin();
302 iTk != result.end(); ++iTk) {
303 LogTrace(category) <<
" -----" << endl
304 <<
"selected pt " << iTk->second->pt()
305 <<
" eta " << iTk->second->eta()
306 <<
" phi " << iTk->second->phi() << endl;
314 LogTrace(category) <<
" Cleaning matched candiates" << endl;
320 for (vector<TrackCandWithTSOS>::const_iterator is = cands.begin(); is != cands.end(); ++is,jj++) {
322 if(!passes[jj])
continue;
324 double distance =
match_d(muonTSOS,(*is).second);
325 double chi2 =
match_Chi2(muonTSOS,(*is).second);
331 int qual = (int)(chi2/min_chisq + distance/min_d + deltaR/min_r_pos);
332 int n_min = ((chi2/min_chisq==1)?1:0) + ((distance/min_d==1)?1:0) + ((deltaR/min_r_pos==1)?1:0);
335 result.push_back((*is).first);
339 result.push_back((*is).first);
343 result.push_back((*is).first);
347 result.push_back((*is).first);
352 for(vector<TrackCand>::const_iterator iTk=result.begin();
353 iTk != result.end(); ++iTk) {
354 LogTrace(category) <<
" -----" << endl
355 <<
"selected pt " << iTk->second->pt()
356 <<
" eta " << iTk->second->eta()
357 <<
" phi " << iTk->second->phi() << endl;
367 std::pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>
371 const string category =
"GlobalMuonTrackMatcher";
379 if (tkCand.second.isNonnull()) {
381 if ( !(tkCand.second->p() <
theMinP || tkCand.second->pt() <
theMinPt )) {
387 if ( !impactMuTSOS.isValid() || !outerTkTsos.
isValid() )
return pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>(empty,empty);
396 if ( !
samePlane(tkTsosFromMu,tkTsosFromTk) ) {
401 same1 =
samePlane(newTkTsosFromTk,tkTsosFromMu);
402 LogTrace(category) <<
"Propagating to same tracker surface (Mu):" << same1;
405 same2 =
samePlane(newTkTsosFromMu,tkTsosFromTk);
406 LogTrace(category) <<
"Propagating to same tracker surface (Tk):" << same2;
408 if (same1) tkTsosFromTk = newTkTsosFromTk;
409 else if (same2) tkTsosFromMu = newTkTsosFromMu;
411 LogTrace(category) <<
"Could not propagate Muon and Tracker track to the same tracker bound!";
412 return pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>(
empty,
empty);
416 return pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>(tkTsosFromMu, tkTsosFromTk);
424 std::pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>
428 const string category =
"GlobalMuonTrackMatcher";
433 if ( tkCand.second.isNonnull() ) {
435 if ( !(tkCand.second->p() <
theMinP || tkCand.second->pt() <
theMinPt ) ) {
441 if ( (innerMuTSOS.globalPosition() - outerTkTsos.
globalPosition()).
mag() > (innerMuTSOS.globalPosition() - innerTkTsos.globalPosition()).
mag() )
442 outerTkTsos = innerTkTsos;
447 if ( !innerMuTSOS.isValid() || !outerTkTsos.
isValid() ) {
448 LogTrace(category) <<
"A TSOS validity problem! MuTSOS " << innerMuTSOS.isValid() <<
" TkTSOS " << outerTkTsos.
isValid();
449 return pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>(
empty,
empty);
452 const Surface& refSurface = innerMuTSOS.surface();
456 LogTrace(category) <<
"Could not propagate Muon and Tracker track to the same muon hit surface!";
457 return pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>(
empty,
empty);
460 return pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>(innerMuTSOS, tkAtMu);
468 std::pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>
472 const string category =
"GlobalMuonTrackMatcher";
481 if ( tkCand.second.isNonnull() ) {
483 if ( !(tkCand.second->p() <
theMinP || tkCand.second->pt() <
theMinPt )) {
490 outerTkTsos = innerTkTsos;
495 if ( !impactMuTSOS.isValid() || !outerTkTsos.
isValid() ) {
496 LogTrace(category) <<
"A TSOS validity problem! MuTSOS " << impactMuTSOS.isValid() <<
" TkTSOS " << outerTkTsos.
isValid();
497 return pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>(
empty,
empty);
504 LogTrace(category) <<
"Could not propagate Muon and Tracker track to the same tracker hit surface!";
505 return pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>(
empty,
empty);
508 return pair<TrajectoryStateOnSurface,TrajectoryStateOnSurface>(muAtTk, outerTkTsos);
522 if ( fabs(
match_D(tsos1,tsos2) -
match_d(tsos1,tsos2)) > 0.1 )
return false;
524 const float maxtilt = 0.999;
525 const float maxdist = 0.01;
530 bool returnValue = ( (fabs(p1->normalVector().dot(p2->normalVector())) > maxtilt) || (fabs((p1->toLocal(p2->position())).z()) < maxdist) ) ?
true :
false;
544 const string category =
"GlobalMuonTrackMatcher";
553 bool ierr = !
m.Invert();
556 edm::LogInfo(category) <<
"Error inverting covariance matrix";
560 double est = ROOT::Math::Similarity(
v,
m);
577 if (tkCand.second.isNonnull()) {
578 dR = (deltaR<double>(staCand.second->eta(),staCand.second->phi(),
579 tkCand.second->eta(),tkCand.second->phi()));
649 const string category =
"GlobalMuonTrackMatcher";
663 LogTrace(category) <<
"Error inverting local matrix ";
667 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
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 * 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)
virtual ReferenceCountingPointer< TangentPlane > tangentPlane(const GlobalPoint &) const =0
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