Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26:16

0001 #include "Phase2TrackerClusterizerAlgorithm.h"
0002 
0003 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
0004 
0005 /*
0006  * Initialise the clusterizer algorithm
0007  */
0008 
0009 Phase2TrackerClusterizerAlgorithm::Phase2TrackerClusterizerAlgorithm(unsigned int maxClusterSize,
0010                                                                      unsigned int maxNumberClusters)
0011     : maxClusterSize_(maxClusterSize), maxNumberClusters_(maxNumberClusters), nrows_(0), ncols_(0) {}
0012 
0013 /* 
0014  * Change the size of the 2D matrix for this module (varies from pixel to strip modules)
0015  */
0016 
0017 void Phase2TrackerClusterizerAlgorithm::setup(const PixelGeomDetUnit* pixDet) {
0018   const PixelTopology& topol(pixDet->specificTopology());
0019   nrows_ = topol.nrows();
0020   ncols_ = topol.ncolumns();
0021   matrix_ = decltype(matrix_)(nrows_, ncols_);
0022 }
0023 
0024 /* 
0025  * Go over the Digis and create clusters
0026  */
0027 
0028 void Phase2TrackerClusterizerAlgorithm::clusterizeDetUnit(const edm::DetSet<Phase2TrackerDigi>& digis,
0029                                                           Phase2TrackerCluster1DCollectionNew::FastFiller& clusters) {
0030   // Fill the 2D matrix with the hit information : (hit or not)
0031   fillMatrix(digis.begin(), digis.end());
0032 
0033   // Number of clusters
0034   unsigned int numberClusters(0);
0035   Phase2TrackerDigi firstDigi;
0036   unsigned int sizeCluster(0);
0037   bool closeCluster(false);
0038   bool HIPbit(false);
0039 
0040   // Loop over the Digis
0041   // for the S modules, 1 column = 1 strip, so adjacent digis are along the rows
0042   // same for P modules
0043   for (unsigned int col(0); col < ncols_; ++col) {
0044     for (unsigned int row(0); row < nrows_; ++row) {
0045       // If the Digi is hit
0046       if (matrix_(row, col)) {
0047         // No cluster is open, create a new one
0048         if (sizeCluster == 0) {
0049           // Define first digi
0050           firstDigi = Phase2TrackerDigi(row, col);
0051           sizeCluster = 1;
0052         }
0053         // A cluster is open, increase its size
0054         else
0055           ++sizeCluster;
0056         // Check if we reached the maximum size of the cluster and need to close it
0057         closeCluster = ((maxClusterSize_ != 0 and sizeCluster >= maxClusterSize_) ? true : false);
0058       }
0059       // Otherwise check if we need to close a cluster (end of cluster)
0060       else
0061         closeCluster = ((sizeCluster != 0) ? true : false);
0062 
0063       // update the HIP bit
0064       HIPbit |= (matrix_(row, col) == 2);
0065 
0066       // Always close a cluster if we reach the end of the loop
0067       if (sizeCluster != 0 and row == (nrows_ - 1))
0068         closeCluster = true;
0069 
0070       // If we have to close a cluster, do it
0071       if (closeCluster) {
0072         // Add the cluster to the list
0073         clusters.push_back(Phase2TrackerCluster1D(firstDigi, sizeCluster, HIPbit));
0074         // Reset the variables
0075         sizeCluster = 0;
0076         // Increase the number of clusters
0077         ++numberClusters;
0078         HIPbit = false;
0079       }
0080 
0081       // Check if we hit the maximum number of clusters per module
0082       if (maxNumberClusters_ != 0 and numberClusters > maxNumberClusters_)
0083         return;
0084     }
0085   }
0086 
0087   // Reset the matrix
0088   clearMatrix(digis.begin(), digis.end());
0089 }
0090 
0091 /* 
0092  * Copy the value of the Digis to the 2D matrix (hit or not). 
0093  */
0094 
0095 void Phase2TrackerClusterizerAlgorithm::fillMatrix(edm::DetSet<Phase2TrackerDigi>::const_iterator begin,
0096                                                    edm::DetSet<Phase2TrackerDigi>::const_iterator end) {
0097   for (edm::DetSet<Phase2TrackerDigi>::const_iterator di(begin); di != end; ++di)
0098     matrix_.set(di->row(), di->column(), true, di->overThreshold());
0099 }
0100 
0101 /*
0102  * Clear the array of hits
0103  */
0104 
0105 void Phase2TrackerClusterizerAlgorithm::clearMatrix(edm::DetSet<Phase2TrackerDigi>::const_iterator begin,
0106                                                     edm::DetSet<Phase2TrackerDigi>::const_iterator end) {
0107   for (edm::DetSet<Phase2TrackerDigi>::const_iterator di(begin); di != end; ++di)
0108     matrix_.set(di->row(), di->column(), false, false);
0109 }