Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-05 00:08:11

0001 // -*- C++ -*-
0002 //
0003 // Package:    PFTracking
0004 // Class:      ElectronSeedMerger
0005 //
0006 // Original Author:  Michele Pioppi
0007 
0008 #include "DataFormats/EgammaReco/interface/ElectronSeed.h"
0009 #include "DataFormats/TrackReco/interface/Track.h"
0010 #include "DataFormats/TrajectorySeed/interface/PropagationDirection.h"
0011 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/MakerMacros.h"
0014 #include "FWCore/Framework/interface/global/EDProducer.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
0017 
0018 class ElectronSeedMerger : public edm::global::EDProducer<> {
0019 public:
0020   explicit ElectronSeedMerger(const edm::ParameterSet&);
0021 
0022 private:
0023   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0024 
0025   const edm::EDGetTokenT<reco::ElectronSeedCollection> ecalSeedToken_;
0026   edm::EDGetTokenT<reco::ElectronSeedCollection> tkSeedToken_;
0027 };
0028 
0029 using namespace edm;
0030 using namespace std;
0031 using namespace reco;
0032 
0033 ElectronSeedMerger::ElectronSeedMerger(const ParameterSet& iConfig)
0034     : ecalSeedToken_{consumes<ElectronSeedCollection>(iConfig.getParameter<InputTag>("EcalBasedSeeds"))} {
0035   edm::InputTag tkSeedLabel_ = iConfig.getParameter<InputTag>("TkBasedSeeds");
0036   if (!tkSeedLabel_.label().empty())
0037     tkSeedToken_ = consumes<ElectronSeedCollection>(tkSeedLabel_);
0038 
0039   produces<ElectronSeedCollection>();
0040 }
0041 
0042 // ------------ method called to produce the data  ------------
0043 void ElectronSeedMerger::produce(edm::StreamID, Event& iEvent, const EventSetup& iSetup) const {
0044   //HANDLE THE INPUT SEED COLLECTIONS
0045   auto const& eSeeds = iEvent.get(ecalSeedToken_);
0046 
0047   ElectronSeedCollection tSeedsEmpty;
0048   auto const& tSeeds = tkSeedToken_.isUninitialized() ? tSeedsEmpty : iEvent.get(tkSeedToken_);
0049 
0050   //CREATE OUTPUT COLLECTION
0051   auto output = std::make_unique<ElectronSeedCollection>();
0052   output->reserve(eSeeds.size() + tSeeds.size());
0053 
0054   //VECTOR FOR MATCHED SEEDS
0055   vector<bool> tSeedsMatched(tSeeds.size(), false);
0056 
0057   //LOOP OVER THE ECAL SEED COLLECTION
0058   for (auto newSeed : eSeeds) {  //  make a copy
0059 
0060     //LOOP OVER THE TK SEED COLLECTION
0061     int it = -1;
0062     for (auto const& tSeed : tSeeds) {
0063       it++;
0064 
0065       //HITS FOR TK SEED
0066       unsigned int hitShared = 0;
0067       unsigned int hitSeed = 0;
0068       for (auto const& eh : newSeed.recHits()) {
0069         if (!eh.isValid())
0070           continue;
0071         hitSeed++;
0072 
0073         for (auto const& th : tSeed.recHits()) {
0074           if (!th.isValid())
0075             continue;
0076           //CHECK THE HIT COMPATIBILITY
0077           if (eh.sharesInput(&th, TrackingRecHit::all)) {
0078             hitShared++;
0079             break;
0080           }
0081         }
0082       }
0083       if (hitShared == hitSeed) {
0084         tSeedsMatched[it] = true;
0085         newSeed.setCtfTrack(tSeed.ctfTrack());
0086         break;
0087       }
0088       if (hitShared == (hitSeed - 1)) {
0089         newSeed.setCtfTrack(tSeed.ctfTrack());
0090       } else if ((hitShared > 0 || tSeed.nHits() == 0) && !newSeed.isTrackerDriven()) {
0091         //try to find hits in the full track
0092         unsigned int hitSharedOnTrack = 0;
0093         for (auto const& eh : newSeed.recHits()) {
0094           if (!eh.isValid())
0095             continue;
0096           for (auto const* th : tSeed.ctfTrack()->recHits()) {
0097             if (!th->isValid())
0098               continue;
0099             // hits on tracks are not matched : use ::some
0100             if (eh.sharesInput(th, TrackingRecHit::some)) {
0101               hitSharedOnTrack++;
0102               break;
0103             }
0104           }
0105         }
0106         if (hitSharedOnTrack == hitSeed) {
0107           tSeedsMatched[it] = true;
0108           newSeed.setCtfTrack(tSeed.ctfTrack());
0109           break;
0110         }
0111         if (hitSharedOnTrack == (hitSeed - 1)) {
0112           newSeed.setCtfTrack(tSeed.ctfTrack());
0113         }
0114       }
0115     }
0116 
0117     output->push_back(newSeed);
0118   }
0119 
0120   //FILL THE COLLECTION WITH UNMATCHED TK-BASED SEED
0121   for (unsigned int it = 0; it < tSeeds.size(); it++) {
0122     if (!tSeedsMatched[it])
0123       output->push_back(tSeeds[it]);
0124   }
0125 
0126   //PUT THE MERGED COLLECTION IN THE EVENT
0127   iEvent.put(std::move(output));
0128 }
0129 
0130 DEFINE_FWK_MODULE(ElectronSeedMerger);