Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:25:53

0001 #ifndef MuonIdentification_MuonArbitrationMethods_h
0002 #define MuonIdentification_MuonArbitrationMethods_h
0003 
0004 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
0005 #include "DataFormats/MuonReco/interface/MuonChamberMatch.h"
0006 
0007 #include <utility>
0008 
0009 // Author: Jake Ribnik (UCSB)
0010 
0011 /// functor predicate for standard library sort algorithm
0012 struct SortMuonSegmentMatches {
0013   /// constructor takes arbitration type
0014   SortMuonSegmentMatches(unsigned int flag) { flag_ = flag; }
0015   /// sorts vector of pairs of chamber and segment pointers
0016   bool operator()(std::pair<reco::MuonChamberMatch*, reco::MuonSegmentMatch*> p1,
0017                   std::pair<reco::MuonChamberMatch*, reco::MuonSegmentMatch*> p2) {
0018     reco::MuonChamberMatch* cm1 = p1.first;
0019     reco::MuonSegmentMatch* sm1 = p1.second;
0020     reco::MuonChamberMatch* cm2 = p2.first;
0021     reco::MuonSegmentMatch* sm2 = p2.second;
0022 
0023     if (flag_ == reco::MuonSegmentMatch::BestInChamberByDX || flag_ == reco::MuonSegmentMatch::BestInStationByDX ||
0024         flag_ == reco::MuonSegmentMatch::BelongsToTrackByDX)
0025       return fabs(sm1->x - cm1->x) < fabs(sm2->x - cm2->x);
0026     if (flag_ == reco::MuonSegmentMatch::BestInChamberByDR || flag_ == reco::MuonSegmentMatch::BestInStationByDR ||
0027         flag_ == reco::MuonSegmentMatch::BelongsToTrackByDR) {
0028       if ((!sm1->hasZed()) || (!sm2->hasZed()))  // no y information so return dx
0029         return fabs(sm1->x - cm1->x) < fabs(sm2->x - cm2->x);
0030       return sqrt(pow(sm1->x - cm1->x, 2) + pow(sm1->y - cm1->y, 2)) <
0031              sqrt(pow(sm2->x - cm2->x, 2) + pow(sm2->y - cm2->y, 2));
0032     }
0033     if (flag_ == reco::MuonSegmentMatch::BestInChamberByDXSlope ||
0034         flag_ == reco::MuonSegmentMatch::BestInStationByDXSlope ||
0035         flag_ == reco::MuonSegmentMatch::BelongsToTrackByDXSlope)
0036       return fabs(sm1->dXdZ - cm1->dXdZ) < fabs(sm2->dXdZ - cm2->dXdZ);
0037     if (flag_ == reco::MuonSegmentMatch::BestInChamberByDRSlope ||
0038         flag_ == reco::MuonSegmentMatch::BestInStationByDRSlope ||
0039         flag_ == reco::MuonSegmentMatch::BelongsToTrackByDRSlope) {
0040       if ((!sm1->hasZed()) || (!sm2->hasZed()))  // no y information so return dx
0041         return fabs(sm1->dXdZ - cm1->dXdZ) < fabs(sm2->dXdZ - cm2->dXdZ);
0042       return sqrt(pow(sm1->dXdZ - cm1->dXdZ, 2) + pow(sm1->dYdZ - cm1->dYdZ, 2)) <
0043              sqrt(pow(sm2->dXdZ - cm2->dXdZ, 2) + pow(sm2->dYdZ - cm2->dYdZ, 2));
0044     }
0045 
0046     return false;  // is this appropriate? fix this
0047   }
0048 
0049   unsigned int flag_;
0050 };
0051 
0052 #endif