test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFBlockAlgo.h
Go to the documentation of this file.
1 #ifndef RecoParticleFlow_PFProducer_PFBlockAlgo_h
2 #define RecoParticleFlow_PFProducer_PFBlockAlgo_h
3 
4 #include <set>
5 #include <vector>
6 #include <iostream>
7 
8 // #include "FWCore/Framework/interface/Handle.h"
10 // #include "FWCore/Framework/interface/OrphanHandle.h"
12 
13 
27 
31 
32 // Glowinski & Gouzevitch
35 // !Glowinski & Gouzevitch
36 
37 // #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
38 
43 
55 
57 
59 
62 
63 #include <map>
64 #include <unordered_map>
65 
66 namespace std {
67  template<>
68  struct hash<std::pair<size_t,size_t> > {
69  typedef std::pair<size_t,size_t> arg_type;
70  typedef std::size_t value_type;
72  return arg.first ^ (arg.second << 1);
73  }
74  };
75  template<>
76  struct equal_to<std::pair<size_t,size_t> > {
77  typedef std::pair<size_t,size_t> arg_type;
78  bool operator()(const arg_type& arg1, const arg_type& arg2) const {
79  return (arg1.first == arg2.first && arg1.second == arg2.second);
80  }
81  };
82 }
83 
85 
90 class PFBlockAlgo {
91 
92  public:
93  // the element list should **always** be a list of (smart) pointers
94  typedef std::vector<std::unique_ptr<reco::PFBlockElement> > ElementList;
95  typedef std::unique_ptr<BlockElementImporterBase> ImporterPtr;
96  typedef std::unique_ptr<BlockElementLinkerBase> LinkTestPtr;
97  typedef std::unique_ptr<KDTreeLinkerBase> KDTreePtr;
99  typedef ElementList::iterator IE;
100  typedef ElementList::const_iterator IEC;
101  typedef reco::PFBlockCollection::const_iterator IBC;
102 
103  PFBlockAlgo();
104 
105  ~PFBlockAlgo();
106 
107  void setLinkers(const std::vector<edm::ParameterSet>&);
108 
109  void setImporters(const std::vector<edm::ParameterSet>&,
111 
112  // update event setup info of all linkers
113  void updateEventSetup(const edm::EventSetup&);
114 
115  // run all of the importers and build KDtrees
116  void buildElements(const edm::Event&);
117 
119  void findBlocks();
120 
122  void setDebug( bool debug ) {debug_ = debug;}
123 
125  /* const reco::PFBlockCollection& blocks() const {return *blocks_;} */
126  const std::auto_ptr< reco::PFBlockCollection >& blocks() const
127  {return blocks_;}
128 
130  std::auto_ptr< reco::PFBlockCollection > transferBlocks() {return blocks_;}
131 
132 
133 
134  private:
135  // flattened version of topological
136  // association of block elements
137  IE associate( ElementList& elems,
138  std::unordered_map<std::pair<size_t,size_t>,PFBlockLink>& links,
139  reco::PFBlock& );
140 
144  const std::unordered_map<std::pair<size_t,size_t>,PFBlockLink>& links) const;
145 
147  inline bool linkPrefilter(const reco::PFBlockElement* last,
148  const reco::PFBlockElement* next) const;
149 
151  inline void link( const reco::PFBlockElement* el1,
152  const reco::PFBlockElement* el2,
153  PFBlockLink::Type& linktype,
154  reco::PFBlock::LinkTest& linktest,
155  double& dist) const;
156 
157  std::auto_ptr< reco::PFBlockCollection > blocks_;
158 
159  // the test elements will be transferred to the blocks
161 
163  bool debug_;
164 
165  friend std::ostream& operator<<(std::ostream&, const PFBlockAlgo&);
166  bool useHO_;
167 
168  std::vector<ImporterPtr> _importers;
169 
170  const std::unordered_map<std::string,reco::PFBlockElement::Type>
172  std::vector<LinkTestPtr> _linkTests;
173 
174  std::vector<KDTreePtr> _kdtrees;
175 };
176 
182 
183 #endif
184 
185 
const std::auto_ptr< reco::PFBlockCollection > & blocks() const
Definition: PFBlockAlgo.h:126
value_type operator()(const arg_type &arg) const
Definition: PFBlockAlgo.h:71
std::unique_ptr< BlockElementLinkerBase > LinkTestPtr
Definition: PFBlockAlgo.h:96
Abstract base class for a PFBlock element (track, cluster...)
std::vector< LinkTestPtr > _linkTests
Definition: PFBlockAlgo.h:172
const std::unordered_map< std::string, reco::PFBlockElement::Type > _elementTypes
Definition: PFBlockAlgo.h:171
ElementList::const_iterator IEC
Definition: PFBlockAlgo.h:100
friend std::ostream & operator<<(std::ostream &, const PFBlockAlgo &)
IE associate(ElementList &elems, std::unordered_map< std::pair< size_t, size_t >, PFBlockLink > &links, reco::PFBlock &)
std::auto_ptr< reco::PFBlockCollection > blocks_
Definition: PFBlockAlgo.h:157
ElementList elements_
Definition: PFBlockAlgo.h:160
ElementList::iterator IE
define these in *Fwd files in DataFormats/ParticleFlowReco?
Definition: PFBlockAlgo.h:99
A arg
Definition: Factorize.h:36
std::vector< std::unique_ptr< reco::PFBlockElement > > ElementList
Definition: PFBlockAlgo.h:94
Particle Flow Algorithm.
Definition: PFBlockAlgo.h:90
bool operator()(const arg_type &arg1, const arg_type &arg2) const
Definition: PFBlockAlgo.h:78
std::unique_ptr< KDTreeLinkerBase > KDTreePtr
Definition: PFBlockAlgo.h:97
void setDebug(bool debug)
sets debug printout flag
Definition: PFBlockAlgo.h:122
void link(const reco::PFBlockElement *el1, const reco::PFBlockElement *el2, PFBlockLink::Type &linktype, reco::PFBlock::LinkTest &linktest, double &dist) const
check whether 2 elements are linked. Returns distance and linktype
void packLinks(reco::PFBlock &block, const std::unordered_map< std::pair< size_t, size_t >, PFBlockLink > &links) const
std::vector< KDTreePtr > _kdtrees
Definition: PFBlockAlgo.h:174
void updateEventSetup(const edm::EventSetup &)
std::pair< size_t, size_t > arg_type
Definition: PFBlockAlgo.h:77
void setImporters(const std::vector< edm::ParameterSet > &, edm::ConsumesCollector &)
reco::PFBlockCollection::const_iterator IBC
Definition: PFBlockAlgo.h:101
std::pair< size_t, size_t > arg_type
Definition: PFBlockAlgo.h:69
#define debug
Definition: HDRShower.cc:19
std::auto_ptr< reco::PFBlockCollection > transferBlocks()
Definition: PFBlockAlgo.h:130
bool linkPrefilter(const reco::PFBlockElement *last, const reco::PFBlockElement *next) const
Avoid to check links when not useful.
void findBlocks()
build blocks
void buildElements(const edm::Event &)
bool debug_
if true, debug printouts activated
Definition: PFBlockAlgo.h:163
void setLinkers(const std::vector< edm::ParameterSet > &)
std::vector< ImporterPtr > _importers
Definition: PFBlockAlgo.h:168
std::unique_ptr< BlockElementImporterBase > ImporterPtr
Definition: PFBlockAlgo.h:95
Block of elements.
Definition: PFBlock.h:30