Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:27

0001 #ifndef RecoParticleFlow_PFProducer_PFBlockAlgo_h
0002 #define RecoParticleFlow_PFProducer_PFBlockAlgo_h
0003 
0004 #include "DataFormats/ParticleFlowReco/interface/PFBlock.h"
0005 #include "DataFormats/ParticleFlowReco/interface/PFBlockElement.h"
0006 #include "DataFormats/ParticleFlowReco/interface/PFBlockFwd.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/Framework/interface/ConsumesCollector.h"
0009 #include "RecoParticleFlow/PFProducer/interface/BlockElementImporterBase.h"
0010 #include "RecoParticleFlow/PFProducer/interface/BlockElementLinkerBase.h"
0011 #include "RecoParticleFlow/PFProducer/interface/KDTreeLinkerBase.h"
0012 #include "DataFormats/Common/interface/OwnVector.h"
0013 
0014 #include <memory>
0015 #include <string>
0016 #include <unordered_map>
0017 #include <vector>
0018 
0019 namespace std {
0020   template <>
0021   struct hash<std::pair<unsigned int, unsigned int>> {
0022     typedef std::pair<unsigned int, unsigned int> arg_type;
0023     typedef unsigned int value_type;
0024     value_type operator()(const arg_type& arg) const { return arg.first ^ (arg.second << 1); }
0025   };
0026 }  // namespace std
0027 
0028 /// \brief Particle Flow Algorithm
0029 /*!
0030   \author Colin Bernet (rewrite/refactor by L. Gray)
0031   \date January 2006 (April 2014) 
0032 */
0033 
0034 class PFBlockAlgo {
0035 public:
0036   // the element list should **always** be a list of (smart) pointers
0037   typedef std::vector<std::unique_ptr<reco::PFBlockElement>> ElementList;
0038   //for skipping ranges
0039   typedef std::array<std::pair<unsigned int, unsigned int>, reco::PFBlockElement::kNBETypes> ElementRanges;
0040 
0041   PFBlockAlgo();
0042 
0043   ~PFBlockAlgo();
0044 
0045   void setLinkers(const std::vector<edm::ParameterSet>&);
0046 
0047   void setImporters(const std::vector<edm::ParameterSet>&, edm::ConsumesCollector&);
0048 
0049   // update event setup info of all linkers
0050   void updateEventSetup(const edm::EventSetup&);
0051 
0052   // run all of the importers and build KDtrees
0053   void buildElements(const edm::Event&);
0054 
0055   /// build blocks
0056   reco::PFBlockCollection findBlocks();
0057 
0058   /// sets debug printout flag
0059   void setDebug(bool debug) { debug_ = debug; }
0060 
0061 private:
0062   /// compute missing links in the blocks
0063   /// (the recursive procedure does not build all links)
0064   void packLinks(reco::PFBlock& block,
0065                  const std::unordered_map<std::pair<unsigned int, unsigned int>, double>& links) const;
0066 
0067   /// check whether 2 elements are linked. Returns distance
0068   inline void link(const reco::PFBlockElement* el1, const reco::PFBlockElement* el2, double& dist) const;
0069 
0070   // the test elements will be transferred to the blocks
0071   ElementList elements_;
0072   ElementRanges ranges_;
0073 
0074   /// if true, debug printouts activated
0075   bool debug_;
0076 
0077   friend std::ostream& operator<<(std::ostream&, const PFBlockAlgo&);
0078   bool useHO_;
0079 
0080   std::vector<std::unique_ptr<BlockElementImporterBase>> importers_;
0081 
0082   const std::unordered_map<std::string, reco::PFBlockElement::Type> elementTypes_;
0083   std::vector<std::unique_ptr<BlockElementLinkerBase>> linkTests_;
0084   unsigned int linkTestSquare_[reco::PFBlockElement::kNBETypes][reco::PFBlockElement::kNBETypes];
0085 
0086   std::vector<std::unique_ptr<KDTreeLinkerBase>> kdtrees_;
0087 };
0088 
0089 #endif