File indexing completed on 2021-11-05 00:08:11
0001
0002
0003
0004
0005
0006
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
0043 void ElectronSeedMerger::produce(edm::StreamID, Event& iEvent, const EventSetup& iSetup) const {
0044
0045 auto const& eSeeds = iEvent.get(ecalSeedToken_);
0046
0047 ElectronSeedCollection tSeedsEmpty;
0048 auto const& tSeeds = tkSeedToken_.isUninitialized() ? tSeedsEmpty : iEvent.get(tkSeedToken_);
0049
0050
0051 auto output = std::make_unique<ElectronSeedCollection>();
0052 output->reserve(eSeeds.size() + tSeeds.size());
0053
0054
0055 vector<bool> tSeedsMatched(tSeeds.size(), false);
0056
0057
0058 for (auto newSeed : eSeeds) {
0059
0060
0061 int it = -1;
0062 for (auto const& tSeed : tSeeds) {
0063 it++;
0064
0065
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
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
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
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
0121 for (unsigned int it = 0; it < tSeeds.size(); it++) {
0122 if (!tSeedsMatched[it])
0123 output->push_back(tSeeds[it]);
0124 }
0125
0126
0127 iEvent.put(std::move(output));
0128 }
0129
0130 DEFINE_FWK_MODULE(ElectronSeedMerger);