47 using CandidateToDuplicate = std::vector<std::pair<int, int>>;
51 using MVACollection = std::vector<float>;
52 using QualityMaskCollection = std::vector<unsigned char>;
99 desc.
add<
std::string>(
"trackAlgoPriorityOrder",
"trackAlgoPriorityOrder");
100 desc.
add<
int>(
"diffHitsCut", 5);
102 descriptions.
add(
"DuplicateListMerger", desc);
106 : collectionCloner(producesCollector(), iPara,
true),
107 mergedTrackSource_(iPara.getParameter<edm::
InputTag>(
"mergedSource"), consumesCollector()),
108 originalTrackSource_(iPara.getParameter<edm::
InputTag>(
"originalSource"), consumesCollector()),
109 priorityName_(iPara.getParameter<std::
string>(
"trackAlgoPriorityOrder")) {
112 candidateComponents_ = consumes<CandidateToDuplicate>(iPara.getParameter<
edm::InputTag>(
"candidateComponents"));
114 mergedMVAValsToken_ = consumes<MVACollection>(iPara.getParameter<
edm::InputTag>(
"mergedMVAVals"));
115 originalMVAValsToken_ = consumes<MVACollection>(iPara.getParameter<
edm::InputTag>(
"originalMVAVals"));
116 priorityOrderToken_ = esConsumes<TrackAlgoPriorityOrder, CkfComponentsRecord>(
edm::ESInputTag(
"", priorityName_));
118 produces<MVACollection>(
"MVAValues");
119 produces<QualityMaskCollection>(
"QualityMasks");
122 DuplicateListMerger::~DuplicateListMerger() {
128 auto const& originals = originalTrackSource_.tracks(iEvent);
129 auto const&
merged = mergedTrackSource_.tracks(iEvent);
130 auto const& candIndices = mergedTrackSource_.indicesInput(iEvent);
133 iEvent.
getByToken(candidateSource_, candidateH);
137 iEvent.
getByToken(candidateComponents_, candidateComponentsH);
138 auto const& candidateComponents = *candidateComponentsH;
143 iEvent.
getByToken(originalMVAValsToken_, originalMVAStore);
144 iEvent.
getByToken(mergedMVAValsToken_, mergedMVAStore);
149 MVACollection mvaVec;
151 auto mergedMVA = *mergedMVAStore;
154 std::vector<std::array<int, 3>> matches;
155 for (
int i = 0;
i < (int)
merged.size(); ++
i) {
156 auto cInd = candIndices[
i];
160 if (mergedMVA[
i] < -0.7
f)
164 int dHits = cand.nRecHits() - matchedTrack.
recHitsSize();
165 if (dHits > diffHitsCut_)
167 matches.push_back(std::array<int, 3>{{
i, candidateComponents[cInd].first, candidateComponents[cInd].second}});
171 if (matches.size() > 1)
172 for (
auto matchIter0 = matches.begin(); matchIter0 != matches.end() - 1; ++matchIter0) {
173 if ((*matchIter0)[0] < 0)
175 auto nchi2 =
merged[(*matchIter0)[0]].normalizedChi2();
176 for (
auto matchIter1 = matchIter0 + 1; matchIter1 != matches.end(); ++matchIter1) {
177 if ((*matchIter1)[0] < 0)
179 if ((*matchIter0)[1] == (*matchIter1)[1] || (*matchIter0)[1] == (*matchIter1)[2] ||
180 (*matchIter0)[2] == (*matchIter1)[1] || (*matchIter0)[2] == (*matchIter1)[2]) {
181 auto nchi2_1 =
merged[(*matchIter1)[0]].normalizedChi2();
182 if (nchi2_1 < nchi2) {
183 (*matchIter0)[0] = -1;
186 (*matchIter1)[0] = -1;
193 auto pmvas = std::make_unique<MVACollection>();
194 auto pquals = std::make_unique<QualityMaskCollection>();
197 std::vector<int> inputTracks;
199 std::vector<unsigned int> selId;
200 auto ntotTk = matches.size();
206 for (
auto matchIter0 = matches.begin(); matchIter0 != matches.end(); matchIter0++) {
207 if ((*matchIter0)[0] < 0)
209 selId.push_back((*matchIter0)[0]);
211 pmvas->push_back(mergedMVA[(*matchIter0)[0]]);
213 const reco::Track& inTrk1 = originals[(*matchIter0)[1]];
214 const reco::Track& inTrk2 = originals[(*matchIter0)[2]];
225 inputTracks.push_back((*matchIter0)[1]);
226 inputTracks.push_back((*matchIter0)[2]);
231 producer(mergedTrackSource_, selId);
234 for (
auto isel = 0U; isel < nsel; ++isel) {
236 auto& otk = (*
producer.selTracks_)[isel];
237 otk.setQualityMask((*pquals)[isel]);
239 otk.setOriginalAlgorithm(oriAlgo[isel]);
240 otk.setAlgoMask(algoMask[isel]);
244 for (
int i = 0;
i < (int)originals.size();
i++) {
246 if (
std::find(inputTracks.begin(), inputTracks.end(),
i) != inputTracks.end())
249 pmvas->push_back((*originalMVAStore)[
i]);
253 producer(originalTrackSource_, selId);
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
static void fill(edm::ParameterSetDescription &desc)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
TrackAlgorithm
track algorithm
TrackAlgorithm algo() const
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::bitset< algoSize > AlgoMask
algo mask
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
AlgoMask algoMask() const
T getParameter(std::string const &) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
constexpr std::array< unsigned int, reco::TrackBase::algoSize > trackAlgoPriorityOrder
#define declareDynArray(T, n, x)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const