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 #include "FWCore/ServiceRegistry/interface/Service.h"
00024 #include "PhysicsTools/UtilAlgos/interface/TFileService.h"
00025
00026 #include <TH1.h>
00027
00028 TSGFromL2Muon::TSGFromL2Muon(const edm::ParameterSet& cfg)
00029 : theConfig(cfg), theTkSeedGenerator(0)
00030 {
00031 produces<L3MuonTrajectorySeedCollection>();
00032
00033 edm::ParameterSet serviceParameters = cfg.getParameter<edm::ParameterSet>("ServiceParameters");
00034 theService = new MuonServiceProxy(serviceParameters);
00035
00036 thePtCut = cfg.getParameter<double>("PtCut");
00037
00038 theL2CollectionLabel = cfg.getParameter<edm::InputTag>("MuonCollectionLabel");
00039 useTFileService_ = cfg.getUntrackedParameter<bool>("UseTFileService",false);
00040 }
00041
00042 TSGFromL2Muon::~TSGFromL2Muon()
00043 {
00044 }
00045
00046 void TSGFromL2Muon::beginJob(const edm::EventSetup& es)
00047 {
00048
00049 theService->update(es);
00050
00051
00052 edm::ParameterSet regionBuilderPSet = theConfig.getParameter<edm::ParameterSet>("MuonTrackingRegionBuilder");
00053
00054 if (regionBuilderPSet.empty()){
00055 theRegionBuilder = 0;}
00056 else{
00057 theRegionBuilder = new MuonTrackingRegionBuilder(regionBuilderPSet,theService);
00058 }
00059
00060
00061 std::string seedGenPSetLabel = theConfig.getParameter<std::string>("tkSeedGenerator");
00062 edm::ParameterSet seedGenPSet = theConfig.getParameter<edm::ParameterSet>(seedGenPSetLabel);
00063 std::string seedGenName = seedGenPSet.getParameter<std::string>("ComponentName");
00064 seedGenPSet.addUntrackedParameter<bool>("UseTFileService",useTFileService_);
00065 theTkSeedGenerator = TrackerSeedGeneratorFactory::get()->create(seedGenName, seedGenPSet);
00066 theTkSeedGenerator->init(theService);
00067
00068
00069 edm::ParameterSet trackerSeedCleanerPSet = theConfig.getParameter<edm::ParameterSet>("TrackerSeedCleaner");
00070
00071 if (trackerSeedCleanerPSet.empty())
00072 theSeedCleaner=0;
00073 else{
00074 theSeedCleaner = new TrackerSeedCleaner(trackerSeedCleanerPSet);
00075 theSeedCleaner->init(theService);
00076 }
00077
00078 if(useTFileService_) {
00079 edm::Service<TFileService> fs;
00080 h_nSeedPerTrack = fs->make<TH1F>("nSeedPerTrack","nSeedPerTrack",76,-0.5,75.5);
00081 h_nGoodSeedPerTrack = fs->make<TH1F>("nGoodSeedPerTrack","nGoodSeedPerTrack",75,-0.5,75.5);
00082 h_nGoodSeedPerEvent = fs->make<TH1F>("nGoodSeedPerEvent","nGoodSeedPerEvent",75,-0.5,75.5);
00083 } else {
00084 h_nSeedPerTrack = 0;
00085 h_nGoodSeedPerEvent = 0;
00086 h_nGoodSeedPerTrack = 0;
00087 }
00088
00089 }
00090
00091
00092 void TSGFromL2Muon::produce(edm::Event& ev, const edm::EventSetup& es)
00093 {
00094 std::auto_ptr<L3MuonTrajectorySeedCollection> result(new L3MuonTrajectorySeedCollection());
00095
00096
00097 theService->update(es);
00098 theTkSeedGenerator->setEvent(ev);
00099 if (theRegionBuilder) theRegionBuilder->setEvent(ev);
00100 if (theSeedCleaner) theSeedCleaner->setEvent(ev);
00101
00102
00103 edm::Handle<reco::TrackCollection> l2muonH;
00104 ev.getByLabel(theL2CollectionLabel ,l2muonH);
00105
00106
00107 uint imu=0;
00108 uint imuMax=l2muonH->size();
00109 LogDebug("TSGFromL2Muon")<<imuMax<<" l2 tracks.";
00110
00111 for (;imu!=imuMax;++imu){
00112
00113 reco::TrackRef muRef(l2muonH, imu);
00114
00115
00116 if ( muRef->pt() < thePtCut
00117 || muRef->innerMomentum().Rho() < thePtCut
00118 || muRef->innerMomentum().R() < 2.5 ) continue;
00119
00120
00121 RectangularEtaPhiTrackingRegion region;
00122 if(theRegionBuilder){
00123 RectangularEtaPhiTrackingRegion * region1 = theRegionBuilder->region(muRef);
00124
00125 TkTrackingRegionsMargin<float> etaMargin(fabs(region1->etaRange().min() - region1->etaRange().mean()),
00126 fabs(region1->etaRange().max() - region1->etaRange().mean()));
00127
00128 region=RectangularEtaPhiTrackingRegion(region1->direction(),
00129 region1->origin(),
00130 region1->ptMin(),
00131 region1->originRBound(),
00132 region1->originZBound(),
00133 etaMargin,
00134 region1->phiMargin());
00135 delete region1;
00136 }
00137
00138
00139 std::vector<TrajectorySeed> tkSeeds;
00140
00141 std::pair<const Trajectory*,reco::TrackRef> staCand(0, muRef);
00142 theTkSeedGenerator->trackerSeeds(staCand, region, tkSeeds);
00143 if(h_nSeedPerTrack) h_nSeedPerTrack->Fill(tkSeeds.size());
00144
00145
00146
00147 if(theSeedCleaner){
00148 theSeedCleaner->clean(muRef,region,tkSeeds);
00149 LogDebug("TSGFromL2Muon") << tkSeeds.size() << " seeds for this L2 afther cleaning.";
00150 }
00151 if(h_nGoodSeedPerTrack) h_nGoodSeedPerTrack->Fill(tkSeeds.size());
00152
00153 uint is=0;
00154 uint isMax=tkSeeds.size();
00155 LogDebug("TSGFromL2Muon")<<isMax<<" seeds for this L2.";
00156 for (;is!=isMax;++is){
00157 result->push_back( L3MuonTrajectorySeed(tkSeeds[is], muRef));
00158 }
00159
00160 }
00161
00162 if(h_nGoodSeedPerEvent) h_nGoodSeedPerEvent->Fill(result->size());
00163
00164
00165
00166
00167 LogDebug("TSGFromL2Muon")<<result->size()<<" trajectory seeds to the events";
00168
00169
00170 ev.put(result);
00171 }
00172