CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes
reco::PFBlock Class Reference

Block of elements. More...

#include <PFBlock.h>

Classes

struct  Link
 

Public Types

typedef edm::OwnVector< reco::PFBlockElement >::const_iterator IE
 
typedef std::map< unsigned int, LinkLinkData
 
enum  LinkTest { LINKTEST_RECHIT, LINKTEST_NLINKTEST, LINKTEST_ALL }
 

Public Member Functions

void addElement (reco::PFBlockElement *element)
 
void associatedElements (unsigned i, const LinkData &linkData, std::multimap< double, unsigned > &sortedAssociates, reco::PFBlockElement::Type type=PFBlockElement::NONE, LinkTest test=LINKTEST_RECHIT) const
 
void bookLinkData ()
 
double dist (unsigned ie1, unsigned ie2, const LinkData &linkData, LinkTest test) const
 
double dist (unsigned ie1, unsigned ie2, const LinkData &linkData) const
 
const edm::OwnVector< reco::PFBlockElement > & elements () const
 
const LinkDatalinkData () const
 
LinkDatalinkData ()
 
bool matrix2vector (unsigned i, unsigned j, unsigned &index) const
 
 PFBlock ()
 
void setLink (unsigned i1, unsigned i2, double dist, LinkData &linkData, LinkTest test=LINKTEST_RECHIT) const
 

Private Member Functions

unsigned linkDataSize () const
 

Private Attributes

edm::OwnVector< reco::PFBlockElementelements_
 all elements More...
 
LinkData linkData_
 link data (permanent) More...
 

Detailed Description

Block of elements.

Author
Colin Bernet
Date
January 2006

A PFBlock is:

Definition at line 30 of file PFBlock.h.

Member Typedef Documentation

Definition at line 42 of file PFBlock.h.

typedef std::map< unsigned int, Link > reco::PFBlock::LinkData

Definition at line 46 of file PFBlock.h.

Member Enumeration Documentation

Enumerator
LINKTEST_RECHIT 
LINKTEST_NLINKTEST 
LINKTEST_ALL 

Definition at line 48 of file PFBlock.h.

Constructor & Destructor Documentation

reco::PFBlock::PFBlock ( )
inline

Member Function Documentation

void PFBlock::addElement ( reco::PFBlockElement element)

add an element to the current PFBlock the block will keep a copy.

Definition at line 12 of file PFBlock.cc.

References reco::PFBlockElement::clone(), reco::PFBlockElement::lock(), and reco::PFBlockElement::setIndex().

Referenced by PFBlock().

12  {
13  element->setIndex( elements_.size() );
14  element->lock();
15  elements_.push_back( element->clone() );
16 
17 }
virtual PFBlockElement * clone() const =0
necessary to have the edm::OwnVector<PFBlockElement> working
void setIndex(unsigned index)
set index
void lock()
lock element
edm::OwnVector< reco::PFBlockElement > elements_
all elements
Definition: PFBlock.h:130
void PFBlock::associatedElements ( unsigned  i,
const LinkData linkData,
std::multimap< double, unsigned > &  sortedAssociates,
reco::PFBlockElement::Type  type = PFBlockElement::NONE,
LinkTest  test = LINKTEST_RECHIT 
) const

lock an element ( unlink it from the others ) Colin: this function is misleading void lock(unsigned i, LinkData& linkData ) const; fills a map with the elements associated to element i. elements are sorted by increasing distance. if specified, only the elements of type "type" will be considered if specified, only the link calculated from a certain "test" will be considered: distance test, etc..

Definition at line 75 of file PFBlock.cc.

References NONE, and PFTauMVAInputDiscriminatorTranslator_cfi::test.

Referenced by PFAlgo::associatePSClusters(), PFPhotonAlgo::EvaluateSingleLegMVA(), PFEGammaAlgo::evaluateSingleLegMVA(), PFEGammaFilters::isElectronSafeForJetMET(), PFBlock(), PFElectronAlgo::SetActive(), PFElectronAlgo::SetCandidates(), PFElectronAlgo::SetIDOutputs(), and PFElectronAlgo::SetLinks().

79  {
80 
81  sortedAssociates.clear();
82 
83  // i is too large
84  if( i > elements_.size() ) return;
85  // assert(i>=0); i >= 0, since i is unsigned
86 
87  for(unsigned ie=0; ie<elements_.size(); ie++) {
88 
89  // considered element itself
90  if( ie == i ) {
91  continue;
92  }
93  // not the right type
94  if(type != PFBlockElement::NONE &&
95  elements_[ie].type() != type ) {
96  continue;
97  }
98 
99  // Order the elements by increasing distance !
100 
101  unsigned index = 0;
102  if( !matrix2vector(i, ie, index) ) continue;
103 
104  double c2=-1;
105  LinkData::const_iterator it = linkData.find(index);
106  if ( it!=linkData.end() &&
107  ( ( (1 << test ) & it->second.test) !=0 || (test == LINKTEST_ALL) ) )
108  c2= it->second.distance;
109 
110  // not associated
111  if( c2 < 0 ) {
112  continue;
113  }
114 
115  sortedAssociates.insert( pair<double,unsigned>(c2, ie) );
116  }
117 }
type
Definition: HCALResponse.h:21
const LinkData & linkData() const
Definition: PFBlock.h:112
edm::OwnVector< reco::PFBlockElement > elements_
all elements
Definition: PFBlock.h:130
bool matrix2vector(unsigned i, unsigned j, unsigned &index) const
Definition: PFBlock.cc:119
void PFBlock::bookLinkData ( )

Definition at line 20 of file PFBlock.cc.

Referenced by PFBlockAlgo::packLinks(), and PFBlock().

20  {
21 
22 }
double reco::PFBlock::dist ( unsigned  ie1,
unsigned  ie2,
const LinkData linkData,
LinkTest  test 
) const
inline
Returns
distance of link

Definition at line 94 of file PFBlock.h.

Referenced by PFBlock(), and PFElectronAlgo::SetLinks().

97  {
98  return dist(ie1,ie2,linkData);
99  }
const LinkData & linkData() const
Definition: PFBlock.h:112
double dist(unsigned ie1, unsigned ie2, const LinkData &linkData, LinkTest test) const
Definition: PFBlock.h:94
double PFBlock::dist ( unsigned  ie1,
unsigned  ie2,
const LinkData linkData 
) const
Returns
distance of link

Definition at line 146 of file PFBlock.cc.

147  {
148 
149  double Dist = -1;
150 
151  unsigned index = 0;
152  if( !matrix2vector(ie1, ie2, index) ) return Dist;
153  LinkData::const_iterator it = linkData.find(index);
154  if( it!=linkData.end() ) Dist= it->second.distance;
155 
156  return Dist;
157 
158 }
const LinkData & linkData() const
Definition: PFBlock.h:112
bool matrix2vector(unsigned i, unsigned j, unsigned &index) const
Definition: PFBlock.cc:119
const edm::OwnVector< reco::PFBlockElement >& reco::PFBlock::elements ( ) const
inline
const LinkData& reco::PFBlock::linkData ( ) const
inline
LinkData& reco::PFBlock::linkData ( )
inline
Returns
link data

Definition at line 117 of file PFBlock.h.

References linkData_, and linkDataSize().

117  {
118  return linkData_;
119  }
LinkData linkData_
link data (permanent)
Definition: PFBlock.h:127
unsigned PFBlock::linkDataSize ( ) const
private
Returns
size of linkData_, calculated from the number of elements

Definition at line 349 of file PFBlock.cc.

References gen::n.

Referenced by linkData().

349  {
350  unsigned n = elements_.size();
351 
352  // number of possible undirected links between n elements.
353  // reflective links impossible.
354 
355  return n*(n-1)/2;
356 }
edm::OwnVector< reco::PFBlockElement > elements_
all elements
Definition: PFBlock.h:130
bool PFBlock::matrix2vector ( unsigned  i,
unsigned  j,
unsigned &  index 
) const

makes the correspondance between a 2d element matrix and the 1D vector which is the most compact way to store the matrix

Definition at line 119 of file PFBlock.cc.

References findQualityFiles::size, and std::swap().

Referenced by PFBlock().

121  {
122 
123  unsigned size = elements_.size();
124  if( iindex == jindex ||
125  iindex >= size ||
126  jindex >= size ) {
127  return false;
128  }
129 
130  if( iindex > jindex )
131  std::swap( iindex, jindex);
132 
133 
134  index = jindex-iindex-1;
135 
136  if(iindex>0) {
137  index += iindex*size;
138  unsigned missing = iindex*(iindex+1)/2;
139  index -= missing;
140  }
141 
142  return true;
143 }
size
Write out results.
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
edm::OwnVector< reco::PFBlockElement > elements_
all elements
Definition: PFBlock.h:130
void PFBlock::setLink ( unsigned  i1,
unsigned  i2,
double  dist,
LinkData linkData,
LinkTest  test = LINKTEST_RECHIT 
) const

set a link between elements of indices i1 and i2, of "distance" dist the link is set in the linkData vector provided as an argument. As indicated by the 'const' statement, 'this' is not modified.

Definition at line 26 of file PFBlock.cc.

References reco::PFBlock::Link::distance, checklumidiff::l, convertSQLiteXML::ok, reco::PFBlock::Link::test, and PFTauMVAInputDiscriminatorTranslator_cfi::test.

Referenced by PFBlockAlgo::packLinks(), and PFBlock().

30  {
31 
32  assert( test<LINKTEST_ALL );
33 
34  unsigned index = 0;
35  bool ok = matrix2vector(i1,i2, index);
36 
37  if(ok) {
38  //ignore the -1, -1 pair
39  if ( Dist > -0.5 ) {
40  Link & l = linkData[index];
41  l.distance=Dist;
42  l.test |= (1 << test);
43  } else //delete if existing
44  {
45  LinkData::iterator it = linkData.find(index);
46  if(it!=linkData.end()) linkData.erase(it);
47  }
48 
49  } else {
50  assert(0);
51  }
52 
53 }
const LinkData & linkData() const
Definition: PFBlock.h:112
bool matrix2vector(unsigned i, unsigned j, unsigned &index) const
Definition: PFBlock.cc:119

Member Data Documentation

edm::OwnVector< reco::PFBlockElement > reco::PFBlock::elements_
private

all elements

Definition at line 130 of file PFBlock.h.

Referenced by elements().

LinkData reco::PFBlock::linkData_
private

link data (permanent)

Definition at line 127 of file PFBlock.h.

Referenced by linkData().