CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
KDTreeLinkerBase.h
Go to the documentation of this file.
1 #ifndef KDTreeLinkerBase_h
2 #define KDTreeLinkerBase_h
3 
8 
9 #include <vector>
10 #include <map>
11 #include <set>
12 
13 using BlockEltSet = std::set<reco::PFBlockElement *>;
14 using RecHitSet = std::set<const reco::PFRecHit *>;
15 
16 using RecHit2BlockEltMap = std::map<const reco::PFRecHit *, BlockEltSet>;
17 using BlockElt2BlockEltMap = std::map<reco::PFBlockElement *, BlockEltSet>;
18 
20 public:
22  virtual ~KDTreeLinkerBase() {}
23 
25 
27 
29 
30  const reco::PFBlockElement::Type &fieldType() const { return _fieldType; }
31 
32  // Get/Set of the maximal size of the cristal (ECAL, HCAL,...) in phi/eta and
33  // X/Y. By default, thus value are set for the ECAL cristal.
34 
35  // Get/Set phi offset. See bellow in the description of phiOffset_ to understand
36  // the application.
37 
38  // Debug flag.
39  void setDebug(bool isDebug);
40 
41  // With this method, we create the list of elements that we want to link.
42  virtual void insertTargetElt(reco::PFBlockElement *target) = 0;
43 
44  // Here, we create the list of cluster that we want to link. From cluster
45  // and fraction, we will create a second list of rechits that will be used to
46  // build the KDTree.
47  virtual void insertFieldClusterElt(reco::PFBlockElement *cluster) = 0;
48 
49  // The KDTree building from rechits list.
50  virtual void buildTree() = 0;
51 
52  // Here we will iterate over all target elements. For each one, we will search the closest
53  // rechits in the KDTree, from rechits we will find the associated clusters and after that
54  // we will check the links between the target and all closest clusters.
55  virtual void searchLinks() = 0;
56 
57  // Here, we will store all target/cluster founded links in the PFBlockElement class
58  // of each target in the PFmultilinks field.
59  virtual void updatePFBlockEltWithLinks() = 0;
60 
61  // Here we free all allocated structures.
62  virtual void clear() = 0;
63 
64  // This method calls is the good order buildTree(), searchLinks(),
65  // updatePFBlockEltWithLinks() and clear()
66  inline void process() {
67  buildTree();
68  searchLinks();
70  clear();
71  }
72 
73 protected:
74  // target and field
76  // Cristal maximal size. By default, thus value are set for the ECAL cristal.
77  float cristalPhiEtaMaxSize_ = 0.04;
78  float cristalXYMaxSize_ = 3.;
79 
80  // Usually, phi is between -Pi and +Pi. But phi space is circular, that's why an element
81  // with phi = 3.13 and another with phi = -3.14 are close. To solve this problem, during
82  // the kdtree building step, we duplicate some elements close enough to +Pi (resp -Pi) by
83  // substracting (adding) 2Pi. This field define the threshold of this operation.
84  float phiOffset_ = 0.25;
85 
86  // rechit with fraction this value will be ignored in KDTreeLinker
87  const float cutOffFrac = 1E-4;
88 
89  // Debug boolean. Not used until now.
90  bool debug_ = false;
91 
92  // Sorted indexes
93  template <typename T>
94  static std::vector<size_t> sort_indexes(const std::vector<T> &v) {
95  std::vector<size_t> idx(v.size());
96  for (size_t i = 0; i != idx.size(); ++i)
97  idx[i] = i;
98  std::sort(idx.begin(), idx.end(), [&v](size_t i1, size_t i2) { return v[i1] < v[i2]; });
99  return idx;
100  }
101 };
102 
105 
106 #endif /* !KDTreeLinkerBase_h */
void setFieldType(const reco::PFBlockElement::Type &fld)
std::set< reco::PFBlockElement * > BlockEltSet
Abstract base class for a PFBlock element (track, cluster...)
virtual void updatePFBlockEltWithLinks()=0
reco::PFBlockElement::Type _fieldType
void setTargetType(const reco::PFBlockElement::Type &tgt)
edmplugin::PluginFactory< KDTreeLinkerBase *(const edm::ParameterSet &)> KDTreeLinkerFactory
std::map< const reco::PFRecHit *, BlockEltSet > RecHit2BlockEltMap
static std::vector< size_t > sort_indexes(const std::vector< T > &v)
std::map< reco::PFBlockElement *, BlockEltSet > BlockElt2BlockEltMap
void setDebug(bool isDebug)
virtual void buildTree()=0
virtual void insertFieldClusterElt(reco::PFBlockElement *cluster)=0
KDTreeLinkerBase(const edm::ParameterSet &conf)
virtual ~KDTreeLinkerBase()
const reco::PFBlockElement::Type & targetType() const
std::set< const reco::PFRecHit * > RecHitSet
virtual void clear()=0
const reco::PFBlockElement::Type & fieldType() const
const float cutOffFrac
virtual void searchLinks()=0
virtual void insertTargetElt(reco::PFBlockElement *target)=0
reco::PFBlockElement::Type _targetType