Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-16 03:24:08

0001 #ifndef DTSegment_DTCombinatorialPatternReco_h
0002 #define DTSegment_DTCombinatorialPatternReco_h
0003 
0004 /** \class DTCombinatorialPatternReco
0005  *
0006  * Algo for reconstructing 2d segment in DT using a combinatorial approach
0007  *  
0008  * \author Stefano Lacaprara - INFN Legnaro <stefano.lacaprara@pd.infn.it>
0009  * \author Riccardo Bellan - INFN TO <riccardo.bellan@cern.ch>
0010  *
0011  */
0012 
0013 /* Base Class Headers */
0014 #include "RecoLocalMuon/DTSegment/src/DTRecSegment2DBaseAlgo.h"
0015 #include "FWCore/Framework/interface/FrameworkfwdMostUsed.h"
0016 
0017 /* Collaborating Class Declarations */
0018 namespace edm {
0019   class ParameterSet;
0020   class EventSetup;
0021   //  class ESHandle;
0022 }  // namespace edm
0023 class DTSegmentUpdator;
0024 class DTSegmentCleaner;
0025 class DTHitPairForFit;
0026 class DTSegmentCand;
0027 class MuonGeometryRecord;
0028 
0029 /* C++ Headers */
0030 #include <deque>
0031 #include <functional>
0032 #include <unordered_set>
0033 #include <utility>
0034 #include <vector>
0035 
0036 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0037 #include "FWCore/Framework/interface/ESHandle.h"
0038 #include "FWCore/Utilities/interface/ESGetToken.h"
0039 #include "RecoLocalMuon/DTSegment/src/DTSegmentCand.h"
0040 
0041 /* ====================================================================== */
0042 
0043 /* Class DTCombinatorialPatternReco Interface */
0044 
0045 class DTCombinatorialPatternReco : public DTRecSegment2DBaseAlgo {
0046 public:
0047   /// Constructor
0048   DTCombinatorialPatternReco(const edm::ParameterSet& pset, edm::ConsumesCollector);
0049 
0050   /// Destructor
0051   ~DTCombinatorialPatternReco() override;
0052 
0053   /* Operations */
0054 
0055   /// this function is called in the producer
0056   edm::OwnVector<DTSLRecSegment2D> reconstruct(const DTSuperLayer* sl,
0057                                                const std::vector<DTRecHit1DPair>& hits) override;
0058 
0059   /// return the algo name
0060   std::string algoName() const override { return theAlgoName; }
0061 
0062   /// Through this function the EventSetup is percolated to the
0063   /// objs which request it
0064   void setES(const edm::EventSetup& setup) override;
0065 
0066 protected:
0067 private:
0068   friend class DTCombinatorialPatternReco4D;
0069 
0070   // typedef std::pair<DTHitPairForFit*, DTEnums::DTCellSide> AssPoint;
0071 
0072   // create the DTHitPairForFit from the pairs for easy use
0073   std::vector<std::shared_ptr<DTHitPairForFit>> initHits(const DTSuperLayer* sl,
0074                                                          const std::vector<DTRecHit1DPair>& hits);
0075 
0076   // search for candidate, starting from pairs of hits in different layers
0077   std::vector<DTSegmentCand*> buildSegments(const DTSuperLayer* sl,
0078                                             const std::vector<std::shared_ptr<DTHitPairForFit>>& hits);
0079 
0080   // find all the hits compatible with the candidate
0081   std::vector<DTSegmentCand::AssPoint> findCompatibleHits(const LocalPoint& pos,
0082                                                           const LocalVector& dir,
0083                                                           const std::vector<std::shared_ptr<DTHitPairForFit>>& hits);
0084 
0085   // build segments from hits collection
0086   DTSegmentCand* buildBestSegment(std::vector<DTSegmentCand::AssPoint>& assHits, const DTSuperLayer* sl);
0087 
0088   bool checkDoubleCandidates(std::vector<DTSegmentCand*>& segs, DTSegmentCand* seg);
0089 
0090   /** build collection of compatible hits for L/R hits: the candidates is
0091      * updated with the segment candidates found */
0092   void buildPointsCollection(std::vector<DTSegmentCand::AssPoint>& points,
0093                              std::deque<std::shared_ptr<DTHitPairForFit>>& pointsNoLR,
0094                              std::vector<DTSegmentCand*>& candidates,
0095                              const DTSuperLayer* sl);
0096 
0097 private:
0098   std::string theAlgoName;
0099   unsigned int theMaxAllowedHits;
0100   double theAlphaMaxTheta;
0101   double theAlphaMaxPhi;
0102   bool debug;
0103   bool usePairs;
0104   DTSegmentUpdator* theUpdator;  // the updator and fitter
0105   DTSegmentCleaner* theCleaner;  // the cleaner
0106 
0107   edm::ESHandle<DTGeometry> theDTGeometry;  // the DT geometry
0108   const edm::ESGetToken<DTGeometry, MuonGeometryRecord> theDTGeometryToken;
0109 
0110 public:
0111   // The type must be public, as otherwise the global 'hash_value' function can't locate it
0112   class TriedPattern {
0113   public:
0114     typedef std::vector<short unsigned int> values;
0115 
0116     // empty costructor
0117     TriedPattern() : hash_(1) { values_.reserve(8); }
0118 
0119     // equality operator
0120     bool operator==(const TriedPattern& other) const {
0121       return (hash_ == other.hash_) &&    // cheap
0122              (values_ == other.values_);  // expensive last resort
0123     }
0124 
0125     //Same implementation as boost::hash_combine
0126     template <class T>
0127     inline void hash_combine(std::size_t& seed, const T& v) {
0128       std::hash<T> hasher;
0129       seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
0130     }
0131 
0132     /// push back value, and update the hash
0133     void push_back(short unsigned int i) {
0134       hash_combine(hash_, i);
0135       values_.push_back(i);
0136     }
0137     /// return the hash: equal objects MUST have the same hash,
0138     ///  different ones should have different ones
0139     size_t hash() const { return hash_; }
0140 
0141     // some extra methods to look like a std::vector
0142     typedef values::const_iterator const_iterator;
0143     const_iterator begin() const { return values_.begin(); }
0144     const_iterator end() const { return values_.end(); }
0145     values::size_type size() const { return values_.size(); }
0146 
0147     //Custom hash functor for std::unordered_set
0148     class HashFunction {
0149     public:
0150       size_t operator()(const TriedPattern& p) const { return p.hash(); }
0151     };
0152 
0153   private:
0154     values values_;
0155     size_t hash_;
0156   };
0157   typedef std::unordered_set<TriedPattern, TriedPattern::HashFunction> TriedPatterns;
0158 
0159 private:
0160   TriedPatterns theTriedPattern;
0161 };
0162 
0163 inline std::size_t hash_value(const DTCombinatorialPatternReco::TriedPattern& t) { return t.hash(); }
0164 
0165 #endif  // DTSegment_DTCombinatorialPatternReco_h