Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:11

0001 /*! \brief   Implementation of methods of TTClusterAlgorithm_neighbor
0002  *  \details Here, in the source file, the methods which do depend
0003  *           on the specific type <T> that can fit the template.
0004  *
0005  *  \author Kristofer Henriksson
0006  *  \date   2013, Jul 15
0007  *
0008  */
0009 
0010 #include "L1Trigger/TrackTrigger/interface/TTClusterAlgorithm_neighbor.h"
0011 
0012 /// Clustering operations
0013 /// Specialize template for Phase2TrackerDigis
0014 template <>
0015 void TTClusterAlgorithm_neighbor<Ref_Phase2TrackerDigi_>::Cluster(
0016     std::vector<std::vector<Ref_Phase2TrackerDigi_> >& output, const std::vector<Ref_Phase2TrackerDigi_>& input) const {
0017   /// Prepare output
0018   output.clear();
0019 
0020   /// Loop over all input hits and delete
0021   /// them once clustered
0022   std::vector<bool> used(input.size(), false);
0023 
0024   for (unsigned int i = 0; i < input.size(); i++) {
0025     if (used[i])
0026       continue;
0027 
0028     std::vector<Ref_Phase2TrackerDigi_> cluster;
0029     cluster.push_back(input[i]);
0030     used[i] = true;
0031     if (i < input.size() - 1) {
0032       addNeighbors(cluster, input, i + 1, used);
0033     }
0034     output.push_back(cluster);
0035   }  /// End of iteration
0036 }  /// End of Clustering Operations
0037 
0038 /// Check if the hit is a neighbour
0039 /// Specialize template for Phase2TrackerDigis
0040 template <>
0041 bool TTClusterAlgorithm_neighbor<Ref_Phase2TrackerDigi_>::isANeighbor(const Ref_Phase2TrackerDigi_& center,
0042                                                                       const Ref_Phase2TrackerDigi_& mayNeigh) const {
0043   unsigned int rowdist = std::abs((int)(center->row()) - (int)(mayNeigh->row()));
0044   unsigned int coldist = std::abs((int)(center->column()) - (int)(mayNeigh->column()));
0045   return rowdist <= 1 && coldist <= 1;
0046 }
0047 
0048 /// Add neighbours to the cluster
0049 /// Specialize template for Phase2TrackerDigis
0050 template <>
0051 void TTClusterAlgorithm_neighbor<Ref_Phase2TrackerDigi_>::addNeighbors(std::vector<Ref_Phase2TrackerDigi_>& cluster,
0052                                                                        const std::vector<Ref_Phase2TrackerDigi_>& input,
0053                                                                        unsigned int startVal,
0054                                                                        std::vector<bool>& used) const {
0055   /// This following line is necessary to ensure the
0056   /// iterators afterward remain valid.
0057   cluster.reserve(input.size());
0058   typename std::vector<Ref_Phase2TrackerDigi_>::iterator clusIter;
0059 
0060   /// Loop over hits
0061   for (clusIter = cluster.begin(); clusIter < cluster.end(); clusIter++) {
0062     /// Loop over candidate neighbours
0063     for (unsigned int i = startVal; i < input.size(); i++) {
0064       /// Is it really a neighbour?
0065       if (isANeighbor(*clusIter, input[i])) {
0066         cluster.push_back(input[i]);
0067         used[i] = true;
0068       }
0069     }  /// End of loop over candidate neighbours
0070   }    /// End of loop over hits
0071 }