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

#include <Constraint.h>

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

Public Types

enum  Type {
  unknown =0, beamspot, lifetime, resonance,
  composite, track, photon, conversion,
  kinematic, massEnergy, geometric, mass,
  beamenergy, merged, ntypes
}
 

Public Member Functions

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
 
 Constraint ()
 
 Constraint (const ParticleBase *node, Type atype, int depth, unsigned int adim, int maxniter=1)
 
virtual ~Constraint ()
 
virtual ErrCode project (const FitParams *fitpar, Projection &p) const
 
virtual ErrCode filter (FitParams *fitpar) const
 
virtual ErrCode filter (FitParams *fitpar, const FitParams *reference) const
 
virtual void print (std::ostream &os=std::cout) const
 
std::string name () const
 
void setWeight (int w)
 

Protected Member Functions

 Constraint (Constraint::Type atype)
 
void setDim (unsigned int d)
 
void setNIter (unsigned int d)
 

Private Attributes

const ParticleBasem_node
 
int m_depth
 
Type m_type
 
unsigned int m_dim
 
int m_weight
 
int m_maxNIter
 

Detailed Description

Definition at line 22 of file Constraint.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

DecayTreeFitter::Constraint::Constraint ( )
inline
DecayTreeFitter::Constraint::Constraint ( const ParticleBase node,
Type  atype,
int  depth,
unsigned int  adim,
int  maxniter = 1 
)
inline

Definition at line 57 of file Constraint.h.

60  : m_node(node), m_depth(depth), m_type(atype), m_dim(adim),
61  m_weight(1), m_maxNIter(maxniter) {}
const ParticleBase * m_node
Definition: Constraint.h:83
virtual DecayTreeFitter::Constraint::~Constraint ( )
inlinevirtual

Definition at line 63 of file Constraint.h.

63 {}
DecayTreeFitter::Constraint::Constraint ( Constraint::Type  atype)
inlineprotected

Definition at line 77 of file Constraint.h.

Member Function Documentation

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

Definition at line 51 of file Constraint.h.

References m_dim.

Referenced by DecayTreeFitter::MergedConstraint::push_back().

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

Definition at line 59 of file Constraint.cxx.

References DecayTreeFitter::FitParams::addChiSquare(), DecayTreeFitter::ErrCode::badsetup, DecayTreeFitter::FitParams::dim(), fabs(), DecayTreeFitter::ErrCode::failure(), kalman, 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
virtual

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, 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
inline

Definition at line 52 of file Constraint.h.

References m_maxNIter.

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

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
inline

Definition at line 53 of file Constraint.h.

References m_maxNIter.

Referenced by DecayTreeFitter::MergedConstraint::push_back().

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

Definition at line 20 of file Constraint.cxx.

References m_depth, and 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
inline

Definition at line 46 of file Constraint.h.

References m_type.

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

Reimplemented in DecayTreeFitter::MergedConstraint.

Definition at line 171 of file Constraint.cxx.

172 {
173  os << "node index = " << m_node->index()
174  << " name = " << m_node->name().c_str()
175  << " constraint type = " << m_type
176  << " depth = " << m_depth << std::endl ;
177 }
const std::string & name() const
Definition: ParticleBase.h:61
virtual int index() const
Definition: ParticleBase.h:59
const ParticleBase * m_node
Definition: Constraint.h:83
ErrCode DecayTreeFitter::Constraint::project ( const FitParams fitpar,
Projection p 
) const
virtual

Reimplemented in DecayTreeFitter::MergedConstraint.

Definition at line 51 of file Constraint.cxx.

References DecayTreeFitter::Projection::setParticle().

52 {
53  // this one will be overruled by the MergedConstraint
54  p.setParticle( *m_node ) ;
55  return m_node->projectConstraint(m_type,fitpar,p) ;
56 }
void setParticle(const ParticleBase &p)
Definition: Projection.h:83
virtual ErrCode projectConstraint(Constraint::Type, const FitParams *, Projection &) const
const ParticleBase * m_node
Definition: Constraint.h:83
void DecayTreeFitter::Constraint::setDim ( unsigned int  d)
inlineprotected

Definition at line 80 of file Constraint.h.

References d, and m_dim.

Referenced by DecayTreeFitter::MergedConstraint::MergedConstraint(), and DecayTreeFitter::MergedConstraint::push_back().

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

Definition at line 81 of file Constraint.h.

References d, and m_maxNIter.

Referenced by DecayTreeFitter::MergedConstraint::push_back().

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

Definition at line 73 of file Constraint.h.

References m_weight.

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

Definition at line 50 of file Constraint.h.

References m_type.

50 { return m_type ; }

Member Data Documentation

int DecayTreeFitter::Constraint::m_depth
private

Definition at line 84 of file Constraint.h.

Referenced by operator<().

unsigned int DecayTreeFitter::Constraint::m_dim
private

Definition at line 86 of file Constraint.h.

Referenced by dim(), and setDim().

int DecayTreeFitter::Constraint::m_maxNIter
private

Definition at line 89 of file Constraint.h.

Referenced by isLineair(), nIter(), and setNIter().

const ParticleBase* DecayTreeFitter::Constraint::m_node
private

Definition at line 83 of file Constraint.h.

Type DecayTreeFitter::Constraint::m_type
private

Definition at line 85 of file Constraint.h.

Referenced by operator<(), operator==(), and type().

int DecayTreeFitter::Constraint::m_weight
private

Definition at line 88 of file Constraint.h.

Referenced by setWeight().


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