CMS 3D CMS Logo

Cluster1DCleaner.h
Go to the documentation of this file.
1 #ifndef _Cluster1DCleaner_H_
2 #define _Cluster1DCleaner_H_
3 
5 
6 #include <cmath>
7 
8 /*
9  * given a vector<Cluster1D<T> >, erase Cluster1D further away than
10  * ZOffeSet from the average position, then
11  * recompute the vertex position. The ZOffeSet is taken as
12  * an aurgument
13 */
14 namespace pixeltemp {
15 template < class T >
17 {
18 public:
19 
20  Cluster1DCleaner(const float zoffset, bool useErr):
21  theZOffSet(zoffset), theUseError(useErr)
22  {
23  theCleanedCluster1Ds.clear();
24  theDiscardedCluster1Ds.clear();
25  }
26  // return the compatible clusters
27  std::vector< Cluster1D< T > > clusters( const std::vector< Cluster1D< T > > &);
28  /*
29  return the vector of discarded Cluster1Ds
30  it should be called after Cluster1DCleaner::clusters
31  otherwise return an empty vector
32  */
33  std::vector< Cluster1D< T > > discardedCluster1Ds() const
34  {
36  }
37 
38 private:
39  void cleanCluster1Ds( const std::vector<Cluster1D<T> > &);
40  float average(const std::vector<Cluster1D<T> >&);
41  std::vector<Cluster1D<T> > theCleanedCluster1Ds;
42  std::vector<Cluster1D<T> > theDiscardedCluster1Ds;
43  float theZOffSet;
45 };
46 
47 /*
48  * implementation
49  */
50 
51 template <class T>
52 std::vector<Cluster1D<T> >
53 Cluster1DCleaner<T>::clusters(const std::vector<Cluster1D<T> >& clust)
54 {
55  cleanCluster1Ds(clust);
56  return theCleanedCluster1Ds;
57 }
58 
59 template <class T>
60 void
62 {
63  theCleanedCluster1Ds.clear();
64  theDiscardedCluster1Ds.clear();
65  if (clust.empty())
66  return;
67  float oldPos = average(clust);
68  for( typename std::vector < Cluster1D<T> >::const_iterator ic=clust.begin();
69  ic != clust.end(); ic++)
70  {
71  float discr =
72  theUseError ? fabs( ((*ic).position().value() - oldPos) / (*ic).position().error())
73  : fabs( ((*ic).position().value() - oldPos) );
74  if ( discr < theZOffSet )
75  {
76  theCleanedCluster1Ds.push_back(*ic);
77  }
78  else
79  {
80  theDiscardedCluster1Ds.push_back(*ic);
81  }
82  }
83  return;
84 }
85 
86 //I could use the Cluster1DMerger...
87 template <class T>
88 float
89 Cluster1DCleaner<T>::average(const std::vector<Cluster1D<T> >& clust)
90 {
91 // float ave = clust.front().position().value();
92 // float err = clust.front().position().error();
93 // for( typename std::vector < Cluster1D<T> >::const_iterator ic=(clust.begin())+1;
94 // ic != clust.end(); ic++)
95 // {
96 // float oldave = ave;
97 // float olderr = err;
98 // ave = ( oldave/olderr/olderr +
99 // ic->position().value()/ic->position().error()/ic->position().error()) /
100 // (1./olderr/olderr + 1./ic->position().error()/ic->position().error());
101 // err = sqrt(olderr*olderr + ic->position().error()*ic->position().error());
102 // }
103  float sumUp = 0;
104  float sumDown = 0;
105  float err = 0;
106  for( typename std::vector < Cluster1D<T> >::const_iterator ic=(clust.begin())+1;
107  ic != clust.end(); ic++)
108  {
109  float err2 = ic->position().error();
110  err2 *= err2;
111  if (err2 != 0){
112  sumUp += ic->position().value() / err2; // error-weighted average of Z at IP
113  sumDown += 1/err2;
114  }
115  err += std::sqrt( err2 );
116  }
117  return (sumDown>0) ? sumUp/sumDown : 0;
118 }
119 } // end of temp namespace
120 #endif
std::vector< Cluster1D< T > > theDiscardedCluster1Ds
std::vector< Cluster1D< T > > theCleanedCluster1Ds
T sqrt(T t)
Definition: SSEVec.h:18
void cleanCluster1Ds(const std::vector< Cluster1D< T > > &)
std::vector< Cluster1D< T > > clusters(const std::vector< Cluster1D< T > > &)
Cluster1DCleaner(const float zoffset, bool useErr)
float average(const std::vector< Cluster1D< T > > &)
std::vector< Cluster1D< T > > discardedCluster1Ds() const