CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/DataFormats/MuonReco/src/Muon.cc

Go to the documentation of this file.
00001 #include "DataFormats/MuonReco/interface/Muon.h"
00002 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00003 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00004 
00005 using namespace reco;
00006 
00007 Muon::Muon(  Charge q, const LorentzVector & p4, const Point & vtx ) :
00008   RecoCandidate( q, p4, vtx, -13 * q ) {
00009      energyValid_  = false;
00010      matchesValid_ = false;
00011      isolationValid_ = false;
00012      pfIsolationValid_ = false;
00013      qualityValid_ = false;
00014      caloCompatibility_ = -9999.;
00015      type_ = 0;
00016      bestTrackType_ = reco::Muon::None;
00017 }
00018 
00019 Muon::Muon() {
00020    energyValid_  = false;
00021    matchesValid_ = false;
00022    isolationValid_ = false;
00023    pfIsolationValid_ = false;
00024    qualityValid_ = false;
00025    caloCompatibility_ = -9999.;
00026    type_ = 0;
00027    bestTrackType_ = reco::Muon::None;
00028 }
00029 
00030 bool Muon::overlap( const Candidate & c ) const {
00031   const RecoCandidate * o = dynamic_cast<const RecoCandidate *>( & c );
00032   return ( o != 0 && 
00033            ( checkOverlap( track(), o->track() ) ||
00034              checkOverlap( standAloneMuon(), o->standAloneMuon() ) ||
00035              checkOverlap( combinedMuon(), o->combinedMuon() ) ||
00036              checkOverlap( standAloneMuon(), o->track() ) ||
00037              checkOverlap( combinedMuon(), o->track() ) )
00038            );
00039 }
00040 
00041 Muon * Muon::clone() const {
00042   return new Muon( * this );
00043 }
00044 
00045 int Muon::numberOfChambersNoRPC() const
00046 {
00047   int total = 0;
00048   int nAll = numberOfChambers();
00049   for (int iC = 0; iC < nAll; ++iC){
00050     if (matches()[iC].detector() == MuonSubdetId::RPC) continue;
00051     total++;
00052   }
00053 
00054   return total;
00055 }
00056 
00057 int Muon::numberOfMatches( ArbitrationType type ) const
00058 {
00059    int matches(0);
00060    for( std::vector<MuonChamberMatch>::const_iterator chamberMatch = muMatches_.begin();
00061          chamberMatch != muMatches_.end(); chamberMatch++ )
00062    {
00063       if(type == RPCHitAndTrackArbitration) {
00064          if(chamberMatch->rpcMatches.empty()) continue;
00065          matches += chamberMatch->rpcMatches.size();
00066          continue;
00067       }
00068 
00069       if(chamberMatch->segmentMatches.empty()) continue;
00070       if(type == NoArbitration) {
00071          matches++;
00072          continue;
00073       }
00074 
00075       for( std::vector<MuonSegmentMatch>::const_iterator segmentMatch = chamberMatch->segmentMatches.begin();
00076             segmentMatch != chamberMatch->segmentMatches.end(); segmentMatch++ )
00077       {
00078          if(type == SegmentArbitration)
00079             if(segmentMatch->isMask(MuonSegmentMatch::BestInChamberByDR)) {
00080                matches++;
00081                break;
00082             }
00083          if(type == SegmentAndTrackArbitration)
00084             if(segmentMatch->isMask(MuonSegmentMatch::BestInChamberByDR) &&
00085                   segmentMatch->isMask(MuonSegmentMatch::BelongsToTrackByDR)) {
00086                matches++;
00087                break;
00088             }
00089          if(type == SegmentAndTrackArbitrationCleaned)
00090            if(segmentMatch->isMask(MuonSegmentMatch::BestInChamberByDR) &&
00091                  segmentMatch->isMask(MuonSegmentMatch::BelongsToTrackByDR) && 
00092                  segmentMatch->isMask(MuonSegmentMatch::BelongsToTrackByCleaning)) {
00093              matches++;
00094              break;
00095            }
00096          if(type > 1<<7)
00097             if(segmentMatch->isMask(type)) {
00098                matches++;
00099                break;
00100             }
00101       }
00102    }
00103 
00104    return matches;
00105 }
00106 
00107 int Muon::numberOfMatchedStations( ArbitrationType type ) const
00108 {
00109    int stations(0);
00110 
00111    unsigned int theStationMask = stationMask(type);
00112    // eight stations, eight bits
00113    for(int it = 0; it < 8; ++it)
00114       if (theStationMask & 1<<it)
00115          ++stations;
00116 
00117    return stations;
00118 }
00119 
00120 unsigned int Muon::stationMask( ArbitrationType type ) const
00121 {
00122    unsigned int totMask(0);
00123    unsigned int curMask(0);
00124 
00125    for( std::vector<MuonChamberMatch>::const_iterator chamberMatch = muMatches_.begin();
00126          chamberMatch != muMatches_.end(); chamberMatch++ )
00127    {
00128       if(type == RPCHitAndTrackArbitration) {
00129          if(chamberMatch->rpcMatches.empty()) continue;
00130 
00131          RPCDetId rollId = chamberMatch->id.rawId();
00132          const int region    = rollId.region();
00133          int rpcIndex = 1; if (region!=0) rpcIndex = 2;
00134 
00135          for( std::vector<MuonRPCHitMatch>::const_iterator rpcMatch = chamberMatch->rpcMatches.begin();
00136                rpcMatch != chamberMatch->rpcMatches.end(); rpcMatch++ )
00137          {
00138             curMask = 1<<( (chamberMatch->station()-1)+4*(rpcIndex-1) );
00139 
00140             // do not double count
00141             if(!(totMask & curMask))
00142                totMask += curMask;
00143          }
00144          continue;
00145       }
00146 
00147       if(chamberMatch->segmentMatches.empty()) continue;
00148       if(type == NoArbitration) {
00149          curMask = 1<<( (chamberMatch->station()-1)+4*(chamberMatch->detector()-1) );
00150          // do not double count
00151          if(!(totMask & curMask))
00152             totMask += curMask;
00153          continue;
00154       }
00155 
00156       for( std::vector<MuonSegmentMatch>::const_iterator segmentMatch = chamberMatch->segmentMatches.begin();
00157             segmentMatch != chamberMatch->segmentMatches.end(); segmentMatch++ )
00158       {
00159          if(type == SegmentArbitration)
00160             if(segmentMatch->isMask(MuonSegmentMatch::BestInStationByDR)) {
00161                curMask = 1<<( (chamberMatch->station()-1)+4*(chamberMatch->detector()-1) );
00162                // do not double count
00163                if(!(totMask & curMask))
00164                   totMask += curMask;
00165                break;
00166             }
00167          if(type == SegmentAndTrackArbitration)
00168             if(segmentMatch->isMask(MuonSegmentMatch::BestInStationByDR) &&
00169                   segmentMatch->isMask(MuonSegmentMatch::BelongsToTrackByDR)) {
00170                curMask = 1<<( (chamberMatch->station()-1)+4*(chamberMatch->detector()-1) );
00171                // do not double count
00172                if(!(totMask & curMask))
00173                   totMask += curMask;
00174                break;
00175             }
00176          if(type == SegmentAndTrackArbitrationCleaned)
00177             if(segmentMatch->isMask(MuonSegmentMatch::BestInStationByDR) &&
00178                   segmentMatch->isMask(MuonSegmentMatch::BelongsToTrackByDR) &&
00179                   segmentMatch->isMask(MuonSegmentMatch::BelongsToTrackByCleaning)) {
00180                curMask = 1<<( (chamberMatch->station()-1)+4*(chamberMatch->detector()-1) );
00181                // do not double count
00182                if(!(totMask & curMask))
00183                   totMask += curMask;
00184                break;
00185             }
00186          if(type > 1<<7)
00187             if(segmentMatch->isMask(type)) {
00188                curMask = 1<<( (chamberMatch->station()-1)+4*(chamberMatch->detector()-1) );
00189                // do not double count
00190                if(!(totMask & curMask))
00191                   totMask += curMask;
00192                break;
00193             }
00194       }
00195    }
00196 
00197    return totMask;
00198 }
00199 
00200 int Muon::numberOfMatchedRPCLayers( ArbitrationType type ) const
00201 {
00202    int layers(0);
00203 
00204    unsigned int theRPCLayerMask = RPClayerMask(type);
00205    // maximum ten layers because of 6 layers in barrel and 3 (4) layers in each endcap before (after) upscope
00206    for(int it = 0; it < 10; ++it)
00207      if (theRPCLayerMask & 1<<it)
00208        ++layers;
00209 
00210    return layers;
00211 }
00212 
00213 unsigned int Muon::RPClayerMask( ArbitrationType type ) const
00214 {
00215    unsigned int totMask(0);
00216    unsigned int curMask(0);
00217    for( std::vector<MuonChamberMatch>::const_iterator chamberMatch = muMatches_.begin();
00218          chamberMatch != muMatches_.end(); chamberMatch++ )
00219    {
00220       if(chamberMatch->rpcMatches.empty()) continue;
00221          
00222       RPCDetId rollId = chamberMatch->id.rawId();
00223       const int region = rollId.region();
00224 
00225       const int layer  = rollId.layer();
00226       int rpcLayer = chamberMatch->station();
00227       if (region==0) {
00228          rpcLayer = chamberMatch->station()-1 + chamberMatch->station()*layer;
00229          if ((chamberMatch->station()==2 && layer==2) || (chamberMatch->station()==4 && layer==1)) rpcLayer -= 1;
00230       } else rpcLayer += 6;
00231          
00232       for( std::vector<MuonRPCHitMatch>::const_iterator rpcMatch = chamberMatch->rpcMatches.begin();
00233             rpcMatch != chamberMatch->rpcMatches.end(); rpcMatch++ )
00234       {
00235          curMask = 1<<(rpcLayer-1);
00236 
00237          // do not double count
00238          if(!(totMask & curMask))
00239             totMask += curMask;
00240       }
00241    }
00242    
00243    return totMask;
00244 
00245 }
00246 
00247 unsigned int Muon::stationGapMaskDistance( float distanceCut ) const
00248 {
00249    unsigned int totMask(0);
00250    for( int stationIndex = 1; stationIndex < 5; stationIndex++ )
00251    {
00252       for( int detectorIndex = 1; detectorIndex < 4; detectorIndex++ )
00253       {
00254          unsigned int curMask(0);
00255          for( std::vector<MuonChamberMatch>::const_iterator chamberMatch = muMatches_.begin();
00256                chamberMatch != muMatches_.end(); chamberMatch++ )
00257          {
00258             if(!(chamberMatch->station()==stationIndex && chamberMatch->detector()==detectorIndex)) continue;
00259 
00260             float edgeX = chamberMatch->edgeX;
00261             float edgeY = chamberMatch->edgeY;
00262             if(edgeX<0 && fabs(edgeX)>fabs(distanceCut) &&
00263                   edgeY<0 && fabs(edgeY)>fabs(distanceCut)) // inside the chamber so negates all gaps for this station
00264             {
00265                curMask = 0;
00266                break;
00267             }
00268             if( ( fabs(edgeX) < fabs(distanceCut) && edgeY < fabs(distanceCut) ) ||
00269                 ( fabs(edgeY) < fabs(distanceCut) && edgeX < fabs(distanceCut) ) ) // inside gap
00270                curMask = 1<<( (stationIndex-1)+4*(detectorIndex-1) );
00271          }
00272 
00273          totMask += curMask; // add to total mask
00274       }
00275    }
00276 
00277    return totMask;
00278 }
00279 
00280 unsigned int Muon::stationGapMaskPull( float sigmaCut ) const
00281 {
00282    unsigned int totMask(0);
00283    for( int stationIndex = 1; stationIndex < 5; stationIndex++ )
00284    {
00285       for( int detectorIndex = 1; detectorIndex < 4; detectorIndex++ )
00286       {
00287          unsigned int curMask(0);
00288          for( std::vector<MuonChamberMatch>::const_iterator chamberMatch = muMatches_.begin();
00289                chamberMatch != muMatches_.end(); chamberMatch++ )
00290          {
00291             if(!(chamberMatch->station()==stationIndex && chamberMatch->detector()==detectorIndex)) continue;
00292 
00293             float edgeX = chamberMatch->edgeX;
00294             float edgeY = chamberMatch->edgeY;
00295             float xErr  = chamberMatch->xErr+0.000001; // protect against division by zero later
00296             float yErr  = chamberMatch->yErr+0.000001; // protect against division by zero later
00297             if(edgeX<0 && fabs(edgeX/xErr)>fabs(sigmaCut) &&
00298                   edgeY<0 && fabs(edgeY/yErr)>fabs(sigmaCut)) // inside the chamber so negates all gaps for this station
00299             {
00300                curMask = 0;
00301                break;
00302             }
00303             if( ( fabs(edgeX/xErr) < fabs(sigmaCut) && edgeY/yErr < fabs(sigmaCut) ) ||
00304                 ( fabs(edgeY/yErr) < fabs(sigmaCut) && edgeX/xErr < fabs(sigmaCut) ) ) // inside gap
00305                curMask = 1<<((stationIndex-1)+4*(detectorIndex-1));
00306          }
00307 
00308          totMask += curMask; // add to total mask
00309       }
00310    }
00311 
00312    return totMask;
00313 }
00314 
00315 int Muon::numberOfSegments( int station, int muonSubdetId, ArbitrationType type ) const
00316 {
00317    int segments(0);
00318    for( std::vector<MuonChamberMatch>::const_iterator chamberMatch = muMatches_.begin();
00319          chamberMatch != muMatches_.end(); chamberMatch++ )
00320    {
00321       if(chamberMatch->segmentMatches.empty()) continue;
00322       if(!(chamberMatch->station()==station && chamberMatch->detector()==muonSubdetId)) continue;
00323 
00324       if(type == NoArbitration) {
00325          segments += chamberMatch->segmentMatches.size();
00326          continue;
00327       }
00328 
00329       for( std::vector<MuonSegmentMatch>::const_iterator segmentMatch = chamberMatch->segmentMatches.begin();
00330             segmentMatch != chamberMatch->segmentMatches.end(); segmentMatch++ )
00331       {
00332          if(type == SegmentArbitration)
00333             if(segmentMatch->isMask(MuonSegmentMatch::BestInStationByDR)) {
00334                segments++;
00335                break;
00336             }
00337          if(type == SegmentAndTrackArbitration)
00338             if(segmentMatch->isMask(MuonSegmentMatch::BestInStationByDR) &&
00339                   segmentMatch->isMask(MuonSegmentMatch::BelongsToTrackByDR)) {
00340                segments++;
00341                break;
00342             }
00343          if(type == SegmentAndTrackArbitrationCleaned)
00344             if(segmentMatch->isMask(MuonSegmentMatch::BestInStationByDR) &&
00345                   segmentMatch->isMask(MuonSegmentMatch::BelongsToTrackByDR) &&
00346                   segmentMatch->isMask(MuonSegmentMatch::BelongsToTrackByCleaning)) {
00347                segments++;
00348                break;
00349             }
00350          if(type > 1<<7)
00351             if(segmentMatch->isMask(type)) {
00352                segments++;
00353                break;
00354             }
00355       }
00356    }
00357 
00358    return segments;
00359 }
00360 
00361 const std::vector<const MuonChamberMatch*> Muon::chambers( int station, int muonSubdetId ) const
00362 {
00363    std::vector<const MuonChamberMatch*> chambers;
00364    for(std::vector<MuonChamberMatch>::const_iterator chamberMatch = muMatches_.begin();
00365          chamberMatch != muMatches_.end(); chamberMatch++)
00366       if(chamberMatch->station()==station && chamberMatch->detector()==muonSubdetId)
00367          chambers.push_back(&(*chamberMatch));
00368    return chambers;
00369 }
00370 
00371 std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> Muon::pair( const std::vector<const MuonChamberMatch*> &chambers,
00372      ArbitrationType type ) const
00373 {
00374    MuonChamberMatch* m = 0;
00375    MuonSegmentMatch* s = 0;
00376    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair(m,s);
00377 
00378    if(chambers.empty()) return chamberSegmentPair;
00379    for( std::vector<const MuonChamberMatch*>::const_iterator chamberMatch = chambers.begin();
00380          chamberMatch != chambers.end(); chamberMatch++ )
00381    {
00382       if((*chamberMatch)->segmentMatches.empty()) continue;
00383       if(type == NoArbitration)
00384          return std::make_pair(*chamberMatch, &((*chamberMatch)->segmentMatches.front()));
00385 
00386       for( std::vector<MuonSegmentMatch>::const_iterator segmentMatch = (*chamberMatch)->segmentMatches.begin();
00387             segmentMatch != (*chamberMatch)->segmentMatches.end(); segmentMatch++ )
00388       {
00389          if(type == SegmentArbitration)
00390             if(segmentMatch->isMask(MuonSegmentMatch::BestInStationByDR)) 
00391                return std::make_pair(*chamberMatch, &(*segmentMatch));
00392          if(type == SegmentAndTrackArbitration)
00393             if(segmentMatch->isMask(MuonSegmentMatch::BestInStationByDR) &&
00394                   segmentMatch->isMask(MuonSegmentMatch::BelongsToTrackByDR))
00395                return std::make_pair(*chamberMatch, &(*segmentMatch));
00396          if(type == SegmentAndTrackArbitrationCleaned)
00397             if(segmentMatch->isMask(MuonSegmentMatch::BestInStationByDR) &&
00398                   segmentMatch->isMask(MuonSegmentMatch::BelongsToTrackByDR) &&
00399                   segmentMatch->isMask(MuonSegmentMatch::BelongsToTrackByCleaning))
00400                return std::make_pair(*chamberMatch, &(*segmentMatch));
00401          if(type > 1<<7)
00402             if(segmentMatch->isMask(type))
00403                return std::make_pair(*chamberMatch, &(*segmentMatch));
00404       }
00405    }
00406 
00407    return chamberSegmentPair;
00408 }
00409 
00410 float Muon::dX( int station, int muonSubdetId, ArbitrationType type ) const
00411 {
00412    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(chambers(station,muonSubdetId),type);
00413    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) return 999999;
00414    if(! chamberSegmentPair.second->hasPhi()) return 999999;
00415    return chamberSegmentPair.first->x-chamberSegmentPair.second->x;
00416 }
00417 
00418 float Muon::dY( int station, int muonSubdetId, ArbitrationType type ) const
00419 {
00420    if(station==4 && muonSubdetId==MuonSubdetId::DT) return 999999; // no y information
00421    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(chambers(station,muonSubdetId),type);
00422    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) return 999999;
00423    if(! chamberSegmentPair.second->hasZed()) return 999999;
00424    return chamberSegmentPair.first->y-chamberSegmentPair.second->y;
00425 }
00426 
00427 float Muon::dDxDz( int station, int muonSubdetId, ArbitrationType type ) const
00428 {
00429    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(chambers(station,muonSubdetId),type);
00430    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) return 999999;
00431    if(! chamberSegmentPair.second->hasPhi()) return 999999;
00432    return chamberSegmentPair.first->dXdZ-chamberSegmentPair.second->dXdZ;
00433 }
00434 
00435 float Muon::dDyDz( int station, int muonSubdetId, ArbitrationType type ) const
00436 {
00437    if(station==4 && muonSubdetId==MuonSubdetId::DT) return 999999; // no y information
00438    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(chambers(station,muonSubdetId),type);
00439    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) return 999999;
00440    if(! chamberSegmentPair.second->hasZed()) return 999999;
00441    return chamberSegmentPair.first->dYdZ-chamberSegmentPair.second->dYdZ;
00442 }
00443 
00444 float Muon::pullX( int station, int muonSubdetId, ArbitrationType type, bool includeSegmentError ) const
00445 {
00446    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(chambers(station,muonSubdetId),type);
00447    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) return 999999;
00448    if(! chamberSegmentPair.second->hasPhi()) return 999999;
00449    if(includeSegmentError)
00450       return (chamberSegmentPair.first->x-chamberSegmentPair.second->x)/sqrt(pow(chamberSegmentPair.first->xErr,2)+pow(chamberSegmentPair.second->xErr,2));
00451    return (chamberSegmentPair.first->x-chamberSegmentPair.second->x)/chamberSegmentPair.first->xErr;
00452 }
00453 
00454 float Muon::pullY( int station, int muonSubdetId, ArbitrationType type, bool includeSegmentError) const
00455 {
00456    if(station==4 && muonSubdetId==MuonSubdetId::DT) return 999999; // no y information
00457    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(chambers(station,muonSubdetId),type);
00458    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) return 999999;
00459    if(! chamberSegmentPair.second->hasZed()) return 999999;
00460    if(includeSegmentError)
00461       return (chamberSegmentPair.first->y-chamberSegmentPair.second->y)/sqrt(pow(chamberSegmentPair.first->yErr,2)+pow(chamberSegmentPair.second->yErr,2));
00462    return (chamberSegmentPair.first->y-chamberSegmentPair.second->y)/chamberSegmentPair.first->yErr;
00463 }
00464 
00465 float Muon::pullDxDz( int station, int muonSubdetId, ArbitrationType type, bool includeSegmentError ) const
00466 {
00467    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(chambers(station,muonSubdetId),type);
00468    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) return 999999;
00469    if(! chamberSegmentPair.second->hasPhi()) return 999999;
00470    if(includeSegmentError)
00471       return (chamberSegmentPair.first->dXdZ-chamberSegmentPair.second->dXdZ)/sqrt(pow(chamberSegmentPair.first->dXdZErr,2)+pow(chamberSegmentPair.second->dXdZErr,2));
00472    return (chamberSegmentPair.first->dXdZ-chamberSegmentPair.second->dXdZ)/chamberSegmentPair.first->dXdZErr;
00473 }
00474 
00475 float Muon::pullDyDz( int station, int muonSubdetId, ArbitrationType type, bool includeSegmentError ) const
00476 {
00477    if(station==4 && muonSubdetId==MuonSubdetId::DT) return 999999; // no y information
00478    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(chambers(station,muonSubdetId),type);
00479    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) return 999999;
00480    if(! chamberSegmentPair.second->hasZed()) return 999999;
00481    if(includeSegmentError)
00482       return (chamberSegmentPair.first->dYdZ-chamberSegmentPair.second->dYdZ)/sqrt(pow(chamberSegmentPair.first->dYdZErr,2)+pow(chamberSegmentPair.second->dYdZErr,2));
00483    return (chamberSegmentPair.first->dYdZ-chamberSegmentPair.second->dYdZ)/chamberSegmentPair.first->dYdZErr;
00484 }
00485 
00486 float Muon::segmentX( int station, int muonSubdetId, ArbitrationType type ) const
00487 {
00488    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(chambers(station,muonSubdetId),type);
00489    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) return 999999;
00490    if(! chamberSegmentPair.second->hasPhi()) return 999999;
00491    return chamberSegmentPair.second->x;
00492 }
00493 
00494 float Muon::segmentY( int station, int muonSubdetId, ArbitrationType type ) const
00495 {
00496    if(station==4 && muonSubdetId==MuonSubdetId::DT) return 999999; // no y information
00497    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(chambers(station,muonSubdetId),type);
00498    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) return 999999;
00499    if(! chamberSegmentPair.second->hasZed()) return 999999;
00500    return chamberSegmentPair.second->y;
00501 }
00502 
00503 float Muon::segmentDxDz( int station, int muonSubdetId, ArbitrationType type ) const
00504 {
00505    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(chambers(station,muonSubdetId),type);
00506    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) return 999999;
00507    if(! chamberSegmentPair.second->hasPhi()) return 999999;
00508    return chamberSegmentPair.second->dXdZ;
00509 }
00510 
00511 float Muon::segmentDyDz( int station, int muonSubdetId, ArbitrationType type ) const
00512 {
00513    if(station==4 && muonSubdetId==MuonSubdetId::DT) return 999999; // no y information
00514    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(chambers(station,muonSubdetId),type);
00515    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) return 999999;
00516    if(! chamberSegmentPair.second->hasZed()) return 999999;
00517    return chamberSegmentPair.second->dYdZ;
00518 }
00519 
00520 float Muon::segmentXErr( int station, int muonSubdetId, ArbitrationType type ) const
00521 {
00522    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(chambers(station,muonSubdetId),type);
00523    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) return 999999;
00524    if(! chamberSegmentPair.second->hasPhi()) return 999999;
00525    return chamberSegmentPair.second->xErr;
00526 }
00527 
00528 float Muon::segmentYErr( int station, int muonSubdetId, ArbitrationType type ) const
00529 {
00530    if(station==4 && muonSubdetId==MuonSubdetId::DT) return 999999; // no y information
00531    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(chambers(station,muonSubdetId),type);
00532    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) return 999999;
00533    if(! chamberSegmentPair.second->hasZed()) return 999999;
00534    return chamberSegmentPair.second->yErr;
00535 }
00536 
00537 float Muon::segmentDxDzErr( int station, int muonSubdetId, ArbitrationType type ) const
00538 {
00539    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(chambers(station,muonSubdetId),type);
00540    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) return 999999;
00541    if(! chamberSegmentPair.second->hasPhi()) return 999999;
00542    return chamberSegmentPair.second->dXdZErr;
00543 }
00544 
00545 float Muon::segmentDyDzErr( int station, int muonSubdetId, ArbitrationType type ) const
00546 {
00547    if(station==4 && muonSubdetId==MuonSubdetId::DT) return 999999; // no y information
00548    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(chambers(station,muonSubdetId),type);
00549    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) return 999999;
00550    if(! chamberSegmentPair.second->hasZed()) return 999999;
00551    return chamberSegmentPair.second->dYdZErr;
00552 }
00553 
00554 float Muon::trackEdgeX( int station, int muonSubdetId, ArbitrationType type ) const
00555 {
00556    const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
00557    if(muonChambers.empty()) return 999999;
00558 
00559    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers,type);
00560    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) {
00561       float dist  = 999999;
00562       float supVar = 999999;
00563       for(std::vector<const MuonChamberMatch*>::const_iterator muonChamber = muonChambers.begin();
00564             muonChamber != muonChambers.end(); ++muonChamber) {
00565          float currDist = (*muonChamber)->dist();
00566          if(currDist<dist) {
00567             dist  = currDist;
00568             supVar = (*muonChamber)->edgeX;
00569          }
00570       }
00571       return supVar;
00572    } else return chamberSegmentPair.first->edgeX;
00573 }
00574 
00575 float Muon::trackEdgeY( int station, int muonSubdetId, ArbitrationType type ) const
00576 {
00577    const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
00578    if(muonChambers.empty()) return 999999;
00579 
00580    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers,type);
00581    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) {
00582       float dist  = 999999;
00583       float supVar = 999999;
00584       for(std::vector<const MuonChamberMatch*>::const_iterator muonChamber = muonChambers.begin();
00585             muonChamber != muonChambers.end(); ++muonChamber) {
00586          float currDist = (*muonChamber)->dist();
00587          if(currDist<dist) {
00588             dist  = currDist;
00589             supVar = (*muonChamber)->edgeY;
00590          }
00591       }
00592       return supVar;
00593    } else return chamberSegmentPair.first->edgeY;
00594 }
00595 
00596 float Muon::trackX( int station, int muonSubdetId, ArbitrationType type ) const
00597 {
00598    const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
00599    if(muonChambers.empty()) return 999999;
00600 
00601    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers,type);
00602    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) {
00603       float dist  = 999999;
00604       float supVar = 999999;
00605       for(std::vector<const MuonChamberMatch*>::const_iterator muonChamber = muonChambers.begin();
00606             muonChamber != muonChambers.end(); ++muonChamber) {
00607          float currDist = (*muonChamber)->dist();
00608          if(currDist<dist) {
00609             dist  = currDist;
00610             supVar = (*muonChamber)->x;
00611          }
00612       }
00613       return supVar;
00614    } else return chamberSegmentPair.first->x;
00615 }
00616 
00617 float Muon::trackY( int station, int muonSubdetId, ArbitrationType type ) const
00618 {
00619    const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
00620    if(muonChambers.empty()) return 999999;
00621 
00622    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers,type);
00623    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) {
00624       float dist  = 999999;
00625       float supVar = 999999;
00626       for(std::vector<const MuonChamberMatch*>::const_iterator muonChamber = muonChambers.begin();
00627             muonChamber != muonChambers.end(); ++muonChamber) {
00628          float currDist = (*muonChamber)->dist();
00629          if(currDist<dist) {
00630             dist  = currDist;
00631             supVar = (*muonChamber)->y;
00632          }
00633       }
00634       return supVar;
00635    } else return chamberSegmentPair.first->y;
00636 }
00637 
00638 float Muon::trackDxDz( int station, int muonSubdetId, ArbitrationType type ) const
00639 {
00640    const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
00641    if(muonChambers.empty()) return 999999;
00642 
00643    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers,type);
00644    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) {
00645       float dist  = 999999;
00646       float supVar = 999999;
00647       for(std::vector<const MuonChamberMatch*>::const_iterator muonChamber = muonChambers.begin();
00648             muonChamber != muonChambers.end(); ++muonChamber) {
00649          float currDist = (*muonChamber)->dist();
00650          if(currDist<dist) {
00651             dist  = currDist;
00652             supVar = (*muonChamber)->dXdZ;
00653          }
00654       }
00655       return supVar;
00656    } else return chamberSegmentPair.first->dXdZ;
00657 }
00658 
00659 float Muon::trackDyDz( int station, int muonSubdetId, ArbitrationType type ) const
00660 {
00661    const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
00662    if(muonChambers.empty()) return 999999;
00663 
00664    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers,type);
00665    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) {
00666       float dist  = 999999;
00667       float supVar = 999999;
00668       for(std::vector<const MuonChamberMatch*>::const_iterator muonChamber = muonChambers.begin();
00669             muonChamber != muonChambers.end(); ++muonChamber) {
00670          float currDist = (*muonChamber)->dist();
00671          if(currDist<dist) {
00672             dist  = currDist;
00673             supVar = (*muonChamber)->dYdZ;
00674          }
00675       }
00676       return supVar;
00677    } else return chamberSegmentPair.first->dYdZ;
00678 }
00679 
00680 float Muon::trackXErr( int station, int muonSubdetId, ArbitrationType type ) const
00681 {
00682    const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
00683    if(muonChambers.empty()) return 999999;
00684 
00685    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers,type);
00686    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) {
00687       float dist  = 999999;
00688       float supVar = 999999;
00689       for(std::vector<const MuonChamberMatch*>::const_iterator muonChamber = muonChambers.begin();
00690             muonChamber != muonChambers.end(); ++muonChamber) {
00691          float currDist = (*muonChamber)->dist();
00692          if(currDist<dist) {
00693             dist  = currDist;
00694             supVar = (*muonChamber)->xErr;
00695          }
00696       }
00697       return supVar;
00698    } else return chamberSegmentPair.first->xErr;
00699 }
00700 
00701 float Muon::trackYErr( int station, int muonSubdetId, ArbitrationType type ) const
00702 {
00703    const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
00704    if(muonChambers.empty()) return 999999;
00705 
00706    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers,type);
00707    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) {
00708       float dist  = 999999;
00709       float supVar = 999999;
00710       for(std::vector<const MuonChamberMatch*>::const_iterator muonChamber = muonChambers.begin();
00711             muonChamber != muonChambers.end(); ++muonChamber) {
00712          float currDist = (*muonChamber)->dist();
00713          if(currDist<dist) {
00714             dist  = currDist;
00715             supVar = (*muonChamber)->yErr;
00716          }
00717       }
00718       return supVar;
00719    } else return chamberSegmentPair.first->yErr;
00720 }
00721 
00722 float Muon::trackDxDzErr( int station, int muonSubdetId, ArbitrationType type ) const
00723 {
00724    const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
00725    if(muonChambers.empty()) return 999999;
00726 
00727    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers,type);
00728    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) {
00729       float dist  = 999999;
00730       float supVar = 999999;
00731       for(std::vector<const MuonChamberMatch*>::const_iterator muonChamber = muonChambers.begin();
00732             muonChamber != muonChambers.end(); ++muonChamber) {
00733          float currDist = (*muonChamber)->dist();
00734          if(currDist<dist) {
00735             dist  = currDist;
00736             supVar = (*muonChamber)->dXdZErr;
00737          }
00738       }
00739       return supVar;
00740    } else return chamberSegmentPair.first->dXdZErr;
00741 }
00742 
00743 float Muon::trackDyDzErr( int station, int muonSubdetId, ArbitrationType type ) const
00744 {
00745    const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
00746    if(muonChambers.empty()) return 999999;
00747 
00748    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers,type);
00749    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) {
00750       float dist  = 999999;
00751       float supVar = 999999;
00752       for(std::vector<const MuonChamberMatch*>::const_iterator muonChamber = muonChambers.begin();
00753             muonChamber != muonChambers.end(); ++muonChamber) {
00754          float currDist = (*muonChamber)->dist();
00755          if(currDist<dist) {
00756             dist  = currDist;
00757             supVar = (*muonChamber)->dYdZErr;
00758          }
00759       }
00760       return supVar;
00761    } else return chamberSegmentPair.first->dYdZErr;
00762 }
00763 
00764 float Muon::trackDist( int station, int muonSubdetId, ArbitrationType type ) const
00765 {
00766    const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
00767    if(muonChambers.empty()) return 999999;
00768 
00769    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers,type);
00770    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) {
00771       float dist  = 999999;
00772       for(std::vector<const MuonChamberMatch*>::const_iterator muonChamber = muonChambers.begin();
00773             muonChamber != muonChambers.end(); ++muonChamber) {
00774          float currDist = (*muonChamber)->dist();
00775          if(currDist<dist) dist  = currDist;
00776       }
00777       return dist;
00778    } else return chamberSegmentPair.first->dist();
00779 }
00780 
00781 float Muon::trackDistErr( int station, int muonSubdetId, ArbitrationType type ) const
00782 {
00783    const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
00784    if(muonChambers.empty()) return 999999;
00785 
00786    std::pair<const MuonChamberMatch*,const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers,type);
00787    if(chamberSegmentPair.first==0 || chamberSegmentPair.second==0) {
00788       float dist  = 999999;
00789       float supVar = 999999;
00790       for(std::vector<const MuonChamberMatch*>::const_iterator muonChamber = muonChambers.begin();
00791             muonChamber != muonChambers.end(); ++muonChamber) {
00792          float currDist = (*muonChamber)->dist();
00793          if(currDist<dist) {
00794             dist  = currDist;
00795             supVar = (*muonChamber)->distErr();
00796          }
00797       }
00798       return supVar;
00799    } else return chamberSegmentPair.first->distErr();
00800 }
00801 
00802 void Muon::setIsolation( const MuonIsolation& isoR03, const MuonIsolation& isoR05 )
00803 { 
00804    isolationR03_ = isoR03;
00805    isolationR05_ = isoR05;
00806    isolationValid_ = true; 
00807 }
00808 
00809 
00810 void Muon::setPFIsolation(const std::string& label, const MuonPFIsolation& deposit) 
00811 { 
00812   if(label=="pfIsolationR03")
00813     pfIsolationR03_ = deposit;
00814 
00815   if(label=="pfIsolationR04")
00816     pfIsolationR04_ = deposit;
00817 
00818   if(label=="pfIsoMeanDRProfileR03")
00819     pfIsoMeanDRR03_ = deposit;
00820 
00821   if(label=="pfIsoMeanDRProfileR04")
00822     pfIsoMeanDRR04_ = deposit;
00823 
00824   if(label=="pfIsoSumDRProfileR03")
00825     pfIsoSumDRR03_ = deposit;
00826 
00827   if(label=="pfIsoSumDRProfileR04")
00828     pfIsoSumDRR04_ = deposit;
00829 
00830    pfIsolationValid_ = true; 
00831 }
00832 
00833 
00834 void Muon::setPFP4( const reco::Candidate::LorentzVector& p4 )
00835 { 
00836     pfP4_ = p4;
00837     type_ = type_ | PFMuon;
00838 }
00839 
00840 
00841 
00842 void Muon::setOuterTrack( const TrackRef & t ) { outerTrack_ = t; }
00843 void Muon::setInnerTrack( const TrackRef & t ) { innerTrack_ = t; }
00844 void Muon::setTrack( const TrackRef & t ) { setInnerTrack(t); }
00845 void Muon::setStandAlone( const TrackRef & t ) { setOuterTrack(t); }
00846 void Muon::setGlobalTrack( const TrackRef & t ) { globalTrack_ = t; }
00847 void Muon::setCombined( const TrackRef & t ) { setGlobalTrack(t); }
00848 
00849 
00850 bool Muon::isAValidMuonTrack(const MuonTrackType& type) const{
00851   return muonTrack(type).isNonnull();
00852 }
00853 
00854 TrackRef Muon::muonTrack(const MuonTrackType& type) const{
00855   switch (type) {
00856   case InnerTrack:     return innerTrack();
00857   case OuterTrack:     return standAloneMuon(); 
00858   case CombinedTrack:  return globalTrack();
00859   case TPFMS:          return tpfmsTrack();
00860   case Picky:          return pickyTrack();
00861   case DYT:            return dytTrack();
00862   default:             return muonTrackFromMap(type);
00863   }
00864 }
00865 
00866 void Muon::setMuonTrack(const MuonTrackType& type, const TrackRef& t) {
00867   
00868   switch (type) {
00869   case InnerTrack:    setInnerTrack(t);             break;
00870   case OuterTrack:    setStandAlone(t);             break;
00871   case CombinedTrack: setGlobalTrack(t);            break;
00872   default:            refittedTrackMap_[type] = t;  break;
00873   }
00874 
00875 }
00876