CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

DivisiveClusterizer1D< T > Class Template Reference

#include <DivisiveClusterizer1D.h>

Inheritance diagram for DivisiveClusterizer1D< T >:
Clusterizer1D< T >

List of all members.

Public Member Functions

virtual DivisiveClusterizer1Dclone () const
 DivisiveClusterizer1D (float zoffset=5., int ntkmin=5, bool useError=true, float zsep=0.05, bool wei=true)
std::pair< std::vector
< Cluster1D< T >
>, std::vector< const T * > > 
operator() (const std::vector< Cluster1D< T > > &) const
 ~DivisiveClusterizer1D ()

Private Member Functions

void findCandidates (const std::vector< Cluster1D< T > > &, std::vector< Cluster1D< T > > &, std::vector< Cluster1D< T > > &) const
void insertTracks (std::vector< Cluster1D< T > > &, std::vector< Cluster1D< T > > &) const
std::vector< Cluster1D< T > > makeCluster1Ds (std::vector< Cluster1D< T > > &, std::vector< Cluster1D< T > > &) const
Cluster1D< TmergeCluster1Ds (std::vector< Cluster1D< T > > &) const
std::vector< const T * > takeTracks (const std::vector< Cluster1D< T > > &) const

Private Attributes

Cluster1DCleaner< T > * theCleaner
Cluster1DMerger< T > * theMerger
unsigned theNTkMin
bool theUseError
bool theWei
float theZOffSet
float theZSeparation

Detailed Description

template<class T>
class DivisiveClusterizer1D< T >

Find the modes with a simple divisive method.

Definition at line 14 of file DivisiveClusterizer1D.h.


Constructor & Destructor Documentation

template<class T >
DivisiveClusterizer1D< T >::DivisiveClusterizer1D ( float  zoffset = 5.,
int  ntkmin = 5,
bool  useError = true,
float  zsep = 0.05,
bool  wei = true 
)
Parameters:
zoffsetmaximum distance between track position and position of its cluster (depending on useError its either weighted or physical distance)
ntkminMinimum number of tracks required to form a cluster.
useErrorphysical distances or weighted distances.
zsepMaximum distance between two adjacent tracks that belong to the same initial cluster.
weiCompute the cluster "center" with an unweighted or a weighted average of the tracks. Weighted means weighted with the error of the data point.

Definition at line 67 of file DivisiveClusterizer1D.h.

References DivisiveClusterizer1D< T >::theCleaner, DivisiveClusterizer1D< T >::theMerger, DivisiveClusterizer1D< T >::theUseError, and DivisiveClusterizer1D< T >::theZOffSet.

        :theZOffSet(zoffset), theZSeparation(zsep), theNTkMin(ntkmin),
        theWei(wei), theUseError(useError)
{
    //  theDiscardedTracks.clear();
    // theTotalDiscardedTracks.clear();
    //  theCluster1Ds.clear();
    TrivialWeightEstimator<T> weightEstimator;
    theMerger = new Cluster1DMerger<T>( weightEstimator );
    theCleaner = new Cluster1DCleaner<T>(theZOffSet,theUseError);
}
template<class T >
DivisiveClusterizer1D< T >::~DivisiveClusterizer1D ( )

Definition at line 83 of file DivisiveClusterizer1D.h.

{
    delete theMerger;
    delete theCleaner;
}

Member Function Documentation

template<class T >
DivisiveClusterizer1D< T > * DivisiveClusterizer1D< T >::clone ( void  ) const [virtual]

Implements Clusterizer1D< T >.

Definition at line 102 of file DivisiveClusterizer1D.h.

{
    return new DivisiveClusterizer1D<T> ( * this );
}
template<class T >
void DivisiveClusterizer1D< T >::findCandidates ( const std::vector< Cluster1D< T > > &  inputo,
std::vector< Cluster1D< T > > &  finalCluster1Ds,
std::vector< Cluster1D< T > > &  totDiscardedTracks 
) const [private]

Definition at line 109 of file DivisiveClusterizer1D.h.

References LaserDQM_cfg::input, and python::multivaluedict::sort().

{
    using namespace Clusterizer1DCommons;

    std::vector < Cluster1D<T> > input = inputo;
    std::vector < Cluster1D<T> > discardedTracks;
    if ( input.size() < theNTkMin)
    {
        insertTracks( input, totDiscardedTracks);
        return;
    }
    sort( input.begin(), input.end(), ComparePairs<T>());
    int ncount =0;
    std::vector < Cluster1D<T> > partOfPTracks;
    partOfPTracks.push_back(input.front());
    for( typename std::vector < Cluster1D<T> >::const_iterator ic=(input.begin())+1;
            ic != input.end(); ic++)
    {
        ncount++;
        if ( fabs( (*ic).position().value()-(*(ic-1)).position().value() )
                < (double) theZSeparation )
        {
            partOfPTracks.push_back((*ic));
        }
        else
        {
            if(partOfPTracks.size() >= theNTkMin)
            {
                std::vector< Cluster1D<T> > clusters = makeCluster1Ds(partOfPTracks,
                                                     discardedTracks);
                for (typename std::vector< Cluster1D<T> >::const_iterator iclus=clusters.begin();
                        iclus != clusters.end(); iclus++)
                {
                    finalCluster1Ds.push_back(*iclus);
                }
                insertTracks(discardedTracks,totDiscardedTracks);
            }
            else
            {
                insertTracks(partOfPTracks,totDiscardedTracks);
            }
            partOfPTracks.clear();
            partOfPTracks.push_back((*ic));
        }
    }
    if (partOfPTracks.size() >= theNTkMin)
    {
        std::vector < Cluster1D<T> > clusters = makeCluster1Ds(partOfPTracks,
                                              discardedTracks);
        for (typename std::vector< Cluster1D<T> >::const_iterator iclus = clusters.begin();
                iclus != clusters.end(); iclus++)
        {
            finalCluster1Ds.push_back(*iclus);
        }
        insertTracks(discardedTracks,totDiscardedTracks);
    }
    else
    {
        insertTracks(partOfPTracks,totDiscardedTracks);
    }

    sort(finalCluster1Ds.begin(), finalCluster1Ds.end(),
         ComparePairs<T>() );
    // reverse(theCluster1Ds.begin(), theCluster1Ds.end());

    return;
}
template<class T >
void DivisiveClusterizer1D< T >::insertTracks ( std::vector< Cluster1D< T > > &  clusou,
std::vector< Cluster1D< T > > &  cludest 
) const [private]

Definition at line 233 of file DivisiveClusterizer1D.h.

{
    if (clusou.size() == 0)
        return;
    for ( typename std::vector< Cluster1D<T> >::const_iterator iclu = clusou.begin();
            iclu != clusou.end(); iclu++)
    {
        cludest.push_back(*iclu);
    }
    /*
    for ( typename std::vector< Cluster1D<T> >::const_iterator iclu = clu.begin(); 
    iclu != clu.end(); iclu++){
      if (total) {
        theTotalDiscardedTracks.push_back(*iclu);
      }else { 
        theDiscardedTracks.push_back(*iclu);
      }
    }
    */
    return;
}
template<class T >
std::vector< Cluster1D< T > > DivisiveClusterizer1D< T >::makeCluster1Ds ( std::vector< Cluster1D< T > > &  clusters,
std::vector< Cluster1D< T > > &  discardedTracks 
) const [private]

Definition at line 181 of file DivisiveClusterizer1D.h.

{

    std::vector < Cluster1D<T> > finalCluster1Ds;
    discardedTracks.clear();
    std::vector<Cluster1D<T> > pvClu0 = clusters;
    std::vector<Cluster1D<T> > pvCluNew = pvClu0;
    bool stop = false;
    while (!stop)
    {
        int nDiscardedAtIteration = 100;
        while ( nDiscardedAtIteration !=0 )
        {
            pvCluNew = theCleaner->clusters(pvClu0);
            std::vector<Cluster1D<T> >
            tracksAtIteration = theCleaner->discardedCluster1Ds();
            nDiscardedAtIteration = tracksAtIteration.size();
            if ( nDiscardedAtIteration!=0 )
            {
                insertTracks(tracksAtIteration,discardedTracks);
                pvClu0 = pvCluNew;
            }
        } // while nDiscardedAtIteration
        unsigned ntkclus = pvCluNew.size();
        unsigned ndiscard = discardedTracks.size();

        if ( ntkclus >=  theNTkMin )
        {
            //save the cluster
            finalCluster1Ds.push_back( mergeCluster1Ds(pvCluNew) );
            if ( ndiscard >= theNTkMin )
            { //make a new cluster and reset
                pvClu0 = discardedTracks;
                discardedTracks.clear();
            }
            else
            { //out of loop
                stop = true;
            }
        }
        else
        {
            insertTracks(pvCluNew, discardedTracks);
            stop = true;
        }
    }// while stop
    return finalCluster1Ds;
}
template<class T >
Cluster1D< T > DivisiveClusterizer1D< T >::mergeCluster1Ds ( std::vector< Cluster1D< T > > &  clusters) const [private]

Definition at line 276 of file DivisiveClusterizer1D.h.

References query::result.

{

    Cluster1D<T> result = clusters.front();
    for ( typename std::vector< Cluster1D<T> >::iterator iclu = (clusters.begin())+1;
            iclu != clusters.end(); iclu++)
    {
        Cluster1D<T> old = result;
        result = (*theMerger)( old , *iclu );
    }
    return result;
}
template<class T >
std::pair< std::vector< Cluster1D< T > >, std::vector< const T * > > DivisiveClusterizer1D< T >::operator() ( const std::vector< Cluster1D< T > > &  input) const [virtual]

Implements Clusterizer1D< T >.

Definition at line 92 of file DivisiveClusterizer1D.h.

References LaserDQM_cfg::input, and convertSQLitetoXML_cfg::output.

{
    std::vector < Cluster1D<T> > discardedCluster1Ds;
    std::vector < Cluster1D<T> > output;
    findCandidates ( input, output, discardedCluster1Ds );
    return std::pair < std::vector < Cluster1D<T> >, std::vector < const T * > >
           ( output, takeTracks(discardedCluster1Ds) );
}
template<class T >
std::vector< const T * > DivisiveClusterizer1D< T >::takeTracks ( const std::vector< Cluster1D< T > > &  clu) const [private]

Definition at line 258 of file DivisiveClusterizer1D.h.

References i, and testEve_cfg::tracks.

{
    std::vector<const T* > tracks;
    for ( typename std::vector< Cluster1D<T> >::const_iterator iclu = clu.begin();
            iclu != clu.end(); iclu++)
    {
        std::vector < const T * > clutks = iclu->tracks();
        for ( typename std::vector< const T * >::const_iterator i=clutks.begin();
                i!=clutks.end() ; ++i )
        {
            tracks.push_back ( *i );
        }
    }
    return tracks;
}

Member Data Documentation

template<class T>
Cluster1DCleaner<T>* DivisiveClusterizer1D< T >::theCleaner [private]
template<class T>
Cluster1DMerger<T>* DivisiveClusterizer1D< T >::theMerger [private]
template<class T>
unsigned DivisiveClusterizer1D< T >::theNTkMin [private]

Definition at line 56 of file DivisiveClusterizer1D.h.

template<class T>
bool DivisiveClusterizer1D< T >::theUseError [private]
template<class T>
bool DivisiveClusterizer1D< T >::theWei [private]

Definition at line 57 of file DivisiveClusterizer1D.h.

template<class T>
float DivisiveClusterizer1D< T >::theZOffSet [private]
template<class T>
float DivisiveClusterizer1D< T >::theZSeparation [private]

Definition at line 55 of file DivisiveClusterizer1D.h.