CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/RecoMuon/TrackerSeedGenerator/plugins/TSGFromL1Muon.cc

Go to the documentation of this file.
00001 #include "TSGFromL1Muon.h"
00002 
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/EventSetup.h"
00005 #include "DataFormats/Common/interface/Handle.h"
00006 #include "FWCore/Framework/interface/ESHandle.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 
00009 #include "RecoTracker/TkTrackingRegions/interface/OrderedHitsGeneratorFactory.h"
00010 #include "RecoTracker/TkTrackingRegions/interface/OrderedHitsGenerator.h"
00011 
00012 #include "RecoPixelVertexing/PixelTrackFitting/interface/PixelFitter.h"
00013 #include "RecoPixelVertexing/PixelTrackFitting/interface/PixelFitterFactory.h"
00014 #include "RecoMuon/TrackerSeedGenerator/interface/L1MuonPixelTrackFitter.h"
00015 #include "RecoMuon/TrackerSeedGenerator/interface/L1MuonSeedsMerger.h"
00016 
00017 #include "RecoTracker/TkTrackingRegions/interface/TrackingRegion.h"
00018 #include "RecoTracker/TkTrackingRegions/interface/TrackingRegionProducer.h"
00019 #include "RecoTracker/TkTrackingRegions/interface/TrackingRegionProducerFactory.h"
00020 #include "RecoMuon/TrackerSeedGenerator/interface/L1MuonRegionProducer.h"
00021 
00022 #include "RecoPixelVertexing/PixelTrackFitting/interface/PixelTrackFilter.h"
00023 #include "RecoPixelVertexing/PixelTrackFitting/interface/PixelTrackFilterFactory.h"
00024 
00025 #include "RecoPixelVertexing/PixelTrackFitting/interface/PixelTrackCleaner.h"
00026 #include "RecoPixelVertexing/PixelTrackFitting/interface/PixelTrackCleanerFactory.h"
00027 
00028 #include "DataFormats/TrackReco/interface/Track.h"
00029 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00030 
00031 #include "RecoTracker/TkSeedGenerator/interface/SeedFromProtoTrack.h"
00032 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
00033 
00034 #include <vector>
00035 
00036 #include "DataFormats/L1Trigger/interface/L1MuonParticle.h"
00037 #include "DataFormats/L1Trigger/interface/L1MuonParticleFwd.h"
00038 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
00039 #include "DataFormats/MuonSeed/interface/L3MuonTrajectorySeedCollection.h"
00040 
00041 using namespace reco;
00042 using namespace ctfseeding;
00043 using namespace l1extra;
00044 
00045 template <class T> T sqr( T t) {return t*t;}
00046 
00047 
00048 TSGFromL1Muon::TSGFromL1Muon(const edm::ParameterSet& cfg)
00049   : theConfig(cfg),theRegionProducer(0),theHitGenerator(0),theFitter(0),theFilter(0),theMerger(0)
00050 {
00051   produces<L3MuonTrajectorySeedCollection>();
00052   theSourceTag = cfg.getParameter<edm::InputTag>("L1MuonLabel");
00053 }
00054 
00055 TSGFromL1Muon::~TSGFromL1Muon()
00056 {
00057   delete theMerger;
00058   delete theFilter;
00059   delete theFitter;
00060   delete theHitGenerator;
00061   delete theRegionProducer;
00062 }
00063 
00064 void TSGFromL1Muon::beginRun(edm::Run & run, const edm::EventSetup&es)
00065 {
00066   edm::ParameterSet regfactoryPSet = theConfig.getParameter<edm::ParameterSet>("RegionFactoryPSet");
00067   std::string regfactoryName = regfactoryPSet.getParameter<std::string>("ComponentName");
00068   TrackingRegionProducer * p =
00069     TrackingRegionProducerFactory::get()->create(regfactoryName,regfactoryPSet);
00070   theRegionProducer = dynamic_cast<L1MuonRegionProducer* >(p);
00071 
00072   edm::ParameterSet hitsfactoryPSet =
00073       theConfig.getParameter<edm::ParameterSet>("OrderedHitsFactoryPSet");
00074   std::string hitsfactoryName = hitsfactoryPSet.getParameter<std::string>("ComponentName");
00075   theHitGenerator = OrderedHitsGeneratorFactory::get()->create( hitsfactoryName, hitsfactoryPSet);
00076 
00077   edm::ParameterSet fitterPSet = theConfig.getParameter<edm::ParameterSet>("FitterPSet");
00078   std::string fitterName = fitterPSet.getParameter<std::string>("ComponentName");
00079   PixelFitter * f = PixelFitterFactory::get()->create( fitterName, fitterPSet);
00080   theFitter = dynamic_cast<L1MuonPixelTrackFitter* >(f);
00081 
00082   edm::ParameterSet filterPSet = theConfig.getParameter<edm::ParameterSet>("FilterPSet");
00083   std::string  filterName = filterPSet.getParameter<std::string>("ComponentName");
00084   theFilter = PixelTrackFilterFactory::get()->create( filterName, filterPSet);
00085 
00086   edm::ParameterSet cleanerPSet = theConfig.getParameter<edm::ParameterSet>("CleanerPSet");
00087   std::string  cleanerName = cleanerPSet.getParameter<std::string>("ComponentName");
00088 //  theMerger = PixelTrackCleanerFactory::get()->create( cleanerName, cleanerPSet);
00089   theMerger = new L1MuonSeedsMerger(cleanerPSet);
00090 }
00091 
00092 
00093 void TSGFromL1Muon::produce(edm::Event& ev, const edm::EventSetup& es)
00094 {
00095   std::auto_ptr<L3MuonTrajectorySeedCollection> result(new L3MuonTrajectorySeedCollection());
00096 
00097   edm::Handle<L1MuonParticleCollection> l1muon;
00098   ev.getByLabel(theSourceTag, l1muon);
00099 
00100   LogDebug("TSGFromL1Muon")<<l1muon->size()<<" l1 muons to seed from.";
00101 
00102   L1MuonParticleCollection::const_iterator muItr = l1muon->begin(); 
00103   L1MuonParticleCollection::const_iterator muEnd = l1muon->end(); 
00104   for  ( size_t iL1 = 0;  muItr < muEnd; ++muItr, ++iL1) {
00105        
00106     if (muItr->gmtMuonCand().empty()) continue;
00107 
00108     const L1MuGMTCand & muon = muItr->gmtMuonCand();
00109     l1extra::L1MuonParticleRef l1Ref(l1muon, iL1);
00110 
00111     theRegionProducer->setL1Constraint(muon);
00112     theFitter->setL1Constraint(muon);
00113 
00114     typedef std::vector<TrackingRegion * > Regions;
00115     Regions regions = theRegionProducer->regions(ev,es);
00116     for (Regions::const_iterator ir=regions.begin(); ir != regions.end(); ++ir) {
00117 
00118       L1MuonSeedsMerger::TracksAndHits tracks;
00119       const TrackingRegion & region = **ir;
00120       const OrderedSeedingHits & candidates = theHitGenerator->run(region,ev,es);
00121 
00122       unsigned int nSets = candidates.size();
00123       for (unsigned int ic= 0; ic <nSets; ic++) {
00124 
00125         const SeedingHitSet & hits =  candidates[ic]; 
00126         std::vector<const TrackingRecHit *> trh;
00127         for (unsigned int i= 0, nHits = hits.size(); i< nHits; ++i) trh.push_back( hits[i]->hit() );
00128 
00129         theFitter->setPxConstraint(hits);
00130         reco::Track* track = theFitter->run(es, trh, region);
00131         if (!track) continue;
00132 
00133         if (!(*theFilter)(track) ) { delete track; continue; }
00134         tracks.push_back(L1MuonSeedsMerger::TrackAndHits(track, hits));
00135       }
00136   
00137       if(theMerger) theMerger->resolve(tracks);
00138       for (L1MuonSeedsMerger::TracksAndHits::const_iterator it = tracks.begin();
00139         it != tracks.end(); ++it) {
00140 
00141         SeedFromProtoTrack seed( *(it->first), it->second, es);
00142         if (seed.isValid()) (*result).push_back(L3MuonTrajectorySeed(seed.trajectorySeed(),l1Ref));
00143 
00144 //      GlobalError vtxerr( sqr(region->originRBound()), 0, sqr(region->originRBound()),
00145 //                                               0, 0, sqr(region->originZBound()));
00146 //      SeedFromConsecutiveHits seed( candidates[ic],region->origin(), vtxerr, es);
00147 //      if (seed.isValid()) (*result).push_back( seed.TrajSeed() );
00148         delete it->first;
00149       }
00150     }
00151     for (Regions::const_iterator it=regions.begin(); it != regions.end(); ++it) delete (*it);
00152   }
00153 
00154   LogDebug("TSGFromL1Muon")<<result->size()<<" seeds to the event.";
00155   ev.put(result);
00156 }
00157