CMS 3D CMS Logo

Public Member Functions | Private Attributes

ClusteringAlgorithm_2d< T > Class Template Reference

#include <ClusteringAlgorithm_2d.h>

Inheritance diagram for ClusteringAlgorithm_2d< T >:
ClusteringAlgorithm< T >

List of all members.

Public Member Functions

void Cluster (std::vector< std::vector< T > > &output, const std::vector< T > &input) const
 Clustering operations.
 ClusteringAlgorithm_2d (const StackedTrackerGeometry *aStackedTracker, bool aDoubleCountingTest)
 This is to manage double counting.
 ~ClusteringAlgorithm_2d ()
 Destructor.

Private Attributes

bool mDoubleCountingTest
 Data members.

Detailed Description

template<typename T>
class ClusteringAlgorithm_2d< T >

************************ DECLARATION OF CLASS ************************

Definition at line 47 of file ClusteringAlgorithm_2d.h.


Constructor & Destructor Documentation

template<typename T>
ClusteringAlgorithm_2d< T >::ClusteringAlgorithm_2d ( const StackedTrackerGeometry aStackedTracker,
bool  aDoubleCountingTest 
) [inline]

This is to manage double counting.

Constructor

Definition at line 55 of file ClusteringAlgorithm_2d.h.

References ClusteringAlgorithm_2d< T >::mDoubleCountingTest.

        : ClusteringAlgorithm< T >( aStackedTracker,__func__ )
      { 
        mDoubleCountingTest = aDoubleCountingTest;
      }
template<typename T>
ClusteringAlgorithm_2d< T >::~ClusteringAlgorithm_2d ( ) [inline]

Destructor.

Definition at line 62 of file ClusteringAlgorithm_2d.h.

{}

Member Function Documentation

template<typename T >
void ClusteringAlgorithm_2d< T >::Cluster ( std::vector< std::vector< T > > &  output,
const std::vector< T > &  input 
) const [virtual]

Clustering operations.

Close class.

***************************** IMPLEMENTATION OF METHODS ***************************** Clustering operations

Prepare the output

Prepare a proper hit container

First fill all, put the hits into a grid Loop over all hits

Assign central Pixel Assign kill bits Assign neighbours

End of loop over all hits

Then search to see if neighbour hits exist Loop over all central pixels

Get the coordinates

Layout of the grid to understand what follows a b c 0 1 2 -->r/phi = increasing row d x e = 3 x 4 | f g h 5 6 7 V z = decreasing column

Just check if there are neighbours and, if so, assign the corresponding bit to be true/false

Column +1, rows from -1 to +1

Column 0, rows -1 and +1

Column -1, rows from -1 to +1

End of loop over all central pixels

Then fill the kill bits Loop over all central pixels

KB 1) The first kill bit, kill0, prevents a cluster to be larger than 2 pixels in r-phi: if both columns adf and ceh contain at least one pixel over threshold each, this bit is set to 1, otherwise it is set to 0 KB 2) The second kill bit, kill1, makes the cluster to be built only if pix is in the leftmostbottom position within the cluster: if there is a pixel over threshold either in column adf or in position g, this bit is set to 1, otherwise it is set to 0

Check row -1

Check row +1

Kill bits are set here

End of loop over all central pixels

Then cross check for the final kill bit Loop over all central pixels

Get the coordinates

KB 3) if at least one of the pixels, in ceh column, fired and features its kill0 = 1, let a third kill bit kill2 be 1, otherwise set it to 0 NOTE that kill2 prevents the pixel to report a cluster when looking at its size out of the 3x3 pixel window under examination

If all the kill bits are fine, then the Cluster can be prepared for output

Store the central pixel

Store all the neighbours

End of "all the kill bits are fine"

End of loop over all central pixels

Eventually, if needed, do the test for double counting!

Loop over Clusters

Loop over Hits inside each Cluster

Are there Hits with same coordinates? If yes, put in doubles vector, else in test one

End of loop over Hits inside each Cluster

End of loop over Clusters

If we found duplicates WARNING is it really doing something more than printout???????

Printout double Pixel

Loop over Clusters

Loop over Hits inside each Cluster

End of loop over Clusters

End of "if we found duplicates"

End of test for double counting

Reimplemented from ClusteringAlgorithm< T >.

Definition at line 77 of file ClusteringAlgorithm_2d.h.

References if(), pixelContainer< T >::kill0, convertSQLitetoXML_cfg::output, groupFilesInBlocks::temp, and run_regression::test.

  {
    output.clear();

    std::map< std::pair< unsigned int, unsigned int>, pixelContainer< T > >                     hitContainer;
    typename std::map< std::pair< unsigned int, unsigned int >, pixelContainer< T > >::iterator centralPixel;

    typename std::vector< T >::const_iterator inputIterator;
    for( inputIterator = input.begin();
         inputIterator != input.end();
         ++inputIterator )
    {
      hitContainer[ std::make_pair( (**inputIterator).row(), (**inputIterator).column() ) ].centrePixel = &(*inputIterator);
      hitContainer[ std::make_pair( (**inputIterator).row(), (**inputIterator).column() ) ].kill0 = false;
      hitContainer[ std::make_pair( (**inputIterator).row(), (**inputIterator).column() ) ].kill1 = false;
      hitContainer[ std::make_pair( (**inputIterator).row(), (**inputIterator).column() ) ].neighbours = 0x00;
    } 

    for( centralPixel = hitContainer.begin();
         centralPixel != hitContainer.end();
         ++centralPixel )
    {
      unsigned int row = centralPixel->first.first;
      unsigned int col = centralPixel->first.second;



      centralPixel->second.neighbours[0] = ( hitContainer.find( std::make_pair( row-1, col+1 ) ) != hitContainer.end() );
      centralPixel->second.neighbours[1] = ( hitContainer.find( std::make_pair( row  , col+1 ) ) != hitContainer.end() );
      centralPixel->second.neighbours[2] = ( hitContainer.find( std::make_pair( row+1, col+1 ) ) != hitContainer.end() );

      centralPixel->second.neighbours[3] = ( hitContainer.find( std::make_pair( row-1, col   ) ) != hitContainer.end() );
      centralPixel->second.neighbours[4] = ( hitContainer.find( std::make_pair( row+1, col   ) ) != hitContainer.end() );

      centralPixel->second.neighbours[5] = ( hitContainer.find( std::make_pair( row-1, col-1 ) ) != hitContainer.end() );
      centralPixel->second.neighbours[6] = ( hitContainer.find( std::make_pair( row  , col-1 ) ) != hitContainer.end() );
      centralPixel->second.neighbours[7] = ( hitContainer.find( std::make_pair( row+1, col-1 ) ) != hitContainer.end() );

    } 

    for( centralPixel = hitContainer.begin();
         centralPixel != hitContainer.end();
         ++centralPixel )
    {

      bool adf = centralPixel->second.neighbours[0] | centralPixel->second.neighbours[3] | centralPixel->second.neighbours[5]  ;
      bool ceh = centralPixel->second.neighbours[2] | centralPixel->second.neighbours[4] | centralPixel->second.neighbours[7]  ;

      centralPixel->second.kill0 = ( adf & ceh );
      centralPixel->second.kill1 = ( adf | centralPixel->second.neighbours[6] );

    } 

    for( centralPixel = hitContainer.begin();
         centralPixel != hitContainer.end();
         ++centralPixel )
    {
      unsigned int row = centralPixel->first.first;
      unsigned int col = centralPixel->first.second;

      bool kill2 = false;
      typename std::map< std::pair< unsigned int, unsigned int >, pixelContainer< T > >::iterator rhs;

      if ( ( rhs = hitContainer.find( std::make_pair( row+1, col-1 ) ) ) != hitContainer.end() ) kill2 |= rhs->second.kill0;
      if ( ( rhs = hitContainer.find( std::make_pair( row+1, col   ) ) ) != hitContainer.end() ) kill2 |= rhs->second.kill0;
      if ( ( rhs = hitContainer.find( std::make_pair( row+1, col+1 ) ) ) != hitContainer.end() ) kill2 |= rhs->second.kill0;

      if ( !centralPixel->second.kill0 && !centralPixel->second.kill1 && !kill2 )
      {
        std::vector< T > temp;
        temp.push_back( *hitContainer[ std::make_pair( row , col ) ].centrePixel );
        if( centralPixel->second.neighbours[0] ) temp.push_back ( *hitContainer[ std::make_pair( row-1, col+1 ) ].centrePixel );
        if( centralPixel->second.neighbours[1] ) temp.push_back ( *hitContainer[ std::make_pair( row  , col+1 ) ].centrePixel );
        if( centralPixel->second.neighbours[2] ) temp.push_back ( *hitContainer[ std::make_pair( row+1, col+1 ) ].centrePixel );
        if( centralPixel->second.neighbours[3] ) temp.push_back ( *hitContainer[ std::make_pair( row-1, col   ) ].centrePixel );
        if( centralPixel->second.neighbours[4] ) temp.push_back ( *hitContainer[ std::make_pair( row+1, col   ) ].centrePixel );
        if( centralPixel->second.neighbours[5] ) temp.push_back ( *hitContainer[ std::make_pair( row-1, col-1 ) ].centrePixel );
        if( centralPixel->second.neighbours[6] ) temp.push_back ( *hitContainer[ std::make_pair( row  , col-1 ) ].centrePixel );
        if( centralPixel->second.neighbours[7] ) temp.push_back ( *hitContainer[ std::make_pair( row+1, col-1 ) ].centrePixel );
        output.push_back(temp);

      } 
    } 

    if( mDoubleCountingTest )
    {
      std::set< std::pair< unsigned int, unsigned int > > test;
      std::set< std::pair< unsigned int, unsigned int > > doubles;
      typename std::vector< std::vector< T > >::iterator outputIterator1;
      typename std::vector< T >::iterator                outputIterator2;
      for ( outputIterator1 = output.begin();
            outputIterator1 != output.end();
            ++outputIterator1 )
      {
        for ( outputIterator2 = outputIterator1->begin();
              outputIterator2 != outputIterator1->end();
              ++outputIterator2 )
        {
          if ( test.find( std::make_pair( (**outputIterator2).row(), (**outputIterator2).column() ) ) != test.end() )
            doubles.insert( std::make_pair( (**outputIterator2).row(), (**outputIterator2).column() ) );
          else
            test.insert( std::make_pair( (**outputIterator2).row(), (**outputIterator2).column() ) );

        } 
      } 

      if ( doubles.size() )
      {
        std::set< std::pair< unsigned int, unsigned int> >::iterator it;
        std::stringstream errmsg;
        for ( it = doubles.begin(); it != doubles.end(); ++it )
        {
          errmsg << "Double counted pixel: (" << it->first << "," << it->second << ")\n";
        }

        for ( outputIterator1 = output.begin();
              outputIterator1 != output.end();
              ++outputIterator1 )
        {
          errmsg <<  "cluster: ";
          for ( outputIterator2 = outputIterator1->begin();
                outputIterator2 != outputIterator1->end();
                ++outputIterator2 )
          {
            errmsg << "| (" <<  (**outputIterator2).row() <<","<< (**outputIterator2).column()<< ") ";
          }
          errmsg << "|\n";
        } 

        edm::LogError("ClusteringAlgorithm_2d") << errmsg.str();

      } 
    } 
  } 


Member Data Documentation

template<typename T>
bool ClusteringAlgorithm_2d< T >::mDoubleCountingTest [private]

Data members.

Definition at line 51 of file ClusteringAlgorithm_2d.h.

Referenced by ClusteringAlgorithm_2d< T >::ClusteringAlgorithm_2d().