CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoMuon/TrackerSeedGenerator/plugins/TSGFromL2Muon.cc

Go to the documentation of this file.
00001 #include "TSGFromL2Muon.h"
00002 #include "FWCore/Framework/interface/Event.h"
00003 #include "FWCore/Framework/interface/EventSetup.h"
00004 #include "DataFormats/Common/interface/Handle.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 
00008 #include "RecoTracker/TkTrackingRegions/interface/RectangularEtaPhiTrackingRegion.h"
00009 
00010 #include "DataFormats/MuonSeed/interface/L3MuonTrajectorySeed.h"
00011 #include "DataFormats/MuonSeed/interface/L3MuonTrajectorySeedCollection.h"
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013 #include <vector>
00014 
00015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00016 
00017 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
00018 #include "RecoMuon/GlobalTrackingTools/interface/MuonTrackingRegionBuilder.h"
00019 #include "RecoMuon/TrackerSeedGenerator/interface/TrackerSeedGenerator.h"
00020 #include "RecoMuon/TrackerSeedGenerator/interface/TrackerSeedGeneratorFactory.h"
00021 #include "RecoMuon/TrackerSeedGenerator/interface/TrackerSeedCleaner.h"
00022 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
00023 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00024 
00025 TSGFromL2Muon::TSGFromL2Muon(const edm::ParameterSet& cfg)
00026   : theConfig(cfg), theService(0), theRegionBuilder(0), theTkSeedGenerator(0), theSeedCleaner(0)
00027 {
00028   produces<L3MuonTrajectorySeedCollection>();
00029 
00030   edm::ParameterSet serviceParameters = cfg.getParameter<edm::ParameterSet>("ServiceParameters");
00031   theService = new MuonServiceProxy(serviceParameters);
00032 
00033   thePtCut = cfg.getParameter<double>("PtCut");
00034   thePCut = cfg.getParameter<double>("PCut");
00035 
00036   theL2CollectionLabel = cfg.getParameter<edm::InputTag>("MuonCollectionLabel");
00037 
00038   //region builder
00039   edm::ParameterSet regionBuilderPSet = theConfig.getParameter<edm::ParameterSet>("MuonTrackingRegionBuilder");
00040   //ability to no define a region
00041   if (!regionBuilderPSet.empty()){
00042     theRegionBuilder = new MuonTrackingRegionBuilder(regionBuilderPSet);
00043   }
00044 
00045   //seed generator
00046   //std::string seedGenPSetLabel = theConfig.getParameter<std::string>("tkSeedGenerator");
00047   //edm::ParameterSet seedGenPSet = theConfig.getParameter<edm::ParameterSet>(seedGenPSetLabel);
00048   edm::ParameterSet seedGenPSet = theConfig.getParameter<edm::ParameterSet>("TkSeedGenerator");
00049   std::string seedGenName = seedGenPSet.getParameter<std::string>("ComponentName");
00050 
00051   theTkSeedGenerator = TrackerSeedGeneratorFactory::get()->create(seedGenName, seedGenPSet);  
00052   
00053   //seed cleaner
00054   edm::ParameterSet trackerSeedCleanerPSet = theConfig.getParameter<edm::ParameterSet>("TrackerSeedCleaner");
00055   //to activate or not the cleaner
00056   if (!trackerSeedCleanerPSet.empty()){
00057     theSeedCleaner = new TrackerSeedCleaner(trackerSeedCleanerPSet);
00058   }
00059 
00060 }
00061 
00062 TSGFromL2Muon::~TSGFromL2Muon()
00063 {
00064   delete theService;
00065   if (theSeedCleaner) delete theSeedCleaner;
00066   delete theTkSeedGenerator;
00067   if (theRegionBuilder) delete theRegionBuilder;
00068 }
00069 
00070 void TSGFromL2Muon::beginRun(const edm::Run & run, const edm::EventSetup&es)
00071 {
00072   //update muon proxy service
00073   theService->update(es);
00074   
00075   if (theRegionBuilder) theRegionBuilder->init(theService);
00076   theTkSeedGenerator->init(theService);
00077   if (theSeedCleaner) theSeedCleaner->init(theService);
00078 
00079 }
00080 
00081 void TSGFromL2Muon::produce(edm::Event& ev, const edm::EventSetup& es)
00082 {
00083   std::auto_ptr<L3MuonTrajectorySeedCollection> result(new L3MuonTrajectorySeedCollection());
00084 
00085   //Retrieve tracker topology from geometry
00086   edm::ESHandle<TrackerTopology> tTopoHand;
00087   es.get<IdealGeometryRecord>().get(tTopoHand);
00088   const TrackerTopology *tTopo=tTopoHand.product();
00089 
00090 
00091   //intialize tools
00092   theService->update(es);
00093   theTkSeedGenerator->setEvent(ev);
00094   if (theRegionBuilder)  theRegionBuilder->setEvent(ev);
00095   if (theSeedCleaner) theSeedCleaner->setEvent(ev);
00096 
00097   //retrieve L2 track collection
00098   edm::Handle<reco::TrackCollection> l2muonH;
00099   ev.getByLabel(theL2CollectionLabel ,l2muonH); 
00100 
00101   // produce trajectoryseed collection
00102   unsigned int imu=0;
00103   unsigned int imuMax=l2muonH->size();
00104   LogDebug("TSGFromL2Muon")<<imuMax<<" l2 tracks.";
00105 
00106   for (;imu!=imuMax;++imu){
00107     //make a ref to l2 muon
00108     reco::TrackRef muRef(l2muonH, imu);
00109     
00110     // cut on muons with low momenta
00111     if ( muRef->pt() < thePtCut 
00112          || muRef->innerMomentum().Rho() < thePtCut 
00113          || muRef->innerMomentum().R() < thePCut ) continue;
00114     
00115     //define the region of interest
00116     std::unique_ptr<RectangularEtaPhiTrackingRegion> region;
00117     if(theRegionBuilder){
00118       region.reset(theRegionBuilder->region(muRef));
00119     }
00120     
00121     //get the seeds
00122     std::vector<TrajectorySeed> tkSeeds;
00123     //make this stupid TrackCand
00124     std::pair<const Trajectory*,reco::TrackRef> staCand((Trajectory*)(0), muRef);
00125     theTkSeedGenerator->trackerSeeds(staCand, *region, tTopo,tkSeeds);
00126 
00127     //Seed Cleaner From Direction
00128     //clean them internatly
00129     if(theSeedCleaner){
00130        theSeedCleaner->clean(muRef,*region,tkSeeds);
00131        LogDebug("TSGFromL2Muon") << tkSeeds.size() << " seeds for this L2 afther cleaning.";
00132     }
00133 
00134     unsigned int is=0;
00135     unsigned int isMax=tkSeeds.size();
00136     LogDebug("TSGFromL2Muon")<<isMax<<" seeds for this L2.";
00137     for (;is!=isMax;++is){
00138       result->push_back( L3MuonTrajectorySeed(tkSeeds[is], muRef));
00139     }//tkseed loop
00140     
00141   }//l2muon loop
00142   
00143 
00144   //ADDME
00145   //remove seed duplicate, keeping the ref to L2
00146 
00147   LogDebug("TSGFromL2Muon")<<result->size()<<" trajectory seeds to the events";
00148 
00149   //put in the event
00150   ev.put(result);
00151 }
00152