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