FairRoot/PandaRoot
Public Types | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
DecayTreeFitter::MergedConstraint Class Reference

#include <MergedConstraint.h>

Inheritance diagram for DecayTreeFitter::MergedConstraint:
DecayTreeFitter::Constraint

Public Types

typedef std::vector< Constraint * > constraintlist
 
enum  Type {
  unknown =0, beamspot, lifetime, resonance,
  composite, track, photon, conversion,
  kinematic, massEnergy, geometric, mass,
  beamenergy, merged, ntypes
}
 

Public Member Functions

 MergedConstraint ()
 
virtual ~MergedConstraint ()
 
 MergedConstraint (const constraintlist &list)
 
virtual ErrCode project (const FitParams *fitpar, Projection &p) const
 
void push_back (Constraint *c)
 
virtual void print (std::ostream &os=std::cout) const
 
bool operator< (const Constraint &rhs) const
 
bool operator== (const Constraint &rhs) const
 
Type type () const
 
unsigned int dim () const
 
bool isLineair () const
 
unsigned int nIter () const
 
virtual ErrCode filter (FitParams *fitpar) const
 
virtual ErrCode filter (FitParams *fitpar, const FitParams *reference) const
 
std::string name () const
 
void setWeight (int w)
 

Protected Member Functions

void setDim (unsigned int d)
 
void setNIter (unsigned int d)
 

Private Attributes

constraintlist m_list
 

Detailed Description

Definition at line 17 of file MergedConstraint.h.

Member Typedef Documentation

Definition at line 20 of file MergedConstraint.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

DecayTreeFitter::MergedConstraint::MergedConstraint ( )
inline
virtual DecayTreeFitter::MergedConstraint::~MergedConstraint ( )
inlinevirtual

Definition at line 23 of file MergedConstraint.h.

23 {}
DecayTreeFitter::MergedConstraint::MergedConstraint ( const constraintlist list)
inline

Definition at line 25 of file MergedConstraint.h.

References d, m_list, and DecayTreeFitter::Constraint::setDim().

25  :
27  int d(0) ;
28  for(constraintlist::iterator it = m_list.begin() ;
29  it != m_list.end(); ++it) d += (*it)->dim() ;
30  setDim(d) ;
31  }
TObjArray * d
void setDim(unsigned int d)
Definition: Constraint.h:80

Member Function Documentation

unsigned int DecayTreeFitter::Constraint::dim ( ) const
inlineinherited

Definition at line 51 of file Constraint.h.

References DecayTreeFitter::Constraint::m_dim.

Referenced by push_back().

51 { return m_dim ; }
ErrCode DecayTreeFitter::Constraint::filter ( FitParams fitpar) const
virtualinherited

Definition at line 59 of file Constraint.cxx.

References DecayTreeFitter::FitParams::addChiSquare(), DecayTreeFitter::ErrCode::badsetup, DecayTreeFitter::FitParams::dim(), fabs(), DecayTreeFitter::ErrCode::failure(), kalman, DecayTreeFitter::Constraint::ntypes, p, DecayTreeFitter::FitParams::par(), print(), DecayTreeFitter::ErrCode::Print(), status, and vtxverbose.

60 {
61  ErrCode status ;
62  if(m_type<=Constraint::unknown || m_type>=Constraint::ntypes) {
63  std::cout << "Constraint::filter(FitParams*): unknown constraint: " << m_type
64  << std::endl ;
65  status |= ErrCode::badsetup ;
66  } else if (m_type!=merged && !m_node) {
67  std::cout << "Constraint::filter(FitParams*): constraint without a node"
68  << std::endl ;
69  status |= ErrCode::badsetup ;
70  } else {
71  if(vtxverbose>=3) { std::cout << "Constraint::filter(FitParams*): filtering " ; print() ;}
72  // save the unfiltered ('predicted') parameters. we need to
73  // store them if we want to iterate constraints.
74  const TVectorD* pred(0) ;
75  if(m_maxNIter>1) pred = new TVectorD(fitpar->par()) ;
76 
77  Projection p(fitpar->dim(),m_dim) ;
79  double chisq(0) ;
80  int iter(0) ;
81  bool finished(false) ;
82  if(vtxverbose>=5) { std::cout << "Constraint::filter(FitParams*): starting loop " ; print() ;}
83  while (!finished && !status.failure()) {
84  p.reset() ;
85  status |= project(fitpar,p) ;
86  if(!status.failure()) {
87  status |= kalman.init( p.r(), p.H(), fitpar, p.V() ) ;
88  //status |= kalman.init( p.r(), p.H(), fitpar, (&p.V()) ? ( p.V().NonZeros()>0 ? &p.V() : 0 ) : 0 ) ;
89  if( !status.failure()) {
90  if(iter==0 || !pred) {
91  kalman.updatePar( fitpar ) ;
92  } else {
93  kalman.updatePar( *pred, fitpar ) ;
94  }
95  const double dchisqconverged = 0.001 ;
96  double newchisq = kalman.chisq() ;
97  double dchisq = newchisq - chisq ;
98  bool diverging = iter > 0 && dchisq>0 ;
99  bool converged = fabs(dchisq) < dchisqconverged ;
100  finished = ++iter >= m_maxNIter || diverging || converged ;
101 
102  if(vtxverbose>=3) {
103  std::cout << "chi2,niter: "
104  << iter << " "<< std::setprecision(7)
105  << std::setw(12) << chisq << " "
106  << std::setw(12)<< newchisq << " "
107  << std::setw(12)<< dchisq << " "
108  << diverging << " "
109  << converged << " ";
110  status.Print(std::cout);
111  std::cout << std::endl ;
112  }
113  chisq = newchisq ;
114  }
115  }
116  }
117  if(!status.failure()) {
118  kalman.updateCov( fitpar ) ;
119  fitpar->addChiSquare( kalman.chisq(), m_dim, p.particle() ) ;
120  }
121  if(pred) delete pred ;
122  if(vtxverbose>=4 &&m_node&&
123  m_node->mother() ) { m_node->mother()->print(fitpar) ; }
124  }
125  if(vtxverbose>=5) { std::cout << "Constraint::filter(FitParams*): done" ; print() ;}
126  return status ;
127 }
Double_t p
Definition: anasim.C:58
bool failure() const
Definition: ErrCode.h:45
void addChiSquare(double chi2, int nconstraints, const ParticleBase *p)
Definition: FitParams.cxx:141
KalmanTask * kalman
virtual void print(std::ostream &os=std::cout) const
Definition: Constraint.cxx:171
void Print(std::ostream &os)
Definition: ErrCode.cxx:34
int vtxverbose
virtual ErrCode project(const FitParams *fitpar, Projection &p) const
Definition: Constraint.cxx:51
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
const ParticleBase * m_node
Definition: Constraint.h:83
virtual void print(const FitParams *) const
const ParticleBase * mother() const
Definition: ParticleBase.h:60
int status[10]
Definition: f_Init.h:28
ErrCode DecayTreeFitter::Constraint::filter ( FitParams fitpar,
const FitParams reference 
) const
virtualinherited

Definition at line 131 of file Constraint.cxx.

References DecayTreeFitter::FitParams::addChiSquare(), DecayTreeFitter::ErrCode::badsetup, DecayTreeFitter::KalmanCalculator::chisq(), DecayTreeFitter::FitParams::dim(), DecayTreeFitter::ErrCode::failure(), DecayTreeFitter::KalmanCalculator::init(), kalman, name, DecayTreeFitter::Constraint::ntypes, p, DecayTreeFitter::FitParams::par(), print(), DecayTreeFitter::ErrCode::Print(), status, DecayTreeFitter::KalmanCalculator::updateCov(), DecayTreeFitter::KalmanCalculator::updatePar(), and vtxverbose.

132 {
133  // filter but linearize around reference
134  ErrCode status ;
135  if(m_type<=Constraint::unknown || m_type>=Constraint::ntypes) {
136  std::cout << "Constraint::filter(FitParams*,FitParams*): unknown constraint: " << m_type
137  << std::endl ;
138  status |= ErrCode::badsetup ;
139  } else if (m_type!=merged && !m_node) {
140  std::cout << "Constraint::filter(FitParams*,FitParams*): filter constraint without a node"
141  << std::endl ;
142  status |= ErrCode::badsetup ;
143  } else {
144  if(vtxverbose>=3) { std::cout << "Constraint::filter(FitParams*,FitParams*): filtering (par&refpar) " ; print() ;}
145 
146  // project using the reference
147  Projection p(fitpar->dim(),m_dim) ;
148  if(vtxverbose>=5) { std::cout << "Constraint::filter(FitParams*,FitParams*): project"<<std::endl;}
149  status = project(reference,p) ;
150  if(vtxverbose>=5) { std::cout << "Constraint::filter(FitParams*,FitParams*): residual"<<std::endl;}
151  // now update the residual
152  p.r() += p.H() * (fitpar->par() - reference->par()) ;
153  if(vtxverbose>=5) { std::cout << "Constraint::filter(FitParams*,FitParams*): kalman"<<std::endl;}
154  // now call the Kalman update as usual
156  status |= kalman.init( p.r(), p.H(), fitpar, p.V() ) ;
157  //status |= kalman.init( p.r(), p.H(), fitpar, (&p.V()) ? ( p.V().NonZeros()>0 ? &p.V() : 0 ) : 0 ) ;
158  kalman.updatePar( fitpar ) ;
159  kalman.updateCov( fitpar ) ;
160  fitpar->addChiSquare( kalman.chisq(), m_dim, p.particle() ) ;
161  if(vtxverbose>=3) { std::cout << "Constraint::filter(FitParams*,FitParams*): \""<<name()<<"\" Chisquare contribution: " <<kalman.chisq()<<" with "<<m_dim<<" dimensions from particle "<<p.particle()->name()<<std::endl;}
162  if(vtxverbose>=5) { std::cout << "Constraint::filter(FitParams*,FitParams*): done"<<std::endl;}
163  }
164  if( status.failure()){
165  std::cout << "Constraint::filter(FitParams*,FitParams*): error filtering constraint: "
166  << name() << " "; status.Print(std::cout); std::cout << std::endl ;}
167 
168  return status ;
169 }
Double_t p
Definition: anasim.C:58
bool failure() const
Definition: ErrCode.h:45
std::string name() const
Definition: Constraint.cxx:179
void addChiSquare(double chi2, int nconstraints, const ParticleBase *p)
Definition: FitParams.cxx:141
KalmanTask * kalman
virtual void print(std::ostream &os=std::cout) const
Definition: Constraint.cxx:171
void Print(std::ostream &os)
Definition: ErrCode.cxx:34
int vtxverbose
virtual ErrCode project(const FitParams *fitpar, Projection &p) const
Definition: Constraint.cxx:51
void updatePar(FitParams *fitparams)
const ParticleBase * m_node
Definition: Constraint.h:83
void updateCov(FitParams *fitparams)
int status[10]
Definition: f_Init.h:28
ErrCode init(const TVectorD &value, const TMatrixD &G, const FitParams *fitparams, const TMatrixDSym &V, int weight=1)
bool DecayTreeFitter::Constraint::isLineair ( ) const
inlineinherited

Definition at line 52 of file Constraint.h.

References DecayTreeFitter::Constraint::m_maxNIter.

52 { return m_maxNIter <=1 ; }
std::string DecayTreeFitter::Constraint::name ( ) const
inherited

Definition at line 179 of file Constraint.cxx.

References track.

180 {
181  std::string rc = "unknown constraint!" ;
182  switch(m_type)
183  {
184  case beamspot: rc = "beamspot" ; break ;
185  case beamenergy: rc = "beamenergy" ; break ;
186  case composite: rc = "composite" ; break ;
187  case resonance: rc = "resonance" ; break ;
188  case track: rc = "track" ; break ;
189  case photon: rc = "photon" ; break ;
190  case kinematic: rc = "kinematic" ; break ;
191  case geometric: rc = "geometric" ; break ;
192  case mass: rc = "mass" ; break ;
193  case massEnergy: rc = "massEnergy" ; break ;
194  case lifetime: rc = "lifetime" ; break ;
195  case merged: rc = "merged" ; break ;
196  case conversion: rc = "conversion" ; break ;
197  case ntypes:
198  case unknown:
199  break ;
200  }
201  return rc ;
202 }
unsigned int DecayTreeFitter::Constraint::nIter ( ) const
inlineinherited

Definition at line 53 of file Constraint.h.

References DecayTreeFitter::Constraint::m_maxNIter.

Referenced by push_back().

53 { return m_maxNIter ; }
bool DecayTreeFitter::Constraint::operator< ( const Constraint rhs) const
inherited

Definition at line 20 of file Constraint.cxx.

References DecayTreeFitter::Constraint::m_depth, and DecayTreeFitter::Constraint::m_type.

21 {
22  // the simple way
23  return m_type < rhs.m_type ||
24  (m_type == rhs.m_type && m_depth < rhs.m_depth) ;
25 
26  // this is probably the second most complicated routine: how do we
27  // order the constraints. there is one very special case:
28  // Ks->pipi0 requires the pi0 mass constraints at the very
29  // end. otherwise, it just doesn't work. in all other cases, we
30  // prefer to fit 'down' the tree'. the 'external' constraints must
31  // be filtered first, but soft pions must be fitted after the
32  // geometric constraints of the D. You see, this is horrible.
33 
34  // if either of the two is external, or either of the two is a
35  // mass constraint, we order by m_typem_
36 
37  // if( (m_type <= Constraint::composite ||
38  // rhs.m_type <= Constraint::composite ) ||
39  // (m_type >= Constraint::mass ||
40  // rhs.m_type >= Constraint::mass ) ) {
41  // return m_type < rhs.m_type ||
42  // (m_type == rhs.m_type && m_depth < rhs.m_depth) ;
43  // }
45  //return m_depth < rhs.m_depth ||
46  //(m_depth == rhs.m_depth && m_type < rhs.m_type ) ;
47 
48 }
bool DecayTreeFitter::Constraint::operator== ( const Constraint rhs) const
inlineinherited

Definition at line 46 of file Constraint.h.

References DecayTreeFitter::Constraint::m_type.

46  {
47  return m_type == rhs.m_type ; }
void DecayTreeFitter::MergedConstraint::print ( std::ostream os = std::cout) const
virtual

Reimplemented from DecayTreeFitter::Constraint.

Definition at line 29 of file MergedConstraint.cxx.

30 {
31  os << "Merged constraint: " << std::endl ;
32  for(constraintlist::const_iterator it = m_list.begin() ;
33  it != m_list.end() ; ++it) {
34  os << " " ;
35  (*it)->print(os) ;
36  }
37 }
ErrCode DecayTreeFitter::MergedConstraint::project ( const FitParams fitpar,
Projection p 
) const
virtual

Reimplemented from DecayTreeFitter::Constraint.

Definition at line 16 of file MergedConstraint.cxx.

References DecayTreeFitter::Projection::incrementOffset(), and status.

18 {
19  ErrCode status ;
20  for(constraintlist::const_iterator it = m_list.begin() ;
21  it != m_list.end() ; ++it) {
22  status |= (*it)->project(fitpar,p) ;
23  p.incrementOffset((*it)->dim()) ;
24  }
25 
26  return status ;
27 }
void incrementOffset(unsigned int i)
Definition: Projection.h:80
int status[10]
Definition: f_Init.h:28
void DecayTreeFitter::MergedConstraint::push_back ( Constraint c)
inline

Definition at line 35 of file MergedConstraint.h.

References DecayTreeFitter::Constraint::dim(), m_list, max(), DecayTreeFitter::Constraint::nIter(), DecayTreeFitter::Constraint::setDim(), and DecayTreeFitter::Constraint::setNIter().

35  {
36  m_list.push_back(c) ;
37  setDim(dim()+c->dim()) ;
38  setNIter(std::max(nIter(),c->nIter())) ;
39  }
unsigned int nIter() const
Definition: Constraint.h:53
void setDim(unsigned int d)
Definition: Constraint.h:80
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:26
unsigned int dim() const
Definition: Constraint.h:51
void setNIter(unsigned int d)
Definition: Constraint.h:81
void DecayTreeFitter::Constraint::setDim ( unsigned int  d)
inlineprotectedinherited

Definition at line 80 of file Constraint.h.

References d, and DecayTreeFitter::Constraint::m_dim.

Referenced by MergedConstraint(), and push_back().

80 { m_dim = d ; }
TObjArray * d
void DecayTreeFitter::Constraint::setNIter ( unsigned int  d)
inlineprotectedinherited

Definition at line 81 of file Constraint.h.

References d, and DecayTreeFitter::Constraint::m_maxNIter.

Referenced by push_back().

81 { m_maxNIter = d ; }
TObjArray * d
void DecayTreeFitter::Constraint::setWeight ( int  w)
inlineinherited

Definition at line 73 of file Constraint.h.

References DecayTreeFitter::Constraint::m_weight.

73 { m_weight = w<0 ? -1 : 1 ; }
Type DecayTreeFitter::Constraint::type ( ) const
inlineinherited

Definition at line 50 of file Constraint.h.

References DecayTreeFitter::Constraint::m_type.

50 { return m_type ; }

Member Data Documentation

constraintlist DecayTreeFitter::MergedConstraint::m_list
private

Definition at line 44 of file MergedConstraint.h.

Referenced by MergedConstraint(), and push_back().


The documentation for this class was generated from the following files: