00001
00014 #include "RecoMuon/MuonSeedGenerator/src/MuonSeedOrcaPatternRecognition.h"
00015
00016 #include "DataFormats/CSCRecHit/interface/CSCRecHit2DCollection.h"
00017 #include "DataFormats/CSCRecHit/interface/CSCRecHit2D.h"
00018 #include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h"
00019 #include "DataFormats/DTRecHit/interface/DTRecSegment4D.h"
00020
00021 #include "DataFormats/Common/interface/Handle.h"
00022
00023 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHit.h"
00024
00025
00026 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00027 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00028
00029 #include "RecoMuon/MeasurementDet/interface/MuonDetLayerMeasurements.h"
00030 #include "RecoMuon/DetLayers/interface/MuonDetLayerGeometry.h"
00031 #include "RecoMuon/Records/interface/MuonRecoGeometryRecord.h"
00032
00033
00034 #include "FWCore/Framework/interface/EventSetup.h"
00035 #include "FWCore/Framework/interface/Event.h"
00036 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00037 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00038 #include "FWCore/Framework/interface/ESHandle.h"
00039
00040
00041 #include <vector>
00042
00043 using namespace std;
00044
00045
00046
00047 MuonSeedOrcaPatternRecognition::MuonSeedOrcaPatternRecognition(const edm::ParameterSet& pset)
00048 : MuonSeedVPatternRecognition(pset),
00049 theCrackEtas(pset.getParameter<std::vector<double> >("crackEtas")),
00050 theCrackWindow(pset.getParameter<double>("crackWindow"))
00051 {
00052 }
00053
00054
00055
00056 void MuonSeedOrcaPatternRecognition::produce(edm::Event& event, const edm::EventSetup& eSetup,
00057 std::vector<MuonRecHitContainer> & result)
00058 {
00059
00060
00061
00062
00063 edm::ESHandle<MuonDetLayerGeometry> muonLayers;
00064 eSetup.get<MuonRecoGeometryRecord>().get(muonLayers);
00065
00066
00067 vector<DetLayer*> dtLayers = muonLayers->allDTLayers();
00068
00069
00070 vector<DetLayer*> cscForwardLayers = muonLayers->forwardCSCLayers();
00071 vector<DetLayer*> cscBackwardLayers = muonLayers->backwardCSCLayers();
00072
00073
00074 const DetLayer* ME4Bwd = cscBackwardLayers[4];
00075 const DetLayer* ME3Bwd = cscBackwardLayers[3];
00076 const DetLayer* ME2Bwd = cscBackwardLayers[2];
00077 const DetLayer* ME12Bwd = cscBackwardLayers[1];
00078 const DetLayer* ME11Bwd = cscBackwardLayers[0];
00079
00080
00081 const DetLayer* ME11Fwd = cscForwardLayers[0];
00082 const DetLayer* ME12Fwd = cscForwardLayers[1];
00083 const DetLayer* ME2Fwd = cscForwardLayers[2];
00084 const DetLayer* ME3Fwd = cscForwardLayers[3];
00085 const DetLayer* ME4Fwd = cscForwardLayers[4];
00086
00087
00088 const DetLayer* MB4DL = dtLayers[3];
00089 const DetLayer* MB3DL = dtLayers[2];
00090 const DetLayer* MB2DL = dtLayers[1];
00091 const DetLayer* MB1DL = dtLayers[0];
00092
00093
00094
00095 MuonDetLayerMeasurements muonMeasurements(theDTRecSegmentLabel.label(),theCSCRecSegmentLabel,edm::InputTag(),
00096 enableDTMeasurement,enableCSCMeasurement,false);
00097
00098 MuonRecHitContainer list9 = muonMeasurements.recHits(MB4DL,event);
00099 MuonRecHitContainer list6 = muonMeasurements.recHits(MB3DL,event);
00100 MuonRecHitContainer list7 = muonMeasurements.recHits(MB2DL,event);
00101 MuonRecHitContainer list8 = muonMeasurements.recHits(MB1DL,event);
00102
00103 bool* MB1 = zero(list8.size());
00104 bool* MB2 = zero(list7.size());
00105 bool* MB3 = zero(list6.size());
00106
00107
00108 endcapPatterns(muonMeasurements.recHits(ME11Bwd,event),
00109 muonMeasurements.recHits(ME12Bwd,event),
00110 muonMeasurements.recHits(ME2Bwd,event),
00111 muonMeasurements.recHits(ME3Bwd,event),
00112 muonMeasurements.recHits(ME4Bwd,event),
00113 list8, list7, list6,
00114 MB1, MB2, MB3, result);
00115
00116 endcapPatterns(muonMeasurements.recHits(ME11Fwd,event),
00117 muonMeasurements.recHits(ME12Fwd,event),
00118 muonMeasurements.recHits(ME2Fwd,event),
00119 muonMeasurements.recHits(ME3Fwd,event),
00120 muonMeasurements.recHits(ME4Fwd,event),
00121 list8, list7, list6,
00122 MB1, MB2, MB3, result);
00123
00124
00125
00126
00127 unsigned int counter = 0;
00128 if ( list9.size() < 100 ) {
00129 for (MuonRecHitContainer::iterator iter=list9.begin(); iter!=list9.end(); iter++ ){
00130 MuonRecHitContainer seedSegments;
00131 seedSegments.push_back(*iter);
00132 complete(seedSegments, list6, MB3);
00133 complete(seedSegments, list7, MB2);
00134 complete(seedSegments, list8, MB1);
00135 if(check(seedSegments)) result.push_back(seedSegments);
00136 }
00137 }
00138
00139
00140 if ( list6.size() < 100 ) {
00141 for ( counter = 0; counter<list6.size(); counter++ ){
00142 if ( !MB3[counter] ) {
00143 MuonRecHitContainer seedSegments;
00144 seedSegments.push_back(list6[counter]);
00145 complete(seedSegments, list7, MB2);
00146 complete(seedSegments, list8, MB1);
00147 complete(seedSegments, list9);
00148 if(check(seedSegments)) result.push_back(seedSegments);
00149 }
00150 }
00151 }
00152
00153
00154 if ( list7.size() < 100 ) {
00155 for ( counter = 0; counter<list7.size(); counter++ ){
00156 if ( !MB2[counter] ) {
00157 MuonRecHitContainer seedSegments;
00158 seedSegments.push_back(list7[counter]);
00159 complete(seedSegments, list8, MB1);
00160 complete(seedSegments, list9);
00161 complete(seedSegments, list6, MB3);
00162 if (seedSegments.size()>1 ||
00163 (seedSegments.size()==1 && seedSegments[0]->dimension()==4) )
00164 {
00165 result.push_back(seedSegments);
00166 }
00167 }
00168 }
00169 }
00170
00171
00172 if ( list8.size() < 100 ) {
00173 for ( counter = 0; counter<list8.size(); counter++ ){
00174 if ( !MB1[counter] ) {
00175 MuonRecHitContainer seedSegments;
00176 seedSegments.push_back(list8[counter]);
00177 complete(seedSegments, list9);
00178 complete(seedSegments, list6, MB3);
00179 complete(seedSegments, list7, MB2);
00180 if (seedSegments.size()>1 ||
00181 (seedSegments.size()==1 && seedSegments[0]->dimension()==4) )
00182 {
00183 result.push_back(seedSegments);
00184 }
00185 }
00186 }
00187 }
00188
00189 if ( MB3 ) delete [] MB3;
00190 if ( MB2 ) delete [] MB2;
00191 if ( MB1 ) delete [] MB1;
00192
00193
00194 if(result.empty())
00195 {
00196 const std::string metname = "Muon|RecoMuon|MuonSeedOrcaPatternRecognition";
00197 MuonRecHitContainer all = muonMeasurements.recHits(ME4Bwd,event);
00198 LogTrace(metname)<<"ME4B "<<all.size();
00199 MuonRecHitContainer tmp = muonMeasurements.recHits(ME3Bwd,event);
00200 copy(tmp.begin(),tmp.end(),back_inserter(all));
00201 LogTrace(metname)<<"ME3B "<<tmp.size();
00202
00203 tmp = muonMeasurements.recHits(ME2Bwd,event);
00204 copy(tmp.begin(),tmp.end(),back_inserter(all));
00205 LogTrace(metname)<<"ME2B "<<tmp.size();
00206
00207 tmp = muonMeasurements.recHits(ME12Bwd,event);
00208 copy(tmp.begin(),tmp.end(),back_inserter(all));
00209 LogTrace(metname)<<"ME12B "<<tmp.size();
00210
00211 tmp = muonMeasurements.recHits(ME11Bwd,event);
00212 copy(tmp.begin(),tmp.end(),back_inserter(all));
00213 LogTrace(metname)<<"ME11B "<<tmp.size();
00214
00215 tmp = muonMeasurements.recHits(ME11Fwd,event);
00216 copy(tmp.begin(),tmp.end(),back_inserter(all));
00217 LogTrace(metname)<<"ME11F "<<tmp.size();
00218
00219 tmp = muonMeasurements.recHits(ME12Fwd,event);
00220 copy(tmp.begin(),tmp.end(),back_inserter(all));
00221 LogTrace(metname)<<"ME12F "<<tmp.size();
00222
00223 tmp = muonMeasurements.recHits(ME2Fwd,event);
00224 copy(tmp.begin(),tmp.end(),back_inserter(all));
00225 LogTrace(metname)<<"ME2F "<<tmp.size();
00226
00227 tmp = muonMeasurements.recHits(ME3Fwd,event);
00228 copy(tmp.begin(),tmp.end(),back_inserter(all));
00229 LogTrace(metname)<<"ME3F "<<tmp.size();
00230
00231 tmp = muonMeasurements.recHits(ME4Fwd,event);
00232 copy(tmp.begin(),tmp.end(),back_inserter(all));
00233 LogTrace(metname)<<"ME4F "<<tmp.size();
00234
00235 tmp = muonMeasurements.recHits(MB4DL,event);
00236 copy(tmp.begin(),tmp.end(),back_inserter(all));
00237 LogTrace(metname)<<"MB4 "<<tmp.size();
00238
00239 tmp = muonMeasurements.recHits(MB3DL,event);
00240 copy(tmp.begin(),tmp.end(),back_inserter(all));
00241 LogTrace(metname)<<"MB3 "<<tmp.size();
00242
00243 tmp = muonMeasurements.recHits(MB2DL,event);
00244 copy(tmp.begin(),tmp.end(),back_inserter(all));
00245 LogTrace(metname)<<"MB2 "<<tmp.size();
00246
00247 tmp = muonMeasurements.recHits(MB1DL,event);
00248 copy(tmp.begin(),tmp.end(),back_inserter(all));
00249 LogTrace(metname)<<"MB1 "<<tmp.size();
00250
00251 LogTrace(metname)<<"Number of segments: "<<all.size();
00252
00253 for(MuonRecHitContainer::const_iterator segmentItr = all.begin();
00254 segmentItr != all.end(); ++segmentItr)
00255 {
00256 MuonRecHitContainer singleSegmentContainer;
00257 singleSegmentContainer.push_back(*segmentItr);
00258 result.push_back(singleSegmentContainer);
00259 }
00260 }
00261
00262 }
00263
00264
00265 bool * MuonSeedOrcaPatternRecognition::zero(unsigned listSize)
00266 {
00267 bool * result = 0;
00268 if (listSize) {
00269 result = new bool[listSize];
00270 for ( size_t i=0; i<listSize; i++ ) result[i]=false;
00271 }
00272 return result;
00273 }
00274
00275
00276 void MuonSeedOrcaPatternRecognition::endcapPatterns(
00277 const MuonRecHitContainer & me11, const MuonRecHitContainer & me12,
00278 const MuonRecHitContainer & me2, const MuonRecHitContainer & me3,
00279 const MuonRecHitContainer & me4, const MuonRecHitContainer & mb1,
00280 const MuonRecHitContainer & mb2, const MuonRecHitContainer & mb3,
00281 bool * MB1, bool * MB2, bool * MB3,
00282 std::vector<MuonRecHitContainer> & result)
00283 {
00284 std::vector<MuonRecHitContainer> patterns;
00285 MuonRecHitContainer crackSegments;
00286 rememberCrackSegments(me11, crackSegments);
00287 rememberCrackSegments(me12, crackSegments);
00288 rememberCrackSegments(me2, crackSegments);
00289 rememberCrackSegments(me3, crackSegments);
00290 rememberCrackSegments(me4, crackSegments);
00291
00292
00293 MuonRecHitContainer list24 = me4;
00294 MuonRecHitContainer list23 = me3;
00295
00296 MuonRecHitContainer list12 = me2;
00297
00298 MuonRecHitContainer list22 = me12;
00299 MuonRecHitContainer list21 = me11;
00300
00301 MuonRecHitContainer list11 = list21;
00302 MuonRecHitContainer list5 = list22;
00303 MuonRecHitContainer list13 = list23;
00304 MuonRecHitContainer list4 = list24;
00305
00306 if ( list21.size() == 0 ) {
00307 list11 = list22; list5 = list21;
00308 }
00309
00310 if ( list24.size() < list23.size() && list24.size() > 0 ) {
00311 list13 = list24; list4 = list23;
00312 }
00313
00314 if ( list23.size() == 0 ) {
00315 list13 = list24; list4 = list23;
00316 }
00317
00318 MuonRecHitContainer list1 = list11;
00319 MuonRecHitContainer list2 = list12;
00320 MuonRecHitContainer list3 = list13;
00321
00322
00323 if ( list12.size() == 0 ) {
00324 list3 = list12;
00325 if ( list11.size() <= list13.size() && list11.size() > 0 ) {
00326 list1 = list11; list2 = list13;}
00327 else { list1 = list13; list2 = list11;}
00328 }
00329
00330 if ( list13.size() == 0 ) {
00331 if ( list11.size() <= list12.size() && list11.size() > 0 ) {
00332 list1 = list11; list2 = list12;}
00333 else { list1 = list12; list2 = list11;}
00334 }
00335
00336 if ( list12.size() != 0 && list13.size() != 0 ) {
00337 if ( list11.size()<=list12.size() && list11.size()<=list13.size() && list11.size()>0 ) {
00338 if ( list12.size() > list13.size() ) {
00339 list2 = list13; list3 = list12;}
00340 }
00341 else if ( list12.size() <= list13.size() ) {
00342 list1 = list12;
00343 if ( list11.size() <= list13.size() && list11.size() > 0 ) {
00344 list2 = list11; list3 = list13;}
00345 else { list2 = list13; list3 = list11;}
00346 }
00347 else {
00348 list1 = list13;
00349 if ( list11.size() <= list12.size() && list11.size() > 0 ) {
00350 list2 = list11; list3 = list12;}
00351 else { list2 = list12; list3 = list11;}
00352 }
00353 }
00354
00355
00356 bool* ME2 = zero(list2.size());
00357 bool* ME3 = zero(list3.size());
00358 bool* ME4 = zero(list4.size());
00359 bool* ME5 = zero(list5.size());
00360
00361
00362
00363
00364 for (MuonRecHitContainer::iterator iter = list1.begin(); iter!=list1.end(); iter++ ){
00365 if ( (*iter)->recHits().size() < 4 && list3.size() > 0 ) continue;
00366 MuonRecHitContainer seedSegments;
00367 seedSegments.push_back(*iter);
00368 complete(seedSegments, list2, ME2);
00369 complete(seedSegments, list3, ME3);
00370 complete(seedSegments, list4, ME4);
00371 complete(seedSegments, list5, ME5);
00372 complete(seedSegments, mb3, MB3);
00373 complete(seedSegments, mb2, MB2);
00374 complete(seedSegments, mb1, MB1);
00375 if(check(seedSegments)) patterns.push_back(seedSegments);
00376 }
00377
00378
00379 unsigned int counter;
00380
00381 for ( counter = 0; counter<list2.size(); counter++ ){
00382
00383 if ( !ME2[counter] ) {
00384 MuonRecHitContainer seedSegments;
00385 seedSegments.push_back(list2[counter]);
00386 complete(seedSegments, list3, ME3);
00387 complete(seedSegments, list4, ME4);
00388 complete(seedSegments, list5, ME5);
00389 complete(seedSegments, mb3, MB3);
00390 complete(seedSegments, mb2, MB2);
00391 complete(seedSegments, mb1, MB1);
00392 if(check(seedSegments)) patterns.push_back(seedSegments);
00393 }
00394 }
00395
00396
00397 if ( list3.size() < 20 ) {
00398 for ( counter = 0; counter<list3.size(); counter++ ){
00399 if ( !ME3[counter] ) {
00400 MuonRecHitContainer seedSegments;
00401 seedSegments.push_back(list3[counter]);
00402 complete(seedSegments, list4, ME4);
00403 complete(seedSegments, list5, ME5);
00404 complete(seedSegments, mb3, MB3);
00405 complete(seedSegments, mb2, MB2);
00406 complete(seedSegments, mb1, MB1);
00407 if(check(seedSegments)) patterns.push_back(seedSegments);
00408 }
00409 }
00410 }
00411
00412 if ( list4.size() < 20 ) {
00413 for ( counter = 0; counter<list4.size(); counter++ ){
00414 if ( !ME4[counter] ) {
00415 MuonRecHitContainer seedSegments;
00416 seedSegments.push_back(list4[counter]);
00417 complete(seedSegments, list5, ME5);
00418 complete(seedSegments, mb3, MB3);
00419 complete(seedSegments, mb2, MB2);
00420 complete(seedSegments, mb1, MB1);
00421 if(check(seedSegments)) patterns.push_back(seedSegments);
00422 }
00423 }
00424 }
00425
00426 if ( ME5 ) delete [] ME5;
00427 if ( ME4 ) delete [] ME4;
00428 if ( ME3 ) delete [] ME3;
00429 if ( ME2 ) delete [] ME2;
00430
00431 if(!patterns.empty())
00432 {
00433 result.insert(result.end(), patterns.begin(), patterns.end());
00434 }
00435 else
00436 {
00437 if(!crackSegments.empty())
00438 {
00439
00440 for(MuonRecHitContainer::const_iterator crackSegmentItr = crackSegments.begin();
00441 crackSegmentItr != crackSegments.end(); ++crackSegmentItr)
00442 {
00443 MuonRecHitContainer singleSegmentPattern;
00444 singleSegmentPattern.push_back(*crackSegmentItr);
00445 result.push_back(singleSegmentPattern);
00446 }
00447 }
00448 }
00449 }
00450
00451
00452
00453 void MuonSeedOrcaPatternRecognition::complete(MuonRecHitContainer& seedSegments,
00454 const MuonRecHitContainer &recHits, bool* used) const {
00455
00456 MuonRecHitContainer good_rhit;
00457
00458
00459
00460 ConstMuonRecHitPointer first = seedSegments[0];
00461
00462 GlobalPoint ptg2 = first->globalPosition();
00463
00464 int nr=0;
00465
00466 for (MuonRecHitContainer::const_iterator iter=recHits.begin(); iter!=recHits.end(); iter++){
00467
00468 GlobalPoint ptg1 = (*iter)->globalPosition();
00469 float deta = fabs (ptg1.eta()-ptg2.eta());
00470
00471 float dphi = fabs (ptg1.phi()-ptg2.phi());
00472 float eta2 = fabs( ptg2.eta() );
00473
00474
00475 if ( deta > .2 || dphi > .1 ) {
00476 nr++;
00477 continue;
00478 }
00479
00480 if( eta2 < 1.0 ) {
00481
00482 LocalPoint pt1 = first->det()->toLocal(ptg1);
00483
00484 LocalVector dir1 = first->localDirection();
00485
00486 LocalPoint pt2 = first->localPosition();
00487
00488 float m = dir1.z()/dir1.x();
00489 float yf = pt1.z();
00490 float yi = pt2.z();
00491 float xi = pt2.x();
00492 float xf = (yf-yi)/m + xi;
00493 float dist = fabs ( xf - pt1.x() );
00494
00495 float d_cut = sqrt((yf-yi)*(yf-yi)+(pt1.x()-pt2.x())*(pt1.x()-pt2.x()))/10.;
00496
00497
00498
00499
00500 if ( dist < d_cut ) {
00501 good_rhit.push_back(*iter);
00502 if (used) used[nr]=true;
00503 }
00504
00505 }
00506
00507 else {
00508
00509
00510 float dphicut = (eta2 > 1.6 && eta2 < 2.0) ? 0.1 : 0.07;
00511
00512 float detacut = (first->isDT() || (*iter)->isDT()) ? 0.2 : 0.1;
00513
00514 if ( deta < detacut && dphi < dphicut ) {
00515 good_rhit.push_back(*iter);
00516 if (used) used[nr]=true;
00517 }
00518
00519 }
00520
00521
00522 nr++;
00523
00524 }
00525
00526
00527
00528 MuonRecHitPointer best=0;
00529
00530 float best_dphiG = M_PI;
00531 float best_dphiD = M_PI;
00532
00533 if( fabs ( ptg2.eta() ) > 1.0 ) {
00534
00535
00536
00537 GlobalVector dir2 = first->globalDirection();
00538
00539 GlobalPoint pos2 = first->globalPosition();
00540
00541 for (MuonRecHitContainer::iterator iter=good_rhit.begin(); iter!=good_rhit.end(); iter++){
00542
00543 GlobalPoint pos1 = (*iter)->globalPosition();
00544
00545 float dphi = pos1.phi()-pos2.phi();
00546
00547 if (dphi < 0.) dphi = -dphi;
00548 if (dphi > M_PI) dphi = 2.*M_PI - dphi;
00549
00550 if ( dphi < best_dphiG*1.5 ) {
00551
00552
00553 if ( dphi < best_dphiG*.67 && best_dphiG > .005 ) best_dphiD = M_PI;
00554
00555 GlobalVector dir1 = (*iter)->globalDirection();
00556
00557 float dphidir = fabs ( dir1.phi()-dir2.phi() );
00558
00559 if (dphidir > M_PI) dphidir = 2.*M_PI - dphidir;
00560 if (dphidir > M_PI*.5) dphidir = M_PI - dphidir;
00561 if ( dphidir < best_dphiD ) {
00562
00563 best_dphiG = dphi;
00564 if ( dphi < .002 ) best_dphiG = .002;
00565 best_dphiD = dphidir;
00566 best = (*iter);
00567
00568 }
00569
00570 }
00571
00572
00573 }
00574
00575 }
00576
00577 if( fabs ( ptg2.eta() ) < 1.0 ) {
00578
00579
00580
00581 float best_dphi = M_PI;
00582
00583 for (MuonRecHitContainer::iterator iter=good_rhit.begin(); iter!=good_rhit.end(); iter++){
00584 GlobalVector dir1 = (*iter)->globalDirection();
00585
00586
00587
00588
00589
00590 GlobalVector dir2 = first->globalDirection();
00591
00592 float dphi = dir1.phi()-dir2.phi();
00593
00594 if (dphi < 0.) dphi = -dphi;
00595 if (dphi > M_PI) dphi = 2.*M_PI - dphi;
00596
00597 if ( dphi < best_dphi ) {
00598
00599 best_dphi = dphi;
00600 best = (*iter);
00601 }
00602
00603 }
00604
00605 }
00606
00607
00608
00609 if(best)
00610 if ( best->isValid() ) seedSegments.push_back(best);
00611
00612 }
00613
00614
00615
00616 bool MuonSeedOrcaPatternRecognition::check(const MuonRecHitContainer & segments)
00617 {
00618 return (segments.size() > 1);
00619 }
00620
00621
00622 void MuonSeedOrcaPatternRecognition::rememberCrackSegments(const MuonRecHitContainer & segments,
00623 MuonRecHitContainer & crackSegments) const
00624 {
00625 for(MuonRecHitContainer::const_iterator segmentItr = segments.begin();
00626 segmentItr != segments.end(); ++segmentItr)
00627 {
00628 if((**segmentItr).hit()->dimension() == 4)
00629 {
00630 double absEta = fabs((**segmentItr).globalPosition().eta());
00631
00632 for(std::vector<double>::const_iterator crackItr = theCrackEtas.begin();
00633 crackItr != theCrackEtas.end(); ++crackItr)
00634 {
00635 if(fabs(absEta-*crackItr) < theCrackWindow) {
00636 crackSegments.push_back(*segmentItr);
00637 }
00638 }
00639 }
00640 }
00641 }