CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/RecoParticleFlow/PFProducer/interface/KDTreeLinkerAlgo.h

Go to the documentation of this file.
00001 #ifndef KDTreeLinkerAlgo_h
00002 #define KDTreeLinkerAlgo_h
00003 
00004 #include "RecoParticleFlow/PFProducer/interface/KDTreeLinkerTools.h"
00005 
00006 #include <vector>
00007 
00008 // Class that implements the KDTree partition of 2D space and 
00009 // a closest point search algorithme.
00010 class KDTreeLinkerAlgo
00011 {
00012  public:
00013   KDTreeLinkerAlgo();
00014   
00015   // Dtor calls clear()
00016   ~KDTreeLinkerAlgo();
00017   
00018   // Here we build the KD tree from the "eltList" in the space define by "region".
00019   void build(std::vector<KDTreeNodeInfo>        &eltList,
00020              const KDTreeBox                    &region);
00021   
00022   // Here we search in the KDTree for all points that would be 
00023   // contained in the given searchbox. The founded points are stored in resRecHitList.
00024   void search(const KDTreeBox                   &searchBox,
00025               std::vector<KDTreeNodeInfo>       &resRecHitList);
00026   
00027   // This method clears all allocated structures.
00028   void clear();
00029   
00030  private:
00031   // The KDTree root
00032   KDTreeNode*   root_;
00033   
00034   // The node pool allow us to do just 1 call to new for each tree building.
00035   KDTreeNode*   nodePool_;
00036   int           nodePoolSize_;
00037   int           nodePoolPos_;
00038 
00039  private:
00040   // Basic swap function.
00041   void swap(KDTreeNodeInfo &e1, KDTreeNodeInfo &e2);
00042 
00043   // Get next node from the node pool.
00044   KDTreeNode* getNextNode();
00045 
00046   //Fast median search with Wirth algorithm in eltList between low and high indexes.
00047   int medianSearch(std::vector<KDTreeNodeInfo>  &eltList,
00048                    int                          low,
00049                    int                          high,
00050                    int                          treeDepth);
00051 
00052   // Recursif kdtree builder. Is called by build()
00053   KDTreeNode *recBuild(std::vector<KDTreeNodeInfo>      &eltList, 
00054                        int                              low,
00055                        int                              hight,
00056                        int                              depth,
00057                        const KDTreeBox&                 region);
00058 
00059   // Recursif kdtree search. Is called by search()
00060   void recSearch(const KDTreeNode               *current,
00061                  const KDTreeBox                &trackBox,
00062                  std::vector<KDTreeNodeInfo>    &recHits);    
00063 
00064   // Add all elements of an subtree to the closest elements. Used during the recSearch().
00065   void addSubtree(const KDTreeNode              *current, 
00066                   std::vector<KDTreeNodeInfo>   &recHits);
00067 
00068   // This method frees the KDTree.     
00069   void clearTree();
00070 };
00071 
00072 #endif