Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-31 02:17:41

0001 #include "TSGFromL1Muon.h"
0002 
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "DataFormats/Common/interface/Handle.h"
0006 #include "FWCore/Framework/interface/ESHandle.h"
0007 #include "FWCore/Framework/interface/ConsumesCollector.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/Framework/interface/ConsumesCollector.h"
0010 
0011 #include "RecoTracker/TkTrackingRegions/interface/OrderedHitsGeneratorFactory.h"
0012 #include "RecoTracker/TkTrackingRegions/interface/OrderedHitsGenerator.h"
0013 
0014 #include "RecoMuon/TrackerSeedGenerator/interface/L1MuonPixelTrackFitter.h"
0015 #include "RecoMuon/TrackerSeedGenerator/interface/L1MuonSeedsMerger.h"
0016 
0017 #include "RecoMuon/TrackerSeedGenerator/interface/L1MuonRegionProducer.h"
0018 
0019 #include "RecoPixelVertexing/PixelTrackFitting/interface/PixelTrackFilter.h"
0020 
0021 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0022 
0023 #include "DataFormats/TrackReco/interface/Track.h"
0024 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0025 
0026 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
0027 
0028 #include <vector>
0029 
0030 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
0031 #include "DataFormats/MuonSeed/interface/L3MuonTrajectorySeedCollection.h"
0032 
0033 using namespace reco;
0034 using namespace l1extra;
0035 
0036 namespace {
0037   template <class T>
0038   T sqr(T t) {
0039     return t * t;
0040   }
0041 }  // namespace
0042 
0043 TSGFromL1Muon::TSGFromL1Muon(const edm::ParameterSet& cfg)
0044     : theFieldToken(esConsumes()), theSFPTConfig(consumesCollector()) {
0045   produces<L3MuonTrajectorySeedCollection>();
0046   theSourceTag = cfg.getParameter<edm::InputTag>("L1MuonLabel");
0047 
0048   edm::ConsumesCollector iC = consumesCollector();
0049   theFilterToken = consumes<PixelTrackFilter>(cfg.getParameter<edm::InputTag>("Filter"));
0050 
0051   edm::ParameterSet hitsfactoryPSet = cfg.getParameter<edm::ParameterSet>("OrderedHitsFactoryPSet");
0052   std::string hitsfactoryName = hitsfactoryPSet.getParameter<std::string>("ComponentName");
0053   theHitGenerator = OrderedHitsGeneratorFactory::get()->create(hitsfactoryName, hitsfactoryPSet, iC);
0054 
0055   theSourceToken = iC.consumes<L1MuonParticleCollection>(theSourceTag);
0056 
0057   theRegionProducer =
0058       std::make_unique<L1MuonRegionProducer>(cfg.getParameter<edm::ParameterSet>("RegionFactoryPSet"), iC);
0059   theFitter = std::make_unique<L1MuonPixelTrackFitter>(cfg.getParameter<edm::ParameterSet>("FitterPSet"));
0060 
0061   edm::ParameterSet cleanerPSet = cfg.getParameter<edm::ParameterSet>("CleanerPSet");
0062   theMerger = std::make_unique<L1MuonSeedsMerger>(cleanerPSet);
0063 }
0064 
0065 TSGFromL1Muon::~TSGFromL1Muon() = default;
0066 
0067 void TSGFromL1Muon::produce(edm::Event& ev, const edm::EventSetup& es) {
0068   auto result = std::make_unique<L3MuonTrajectorySeedCollection>();
0069 
0070   edm::Handle<L1MuonParticleCollection> l1muon;
0071   ev.getByToken(theSourceToken, l1muon);
0072 
0073   edm::Handle<PixelTrackFilter> hfilter;
0074   ev.getByToken(theFilterToken, hfilter);
0075   const PixelTrackFilter& filter = *hfilter;
0076 
0077   const auto& field = es.getData(theFieldToken);
0078   LogDebug("TSGFromL1Muon") << l1muon->size() << " l1 muons to seed from.";
0079 
0080   L1MuonParticleCollection::const_iterator muItr = l1muon->begin();
0081   L1MuonParticleCollection::const_iterator muEnd = l1muon->end();
0082   for (size_t iL1 = 0; muItr < muEnd; ++muItr, ++iL1) {
0083     if (muItr->gmtMuonCand().empty())
0084       continue;
0085 
0086     const L1MuGMTCand& muon = muItr->gmtMuonCand();
0087     l1extra::L1MuonParticleRef l1Ref(l1muon, iL1);
0088 
0089     theRegionProducer->setL1Constraint(muon);
0090     theFitter->setL1Constraint(muon);
0091 
0092     typedef std::vector<std::unique_ptr<TrackingRegion> > Regions;
0093     Regions regions = theRegionProducer->regions(es);
0094     for (Regions::const_iterator ir = regions.begin(); ir != regions.end(); ++ir) {
0095       L1MuonSeedsMerger::TracksAndHits tracks;
0096       const TrackingRegion& region = **ir;
0097       const OrderedSeedingHits& candidates = theHitGenerator->run(region, ev, es);
0098 
0099       unsigned int nSets = candidates.size();
0100       for (unsigned int ic = 0; ic < nSets; ic++) {
0101         const SeedingHitSet& hits = candidates[ic];
0102         std::vector<const TrackingRecHit*> trh;
0103         for (unsigned int i = 0, nHits = hits.size(); i < nHits; ++i)
0104           trh.push_back(hits[i]->hit());
0105 
0106         theFitter->setPxConstraint(hits);
0107         reco::Track* track = theFitter->run(field, trh, region);
0108         if (!track)
0109           continue;
0110 
0111         if (!filter(track, trh)) {
0112           delete track;
0113           continue;
0114         }
0115         tracks.push_back(L1MuonSeedsMerger::TrackAndHits(track, hits));
0116       }
0117 
0118       if (theMerger)
0119         theMerger->resolve(tracks);
0120       for (L1MuonSeedsMerger::TracksAndHits::const_iterator it = tracks.begin(); it != tracks.end(); ++it) {
0121         SeedFromProtoTrack seed(theSFPTConfig, *(it->first), it->second, es);
0122         if (seed.isValid())
0123           (*result).push_back(L3MuonTrajectorySeed(seed.trajectorySeed(), l1Ref));
0124 
0125         //      GlobalError vtxerr( sqr(region->originRBound()), 0, sqr(region->originRBound()),
0126         //                                               0, 0, sqr(region->originZBound()));
0127         //      SeedFromConsecutiveHits seed( candidates[ic],region->origin(), vtxerr, es);
0128         //      if (seed.isValid()) (*result).push_back( seed.TrajSeed() );
0129         delete it->first;
0130       }
0131     }
0132   }
0133 
0134   LogDebug("TSGFromL1Muon") << result->size() << " seeds to the event.";
0135   ev.put(std::move(result));
0136 }