24 double lenght(
const std::vector<int>& );
30 std::vector < std::vector<float> >
AllDist;
51 #include <Math/VectorUtil.h> 64 produces<CandViewMatchMap>(
"src2mtc");
65 produces<CandViewMatchMap>(
"mtc2src");
78 edm::LogVerbatim(
"CandOneToOneDeltaRMatcher") <<
"======== Source Collection =======";
80 edm::LogVerbatim(
"CandOneToOneDeltaRMatcher") <<
" pt source " <<
c->pt() <<
" " <<
c->eta() <<
" " <<
c->phi() << endl;
82 edm::LogVerbatim(
"CandOneToOneDeltaRMatcher") <<
"======== Matched Collection =======";
84 edm::LogVerbatim(
"CandOneToOneDeltaRMatcher") <<
" pt source " <<
c->pt() <<
" " <<
c->eta() <<
" " <<
c->phi() << endl;
87 const int nSrc = source->
size();
88 const int nMtc = matched->
size();
90 const int nMin =
min( source->
size() , matched->
size() );
91 const int nMax =
max( source->
size() , matched->
size() );
92 if( nMin < 1 )
return;
98 vector <float> tempAllDist;
100 iMt != matched->
end();
102 tempAllDist.push_back(
DeltaR( iSr->p4() , iMt->p4() ) );
104 AllDist.push_back(tempAllDist);
109 iMt != matched->
end();
111 vector <float> tempAllDist;
113 iSr != source->
end();
115 tempAllDist.push_back(
DeltaR( iSr->p4() , iMt->p4() ) );
117 AllDist.push_back(tempAllDist);
133 int nLoopToDo = (
int) ( TMath::Factorial(nMax) / TMath::Factorial(nMax - nMin) );
134 edm::LogVerbatim(
"CandOneToOneDeltaRMatcher") <<
"nLoop:" << nLoopToDo << endl;
151 if( nLoopToDo < 10000 ) {
158 throw cms::Exception(
"OneToOne Constructor") <<
"wrong matching method in ParameterSet";
161 for(
int i1=0; i1<nMin; i1++)
edm::LogVerbatim(
"CandOneToOneDeltaRMatcher") <<
"min: " << i1 <<
" " << bestCB[i1] <<
" " <<
AllDist[i1][bestCB[i1]];
170 auto matchMapSrMt = std::make_unique<CandViewMatchMap>();
171 auto matchMapMtSr = std::make_unique<CandViewMatchMap>();
173 for(
int c = 0;
c != nMin;
c ++ ) {
174 if( source->
size() <= matched->
size() ) {
175 matchMapSrMt->insert( source ->refAt(
c ), matched->
refAt(bestCB[
c] ) );
176 matchMapMtSr->insert( matched->
refAt(bestCB[c] ), source ->
refAt(c ) );
178 matchMapSrMt->insert( source ->refAt(bestCB[
c] ), matched->
refAt(c ) );
179 matchMapMtSr->insert( matched->
refAt(c ), source ->
refAt(bestCB[c] ) );
204 for(vector<int>::const_iterator it=best.begin(); it!=best.end(); it++ ) {
226 float BestTotalDeltaR=1000;
228 for(
int i1=0; i1<nMax; i1++) ca.push_back(i1);
229 for(
int i1=0; i1<nMin; i1++) cb.push_back(i1);
234 for(
int cnt=0;cnt<TMath::Factorial(nMin); cnt++)
237 if ( totalDeltaR < BestTotalDeltaR ) {
238 BestTotalDeltaR = totalDeltaR;
241 next_permutation( cb.begin() , cb.end() );
263 for(
int i1=0; i1<nMin; i1++) {
265 for(
int i2=1; i2<nMax; i2++)
if(
AllDist[i1][i2] <
AllDist[i1][minInd] ) minInd = i2;
266 bestCB.push_back(minInd);
272 for(
int i1=0;i1<nMin;i1++){
273 for(
int i2=i1+1;i2<nMin;i2++){
274 if ( bestCB[i1] == bestCB[i2] ) {
277 AllDist[i2][(bestCB[i2])]= 1000;
279 for(
int i3=1; i3<nMax; i3++)
if(
AllDist[i2][i3] <
AllDist[i2][minInd] ) minInd = i3;
282 AllDist[i1][(bestCB[i1])]= 1000;
284 for(
int i3=1; i3<nMax; i3++)
if(
AllDist[i1][i3] <
AllDist[i1][minInd] ) minInd = i3;
edm::EDGetTokenT< reco::CandidateView > sourceToken_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
std::vector< std::vector< float > > AllDist
bool getByToken(EDGetToken token, Handle< PROD > &result) const
~CandOneToOneDeltaRMatcher() override
std::vector< int > AlgoSwitchMethod(int, int)
std::vector< int > AlgoBruteForce(int, int)
CandOneToOneDeltaRMatcher(const edm::ParameterSet &)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
RefToBase< value_type > refAt(size_type i) const
#define DEFINE_FWK_MODULE(type)
const_iterator begin() const
void produce(edm::Event &, const edm::EventSetup &) override
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
const_iterator end() const
double lenght(const std::vector< int > &)
bool next_combination(BidIt n_begin, BidIt n_end, BidIt r_begin, BidIt r_end)
static std::string const source
edm::EDGetTokenT< reco::CandidateView > matchedToken_