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 #include <unordered_set>
66 
67 namespace std {
68  template<>
69  struct hash<std::pair<unsigned int,unsigned int> > {
70  typedef std::pair<unsigned int,unsigned int> arg_type;
71  typedef unsigned int value_type;
73  return arg.first ^ (arg.second << 1);
74  }
75  };
76  template<>
77  struct equal_to<std::pair<unsigned int,unsigned int> > {
78  typedef std::pair<unsigned int,unsigned int> arg_type;
79  bool operator()(const arg_type& arg1, const arg_type& arg2) const {
80  return ( (arg1.first == arg2.first) & (arg1.second == arg2.second) );
81  }
82  };
83 }
84 
86 
91 class PFBlockAlgo {
92 
93  public:
94  // the element list should **always** be a list of (smart) pointers
95  typedef std::vector<std::unique_ptr<reco::PFBlockElement> > ElementList;
96  typedef std::unique_ptr<BlockElementImporterBase> ImporterPtr;
97  typedef std::unique_ptr<BlockElementLinkerBase> LinkTestPtr;
98  typedef std::unique_ptr<KDTreeLinkerBase> KDTreePtr;
100  typedef ElementList::iterator IE;
101  typedef ElementList::const_iterator IEC;
102  typedef reco::PFBlockCollection::const_iterator IBC;
103  //for skipping ranges
104  typedef std::array<std::pair<unsigned int,unsigned int>,reco::PFBlockElement::kNBETypes> ElementRanges;
105 
106  PFBlockAlgo();
107 
108  ~PFBlockAlgo();
109 
110  void setLinkers(const std::vector<edm::ParameterSet>&);
111 
112  void setImporters(const std::vector<edm::ParameterSet>&,
114 
115  // update event setup info of all linkers
116  void updateEventSetup(const edm::EventSetup&);
117 
118  // run all of the importers and build KDtrees
119  void buildElements(const edm::Event&);
120 
122  void findBlocks();
123 
125  void setDebug( bool debug ) {debug_ = debug;}
126 
128  /* const reco::PFBlockCollection& blocks() const {return *blocks_;} */
129  const std::auto_ptr< reco::PFBlockCollection >& blocks() const
130  {return blocks_;}
131 
133  std::auto_ptr< reco::PFBlockCollection > transferBlocks() {return blocks_;}
134 
135 
136 
137  private:
138 
142  const std::unordered_map<std::pair<unsigned int,unsigned int>,PFBlockLink>& links) const;
143 
145  inline bool linkPrefilter(const reco::PFBlockElement* last,
146  const reco::PFBlockElement* next) const;
147 
149  inline void link( const reco::PFBlockElement* el1,
150  const reco::PFBlockElement* el2,
151  PFBlockLink::Type& linktype,
152  reco::PFBlock::LinkTest& linktest,
153  double& dist) const;
154 
155  std::auto_ptr< reco::PFBlockCollection > blocksNew_;
156  std::auto_ptr< reco::PFBlockCollection > blocks_;
157 
158  // the test elements will be transferred to the blocks
160  std::vector<ElementList::value_type::pointer> bare_elements_;
162 
164  bool debug_;
165 
166  friend std::ostream& operator<<(std::ostream&, const PFBlockAlgo&);
167  bool useHO_;
168 
169  std::vector<ImporterPtr> _importers;
170 
171  const std::unordered_map<std::string,reco::PFBlockElement::Type>
173  std::vector<LinkTestPtr> _linkTests;
175 
176  std::vector<KDTreePtr> _kdtrees;
177 };
178 
184 
185 #endif
186 
187 
const std::auto_ptr< reco::PFBlockCollection > & blocks() const
Definition: PFBlockAlgo.h:129
std::unique_ptr< BlockElementLinkerBase > LinkTestPtr
Definition: PFBlockAlgo.h:97
Abstract base class for a PFBlock element (track, cluster...)
std::vector< LinkTestPtr > _linkTests
Definition: PFBlockAlgo.h:173
const std::unordered_map< std::string, reco::PFBlockElement::Type > _elementTypes
Definition: PFBlockAlgo.h:172
std::auto_ptr< reco::PFBlockCollection > blocksNew_
Definition: PFBlockAlgo.h:155
ElementList::const_iterator IEC
Definition: PFBlockAlgo.h:101
friend std::ostream & operator<<(std::ostream &, const PFBlockAlgo &)
std::pair< unsigned int, unsigned int > arg_type
Definition: PFBlockAlgo.h:70
std::auto_ptr< reco::PFBlockCollection > blocks_
Definition: PFBlockAlgo.h:156
ElementList elements_
Definition: PFBlockAlgo.h:159
ElementList::iterator IE
define these in *Fwd files in DataFormats/ParticleFlowReco?
Definition: PFBlockAlgo.h:100
A arg
Definition: Factorize.h:36
bool operator()(const arg_type &arg1, const arg_type &arg2) const
Definition: PFBlockAlgo.h:79
std::vector< std::unique_ptr< reco::PFBlockElement > > ElementList
Definition: PFBlockAlgo.h:95
Particle Flow Algorithm.
Definition: PFBlockAlgo.h:91
std::pair< unsigned int, unsigned int > arg_type
Definition: PFBlockAlgo.h:78
std::unique_ptr< KDTreeLinkerBase > KDTreePtr
Definition: PFBlockAlgo.h:98
void setDebug(bool debug)
sets debug printout flag
Definition: PFBlockAlgo.h:125
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
std::vector< KDTreePtr > _kdtrees
Definition: PFBlockAlgo.h:176
void updateEventSetup(const edm::EventSetup &)
void setImporters(const std::vector< edm::ParameterSet > &, edm::ConsumesCollector &)
ElementRanges ranges_
Definition: PFBlockAlgo.h:161
void packLinks(reco::PFBlock &block, const std::unordered_map< std::pair< unsigned int, unsigned int >, PFBlockLink > &links) const
reco::PFBlockCollection::const_iterator IBC
Definition: PFBlockAlgo.h:102
#define debug
Definition: HDRShower.cc:19
std::auto_ptr< reco::PFBlockCollection > transferBlocks()
Definition: PFBlockAlgo.h:133
bool linkPrefilter(const reco::PFBlockElement *last, const reco::PFBlockElement *next) const
Avoid to check links when not useful.
void findBlocks()
build blocks
std::array< std::pair< unsigned int, unsigned int >, reco::PFBlockElement::kNBETypes > ElementRanges
Definition: PFBlockAlgo.h:104
value_type operator()(const arg_type &arg) const
Definition: PFBlockAlgo.h:72
std::vector< ElementList::value_type::pointer > bare_elements_
Definition: PFBlockAlgo.h:160
void buildElements(const edm::Event &)
unsigned int _linkTestSquare[reco::PFBlockElement::kNBETypes][reco::PFBlockElement::kNBETypes]
Definition: PFBlockAlgo.h:174
bool debug_
if true, debug printouts activated
Definition: PFBlockAlgo.h:164
void setLinkers(const std::vector< edm::ParameterSet > &)
std::vector< ImporterPtr > _importers
Definition: PFBlockAlgo.h:169
std::unique_ptr< BlockElementImporterBase > ImporterPtr
Definition: PFBlockAlgo.h:96
Block of elements.
Definition: PFBlock.h:30