Go to the documentation of this file.00001 #include "FWCore/Framework/interface/Event.h"
00002
00003 #include "DataFormats/MuonSeed/interface/L3MuonTrajectorySeedCollection.h"
00004 #include "DataFormats/TrackerRecHit2D/interface/SiTrackerGSMatchedRecHit2DCollection.h"
00005 #include "DataFormats/TrackReco/interface/Track.h"
00006 #include "DataFormats/Math/interface/deltaPhi.h"
00007
00008 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00009
00010 #include "RecoTracker/TkTrackingRegions/interface/RectangularEtaPhiTrackingRegion.h"
00011
00012 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
00013 #include "RecoMuon/GlobalTrackingTools/interface/MuonTrackingRegionBuilder.h"
00014
00015 #include "FastSimulation/Muons/plugins/FastTSGFromL2Muon.h"
00016
00017
00018
00019 #include <set>
00020
00021 FastTSGFromL2Muon::FastTSGFromL2Muon(const edm::ParameterSet& cfg) : theConfig(cfg)
00022 {
00023 produces<L3MuonTrajectorySeedCollection>();
00024
00025 edm::ParameterSet serviceParameters =
00026 cfg.getParameter<edm::ParameterSet>("ServiceParameters");
00027 theService = new MuonServiceProxy(serviceParameters);
00028
00029 thePtCut = cfg.getParameter<double>("PtCut");
00030
00031 theL2CollectionLabel = cfg.getParameter<edm::InputTag>("MuonCollectionLabel");
00032 theSeedCollectionLabels = cfg.getParameter<std::vector<edm::InputTag> >("SeedCollectionLabels");
00033 theSimTrackCollectionLabel = cfg.getParameter<edm::InputTag>("SimTrackCollectionLabel");
00034
00035
00036 }
00037
00038 FastTSGFromL2Muon::~FastTSGFromL2Muon()
00039 {
00040 }
00041
00042 void
00043 FastTSGFromL2Muon::beginRun(edm::Run const& run, edm::EventSetup const& es)
00044 {
00045
00046 theService->update(es);
00047
00048
00049 edm::ParameterSet regionBuilderPSet =
00050 theConfig.getParameter<edm::ParameterSet>("MuonTrackingRegionBuilder");
00051 theRegionBuilder = new MuonTrackingRegionBuilder(regionBuilderPSet,theService);
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 }
00067
00068
00069 void
00070 FastTSGFromL2Muon::produce(edm::Event& ev, const edm::EventSetup& es)
00071 {
00072
00073
00074 std::auto_ptr<L3MuonTrajectorySeedCollection> result(new L3MuonTrajectorySeedCollection());
00075
00076
00077 theService->update(es);
00078
00079
00080 theRegionBuilder->setEvent(ev);
00081
00082
00083 edm::Handle<edm::SimTrackContainer> theSimTracks;
00084 ev.getByLabel(theSimTrackCollectionLabel,theSimTracks);
00085
00086
00087 edm::Handle<reco::TrackCollection> l2muonH;
00088 ev.getByLabel(theL2CollectionLabel ,l2muonH);
00089
00090
00091 unsigned seedCollections = theSeedCollectionLabels.size();
00092 std::vector<edm::Handle<edm::View<TrajectorySeed> > > theSeeds;
00093 theSeeds.resize(seedCollections);
00094 unsigned seed_size = 0;
00095 for ( unsigned iseed=0; iseed<seedCollections; ++iseed ) {
00096 ev.getByLabel(theSeedCollectionLabels[iseed], theSeeds[iseed]);
00097 seed_size += theSeeds[iseed]->size();
00098 }
00099
00100
00101 unsigned int imu=0;
00102 unsigned int imuMax=l2muonH->size();
00103
00104 for (;imu!=imuMax;++imu){
00105
00106
00107 reco::TrackRef muRef(l2muonH, imu);
00108
00109
00110 if ( muRef->pt() < thePtCut
00111 || muRef->innerMomentum().Rho() < thePtCut
00112 || muRef->innerMomentum().R() < 2.5 ) continue;
00113
00114
00115 RectangularEtaPhiTrackingRegion * region = theRegionBuilder->region(muRef);
00116
00117
00118 std::vector<TrajectorySeed> tkSeeds;
00119 std::set<unsigned> tkIds;
00120 tkSeeds.reserve(seed_size);
00121 for ( unsigned iseed=0; iseed<seedCollections; ++iseed ) {
00122 edm::Handle<edm::View<TrajectorySeed> > aSeedCollection = theSeeds[iseed];
00123 unsigned nSeeds = aSeedCollection->size();
00124 for (unsigned seednr = 0; seednr < nSeeds; ++seednr) {
00125
00126
00127 const BasicTrajectorySeed* aSeed = &((*aSeedCollection)[seednr]);
00128
00129
00130 TrajectorySeed::range theSeedingRecHitRange = aSeed->recHits();
00131 const SiTrackerGSMatchedRecHit2D * theFirstSeedingRecHit =
00132 (const SiTrackerGSMatchedRecHit2D*) (&(*(theSeedingRecHitRange.first)));
00133
00134
00135 int simTrackId = theFirstSeedingRecHit->simtrackId();
00136
00137
00138 std::set<unsigned>::iterator tkId = tkIds.find(simTrackId);
00139 if( tkId != tkIds.end() ) continue;
00140
00141 const SimTrack& theSimTrack = (*theSimTracks)[simTrackId];
00142
00143 if ( clean(muRef,region,aSeed,theSimTrack) ) tkSeeds.push_back(*aSeed);
00144 tkIds.insert(simTrackId);
00145
00146 }
00147
00148 }
00149
00150
00151 delete region;
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 unsigned int is=0;
00162 unsigned int isMax=tkSeeds.size();
00163 for (;is!=isMax;++is){
00164 result->push_back( L3MuonTrajectorySeed(tkSeeds[is], muRef));
00165 }
00166
00167 }
00168
00169
00170
00171
00172
00173
00174
00175 ev.put(result);
00176
00177 }
00178
00179 bool
00180 FastTSGFromL2Muon::clean(reco::TrackRef muRef,
00181 RectangularEtaPhiTrackingRegion* region,
00182 const BasicTrajectorySeed* aSeed,
00183 const SimTrack& theSimTrack) {
00184
00185
00186 const PixelRecoRange<float>& etaRange = region->etaRange() ;
00187 double etaSeed = theSimTrack.momentum().Eta();
00188 double etaLimit = (fabs(fabs(etaRange.max())-fabs(etaRange.mean())) <0.05) ?
00189 0.05 : fabs(fabs(etaRange.max()) - fabs(etaRange.mean())) ;
00190 bool inEtaRange =
00191 etaSeed >= (etaRange.mean() - etaLimit) &&
00192 etaSeed <= (etaRange.mean() + etaLimit) ;
00193 if ( !inEtaRange ) return false;
00194
00195
00196 const TkTrackingRegionsMargin<float>& phiMargin = region->phiMargin();
00197 double phiSeed = theSimTrack.momentum().Phi();
00198 double phiLimit = (phiMargin.right() < 0.05 ) ? 0.05 : phiMargin.right();
00199 bool inPhiRange =
00200 (fabs(deltaPhi(phiSeed,double(region->direction().phi()))) < phiLimit );
00201 if ( !inPhiRange ) return false;
00202
00203
00204 double ptSeed = std::sqrt(theSimTrack.momentum().Perp2());
00205 double ptMin = (region->ptMin()>3.5) ? 3.5: region->ptMin();
00206 bool inPtRange = ptSeed >= ptMin && ptSeed<= 2*(muRef->pt());
00207 return inPtRange;
00208
00209 }