Go to the documentation of this file.00001
00005 #include "RecoMuon/MuonSeedGenerator/src/SETPatternRecognition.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00011 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00012 #include "DataFormats/DTRecHit/interface/DTRecSegment4D.h"
00013 #include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h"
00014 #include "DataFormats/CSCRecHit/interface/CSCSegmentCollection.h"
00015 #include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
00016 #include "TMath.h"
00017
00018
00019 using namespace edm;
00020 using namespace std;
00021
00022 SETPatternRecognition::SETPatternRecognition(const ParameterSet& parameterSet)
00023 : MuonSeedVPatternRecognition(parameterSet.getParameter<ParameterSet>("SETTrajBuilderParameters").getParameter<ParameterSet>("FilterParameters"))
00024 {
00025 const string metname = "Muon|RecoMuon|SETPatternRecognition";
00026
00027 ParameterSet trajectoryBuilderParameters = parameterSet.getParameter<ParameterSet>("SETTrajBuilderParameters");
00028
00029 ParameterSet filterPSet = trajectoryBuilderParameters.getParameter<ParameterSet>("FilterParameters");
00030 maxActiveChambers = filterPSet.getParameter<int>("maxActiveChambers");
00031 useRPCs = filterPSet.getParameter<bool>("EnableRPCMeasurement");
00032 DTRecSegmentLabel = filterPSet.getParameter<edm::InputTag>("DTRecSegmentLabel");
00033 CSCRecSegmentLabel = filterPSet.getParameter<edm::InputTag>("CSCRecSegmentLabel");
00034 RPCRecSegmentLabel = filterPSet.getParameter<edm::InputTag>("RPCRecSegmentLabel");
00035
00036 outsideChamberErrorScale = filterPSet.getParameter<double>("OutsideChamberErrorScale");
00037 minLocalSegmentAngle = filterPSet.getParameter<double>("MinLocalSegmentAngle");
00038
00039
00040 }
00041
00042
00043 void SETPatternRecognition::produce(const edm::Event& event, const edm::EventSetup& eventSetup,
00044 std::vector<MuonRecHitContainer> & segments_clusters)
00045 {
00046 const string metname = "Muon|RecoMuon|SETMuonSeedSeed";
00047
00048
00049 MuonRecHitContainer muonRecHits;
00050 MuonRecHitContainer muonRecHits_DT2D_hasPhi;
00051 MuonRecHitContainer muonRecHits_DT2D_hasZed;
00052 MuonRecHitContainer muonRecHits_RPC;
00053
00054
00055
00056
00057
00058 edm::Handle<DTRecSegment4DCollection> dtRecHits;
00059 event.getByLabel(DTRecSegmentLabel, dtRecHits);
00060 std::vector<DTChamberId> chambers_DT;
00061 std::vector<DTChamberId>::const_iterator chIt_DT;
00062 for (DTRecSegment4DCollection::const_iterator rechit = dtRecHits->begin(); rechit!=dtRecHits->end();++rechit) {
00063 bool insert = true;
00064 for(chIt_DT=chambers_DT.begin(); chIt_DT != chambers_DT.end(); ++chIt_DT){
00065 if (((*rechit).chamberId().wheel() == (*chIt_DT).wheel()) &&
00066 ((*rechit).chamberId().station() == (*chIt_DT).station()) &&
00067 ((*rechit).chamberId().sector() == (*chIt_DT).sector())){
00068 insert = false;
00069 }
00070 }
00071 if (insert){
00072 chambers_DT.push_back((*rechit).chamberId());
00073 }
00074 if(segmentCleaning((*rechit).geographicalId(),
00075 rechit->localPosition(), rechit->localPositionError(),
00076 rechit->localDirection(), rechit->localDirectionError(),
00077 rechit->chi2(), rechit->degreesOfFreedom())){
00078 continue;
00079 }
00080 if( (rechit->hasZed() && rechit->hasPhi()) ) {
00081 muonRecHits.push_back(MuonTransientTrackingRecHit::specificBuild(theService->trackingGeometry()->idToDet((*rechit).geographicalId()),&*rechit));
00082 }
00083 else if(rechit->hasZed()) {
00084 muonRecHits_DT2D_hasZed.push_back(MuonTransientTrackingRecHit::specificBuild(theService->trackingGeometry()->idToDet((*rechit).geographicalId()),&*rechit));
00085 }
00086 else if(rechit->hasPhi()) {
00087 muonRecHits_DT2D_hasPhi.push_back(MuonTransientTrackingRecHit::specificBuild(theService->trackingGeometry()->idToDet((*rechit).geographicalId()),&*rechit));
00088 }
00089 else {
00090
00091 }
00092 }
00093
00094
00095
00096
00097
00098
00099 edm::Handle<CSCSegmentCollection> cscSegments;
00100 event.getByLabel(CSCRecSegmentLabel, cscSegments);
00101 std::vector<CSCDetId> chambers_CSC;
00102 std::vector<CSCDetId>::const_iterator chIt_CSC;
00103 for(CSCSegmentCollection::const_iterator rechit=cscSegments->begin(); rechit != cscSegments->end(); ++rechit) {
00104 bool insert = true;
00105 for(chIt_CSC=chambers_CSC.begin(); chIt_CSC != chambers_CSC.end(); ++chIt_CSC){
00106 if (((*rechit).cscDetId().chamber() == (*chIt_CSC).chamber()) &&
00107 ((*rechit).cscDetId().station() == (*chIt_CSC).station()) &&
00108 ((*rechit).cscDetId().ring() == (*chIt_CSC).ring()) &&
00109 ((*rechit).cscDetId().endcap() == (*chIt_CSC).endcap())){
00110 insert = false;
00111 }
00112 }
00113 if (insert){
00114 chambers_CSC.push_back((*rechit).cscDetId().chamberId());
00115 }
00116 if(segmentCleaning((*rechit).geographicalId(),
00117 rechit->localPosition(), rechit->localPositionError(),
00118 rechit->localDirection(), rechit->localDirectionError(),
00119 rechit->chi2(), rechit->degreesOfFreedom())){
00120 continue;
00121 }
00122 muonRecHits.push_back(MuonTransientTrackingRecHit::specificBuild(theService->trackingGeometry()->idToDet((*rechit).geographicalId()),&*rechit));
00123 }
00124
00125
00126
00127
00128
00129
00130 edm::Handle<RPCRecHitCollection> rpcRecHits;
00131 event.getByLabel(RPCRecSegmentLabel, rpcRecHits);
00132 if(useRPCs){
00133 for(RPCRecHitCollection::const_iterator rechit=rpcRecHits->begin(); rechit != rpcRecHits->end(); ++rechit) {
00134
00135 const LocalVector localDirection(0.,0.,1.);
00136 const LocalError localDirectionError (0.,0.,0.);
00137 const double chi2 = 1.;
00138 const int ndf = 1;
00139 if(segmentCleaning((*rechit).geographicalId(),
00140 rechit->localPosition(), rechit->localPositionError(),
00141 localDirection, localDirectionError,
00142 chi2, ndf)){
00143 continue;
00144 }
00145 muonRecHits_RPC.push_back(MuonTransientTrackingRecHit::specificBuild(theService->trackingGeometry()->idToDet((*rechit).geographicalId()),&*rechit));
00146 }
00147 }
00148
00149
00150 if(int(chambers_DT.size() + chambers_CSC.size()) > maxActiveChambers){
00151
00152
00153 edm::LogWarning("tooManyActiveChambers")<<" Too many active chambers : nDT = "<<chambers_DT.size()
00154 <<" nCSC = "<<chambers_CSC.size()<<" Skip them all.";
00155 muonRecHits.clear();
00156 muonRecHits_DT2D_hasPhi.clear();
00157 muonRecHits_DT2D_hasZed.clear();
00158 muonRecHits_RPC.clear();
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 bool useDT2D_hasPhi = true;
00170 bool useDT2D_hasZed = true;
00171 double dXclusBoxMax = 0.60;
00172 double dYclusBoxMax = 0.;
00173
00174
00175
00176
00177
00178
00179
00180 dYclusBoxMax = 0.02;
00181
00182
00183
00184 float dXclus = 0.0;
00185 float dXclus_box = 0.0;
00186 float dYclus_box = 0.0;
00187
00188 MuonRecHitContainer temp;
00189
00190 std::vector< MuonRecHitContainer > seeds;
00191
00192 std::vector<float> running_meanX;
00193 std::vector<float> running_meanY;
00194
00195 std::vector<float> seed_minX;
00196 std::vector<float> seed_maxX;
00197 std::vector<float> seed_minY;
00198 std::vector<float> seed_maxY;
00199
00200
00201
00202
00203 for (MuonRecHitContainer::const_iterator it = muonRecHits.begin(); it != muonRecHits.end(); ++it ) {
00204
00205
00206
00207
00208
00209
00210
00211 temp.clear();
00212
00213 temp.push_back((*it));
00214
00215 seeds.push_back(temp);
00216
00217
00218
00219
00220 running_meanX.push_back( (*it)->globalPosition().phi() );
00221 running_meanY.push_back( (*it)->globalPosition().theta() );
00222
00223
00224 seed_minX.push_back( (*it)->globalPosition().phi() );
00225 seed_maxX.push_back( (*it)->globalPosition().phi() );
00226 seed_minY.push_back( (*it)->globalPosition().theta() );
00227 seed_maxY.push_back( (*it)->globalPosition().theta() );
00228 }
00229
00230
00231
00232 for(unsigned int NNN = 0; NNN < seeds.size(); ++NNN) {
00233
00234 for(unsigned int MMM = NNN+1; MMM < seeds.size(); ++MMM) {
00235 if(running_meanX[MMM] == 999999. || running_meanX[NNN] == 999999. ) {
00236
00237
00238 continue;
00239 }
00240
00241
00242
00243 double temp_meanX = running_meanX[NNN];
00244 double temp_minX = seed_minX[NNN];
00245 double temp_maxX = seed_maxX[NNN];
00246
00247
00248
00249 dXclus = running_meanX[NNN] - running_meanX[MMM];
00250 if (dXclus > TMath::Pi()) {
00251 temp_meanX = temp_meanX - 2.*TMath::Pi();
00252 temp_minX = temp_minX - 2.*TMath::Pi();
00253 temp_maxX = temp_maxX - 2.*TMath::Pi();
00254 }
00255 if (dXclus < -TMath::Pi()) {
00256 temp_meanX = temp_meanX + 2.*TMath::Pi();
00257 temp_minX = temp_minX + 2.*TMath::Pi();
00258 temp_maxX = temp_maxX + 2.*TMath::Pi();
00259 }
00260
00261
00262
00263
00264
00265
00266 if ( temp_meanX > running_meanX[MMM] ) dXclus_box = temp_minX - seed_maxX[MMM];
00267 else dXclus_box = seed_minX[MMM] - temp_maxX;
00268 if ( running_meanY[NNN] > running_meanY[MMM] ) dYclus_box = seed_minY[NNN] - seed_maxY[MMM];
00269 else dYclus_box = seed_minY[MMM] - seed_maxY[NNN];
00270
00271
00272 if( dXclus_box < dXclusBoxMax && dYclus_box < dYclusBoxMax ) {
00273
00274
00275
00276
00277
00278 running_meanX[MMM] = (temp_meanX*seeds[NNN].size() + running_meanX[MMM]*seeds[MMM].size()) / (seeds[NNN].size()+seeds[MMM].size());
00279 running_meanY[MMM] = (running_meanY[NNN]*seeds[NNN].size() + running_meanY[MMM]*seeds[MMM].size()) / (seeds[NNN].size()+seeds[MMM].size());
00280
00281
00282
00283 if ( temp_minX <= seed_minX[MMM] ) seed_minX[MMM] = temp_minX;
00284 if ( temp_maxX > seed_maxX[MMM] ) seed_maxX[MMM] = temp_maxX;
00285 if ( seed_minY[NNN] <= seed_minY[MMM] ) seed_minY[MMM] = seed_minY[NNN];
00286 if ( seed_maxY[NNN] > seed_maxY[MMM] ) seed_maxY[MMM] = seed_maxY[NNN];
00287
00288
00289
00290 if (running_meanX[MMM] > TMath::Pi()) {
00291 running_meanX[MMM] = running_meanX[MMM] - 2.*TMath::Pi();
00292 seed_minX[MMM] = seed_minX[MMM] - 2.*TMath::Pi();
00293 seed_maxX[MMM] = seed_maxX[MMM] - 2.*TMath::Pi();
00294 }
00295 if (running_meanX[MMM] < -TMath::Pi()) {
00296 running_meanX[MMM] = running_meanX[MMM] + 2.*TMath::Pi();
00297 seed_minX[MMM] = seed_minX[MMM] + 2.*TMath::Pi();
00298 seed_maxX[MMM] = seed_maxX[MMM] + 2.*TMath::Pi();
00299 }
00300
00301
00302 seeds[MMM].insert(seeds[MMM].end(),seeds[NNN].begin(),seeds[NNN].end());
00303
00304
00305 running_meanX[NNN] = 999999.;
00306 running_meanY[NNN] = 999999.;
00307
00308
00309 break;
00310 }
00311
00312 }
00313 }
00314 bool tooCloseClusters = false;
00315 if(seeds.size()>1){
00316 std::vector <double> seedTheta(seeds.size());
00317 for(unsigned int iSeed = 0;iSeed<seeds.size();++iSeed){
00318 seedTheta[iSeed] = seeds[iSeed][0]->globalPosition().theta();
00319 if(iSeed){
00320 double dTheta = fabs(seedTheta[iSeed] - seedTheta[iSeed-1]);
00321 if (dTheta < 0.5){
00322 tooCloseClusters = true;
00323 break;
00324 }
00325 }
00326 }
00327
00328 }
00329
00330
00331
00332
00333
00334 for(unsigned int NNN = 0; NNN < seeds.size(); ++NNN) {
00335 if(running_meanX[NNN] == 999999.) continue;
00336
00337
00338 if(useDT2D_hasZed) {
00339 for (MuonRecHitContainer::const_iterator it2 = muonRecHits_DT2D_hasZed.begin(); it2 != muonRecHits_DT2D_hasZed.end(); ++it2 ) {
00340
00341 if (((*it2)->globalPosition().theta() < seed_maxY[NNN] + dYclusBoxMax) && ((*it2)->globalPosition().theta() > seed_minY[NNN] - dYclusBoxMax)) {
00342
00343
00344
00345 if(
00346 !(
00347 (
00348 ((*it2)->globalPosition().phi() + 0.09) < (seed_minX[NNN] - dXclusBoxMax)
00349 &&
00350 ((*it2)->globalPosition().phi() - 0.09) < (seed_minX[NNN] - dXclusBoxMax)
00351 )
00352 ||
00353 (
00354 ((*it2)->globalPosition().phi() + 0.09) > (seed_maxX[NNN] + dXclusBoxMax)
00355 &&
00356 ((*it2)->globalPosition().phi() - 0.09) > (seed_maxX[NNN] + dXclusBoxMax)
00357 )
00358 )
00359 ) {
00360 seeds[NNN].push_back((*it2));
00361
00362 }
00363 }
00364 }
00365
00366 }
00367
00368
00369 if (useDT2D_hasPhi) {
00370
00371 for (MuonRecHitContainer::const_iterator it2 = muonRecHits_DT2D_hasPhi.begin(); it2 != muonRecHits_DT2D_hasPhi.end(); ++it2 ) {
00372 if (((*it2)->globalPosition().phi() < seed_maxX[NNN] + dXclusBoxMax) && ((*it2)->globalPosition().phi() > seed_minX[NNN] - dXclusBoxMax)) {
00373 if(
00374 !(
00375 (
00376 ((*it2)->globalPosition().theta() + 0.3) < (seed_minY[NNN] - dYclusBoxMax)
00377 &&
00378 ((*it2)->globalPosition().theta() - 0.3) < (seed_minY[NNN] - dYclusBoxMax)
00379 )
00380 ||
00381 (
00382 ((*it2)->globalPosition().theta() + 0.3) > (seed_maxY[NNN] + dYclusBoxMax)
00383 &&
00384 ((*it2)->globalPosition().theta() - 0.3) > (seed_maxY[NNN] + dYclusBoxMax)
00385 )
00386 )
00387 ) {
00388 seeds[NNN].push_back((*it2));
00389
00390 }
00391 }
00392 }
00393 }
00394
00395
00396 int secondCh = 0;
00397 DetId detId_prev;
00398 if(seeds[NNN].size()>1){
00399 for(unsigned int iRH = 0 ;iRH<seeds[NNN].size() ;++iRH){
00400 if( iRH && detId_prev != seeds[NNN][iRH]->hit()->geographicalId()){
00401 ++secondCh;
00402 break;
00403 }
00404 detId_prev = seeds[NNN][iRH]->hit()->geographicalId();
00405 }
00406 }
00407
00408 if (useRPCs && !secondCh && !tooCloseClusters) {
00409 for (MuonRecHitContainer::const_iterator it2 = muonRecHits_RPC.begin(); it2 != muonRecHits_RPC.end(); ++it2 ) {
00410 if (((*it2)->globalPosition().phi() < seed_maxX[NNN] + dXclusBoxMax) && ((*it2)->globalPosition().phi() > seed_minX[NNN] - dXclusBoxMax)) {
00411 if(
00412 !(
00413 (
00414 ((*it2)->globalPosition().theta() + 0.3) < (seed_minY[NNN] - dYclusBoxMax)
00415 &&
00416 ((*it2)->globalPosition().theta() - 0.3) < (seed_minY[NNN] - dYclusBoxMax)
00417 )
00418 ||
00419 (
00420 ((*it2)->globalPosition().theta() + 0.3) > (seed_maxY[NNN] + dYclusBoxMax)
00421 &&
00422 ((*it2)->globalPosition().theta() - 0.3) > (seed_maxY[NNN] + dYclusBoxMax)
00423 )
00424 )
00425 ) {
00426 seeds[NNN].push_back((*it2));
00427
00428 }
00429 }
00430 }
00431 }
00432 }
00433
00434
00435
00436
00437 for(unsigned int NNN = 0; NNN < seeds.size(); ++NNN) {
00438 if(running_meanX[NNN] == 999999.) continue;
00439
00440 segments_clusters.push_back(seeds[NNN]);
00441 }
00442 }
00443
00444
00445 bool SETPatternRecognition::segmentCleaning(const DetId & detId,
00446 const LocalPoint& localPosition, const LocalError& localError,
00447 const LocalVector& localDirection, const LocalError& localDirectionError,
00448 const double& chi2, const int& ndf){
00449
00450 bool dropTheSegment = true;
00451 const GeomDet* geomDet = theService->trackingGeometry()->idToDet( detId );
00452
00453 bool insideCh = geomDet->surface().bounds().inside(localPosition, localError,outsideChamberErrorScale);
00454
00455
00456
00457 bool parallelSegment = fabs(localDirection.z())>minLocalSegmentAngle? false: true;
00458
00459 if(insideCh && !parallelSegment){
00460 dropTheSegment = false;
00461 }
00462
00463
00464
00465 return dropTheSegment;
00466 }