CMS 3D CMS Logo

ElectronSeedMerger.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PFTracking
4 // Class: ElectronSeedMerger
5 //
6 // Original Author: Michele Pioppi
7 
17 
19 public:
20  explicit ElectronSeedMerger(const edm::ParameterSet&);
21  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
22 
23 private:
24  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
25 
28 };
29 
30 using namespace edm;
31 using namespace std;
32 using namespace reco;
33 
36  desc.add<edm::InputTag>("EcalBasedSeeds", edm::InputTag("ecalDrivenElectronSeeds"));
37  desc.add<edm::InputTag>("TkBasedSeeds", edm::InputTag("trackerDrivenElectronSeeds:SeedsForGsf"));
38  descriptions.addWithDefaultLabel(desc);
39 }
40 
42  : ecalSeedToken_{consumes<ElectronSeedCollection>(iConfig.getParameter<InputTag>("EcalBasedSeeds"))} {
43  edm::InputTag tkSeedLabel_ = iConfig.getParameter<InputTag>("TkBasedSeeds");
44  if (!tkSeedLabel_.label().empty())
45  tkSeedToken_ = consumes<ElectronSeedCollection>(tkSeedLabel_);
46 
47  produces<ElectronSeedCollection>();
48 }
49 
50 // ------------ method called to produce the data ------------
52  //HANDLE THE INPUT SEED COLLECTIONS
53  auto const& eSeeds = iEvent.get(ecalSeedToken_);
54 
55  ElectronSeedCollection tSeedsEmpty;
56  auto const& tSeeds = tkSeedToken_.isUninitialized() ? tSeedsEmpty : iEvent.get(tkSeedToken_);
57 
58  //CREATE OUTPUT COLLECTION
59  auto output = std::make_unique<ElectronSeedCollection>();
60  output->reserve(eSeeds.size() + tSeeds.size());
61 
62  //VECTOR FOR MATCHED SEEDS
63  vector<bool> tSeedsMatched(tSeeds.size(), false);
64 
65  //LOOP OVER THE ECAL SEED COLLECTION
66  for (auto newSeed : eSeeds) { // make a copy
67 
68  //LOOP OVER THE TK SEED COLLECTION
69  int it = -1;
70  for (auto const& tSeed : tSeeds) {
71  it++;
72 
73  //HITS FOR TK SEED
74  unsigned int hitShared = 0;
75  unsigned int hitSeed = 0;
76  for (auto const& eh : newSeed.recHits()) {
77  if (!eh.isValid())
78  continue;
79  hitSeed++;
80 
81  for (auto const& th : tSeed.recHits()) {
82  if (!th.isValid())
83  continue;
84  //CHECK THE HIT COMPATIBILITY
85  if (eh.sharesInput(&th, TrackingRecHit::all)) {
86  hitShared++;
87  break;
88  }
89  }
90  }
91  if (hitShared == hitSeed) {
92  tSeedsMatched[it] = true;
93  newSeed.setCtfTrack(tSeed.ctfTrack());
94  break;
95  }
96  if (hitShared == (hitSeed - 1)) {
97  newSeed.setCtfTrack(tSeed.ctfTrack());
98  } else if ((hitShared > 0 || tSeed.nHits() == 0) && !newSeed.isTrackerDriven()) {
99  //try to find hits in the full track
100  unsigned int hitSharedOnTrack = 0;
101  for (auto const& eh : newSeed.recHits()) {
102  if (!eh.isValid())
103  continue;
104  for (auto const* th : tSeed.ctfTrack()->recHits()) {
105  if (!th->isValid())
106  continue;
107  // hits on tracks are not matched : use ::some
108  if (eh.sharesInput(th, TrackingRecHit::some)) {
109  hitSharedOnTrack++;
110  break;
111  }
112  }
113  }
114  if (hitSharedOnTrack == hitSeed) {
115  tSeedsMatched[it] = true;
116  newSeed.setCtfTrack(tSeed.ctfTrack());
117  break;
118  }
119  if (hitSharedOnTrack == (hitSeed - 1)) {
120  newSeed.setCtfTrack(tSeed.ctfTrack());
121  }
122  }
123  }
124 
125  output->push_back(newSeed);
126  }
127 
128  //FILL THE COLLECTION WITH UNMATCHED TK-BASED SEED
129  for (unsigned int it = 0; it < tSeeds.size(); it++) {
130  if (!tSeedsMatched[it])
131  output->push_back(tSeeds[it]);
132  }
133 
134  //PUT THE MERGED COLLECTION IN THE EVENT
135  iEvent.put(std::move(output));
136 }
137 
138 DEFINE_FWK_MODULE(ElectronSeedMerger);
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
ElectronSeedMerger(const edm::ParameterSet &)
std::string const & label() const
Definition: InputTag.h:36
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< ElectronSeed > ElectronSeedCollection
collection of ElectronSeed objects
static void fillDescriptions(ConfigurationDescriptions &descriptions)
virtual void produce(StreamID, Event &, EventSetup const &) const =0
fixed size matrix
HLT enums.
edm::EDGetTokenT< reco::ElectronSeedCollection > tkSeedToken_
Definition: output.py:1
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
def move(src, dest)
Definition: eostools.py:511
const edm::EDGetTokenT< reco::ElectronSeedCollection > ecalSeedToken_