CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Matchers.h
Go to the documentation of this file.
1 #ifndef __RecoParticleFlow_Benchmark_Matchers__
2 #define __RecoParticleFlow_Benchmark_Matchers__
3 
5 
6 #include <vector>
7 #include <iostream>
8 
9 
10 namespace PFB {
11 
12 
13  template< typename C, typename M>
14  void match( const C& candCollection,
15  const M& matchedCandCollection,
16  std::vector<int>& matchIndices,
17  bool matchCharge = false,
18  float dRMax=-1 ) {
19 
20  // compute distance to each candidate in the matchedCandCollection.
21 
22  float dR2Max = 0;
23  if(dRMax>0) dR2Max = dRMax*dRMax;
24 
25  matchIndices.clear();
26  matchIndices.resize( candCollection.size(), -1);
27 
28  for( unsigned i=0; i<candCollection.size(); ++i) {
29 
30  static const double bigNumber = 1e14;
31  double dR2min = bigNumber;
32  int jMin = -1;
33  for( unsigned jm=0; jm<matchedCandCollection.size(); ++jm) {
34 
35  if( matchCharge &&
36  candCollection[i].charge()!=matchedCandCollection[jm].charge() )
37  continue;
38 
39  double dR2 = reco::deltaR2( candCollection[i],
40  matchedCandCollection[jm] );
41  if( dR2<dR2min ) {
42  dR2min = dR2;
43  jMin = jm;
44  }
45  }
46 
47  if( (dR2Max>0 && dR2min < dR2Max) || dRMax<=0 ) {
48  matchIndices[i] = jMin;
49  /* std::cout<<"match "<<dR2min<<std::endl; */
50  }
51  // store the closest match, no cut on deltaR.
52  }
53  }
54 
55 }
56 
57 #endif
int i
Definition: DBlmapReader.cc:9
void match(const C &candCollection, const M &matchedCandCollection, std::vector< int > &matchIndices, bool matchCharge=false, float dRMax=-1)
Definition: Matchers.h:14
double charge(const std::vector< uint8_t > &Ampls)
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:58