00001 #include <iostream>
00002 #include <memory>
00003 #include <string>
00004
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 #include "DataFormats/Common/interface/RefToBase.h"
00008 #include "DataFormats/Common/interface/Handle.h"
00009
00010 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00011 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00012 #include "MagneticField/Engine/interface/MagneticField.h"
00013
00014 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2DCollection.h"
00015 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
00016
00017 #include "DataFormats/MuonReco/interface/Muon.h"
00018 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00019 #include "DataFormats/MuonReco/interface/MuonTrackLinks.h"
00020
00021 #include "DataFormats/JetReco/interface/CaloJet.h"
00022 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00023
00024 #include "DataFormats/TrackReco/interface/Track.h"
00025 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00026
00027 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00028 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00029
00030 #include "RecoTracker/SpecialSeedGenerators/interface/CosmicRegionalSeedGenerator.h"
00031
00032 #include <TMath.h>
00033
00034 using namespace std;
00035 using namespace trigger;
00036 using namespace reco;
00037 using namespace edm;
00038
00039 CosmicRegionalSeedGenerator::CosmicRegionalSeedGenerator(edm::ParameterSet const& conf) :
00040 conf_(conf)
00041 {
00042 edm::LogInfo ("CosmicRegionalSeedGenerator") << "Begin Run:: Constructing CosmicRegionalSeedGenerator";
00043
00044 regionPSet = conf_.getParameter<edm::ParameterSet>("RegionPSet");
00045 ptMin_ = regionPSet.getParameter<double>("ptMin");
00046 rVertex_ = regionPSet.getParameter<double>("rVertex");
00047 zVertex_ = regionPSet.getParameter<double>("zVertex");
00048 deltaEta_ = regionPSet.getParameter<double>("deltaEtaRegion");
00049 deltaPhi_ = regionPSet.getParameter<double>("deltaPhiRegion");
00050
00051 edm::ParameterSet toolsPSet = conf_.getParameter<edm::ParameterSet>("ToolsPSet");
00052 thePropagatorName_ = toolsPSet.getParameter<std::string>("thePropagatorName");
00053 regionBase_ = toolsPSet.getParameter<std::string>("regionBase");
00054
00055 edm::ParameterSet collectionsPSet = conf_.getParameter<edm::ParameterSet>("CollectionsPSet");
00056 recoMuonsCollection_ = collectionsPSet.getParameter<edm::InputTag>("recoMuonsCollection");
00057 recoTrackMuonsCollection_ = collectionsPSet.getParameter<edm::InputTag>("recoTrackMuonsCollection");
00058 recoL2MuonsCollection_ = collectionsPSet.getParameter<edm::InputTag>("recoL2MuonsCollection");
00059
00060 edm::ParameterSet regionInJetsCheckPSet = conf_.getParameter<edm::ParameterSet>("RegionInJetsCheckPSet");
00061 doJetsExclusionCheck_ = regionInJetsCheckPSet.getParameter<bool>("doJetsExclusionCheck");
00062 deltaRExclusionSize_ = regionInJetsCheckPSet.getParameter<double>("deltaRExclusionSize");
00063 jetsPtMin_ = regionInJetsCheckPSet.getParameter<double>("jetsPtMin");
00064 recoCaloJetsCollection_ = regionInJetsCheckPSet.getParameter<edm::InputTag>("recoCaloJetsCollection");
00065
00066
00067 edm::LogInfo ("CosmicRegionalSeedGenerator") << "Reco muons collection: " << recoMuonsCollection_ << "\n"
00068 << "Reco tracks muons collection: " << recoTrackMuonsCollection_<< "\n"
00069 << "Reco L2 muons collection: " << recoL2MuonsCollection_;
00070 }
00071
00072 std::vector<TrackingRegion*, std::allocator<TrackingRegion*> > CosmicRegionalSeedGenerator::regions(const edm::Event& event, const edm::EventSetup& es) const
00073 {
00074
00075 std::vector<TrackingRegion* > result;
00076
00077
00078
00079
00080
00081
00082
00083
00084 if(regionBase_=="seedOnStaMuon"||regionBase_=="") {
00085
00086 LogDebug("CosmicRegionalSeedGenerator") << "Seeding on stand alone muons ";
00087
00088
00089
00090
00091
00092 edm::Handle<reco::MuonCollection> muonsHandle;
00093 event.getByLabel(recoMuonsCollection_,muonsHandle);
00094 if (!muonsHandle.isValid())
00095 {
00096 edm::LogError("CollectionNotFound") << "Error::No reco muons collection (" << recoMuonsCollection_ << ") in the event - Please verify the name of the muon collection";
00097 return result;
00098 }
00099
00100 LogDebug("CosmicRegionalSeedGenerator") << "Muons collection size = " << muonsHandle->size();
00101
00102
00103 edm::Handle<CaloJetCollection> caloJetsHandle;
00104 event.getByLabel(recoCaloJetsCollection_,caloJetsHandle);
00105
00106
00107 edm::ESHandle<Propagator> thePropagator;
00108 es.get<TrackingComponentsRecord>().get(thePropagatorName_, thePropagator);
00109
00110
00111 edm::ESHandle<TrackerGeometry> theTrackerGeometry;
00112 es.get<TrackerDigiGeometryRecord>().get(theTrackerGeometry);
00113
00114 DetId outerid;
00115
00116
00117
00118
00119
00120 int nmuons = 0;
00121 for (reco::MuonCollection::const_iterator staMuon = muonsHandle->begin(); staMuon != muonsHandle->end(); ++staMuon) {
00122
00123
00124 if (!staMuon->isStandAloneMuon()) {
00125 LogDebug("CosmicRegionalSeedGenerator") << "This muon is not a stand alone muon";
00126 continue;
00127 }
00128
00129
00130 if ( abs( staMuon->standAloneMuon()->eta() ) > 1.5 ) continue;
00131
00132
00133 nmuons++;
00134 LogDebug("CosmicRegionalSeedGenerator") << "Muon stand alone found in the collection - in muons chambers: \n "
00135 << "Position = " << staMuon->standAloneMuon()->outerPosition() << "\n "
00136 << "Momentum = " << staMuon->standAloneMuon()->outerMomentum() << "\n "
00137 << "Eta = " << staMuon->standAloneMuon()->eta() << "\n "
00138 << "Phi = " << staMuon->standAloneMuon()->phi();
00139
00140
00141
00142 GlobalPoint initialRegionPosition(staMuon->standAloneMuon()->referencePoint().x(), staMuon->standAloneMuon()->referencePoint().y(), staMuon->standAloneMuon()->referencePoint().z());
00143 GlobalVector initialRegionMomentum(staMuon->standAloneMuon()->momentum().x(), staMuon->standAloneMuon()->momentum().y(), staMuon->standAloneMuon()->momentum().z());
00144 int charge = (int) staMuon->standAloneMuon()->charge();
00145
00146 LogDebug("CosmicRegionalSeedGenerator") << "Initial region - Reference point of the sta muon: \n "
00147 << "Position = " << initialRegionPosition << "\n "
00148 << "Momentum = " << initialRegionMomentum << "\n "
00149 << "Eta = " << initialRegionPosition.eta() << "\n "
00150 << "Phi = " << initialRegionPosition.phi() << "\n "
00151 << "Charge = " << charge;
00152
00153
00154 if ( staMuon->standAloneMuon()->outerPosition().y()>0 ) initialRegionMomentum *=-1;
00155 GlobalTrajectoryParameters glb_parameters(initialRegionPosition,
00156 initialRegionMomentum,
00157 charge,
00158 thePropagator->magneticField());
00159 FreeTrajectoryState fts(glb_parameters);
00160 StateOnTrackerBound onBounds(thePropagator.product());
00161 TrajectoryStateOnSurface outer = onBounds(fts);
00162
00163 if (!outer.isValid())
00164 {
00165
00166 LogDebug("CosmicRegionalSeedGenerator") << "Trajectory state on surface not valid" ;
00167 continue;
00168 }
00169
00170
00171
00172 GlobalPoint regionPosition = outer.globalPosition();
00173 GlobalVector regionMom = outer.globalMomentum();
00174
00175 LogDebug("CosmicRegionalSeedGenerator") << "Region after propagation: \n "
00176 << "Position = " << outer.globalPosition() << "\n "
00177 << "Momentum = " << outer.globalMomentum() << "\n "
00178 << "R = " << regionPosition.perp() << " ---- z = " << regionPosition.z() << "\n "
00179 << "Eta = " << outer.globalPosition().eta() << "\n "
00180 << "Phi = " << outer.globalPosition().phi();
00181
00182
00183
00184 double stepBack = 1;
00185 GlobalPoint center = regionPosition + stepBack * regionMom.unit();
00186 GlobalVector v = stepBack * regionMom.unit();
00187 LogDebug("CosmicRegionalSeedGenerator") << "Step back vector = " << v << "\n";
00188
00189
00190 if ( doJetsExclusionCheck_ ) {
00191 double delta_R_min = 1000.;
00192 for ( CaloJetCollection::const_iterator jet = caloJetsHandle->begin (); jet != caloJetsHandle->end(); jet++ ) {
00193 if ( jet->pt() < jetsPtMin_ ) continue;
00194
00195 double deta = center.eta() - jet->eta();
00196 double dphi = fabs( center.phi() - jet->phi() );
00197 if ( dphi > TMath::Pi() ) dphi = 2*TMath::Pi() - dphi;
00198
00199 double delta_R = sqrt(deta*deta + dphi*dphi);
00200 if ( delta_R < delta_R_min ) delta_R_min = delta_R;
00201
00202 }
00203
00204 if ( delta_R_min < deltaRExclusionSize_ ) {
00205 LogDebug("CosmicRegionalSeedGenerator") << "Region built too close from a jet";
00206 continue;
00207 }
00208 }
00209
00210
00211
00212 CosmicTrackingRegion *etaphiRegion = new CosmicTrackingRegion((-1)*regionMom,
00213 center,
00214 ptMin_,
00215 rVertex_,
00216 zVertex_,
00217 deltaEta_,
00218 deltaPhi_,
00219 regionPSet
00220 );
00221
00222
00223
00224
00225 result.push_back(etaphiRegion);
00226
00227 LogDebug("CosmicRegionalSeedGenerator") << "Final CosmicTrackingRegion \n "
00228 << "Position = "<< center << "\n "
00229 << "Direction = "<< etaphiRegion->direction() << "\n "
00230 << "Distance from the region on the layer = " << (regionPosition -center).mag() << "\n "
00231 << "Eta = " << center.eta() << "\n "
00232 << "Phi = " << center.phi();
00233
00234
00235 }
00236
00237 }
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 if(regionBase_=="seedOnCosmicMuon") {
00250
00251 LogDebug("CosmicRegionalSeedGenerator") << "Seeding on cosmic muons tracks";
00252
00253
00254
00255
00256
00257 edm::Handle<reco::TrackCollection> cosmicMuonsHandle;
00258 event.getByLabel(recoTrackMuonsCollection_,cosmicMuonsHandle);
00259 if (!cosmicMuonsHandle.isValid())
00260 {
00261 edm::LogError("CollectionNotFound") << "Error::No cosmic muons collection (" << recoTrackMuonsCollection_ << ") in the event - Please verify the name of the muon reco track collection";
00262 return result;
00263 }
00264
00265 LogDebug("CosmicRegionalSeedGenerator") << "Cosmic muons tracks collection size = " << cosmicMuonsHandle->size();
00266
00267
00268 edm::Handle<CaloJetCollection> caloJetsHandle;
00269 event.getByLabel(recoCaloJetsCollection_,caloJetsHandle);
00270
00271
00272 edm::ESHandle<Propagator> thePropagator;
00273 es.get<TrackingComponentsRecord>().get(thePropagatorName_, thePropagator);
00274
00275
00276 edm::ESHandle<TrackerGeometry> theTrackerGeometry;
00277 es.get<TrackerDigiGeometryRecord>().get(theTrackerGeometry);
00278 DetId outerid;
00279
00280
00281
00282
00283
00284 int nmuons = 0;
00285 for (reco::TrackCollection::const_iterator cosmicMuon = cosmicMuonsHandle->begin(); cosmicMuon != cosmicMuonsHandle->end(); ++cosmicMuon) {
00286
00287
00288 if ( abs( cosmicMuon->eta() ) > 1.5 ) continue;
00289
00290 nmuons++;
00291
00292
00293 GlobalPoint initialRegionPosition(cosmicMuon->referencePoint().x(), cosmicMuon->referencePoint().y(), cosmicMuon->referencePoint().z());
00294 GlobalVector initialRegionMomentum(cosmicMuon->momentum().x(), cosmicMuon->momentum().y(), cosmicMuon->momentum().z());
00295 int charge = (int) cosmicMuon->charge();
00296
00297 LogDebug("CosmicRegionalSeedGenerator") << "Position and momentum of the muon track in the muon chambers: \n "
00298 << "x = " << cosmicMuon->outerPosition().x() << "\n "
00299 << "y = " << cosmicMuon->outerPosition().y() << "\n "
00300 << "y = " << cosmicMuon->pt() << "\n "
00301 << "Initial region - Reference point of the cosmic muon track: \n "
00302 << "Position = " << initialRegionPosition << "\n "
00303 << "Momentum = " << initialRegionMomentum << "\n "
00304 << "Eta = " << initialRegionPosition.eta() << "\n "
00305 << "Phi = " << initialRegionPosition.phi() << "\n "
00306 << "Charge = " << charge;
00307
00308
00309 if ( cosmicMuon->outerPosition().y()>0 && cosmicMuon->momentum().y()<0 ) initialRegionMomentum *=-1;
00310 GlobalTrajectoryParameters glb_parameters(initialRegionPosition,
00311 initialRegionMomentum,
00312 charge,
00313 thePropagator->magneticField());
00314 FreeTrajectoryState fts(glb_parameters);
00315 StateOnTrackerBound onBounds(thePropagator.product());
00316 TrajectoryStateOnSurface outer = onBounds(fts);
00317
00318 if (!outer.isValid())
00319 {
00320
00321 LogDebug("CosmicRegionalSeedGenerator") << "Trajectory state on surface not valid" ;
00322 continue;
00323 }
00324
00325
00326
00327 GlobalPoint regionPosition = outer.globalPosition();
00328 GlobalVector regionMom = outer.globalMomentum();
00329
00330 LogDebug("CosmicRegionalSeedGenerator") << "Region after propagation: \n "
00331 << "Position = " << outer.globalPosition() << "\n "
00332 << "Momentum = " << outer.globalMomentum() << "\n "
00333 << "R = " << regionPosition.perp() << " ---- z = " << regionPosition.z() << "\n "
00334 << "Eta = " << outer.globalPosition().eta() << "\n "
00335 << "Phi = " << outer.globalPosition().phi();
00336
00337
00338
00339 double stepBack = 1;
00340 GlobalPoint center = regionPosition + stepBack * regionMom.unit();
00341 GlobalVector v = stepBack * regionMom.unit();
00342 LogDebug("CosmicRegionalSeedGenerator") << "Step back vector = " << v << "\n";
00343
00344
00345 if ( doJetsExclusionCheck_ ) {
00346 double delta_R_min = 1000.;
00347 for ( CaloJetCollection::const_iterator jet = caloJetsHandle->begin (); jet != caloJetsHandle->end(); jet++ ) {
00348 if ( jet->pt() < jetsPtMin_ ) continue;
00349
00350 double deta = center.eta() - jet->eta();
00351 double dphi = fabs( center.phi() - jet->phi() );
00352 if ( dphi > TMath::Pi() ) dphi = 2*TMath::Pi() - dphi;
00353
00354 double delta_R = sqrt(deta*deta + dphi*dphi);
00355 if ( delta_R < delta_R_min ) delta_R_min = delta_R;
00356
00357 }
00358
00359 if ( delta_R_min < deltaRExclusionSize_ ) {
00360 LogDebug("CosmicRegionalSeedGenerator") << "Region built too close from a jet";
00361 continue;
00362 }
00363 }
00364
00365
00366 CosmicTrackingRegion *etaphiRegion = new CosmicTrackingRegion((-1)*regionMom,
00367 center,
00368 ptMin_,
00369 rVertex_,
00370 zVertex_,
00371 deltaEta_,
00372 deltaPhi_,
00373 regionPSet
00374 );
00375
00376
00377
00378 result.push_back(etaphiRegion);
00379
00380 LogDebug("CosmicRegionalSeedGenerator") << "Final CosmicTrackingRegion \n "
00381 << "Position = "<< center << "\n "
00382 << "Direction = "<< etaphiRegion->direction() << "\n "
00383 << "Distance from the region on the layer = " << (regionPosition -center).mag() << "\n "
00384 << "Eta = " << center.eta() << "\n "
00385 << "Phi = " << center.phi();
00386
00387 }
00388
00389 }
00390
00391
00392
00393
00394
00395
00396
00397 if(regionBase_=="seedOnL2Muon") {
00398
00399 LogDebug("CosmicRegionalSeedGenerator") << "Seeding on L2 muons";
00400
00401
00402
00403
00404
00405 edm::Handle<reco::RecoChargedCandidateCollection> L2MuonsHandle;
00406 event.getByLabel(recoL2MuonsCollection_,L2MuonsHandle);
00407
00408 if (!L2MuonsHandle.isValid())
00409 {
00410 edm::LogError("CollectionNotFound") << "Error::No L2 muons collection (" << recoL2MuonsCollection_ <<") in the event - Please verify the name of the L2 muon collection";
00411 return result;
00412 }
00413
00414 LogDebug("CosmicRegionalSeedGenerator") << "L2 muons collection size = " << L2MuonsHandle->size();
00415
00416
00417 edm::ESHandle<Propagator> thePropagator;
00418 es.get<TrackingComponentsRecord>().get(thePropagatorName_, thePropagator);
00419
00420
00421 edm::ESHandle<TrackerGeometry> theTrackerGeometry;
00422 es.get<TrackerDigiGeometryRecord>().get(theTrackerGeometry);
00423 DetId outerid;
00424
00425
00426
00427
00428
00429 int nmuons = 0;
00430 for (reco::RecoChargedCandidateCollection::const_iterator L2Muon = L2MuonsHandle->begin(); L2Muon != L2MuonsHandle->end(); ++L2Muon) {
00431 reco::TrackRef tkL2Muon = L2Muon->get<reco::TrackRef>();
00432
00433
00434 if ( abs( tkL2Muon->eta() ) > 1.5 ) continue;
00435
00436 nmuons++;
00437
00438
00439 GlobalPoint initialRegionPosition(tkL2Muon->referencePoint().x(), tkL2Muon->referencePoint().y(), tkL2Muon->referencePoint().z());
00440 GlobalVector initialRegionMomentum(tkL2Muon->momentum().x(), tkL2Muon->momentum().y(), tkL2Muon->momentum().z());
00441 int charge = (int) tkL2Muon->charge();
00442
00443 LogDebug("CosmicRegionalSeedGenerator") << "Position and momentum of the L2 muon track in the muon chambers: \n "
00444 << "x = " << tkL2Muon->outerPosition().x() << "\n "
00445 << "y = " << tkL2Muon->outerPosition().y() << "\n "
00446 << "y = " << tkL2Muon->pt() << "\n "
00447 << "Initial region - Reference point of the L2 muon track: \n "
00448 << "Position = " << initialRegionPosition << "\n "
00449 << "Momentum = " << initialRegionMomentum << "\n "
00450 << "Eta = " << initialRegionPosition.eta() << "\n "
00451 << "Phi = " << initialRegionPosition.phi() << "\n "
00452 << "Charge = " << charge;
00453
00454
00455
00456 if ( tkL2Muon->outerPosition().y() > 0 )
00457 {
00458 LogDebug("CosmicRegionalSeedGenerator") << "L2 muon in the TOP --- Region not created";
00459 return result;
00460 }
00461
00462 GlobalTrajectoryParameters glb_parameters(initialRegionPosition,
00463 initialRegionMomentum,
00464 charge,
00465 thePropagator->magneticField());
00466 FreeTrajectoryState fts(glb_parameters);
00467 StateOnTrackerBound onBounds(thePropagator.product());
00468 TrajectoryStateOnSurface outer = onBounds(fts);
00469
00470 if (!outer.isValid())
00471 {
00472
00473 LogDebug("CosmicRegionalSeedGenerator") << "Trajectory state on surface not valid" ;
00474 continue;
00475 }
00476
00477
00478
00479 GlobalPoint regionPosition = outer.globalPosition();
00480 GlobalVector regionMom = outer.globalMomentum();
00481
00482 LogDebug("CosmicRegionalSeedGenerator") << "Region after propagation: \n "
00483 << "Position = " << outer.globalPosition() << "\n "
00484 << "Momentum = " << outer.globalMomentum() << "\n "
00485 << "R = " << regionPosition.perp() << " ---- z = " << regionPosition.z() << "\n "
00486 << "Eta = " << outer.globalPosition().eta() << "\n "
00487 << "Phi = " << outer.globalPosition().phi();
00488
00489
00490
00491 double stepBack = 1;
00492 GlobalPoint center = regionPosition + stepBack * regionMom.unit();
00493 GlobalVector v = stepBack * regionMom.unit();
00494 LogDebug("CosmicRegionalSeedGenerator") << "Step back vector = " << v << "\n";
00495
00496
00497
00498 CosmicTrackingRegion *etaphiRegion = new CosmicTrackingRegion((-1)*regionMom,
00499 center,
00500 ptMin_,
00501 rVertex_,
00502 zVertex_,
00503 deltaEta_,
00504 deltaPhi_,
00505 regionPSet
00506 );
00507
00508 result.push_back(etaphiRegion);
00509
00510 LogDebug("CosmicRegionalSeedGenerator") << "Final L2TrackingRegion \n "
00511 << "Position = "<< center << "\n "
00512 << "Direction = "<< etaphiRegion->direction() << "\n "
00513 << "Distance from the region on the layer = " << (regionPosition -center).mag() << "\n "
00514 << "Eta = " << center.eta() << "\n "
00515 << "Phi = " << center.phi();
00516
00517
00518 }
00519
00520 }
00521
00522 return result;
00523
00524 }
00525