CMS 3D CMS Logo

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;
72  value_type operator()(const arg_type& arg) const {
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::unique_ptr< reco::PFBlockCollection >& blocks() const
130  {return blocks_;}
131 
132  //uniquen unique_ptr to collection of blocks
133  std::unique_ptr< reco::PFBlockCollection > transferBlocks() {return std::move(blocks_);}
134 
135 
136 
137  private:
138 
141  void packLinks(reco::PFBlock& block,
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::unique_ptr< reco::PFBlockCollection > blocks_;
156 
157  // the test elements will be transferred to the blocks
158  ElementList elements_;
159  std::vector<ElementList::value_type::pointer> bare_elements_;
160  ElementRanges ranges_;
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_;
174 
175  std::vector<KDTreePtr> kdtrees_;
176 };
177 
183 
184 #endif
185 
186 
std::unique_ptr< reco::PFBlockCollection > blocks_
Definition: PFBlockAlgo.h:155
std::unique_ptr< BlockElementLinkerBase > LinkTestPtr
Definition: PFBlockAlgo.h:97
Abstract base class for a PFBlock element (track, cluster...)
ElementList::const_iterator IEC
Definition: PFBlockAlgo.h:101
const std::unique_ptr< reco::PFBlockCollection > & blocks() const
Definition: PFBlockAlgo.h:129
std::pair< unsigned int, unsigned int > arg_type
Definition: PFBlockAlgo.h:70
ElementList elements_
Definition: PFBlockAlgo.h:158
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::vector< KDTreePtr > kdtrees_
Definition: PFBlockAlgo.h:175
const std::unordered_map< std::string, reco::PFBlockElement::Type > elementTypes_
Definition: PFBlockAlgo.h:171
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
std::ostream & operator<<(std::ostream &out, const std::tuple< Types... > &value)
Definition: Utilities.h:38
ElementRanges ranges_
Definition: PFBlockAlgo.h:160
reco::PFBlockCollection::const_iterator IBC
Definition: PFBlockAlgo.h:102
#define debug
Definition: HDRShower.cc:19
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:159
std::unique_ptr< reco::PFBlockCollection > transferBlocks()
Definition: PFBlockAlgo.h:133
bool debug_
if true, debug printouts activated
Definition: PFBlockAlgo.h:163
std::vector< LinkTestPtr > linkTests_
Definition: PFBlockAlgo.h:172
def move(src, dest)
Definition: eostools.py:510
std::unique_ptr< BlockElementImporterBase > ImporterPtr
Definition: PFBlockAlgo.h:96
std::vector< ImporterPtr > importers_
Definition: PFBlockAlgo.h:168
Block of elements.
Definition: PFBlock.h:30