CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
DivisiveClusterizer1D< T > Class Template Reference

#include <DivisiveClusterizer1D.h>

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

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 ()
 
- Public Member Functions inherited from Clusterizer1D< T >
virtual ~Clusterizer1D ()
 

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.

71  :theZOffSet(zoffset), theZSeparation(zsep), theNTkMin(ntkmin),
72  theWei(wei), theUseError(useError)
73 {
74  // theDiscardedTracks.clear();
75  // theTotalDiscardedTracks.clear();
76  // theCluster1Ds.clear();
77  TrivialWeightEstimator<T> weightEstimator;
78  theMerger = new Cluster1DMerger<T>( weightEstimator );
80 }
Cluster1DCleaner< T > * theCleaner
Cluster1DMerger< T > * theMerger
template<class T >
DivisiveClusterizer1D< T >::~DivisiveClusterizer1D ( )

Definition at line 83 of file DivisiveClusterizer1D.h.

84 {
85  delete theMerger;
86  delete theCleaner;
87 }
Cluster1DCleaner< T > * theCleaner
Cluster1DMerger< T > * theMerger

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.

103 {
104  return new DivisiveClusterizer1D<T> ( * this );
105 }
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 HLT_25ns14e33_v1_cff::clusters, input, and python.multivaluedict::sort().

112 {
113  using namespace Clusterizer1DCommons;
114 
115  std::vector < Cluster1D<T> > input = inputo;
116  std::vector < Cluster1D<T> > discardedTracks;
117  if ( input.size() < theNTkMin)
118  {
119  insertTracks( input, totDiscardedTracks);
120  return;
121  }
122  sort( input.begin(), input.end(), ComparePairs<T>());
123  int ncount =0;
124  std::vector < Cluster1D<T> > partOfPTracks;
125  partOfPTracks.push_back(input.front());
126  for( typename std::vector < Cluster1D<T> >::const_iterator ic=(input.begin())+1;
127  ic != input.end(); ic++)
128  {
129  ncount++;
130  if ( fabs( (*ic).position().value()-(*(ic-1)).position().value() )
131  < (double) theZSeparation )
132  {
133  partOfPTracks.push_back((*ic));
134  }
135  else
136  {
137  if(partOfPTracks.size() >= theNTkMin)
138  {
139  std::vector< Cluster1D<T> > clusters = makeCluster1Ds(partOfPTracks,
140  discardedTracks);
141  for (typename std::vector< Cluster1D<T> >::const_iterator iclus=clusters.begin();
142  iclus != clusters.end(); iclus++)
143  {
144  finalCluster1Ds.push_back(*iclus);
145  }
146  insertTracks(discardedTracks,totDiscardedTracks);
147  }
148  else
149  {
150  insertTracks(partOfPTracks,totDiscardedTracks);
151  }
152  partOfPTracks.clear();
153  partOfPTracks.push_back((*ic));
154  }
155  }
156  if (partOfPTracks.size() >= theNTkMin)
157  {
158  std::vector < Cluster1D<T> > clusters = makeCluster1Ds(partOfPTracks,
159  discardedTracks);
160  for (typename std::vector< Cluster1D<T> >::const_iterator iclus = clusters.begin();
161  iclus != clusters.end(); iclus++)
162  {
163  finalCluster1Ds.push_back(*iclus);
164  }
165  insertTracks(discardedTracks,totDiscardedTracks);
166  }
167  else
168  {
169  insertTracks(partOfPTracks,totDiscardedTracks);
170  }
171 
172  sort(finalCluster1Ds.begin(), finalCluster1Ds.end(),
173  ComparePairs<T>() );
174  // reverse(theCluster1Ds.begin(), theCluster1Ds.end());
175 
176  return;
177 }
std::vector< Cluster1D< T > > makeCluster1Ds(std::vector< Cluster1D< T > > &, std::vector< Cluster1D< T > > &) const
static std::string const input
Definition: EdmProvDump.cc:43
void insertTracks(std::vector< Cluster1D< T > > &, std::vector< Cluster1D< T > > &) const
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.

235 {
236  if (clusou.size() == 0)
237  return;
238  for ( typename std::vector< Cluster1D<T> >::const_iterator iclu = clusou.begin();
239  iclu != clusou.end(); iclu++)
240  {
241  cludest.push_back(*iclu);
242  }
243  /*
244  for ( typename std::vector< Cluster1D<T> >::const_iterator iclu = clu.begin();
245  iclu != clu.end(); iclu++){
246  if (total) {
247  theTotalDiscardedTracks.push_back(*iclu);
248  }else {
249  theDiscardedTracks.push_back(*iclu);
250  }
251  }
252  */
253  return;
254 }
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.

References HLT_25ns14e33_v1_cff::clusters.

183 {
184 
185  std::vector < Cluster1D<T> > finalCluster1Ds;
186  discardedTracks.clear();
187  std::vector<Cluster1D<T> > pvClu0 = clusters;
188  std::vector<Cluster1D<T> > pvCluNew = pvClu0;
189  bool stop = false;
190  while (!stop)
191  {
192  int nDiscardedAtIteration = 100;
193  while ( nDiscardedAtIteration !=0 )
194  {
195  pvCluNew = theCleaner->clusters(pvClu0);
196  std::vector<Cluster1D<T> >
197  tracksAtIteration = theCleaner->discardedCluster1Ds();
198  nDiscardedAtIteration = tracksAtIteration.size();
199  if ( nDiscardedAtIteration!=0 )
200  {
201  insertTracks(tracksAtIteration,discardedTracks);
202  pvClu0 = pvCluNew;
203  }
204  } // while nDiscardedAtIteration
205  unsigned ntkclus = pvCluNew.size();
206  unsigned ndiscard = discardedTracks.size();
207 
208  if ( ntkclus >= theNTkMin )
209  {
210  //save the cluster
211  finalCluster1Ds.push_back( mergeCluster1Ds(pvCluNew) );
212  if ( ndiscard >= theNTkMin )
213  { //make a new cluster and reset
214  pvClu0 = discardedTracks;
215  discardedTracks.clear();
216  }
217  else
218  { //out of loop
219  stop = true;
220  }
221  }
222  else
223  {
224  insertTracks(pvCluNew, discardedTracks);
225  stop = true;
226  }
227  }// while stop
228  return finalCluster1Ds;
229 }
Cluster1DCleaner< T > * theCleaner
Cluster1D< T > mergeCluster1Ds(std::vector< Cluster1D< T > > &) const
void insertTracks(std::vector< Cluster1D< T > > &, std::vector< Cluster1D< T > > &) const
template<class T >
Cluster1D< T > DivisiveClusterizer1D< T >::mergeCluster1Ds ( std::vector< Cluster1D< T > > &  clusters) const
private

Definition at line 276 of file DivisiveClusterizer1D.h.

References HLT_25ns14e33_v1_cff::clusters, and query::result.

277 {
278 
279  Cluster1D<T> result = clusters.front();
280  for ( typename std::vector< Cluster1D<T> >::iterator iclu = (clusters.begin())+1;
281  iclu != clusters.end(); iclu++)
282  {
283  Cluster1D<T> old = result;
284  result = (*theMerger)( old , *iclu );
285  }
286  return result;
287 }
tuple result
Definition: query.py:137
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 input, and convertSQLitetoXML_cfg::output.

93 {
94  std::vector < Cluster1D<T> > discardedCluster1Ds;
95  std::vector < Cluster1D<T> > output;
96  findCandidates ( input, output, discardedCluster1Ds );
97  return std::pair < std::vector < Cluster1D<T> >, std::vector < const T * > >
98  ( output, takeTracks(discardedCluster1Ds) );
99 }
std::vector< const T * > takeTracks(const std::vector< Cluster1D< T > > &) const
static std::string const input
Definition: EdmProvDump.cc:43
void findCandidates(const std::vector< Cluster1D< T > > &, std::vector< Cluster1D< T > > &, std::vector< Cluster1D< T > > &) const
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.

259 {
260  std::vector<const T* > tracks;
261  for ( typename std::vector< Cluster1D<T> >::const_iterator iclu = clu.begin();
262  iclu != clu.end(); iclu++)
263  {
264  std::vector < const T * > clutks = iclu->tracks();
265  for ( typename std::vector< const T * >::const_iterator i=clutks.begin();
266  i!=clutks.end() ; ++i )
267  {
268  tracks.push_back ( *i );
269  }
270  }
271  return tracks;
272 }
int i
Definition: DBlmapReader.cc:9
tuple tracks
Definition: testEve_cfg.py:39

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.