CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Cluster1DCleaner.h
Go to the documentation of this file.
1 #ifndef _Cluster1DCleaner_H_
2 #define _Cluster1DCleaner_H_
3 
5 
6 /*
7  * given a vector<Cluster1D<T> >, erase Cluster1D further away than
8  * ZOffeSet from the average position, then
9  * recompute the vertex position. The ZOffeSet is taken as
10  * an aurgument
11 */
12 template < class T >
14 {
15 public:
16 
17  Cluster1DCleaner(const float zoffset, bool useErr):
18  theZOffSet(zoffset), theUseError(useErr)
19  {
20  theCleanedCluster1Ds.clear();
21  theDiscardedCluster1Ds.clear();
22  }
23  // return the compatible clusters
24  std::vector< Cluster1D< T > > clusters( const std::vector< Cluster1D< T > >& );
25  /*
26  return the vector of discarded Cluster1Ds
27  it should be called after Cluster1DCleaner::clusters
28  otherwise return an empty vector
29  */
30  std::vector< Cluster1D< T > > discardedCluster1Ds() const
31  {
33  }
34 
35 private:
36  void cleanCluster1Ds(const std::vector<Cluster1D<T> >& );
37  float average(const std::vector<Cluster1D<T> >&);
38  std::vector<Cluster1D<T> > theCleanedCluster1Ds;
39  std::vector<Cluster1D<T> > theDiscardedCluster1Ds;
40  float theZOffSet;
42 };
43 
44 /*
45  * implementation
46  */
47 
48 template <class T>
49 std::vector<Cluster1D<T> >
50 Cluster1DCleaner<T>::clusters(const std::vector<Cluster1D<T> >& _clust)
51 {
52  std::vector<Cluster1D<T> > clust = _clust;
53  cleanCluster1Ds(clust);
54  return theCleanedCluster1Ds;
55 }
56 
57 template <class T>
58 void
60 {
61  std::vector<Cluster1D<T> > clust = _clust;
62  theCleanedCluster1Ds.clear();
63  theDiscardedCluster1Ds.clear();
64  if (clust.size() == 0)
65  return;
66  float oldPos = average(clust);
67  for( typename std::vector < Cluster1D<T> >::const_iterator ic=clust.begin();
68  ic != clust.end(); ic++)
69  {
70  float discr =
71  theUseError ? fabs( ((*ic).position().value() - oldPos) / (*ic).position().error())
72  : fabs( ((*ic).position().value() - oldPos) );
73  if ( discr < theZOffSet )
74  {
75  theCleanedCluster1Ds.push_back(*ic);
76  }
77  else
78  {
79  theDiscardedCluster1Ds.push_back(*ic);
80  }
81  }
82  return;
83 }
84 
85 //I could use the Cluster1DMerger...
86 template <class T>
87 float
88 Cluster1DCleaner<T>::average(const std::vector<Cluster1D<T> >& clust)
89 {
90  float ave = clust.front().position().value();
91  float err = clust.front().position().error();
92  for( typename std::vector < Cluster1D<T> >::const_iterator ic=(clust.begin())+1;
93  ic != clust.end(); ic++)
94  {
95  float oldave = ave;
96  float olderr = err;
97  ave = ( oldave/olderr/olderr +
98  ic->position().value()/ic->position().error()/ic->position().error()) /
99  (1./olderr/olderr + 1./ic->position().error()/ic->position().error());
100  err = sqrt(olderr*olderr + ic->position().error()*ic->position().error());
101  }
102  return ave;
103 }
104 
105 #endif
std::vector< Cluster1D< T > > discardedCluster1Ds() const
float average(const std::vector< Cluster1D< T > > &)
void cleanCluster1Ds(const std::vector< Cluster1D< T > > &)
T sqrt(T t)
Definition: SSEVec.h:48
std::vector< Cluster1D< T > > theDiscardedCluster1Ds
std::vector< Cluster1D< T > > clusters(const std::vector< Cluster1D< T > > &)
std::vector< Cluster1D< T > > theCleanedCluster1Ds
int average
Definition: PDRates.py:137
Cluster1DCleaner(const float zoffset, bool useErr)
tuple discr
Definition: listHistos.py:51