CMS 3D CMS Logo

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