CMS 3D CMS Logo

Cluster1DMerger.h
Go to the documentation of this file.
1 #ifndef _Cluster1DMerger_H_
2 #define _Cluster1DMerger_H_
3 
6 
8 
14 namespace pixeltemp {
15 
16 template < class T >
18 {
19 public:
20  Cluster1DMerger ( const WeightEstimator<T> &, const math::XYZPoint & bs = math::XYZPoint(0.,0.,0.) );
21  void setBeamSpot(const math::XYZPoint & bs) { theBS = bs; }
23  Cluster1DMerger ( const Cluster1DMerger & );
25  const Cluster1D<T> & second ) const;
26 private:
29 };
30 
31 /*
32  * implementation
33  */
34 
35 template <class T>
37 ( const WeightEstimator<T> & est, const math::XYZPoint & bs ) : theEstimator ( est.clone() ), theBS(bs)
38 {}
39 
40 template <class T>
42 {
43  delete theEstimator;
44 }
45 
46 template <class T>
48  theEstimator ( other.theEstimator->clone() ), theBS(other.theBS)
49 {}
50 
51 template <class T>
53  const Cluster1D<T> & second ) const
54 {
55  std::vector < const T * > tracks = first.tracks();
56  std::vector < const T * > sectracks = second.tracks();
57  for ( typename std::vector< const T * >::const_iterator i=sectracks.begin(); i!=sectracks.end() ; ++i )
58  {
59  tracks.push_back ( *i );
60  };
61  float newpos = ( first.position().value() * first.weight() / first.position().error() / first.position().error() +
62  second.position().value() * second.weight() / second.position().error() / second.position().error() ) /
63  ( first.weight() / first.position().error()/ first.position().error() +
64  second.weight() / second.position().error()/ second.position().error() );
65 
66  float newerr = sqrt ( first.position().error() * first.position().error() +
67  second.position().error() * second.position().error() );
68  float newWeight = theEstimator->weight ( tracks );
69 
70  // Now try a different method
71  float sumUp = 0;
72  float sumDown = 0;
73  float err = 0;
74  for (unsigned int i=0; i<tracks.size(); ++i) {
75 
76 // float err2 = tracks[i]->covariance( reco::TrackBase::i_dz, reco::TrackBase::i_dz );
77  float err2 = tracks[i]->dzError(); err2 *= err2;
78 
79  if (err2 != 0){
80  sumUp += tracks[i]->dz(theBS) * 1/err2; // error-weighted average of Z at IP
81  sumDown += 1/err2;
82  }
83  err += sqrt( err2 );
84  }
85 
86  newpos = sumUp/sumDown;
87  newerr = err/tracks.size()/sqrt(1.0*tracks.size());
88 
89  Measurement1D newmeas ( newpos, newerr );
90  return Cluster1D<T> ( newmeas, tracks, newWeight );
91 }
92 } // end of temporary namespace
93 #endif
void setBeamSpot(const math::XYZPoint &bs)
Cluster1D< T > operator()(const Cluster1D< T > &first, const Cluster1D< T > &second) const
double error() const
Definition: Measurement1D.h:27
Cluster1DMerger(const WeightEstimator< T > &, const math::XYZPoint &bs=math::XYZPoint(0., 0., 0.))
U second(std::pair< T, U > const &p)
T sqrt(T t)
Definition: SSEVec.h:18
WeightEstimator< T > * theEstimator
std::vector< const T * > tracks() const
Definition: Cluster1D.h:49
Measurement1D position() const
Definition: Cluster1D.h:55
virtual WeightEstimator * clone() const =0
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
double weight() const
Definition: Cluster1D.h:61
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
double value() const
Definition: Measurement1D.h:25