CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Static Public Member Functions | Static Private Member Functions
PFBenchmarkAlgo Class Reference

#include <PFBenchmarkAlgo.h>

Static Public Member Functions

template<typename T , typename Collection >
static Collection copyCollection (const Collection *)
 
template<typename T , typename U >
static double deltaEt (const T *, const U *)
 
template<typename T , typename U >
static double deltaEta (const T *, const U *)
 
template<typename T , typename U >
static double deltaPhi (const T *, const U *)
 
template<typename T , typename U >
static double deltaR (const T *, const U *)
 
template<typename T , typename Collection >
static Collection findAllInCone (const T *, const Collection *, double)
 
template<typename T , typename Collection >
static Collection findAllInEtWindow (const T *, const Collection *, double)
 
template<typename T , typename Collection >
static const
Collection::value_type * 
matchByDeltaEt (const T *, const Collection *)
 
template<typename T , typename Collection >
static const
Collection::value_type * 
matchByDeltaR (const T *, const Collection *)
 
template<typename T , typename Collection >
static void sortByDeltaEt (const T *, Collection &)
 
template<typename T , typename Collection >
static void sortByDeltaR (const T *, Collection &)
 

Static Private Member Functions

template<typename T >
static void vector_add (const T *c1, std::vector< T > &candidates)
 
template<typename T >
static void vector_add (const T *c1, edm::OwnVector< T > &candidates)
 
template<typename T , typename U , template< typename, typename > class Sorter>
static void vector_sort (std::vector< T > &candidates, Sorter< T, U > S)
 
template<typename T , typename U , template< typename, typename > class Sorter>
static void vector_sort (edm::OwnVector< T > &candidates, Sorter< T, U > S)
 

Detailed Description

Definition at line 16 of file PFBenchmarkAlgo.h.

Member Function Documentation

template<typename T , typename Collection >
Collection PFBenchmarkAlgo::copyCollection ( const Collection *  candidates)
static

Definition at line 260 of file PFBenchmarkAlgo.h.

References filterCSVwithJSON::copy, Exception, i, and vector_add().

260  {
261 
262  typedef typename Collection::value_type U;
263 
264  // Try to verify the validity of the Collection
265  if (!candidates) throw cms::Exception("Invalid Arg") << "attempted to copy invalid Collection";
266 
267  Collection copy;
268 
269  for (unsigned int i = 0; i < candidates->size(); i++)
270  vector_add(&(*candidates)[i],copy);
271 
272  return copy;
273 
274 }
int i
Definition: DBlmapReader.cc:9
static void vector_add(const T *c1, std::vector< T > &candidates)
template<typename T , typename U >
double PFBenchmarkAlgo::deltaEt ( const T c1,
const U *  c2 
)
static

Definition at line 127 of file PFBenchmarkAlgo.h.

References Exception, and NULL.

Referenced by findAllInEtWindow(), matchByDeltaEt(), and deltaEtSorter< T, U >::operator()().

127  {
128 
129  if (c1 == NULL || c2 == NULL)
130  throw cms::Exception("Invalid Arg") << "attempted to calculate deltaEt for invalid Candidate(s)";
131 
132  return c1->et() - c2->et();
133 
134 }
#define NULL
Definition: scimark2.h:8
template<typename T , typename U >
double PFBenchmarkAlgo::deltaEta ( const T c1,
const U *  c2 
)
static

Definition at line 138 of file PFBenchmarkAlgo.h.

References Exception, and NULL.

Referenced by deltaR().

138  {
139 
140  if (c1 == NULL || c2 == NULL)
141  throw cms::Exception("Invalid Arg") << "attempted to calculate deltaEta for invalid Candidate(s)";
142 
143  return c1->eta() - c2->eta();
144 
145 }
#define NULL
Definition: scimark2.h:8
template<typename T , typename U >
double PFBenchmarkAlgo::deltaPhi ( const T c1,
const U *  c2 
)
static

Definition at line 149 of file PFBenchmarkAlgo.h.

References Exception, M_PI, and NULL.

Referenced by deltaR().

149  {
150 
151  if (c1 == NULL || c2 == NULL)
152  throw cms::Exception("Invalid Arg") << "attempted to calculate deltaPhi for invalid Candidate(s)";
153 
154 
155  double phi1 = c1->phi();
156  if (phi1 > M_PI) phi1 -= ceil((phi1 - M_PI) / (2 * M_PI)) * 2 * M_PI;
157  if (phi1 <= - M_PI) phi1 += ceil((phi1 + M_PI) / (-2. * M_PI)) * 2. * M_PI;
158 
159  double phi2 = c2->phi();
160  if (phi2 > M_PI) phi2 -= ceil((phi2 - M_PI) / (2 * M_PI)) * 2 * M_PI;
161  if (phi2 <= - M_PI) phi2 += ceil((phi2 + M_PI) / (-2. * M_PI)) * 2 * M_PI;
162 
163  // alternative method:
164  // while (phi > M_PI) phi -= 2 * M_PI;
165  // while (phi <= - M_PI) phi += 2 * M_PI;
166 
167  double deltaphi=-999.0;
168  if (fabs(phi1 - phi2)<M_PI)
169  {
170  deltaphi=(phi1-phi2);
171  }
172  else
173  {
174  if ((phi1-phi2)>0.0)
175  {
176  deltaphi=(2*M_PI - fabs(phi1 - phi2));
177  }
178  else
179  {
180  deltaphi=-(2*M_PI - fabs(phi1 - phi2));
181  }
182  }
183  return deltaphi;
184  //return ( (fabs(phi1 - phi2)<M_PI)?(phi1-phi2):(2*M_PI - fabs(phi1 - phi2) ) ); // FL: wrong
185 }
#define NULL
Definition: scimark2.h:8
#define M_PI
template<typename T , typename U >
double PFBenchmarkAlgo::deltaR ( const T c1,
const U *  c2 
)
static

Definition at line 189 of file PFBenchmarkAlgo.h.

References deltaEta(), deltaPhi(), Exception, NULL, funct::pow(), and mathSSE::sqrt().

Referenced by TauTagValidation::analyze(), GenericBenchmark::fill(), findAllInCone(), matchByDeltaR(), deltaRSorter< T, U >::operator()(), and PFJetBenchmark::process().

189  {
190 
191  if (c1 == NULL || c2 == NULL)
192  throw cms::Exception("Invalid Arg") << "attempted to calculate deltaR for invalid Candidate(s)";
193 
194  return sqrt(std::pow(deltaPhi(c1,c2),2) + std::pow(deltaEta(c1,c2),2));
195 
196 }
#define NULL
Definition: scimark2.h:8
static double deltaEta(const T *, const U *)
T sqrt(T t)
Definition: SSEVec.h:18
static double deltaPhi(const T *, const U *)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
template<typename T , typename Collection >
Collection PFBenchmarkAlgo::findAllInCone ( const T c1,
const Collection *  candidates,
double  ConeSize 
)
static

Definition at line 309 of file PFBenchmarkAlgo.h.

References deltaR(), PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi::dR, Exception, i, sortByDeltaR(), and vector_add().

309  {
310 
311  typedef typename Collection::value_type U;
312 
313  // Try to verify the validity of Candidate and the 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";
317 
318  Collection constrained;
319 
320  for (unsigned int i = 0; i < candidates->size(); i++) {
321 
322  const U *c2 = &(*candidates)[i];
323 
324  // Add in-cone Candidates to the new Collection
325  double dR = deltaR(c1,c2);
326  if (dR < ConeSize) vector_add(c2,constrained);
327 
328  }
329 
330  // Sort and return Collection
331  sortByDeltaR(c1,constrained);
332  return constrained;
333 
334 }
int i
Definition: DBlmapReader.cc:9
static void vector_add(const T *c1, std::vector< T > &candidates)
static void sortByDeltaR(const T *, Collection &)
static double deltaR(const T *, const U *)
template<typename T , typename Collection >
Collection PFBenchmarkAlgo::findAllInEtWindow ( const T c1,
const Collection *  candidates,
double  EtWindow 
)
static

Definition at line 338 of file PFBenchmarkAlgo.h.

References deltaEt(), Exception, i, sortByDeltaEt(), and vector_add().

338  {
339 
340  typedef typename Collection::value_type U;
341 
342  // Try to verify the validity of Candidate and the 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";
346 
347  Collection constrained;
348 
349  //CandidateCollection::const_iterator candidate;
350  //for (candidate = candidates->begin(); candidate != candidates->end(); candidate++) {
351  for (unsigned int i = 0; i < candidates->size(); i++) {
352 
353  const U *c2 = &(*candidates)[i];
354 
355  // Add in-cone Candidates to the new Collection
356  double dEt = fabs(deltaEt(c1,c2));
357  if (dEt < EtWindow) vector_add(c2,constrained);
358 
359  }
360 
361  // Sort and return Collection
362  sortByDeltaEt(c1,constrained);
363  return constrained;
364 
365 }
int i
Definition: DBlmapReader.cc:9
static void vector_add(const T *c1, std::vector< T > &candidates)
static double deltaEt(const T *, const U *)
static void sortByDeltaEt(const T *, Collection &)
template<typename T , typename Collection >
const Collection::value_type * PFBenchmarkAlgo::matchByDeltaEt ( const T c1,
const Collection *  candidates 
)
static

Definition at line 230 of file PFBenchmarkAlgo.h.

References deltaEt(), Exception, i, match(), benchmark_cfg::minDeltaEt, and NULL.

230  {
231 
232  typedef typename Collection::value_type U;
233 
234  // Try to verify the validity of the Candidate and 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";
237 
238  double minDeltaEt = 9999.;
239  const U *match = NULL;
240 
241  // Loop Over the Candidates...
242  for (unsigned int i = 0; i < candidates->size(); i++) {
243 
244  const T *c2 = &(*candidates)[i];
245  if (!c2) throw cms::Exception("Invalid Arg") << "attempted to match to invalid Candidate";
246 
247  // Find Minimal Delta-R
248  double dEt = fabs(deltaEt(c1,c2));
249  if (dEt <= minDeltaEt) { match = c2; minDeltaEt = dEt; }
250 
251  }
252 
253  // Return the Candidate with the smallest dR
254  return match;
255 
256 }
int i
Definition: DBlmapReader.cc:9
#define NULL
Definition: scimark2.h:8
static double deltaEt(const T *, const U *)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
long double T
template<typename T , typename Collection >
const Collection::value_type * PFBenchmarkAlgo::matchByDeltaR ( const T c1,
const Collection *  candidates 
)
static

Definition at line 200 of file PFBenchmarkAlgo.h.

References deltaR(), PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi::dR, Exception, i, match(), HLT_25ns10e33_v2_cff::minDeltaR, and NULL.

Referenced by GenericBenchmark::fill(), and PFJetBenchmark::process().

200  {
201 
202  typedef typename Collection::value_type U;
203 
204  // Try to verify the validity of the Candidate and 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";
207 
208  double minDeltaR = 9999.;
209  const U *match = NULL;
210 
211  // Loop Over the Candidates...
212  for (unsigned int i = 0; i < candidates->size(); i++) {
213 
214  const U *c2 = &(*candidates)[i];
215  if (!c2) throw cms::Exception("Invalid Arg") << "attempted to match to invalid Candidate";
216 
217  // Find Minimal Delta-R
218  double dR = deltaR(c1,c2);
219  if (dR <= minDeltaR) { match = c2; minDeltaR = dR; }
220 
221  }
222 
223  // Return the Candidate with the smallest dR
224  return match;
225 
226 }
int i
Definition: DBlmapReader.cc:9
#define NULL
Definition: scimark2.h:8
static double deltaR(const T *, const U *)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
template<typename T , typename Collection >
void PFBenchmarkAlgo::sortByDeltaEt ( const T c1,
Collection &  candidates 
)
static

Definition at line 294 of file PFBenchmarkAlgo.h.

References Exception, and vector_sort().

Referenced by findAllInEtWindow().

294  {
295 
296  typedef typename Collection::value_type U;
297 
298  // Try to verify the validity of Candidate and 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";
301 
302  // Sort the collection
304 
305 }
static void vector_sort(std::vector< T > &candidates, Sorter< T, U > S)
template<typename T , typename Collection >
void PFBenchmarkAlgo::sortByDeltaR ( const T c1,
Collection &  candidates 
)
static

Definition at line 279 of file PFBenchmarkAlgo.h.

References Exception, and vector_sort().

Referenced by findAllInCone().

279  {
280 
281  typedef typename Collection::value_type U;
282 
283  // Try to verify the validity of Candidate and 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";
286 
287  // Sort the collection
289 
290 }
static void vector_sort(std::vector< T > &candidates, Sorter< T, U > S)
template<typename T >
static void PFBenchmarkAlgo::vector_add ( const T c1,
std::vector< T > &  candidates 
)
inlinestaticprivate

Definition at line 73 of file PFBenchmarkAlgo.h.

Referenced by copyCollection(), findAllInCone(), and findAllInEtWindow().

73  {
74  candidates.push_back(*c1);
75  }
template<typename T >
static void PFBenchmarkAlgo::vector_add ( const T c1,
edm::OwnVector< T > &  candidates 
)
inlinestaticprivate

Definition at line 85 of file PFBenchmarkAlgo.h.

References edm::OwnVector< T, P >::push_back().

85  {
86  candidates.push_back((T *const)c1->clone());
87  }
void push_back(D *&d)
Definition: OwnVector.h:290
long double T
template<typename T , typename U , template< typename, typename > class Sorter>
static void PFBenchmarkAlgo::vector_sort ( std::vector< T > &  candidates,
Sorter< T, U >  S 
)
inlinestaticprivate

Definition at line 67 of file PFBenchmarkAlgo.h.

References S().

Referenced by sortByDeltaEt(), and sortByDeltaR().

67  {
68  sort(candidates.begin(),candidates.end(),S);
69  }
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
template<typename T , typename U , template< typename, typename > class Sorter>
static void PFBenchmarkAlgo::vector_sort ( edm::OwnVector< T > &  candidates,
Sorter< T, U >  S 
)
inlinestaticprivate

Definition at line 79 of file PFBenchmarkAlgo.h.

References edm::OwnVector< T, P >::sort().

79  {
80  candidates.sort(S);
81  }
void sort(S s)
Definition: OwnVector.h:471
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99