22 using AllDist = std::vector<std::vector<float>>;
54 #include <Math/VectorUtil.h>
60 using namespace ROOT::Math::VectorUtil;
61 using namespace stdcomb;
64 if (algoName ==
"BruteForce") {
65 return Algo::kBruteForce;
66 }
else if (algoName ==
"SwitchMode") {
67 return Algo::kSwitchMode;
68 }
else if (algoName ==
"MixMode") {
69 return Algo::kMixMode;
71 throw cms::Exception(
"OneToOne Constructor") <<
"wrong matching method in ParameterSet";
77 case Algo::kBruteForce:
79 case Algo::kSwitchMode:
91 algoMethod_(
algo(cfg.getParameter<
string>(
"algoMethod"))) {
92 produces<CandViewMatchMap>(
"src2mtc");
93 produces<CandViewMatchMap>(
"mtc2src");
102 edm::LogVerbatim(
"CandOneToOneDeltaRMatcher") <<
"======== Source Collection =======";
105 <<
" pt source " <<
c->pt() <<
" " <<
c->eta() <<
" " <<
c->phi() << endl;
107 edm::LogVerbatim(
"CandOneToOneDeltaRMatcher") <<
"======== Matched Collection =======";
110 <<
" pt source " <<
c->pt() <<
" " <<
c->eta() <<
" " <<
c->phi() << endl;
113 const int nSrc = source->size();
114 const int nMtc = matched->size();
116 const int nMin =
min(source->size(), matched->size());
117 const int nMax =
max(source->size(), matched->size());
121 std::vector<std::vector<float>> allDist;
124 allDist.reserve(source->size());
126 vector<float> tempAllDist;
127 tempAllDist.reserve(matched->size());
129 tempAllDist.push_back(
DeltaR(iSr->p4(), iMt->p4()));
131 allDist.emplace_back(
std::move(tempAllDist));
134 allDist.reserve(matched->size());
136 vector<float> tempAllDist;
137 tempAllDist.reserve(source->size());
139 tempAllDist.push_back(
DeltaR(iSr->p4(), iMt->p4()));
141 allDist.emplace_back(
std::move(tempAllDist));
156 int nLoopToDo = (int)(TMath::Factorial(nMax) / TMath::Factorial(nMax - nMin));
157 edm::LogVerbatim(
"CandOneToOneDeltaRMatcher") <<
"nLoop:" << nLoopToDo << endl;
171 if (nLoopToDo < 10000) {
178 for (
int i1 = 0; i1 < nMin; i1++)
180 <<
"min: " << i1 <<
" " << bestCB[i1] <<
" " << allDist[i1][bestCB[i1]];
189 auto matchMapSrMt = std::make_unique<CandViewMatchMap>();
190 auto matchMapMtSr = std::make_unique<CandViewMatchMap>();
192 for (
int c = 0;
c != nMin;
c++) {
193 if (source->size() <= matched->size()) {
194 matchMapSrMt->insert(source->refAt(
c), matched->refAt(bestCB[
c]));
195 matchMapMtSr->insert(matched->refAt(bestCB[c]), source->refAt(c));
197 matchMapSrMt->insert(source->refAt(bestCB[
c]), matched->refAt(c));
198 matchMapMtSr->insert(matched->refAt(c), source->refAt(bestCB[c]));
220 for (vector<int>::const_iterator it = best.begin(); it != best.end(); it++) {
221 myLength += allDist[row][*it];
240 float totalDeltaR = 0;
241 float BestTotalDeltaR = 1000;
244 for (
int i1 = 0; i1 < nMax; i1++)
247 for (
int i1 = 0; i1 < nMin; i1++)
252 for (
int cnt = 0; cnt < TMath::Factorial(nMin); cnt++) {
253 totalDeltaR =
length(cb, allDist);
254 if (totalDeltaR < BestTotalDeltaR) {
255 BestTotalDeltaR = totalDeltaR;
258 next_permutation(cb.begin(), cb.end());
278 for (
int i1 = 0; i1 < nMin; i1++) {
280 for (
int i2 = 1; i2 < nMax; i2++)
281 if (allDist[i1][i2] < allDist[i1][minInd])
283 bestCB.push_back(minInd);
289 for (
int i1 = 0; i1 < nMin; i1++) {
290 for (
int i2 = i1 + 1; i2 < nMin; i2++) {
291 if (bestCB[i1] == bestCB[i2]) {
293 if (allDist[i1][(bestCB[i1])] <= allDist[i2][(bestCB[i2])]) {
294 allDist[i2][(bestCB[i2])] = 1000;
296 for (
int i3 = 1; i3 < nMax; i3++)
297 if (allDist[i2][i3] < allDist[i2][minInd])
301 allDist[i1][(bestCB[i1])] = 1000;
303 for (
int i3 = 1; i3 < nMax; i3++)
304 if (allDist[i1][i3] < allDist[i1][minInd])
std::vector< int > AlgoSwitchMethod(int, int, AllDist &) const
Log< level::Info, true > LogVerbatim
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
const edm::EventSetup & c
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
CandOneToOneDeltaRMatcher(const edm::ParameterSet &)
static Algo algo(std::string const &)
std::vector< std::vector< float >> AllDist
const edm::EDGetTokenT< reco::CandidateView > sourceToken_
std::vector< int > AlgoBruteForce(int, int, const AllDist &) const
double length(const std::vector< int > &, const AllDist &) const
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
const edm::EDGetTokenT< reco::CandidateView > matchedToken_
static const char * algoName(Algo)
bool next_combination(BidIt n_begin, BidIt n_end, BidIt r_begin, BidIt r_end)
static std::string const source