1 #ifndef RecoParticleFlow_Benchmark_PFBenchmarkAlgo_h
2 #define RecoParticleFlow_Benchmark_PFBenchmarkAlgo_h
20 template <
typename T,
typename U>
21 static double deltaEt(
const T *,
const U *);
24 template <
typename T,
typename U>
25 static double deltaEta(
const T *,
const U *);
28 template <
typename T,
typename U>
29 static double deltaPhi(
const T *,
const U *);
32 template <
typename T,
typename U>
33 static double deltaR(
const T *,
const U *);
36 template <
typename T,
typename Collection>
40 template <
typename T,
typename Collection>
44 template <
typename T,
typename Collection>
48 template <
typename T,
typename Collection>
52 template <
typename T,
typename Collection>
56 template <
typename T,
typename Collection>
57 static Collection
findAllInCone(
const T *,
const Collection *,
double);
60 template <
typename T,
typename Collection>
66 template <
typename T,
typename U,
template <
typename,
typename>
class Sorter>
67 static void vector_sort(std::vector<T> &candidates, Sorter<T,U> S) {
68 sort(candidates.begin(),candidates.end(),S);
74 candidates.push_back(*c1);
78 template <
typename T,
typename U,
template <
typename,
typename>
class Sorter>
126 template <
typename T,
typename U>
130 throw cms::Exception(
"Invalid Arg") <<
"attempted to calculate deltaEt for invalid Candidate(s)";
132 return c1->et() - c2->et();
137 template <
typename T,
typename U>
141 throw cms::Exception(
"Invalid Arg") <<
"attempted to calculate deltaEta for invalid Candidate(s)";
143 return c1->eta() - c2->eta();
148 template <
typename T,
typename U>
152 throw cms::Exception(
"Invalid Arg") <<
"attempted to calculate deltaPhi for invalid Candidate(s)";
155 double phi1 = c1->phi();
159 double phi2 = c2->phi();
167 double deltaphi=-999.0;
168 if (fabs(phi1 - phi2)<
M_PI)
170 deltaphi=(phi1-phi2);
176 deltaphi=(2*
M_PI - fabs(phi1 - phi2));
180 deltaphi=-(2*
M_PI - fabs(phi1 - phi2));
188 template <
typename T,
typename U>
192 throw cms::Exception(
"Invalid Arg") <<
"attempted to calculate deltaR for invalid Candidate(s)";
199 template <
typename T,
typename Collection>
205 if (!c1)
throw cms::Exception(
"Invalid Arg") <<
"attempted to match invalid Candidate";
206 if (!candidates)
throw cms::Exception(
"Invalid Arg") <<
"attempted to match to invalid Collection";
208 double minDeltaR = 9999.;
212 for (
unsigned int i = 0;
i < candidates->size();
i++) {
214 const U *c2 = &(*candidates)[
i];
215 if (!c2)
throw cms::Exception(
"Invalid Arg") <<
"attempted to match to invalid Candidate";
219 if (dR <= minDeltaR) { match = c2; minDeltaR =
dR; }
229 template <
typename T,
typename Collection>
235 if (!c1)
throw cms::Exception(
"Invalid Arg") <<
"attempted to match invalid Candidate";
236 if (!candidates)
throw cms::Exception(
"Invalid Arg") <<
"attempted to match to invalid Collection";
242 for (
unsigned int i = 0;
i < candidates->size();
i++) {
244 const T *c2 = &(*candidates)[
i];
245 if (!c2)
throw cms::Exception(
"Invalid Arg") <<
"attempted to match to invalid Candidate";
248 double dEt = fabs(
deltaEt(c1,c2));
249 if (dEt <= minDeltaEt) { match = c2; minDeltaEt = dEt; }
259 template <
typename T,
typename Collection>
265 if (!candidates)
throw cms::Exception(
"Invalid Arg") <<
"attempted to copy invalid Collection";
269 for (
unsigned int i = 0;
i < candidates->size();
i++)
278 template <
typename T,
typename Collection>
284 if (!c1)
throw cms::Exception(
"Invalid Arg") <<
"attempted to sort by invalid Candidate";
285 if (!candidates)
throw cms::Exception(
"Invalid Arg") <<
"attempted to sort invalid Candidates";
293 template <
typename T,
typename Collection>
299 if (!c1)
throw cms::Exception(
"Invalid Arg") <<
"attempted to sort by invalid Candidate";
300 if (!candidates)
throw cms::Exception(
"Invalid Arg") <<
"attempted to sort invalid Candidates";
308 template <
typename T,
typename Collection>
314 if (!c1)
throw cms::Exception(
"Invalid Arg") <<
"attempted to constrain to invalid Candidate";
315 if (!candidates)
throw cms::Exception(
"Invalid Arg") <<
"attempted to constrain invalid Collection";
316 if (ConeSize <= 0)
throw cms::Exception(
"Invalid Arg") <<
"zero or negative cone size specified";
318 Collection constrained;
320 for (
unsigned int i = 0;
i < candidates->size();
i++) {
322 const U *c2 = &(*candidates)[
i];
326 if (dR < ConeSize)
vector_add(c2,constrained);
337 template <
typename T,
typename Collection>
343 if (!c1)
throw cms::Exception(
"Invalid Arg") <<
"attempted to constrain to invalid Candidate";
344 if (!candidates)
throw cms::Exception(
"Invalid Arg") <<
"attempted to constrain invalid Collection";
345 if (EtWindow <= 0)
throw cms::Exception(
"Invalid Arg") <<
"zero or negative cone size specified";
347 Collection constrained;
351 for (
unsigned int i = 0;
i < candidates->size();
i++) {
353 const U *c2 = &(*candidates)[
i];
356 double dEt = fabs(
deltaEt(c1,c2));
357 if (dEt < EtWindow)
vector_add(c2,constrained);
367 #endif // RecoParticleFlow_Benchmark_PFBenchmarkAlgo_h
static Collection copyCollection(const Collection *)
edm::Ref< Container > Ref
static void vector_add(const T *c1, edm::OwnVector< T > &candidates)
static void vector_add(const T *c1, std::vector< T > &candidates)
bool operator()(const U &c1, const U &c2) const
static void sortByDeltaR(const T *, Collection &)
static const Collection::value_type * matchByDeltaEt(const T *, const Collection *)
static double deltaEt(const T *, const U *)
bool operator()(const U &c1, const U &c2) const
static double deltaEta(const T *, const U *)
static void vector_sort(std::vector< T > &candidates, Sorter< T, U > S)
static Collection findAllInCone(const T *, const Collection *, double)
static double deltaR(const T *, const U *)
deltaRSorter(const T *Ref)
Container::value_type value_type
static const Collection::value_type * matchByDeltaR(const T *, const Collection *)
static void sortByDeltaEt(const T *, Collection &)
static void vector_sort(edm::OwnVector< T > &candidates, Sorter< T, U > S)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
static double deltaPhi(const T *, const U *)
static Collection findAllInEtWindow(const T *, const Collection *, double)
deltaEtSorter(const T *Ref)
Power< A, B >::type pow(const A &a, const B &b)