CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQMOffline/PFTau/interface/Matchers.h

Go to the documentation of this file.
00001 #ifndef __RecoParticleFlow_Benchmark_Matchers__
00002 #define __RecoParticleFlow_Benchmark_Matchers__
00003 
00004 #include "DataFormats/Math/interface/deltaR.h"
00005 
00006 #include <vector>
00007 #include <iostream>
00008 
00009 namespace PFB {
00010 
00011    
00012   template< typename C, typename M>
00013     void match(const C& candCollection,
00014                const M& matchedCandCollection, 
00015                std::vector<int>& matchIndices,
00016                bool  matchCharge = false, 
00017                float dRMax=-1)  {
00018     
00019     // compute distance to each candidate in the matchedCandCollection. 
00020   
00021     float dR2Max = 0;
00022     if(dRMax>0) dR2Max = dRMax*dRMax;
00023 
00024     matchIndices.clear();
00025     matchIndices.resize( candCollection.size(), -1);
00026     
00027     for( unsigned i=0; i<candCollection.size(); ++i) {
00028       
00029       static const double bigNumber = 1e14;
00030       double dR2min = bigNumber;
00031       int jMin = -1;
00032       for( unsigned jm=0; jm<matchedCandCollection.size(); ++jm) {
00033         
00034         if( matchCharge && 
00035             candCollection[i].charge()!=matchedCandCollection[jm].charge() ) 
00036           continue;
00037 
00038         double dR2 = reco::deltaR2( candCollection[i],
00039                                     matchedCandCollection[jm] );
00040         
00041         if( dR2<dR2min ) {
00042           dR2min = dR2;
00043           jMin = jm;
00044         }
00045       }
00046       
00047       if( (dR2Max>0 && dR2min < dR2Max) || dRMax<=0 ) {
00048         matchIndices[i] = jMin; 
00049 /*      std::cout<<"match "<<dR2min<<std::endl;  */
00050       }
00051       // store the closest match, no cut on deltaR. 
00052     }
00053   }
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 }
00062    
00063 
00064 #endif