FairRoot/PandaRoot
DecayChain.cxx
Go to the documentation of this file.
1 // ******************************************************
2 // DecayTreeFitter Package
3 // We thank the original author Wouter Hulsbergen
4 // (BaBar, LHCb) for providing the sources.
5 // http://arxiv.org/abs/physics/0503191v1 (2005)
6 // Adaptation & Development for PANDA: Ralf Kliemt (2015)
7 // ******************************************************
8 #include <algorithm>
9 #include "FitParams.h"
10 #include "ParticleBase.h"
11 #include "InteractionPoint.h"
12 #include "DecayChain.h"
13 
14 using namespace DecayTreeFitter;
15 
17 
18 extern int vtxverbose ;
19 
20 void
22 {
23  os << "Constraints in decay tree: " << m_constraintlist.size() << std::endl ;
24  for( ParticleBase::constraintlist::const_iterator
25  it = m_constraintlist.begin() ;
26  it != m_constraintlist.end(); ++it)
27  it->print(os) ;
28 }
29 
31 : m_dim(0),m_mother(0),m_isOwner(true)
32 {
33  //std::cout<<"DecayTreeFitter::DecayChain::DecayChain(RhoCandidate* bc="<<bc<<")"<<std::endl;
34  m_mother = (ParticleBase*) new InteractionPoint(bc,config) ;
35  //m_mother = ParticleBase::createParticle(bc,0,config) ;
36  //std::cout<<"DecayTreeFitter::DecayChain::DecayChain(RhoCandidate*) - updateIndex() now"<<std::endl;
38  //std::cout<<"DecayTreeFitter::DecayChain::DecayChain(RhoCandidate*) - locate() now"<<std::endl;
39  m_cand = locate(bc) ;
40  //std::cout<<"DecayTreeFitter::DecayChain::DecayChain(RhoCandidate*) - done"<<std::endl;
41 }
42 
44 : m_dim(0),m_mother(0),m_isOwner(true)
45 {
46  //std::cout<<"DecayTreeFitter::DecayChain::DecayChain(RhoCandidate* bc="<<bc<<",RhoVector3Err v("<<pv.x()<<","<<pv.y()<<","<<pv.z()<<"))"<<std::endl;
47  m_mother = (ParticleBase*) new InteractionPoint(pv,bc,config) ;
48  //std::cout<<"DecayTreeFitter::DecayChain::DecayChain(RhoCandidate*,RhoVector3Err) - updateIndex() now"<<std::endl;
50  //std::cout<<"DecayTreeFitter::DecayChain::DecayChain(RhoCandidate*,RhoVector3Err) - locate() now"<<std::endl;
51  m_cand = locate(bc) ;
52  //std::cout<<"DecayTreeFitter::DecayChain::DecayChain(RhoCandidate*,RhoVector3Err) - done"<<std::endl;
53 }
54 
56 : m_dim(0),m_mother(0),m_isOwner(true)
57 {
58  //std::cout<<"DecayTreeFitter::DecayChain::DecayChain(RhoCandidate* bc="<<bc<<",RhoLorentzVectorErr p("<<lv.X()<<","<<lv.Y()<<","<<lv.Z()<<","<<lv.E()<<"))"<<std::endl;
59  m_mother = (ParticleBase*) new InteractionPoint(lv,bc,config) ;
60  //std::cout<<"DecayTreeFitter::DecayChain::DecayChain(RhoCandidate*,RhoVector3Err) - updateIndex() now"<<std::endl;
62  //std::cout<<"DecayTreeFitter::DecayChain::DecayChain(RhoCandidate*,RhoVector3Err) - locate() now"<<std::endl;
63  m_cand = locate(bc) ;
64  //std::cout<<"DecayTreeFitter::DecayChain::DecayChain(RhoCandidate*,RhoVector3Err) - done"<<std::endl;
65 }
66 
68 : m_dim(0),m_mother(0),m_isOwner(true)
69 {
70  //std::cout<<"DecayTreeFitter::DecayChain::DecayChain(RhoCandidate* bc="<<bc<<",RhoLorentzVectorErr p("<<lv.X()<<","<<lv.Y()<<","<<lv.Z()<<","<<lv.E()<<")"<<",RhoVector3Err v("<<pv.x()<<","<<pv.y()<<","<<pv.z()<<"))"<<std::endl;
71  m_mother = (ParticleBase*) new InteractionPoint(lv,pv,bc,config) ;
72  //std::cout<<"DecayTreeFitter::DecayChain::DecayChain(RhoCandidate*,RhoVector3Err) - updateIndex() now"<<std::endl;
74  //std::cout<<"DecayTreeFitter::DecayChain::DecayChain(RhoCandidate*,RhoVector3Err) - locate() now"<<std::endl;
75  m_cand = locate(bc) ;
76  //std::cout<<"DecayTreeFitter::DecayChain::DecayChain(RhoCandidate*,RhoVector3Err) - done"<<std::endl;
77 }
78 
80 {
81  if(m_mother && m_isOwner) delete m_mother ;
82 }
83 
84 void
86 {
87  if( m_dim==0 ) m_mother->updateIndex(m_dim) ;
88  m_constraintlist.clear() ;
89  m_mother->addToConstraintList(m_constraintlist,0) ;
90 
91  // the order of the constraints is a rather delicate thing
92  std::sort(m_constraintlist.begin(),m_constraintlist.end()) ;
93 
94  // merge all non-lineair constraints
95  m_mergedconstraintlist.clear() ;
96  if(false) {
97  m_mergedconstraint = MergedConstraint() ;
98  for( ParticleBase::constraintlist::iterator it = m_constraintlist.begin() ;
99  it != m_constraintlist.end(); ++it) {
100  if( it->isLineair() ) m_mergedconstraintlist.push_back(&(*it)) ;
101  else m_mergedconstraint.push_back(&(*it)) ;
102  }
103  if( m_mergedconstraint.dim()>0 )
104  m_mergedconstraintlist.push_back(&m_mergedconstraint) ;
105  }
106  if(vtxverbose>=2) {
107  std::cout << "DecayTreeFitter::DecayChain::initConstraintList(): " << m_constraintlist.size() << " "
108  << m_mergedconstraintlist.size()<< std::endl ;
109  printConstraints() ;
110  }
111 }
112 
113 ErrCode
115 {
116  if(vtxverbose>5){std::cout<<"DecayChain::init(): - start"<<std::endl;}
117  ErrCode status ;
119  if( m_dim==0 ){
120  if(vtxverbose>5){std::cout<<"DecayChain::init(): - update index"<<std::endl;}
121  m_mother->updateIndex(m_dim) ;
122  }
123  //if( par.dim() != m_dim ) par = FitParams(m_dim) ;
124  if( par->dim() != m_dim ){
125  if(vtxverbose>5){std::cout<<"DecayChain::init(): - reset 1"<<std::endl;}
126  par->reset(m_dim);
127  } else {
128  // set everything to 0
129  if(vtxverbose>5){std::cout<<"DecayChain::init(): - reset 2"<<std::endl;}
130  par->resetPar() ;
131  par->resetCov() ;
132  }
133  // let the mother do it
134  if(vtxverbose>5){std::cout<<"DecayChain::init(): - initpar"<<std::endl;}
135  status |= m_mother->initPar1(par) ;
136  if(vtxverbose>5){std::cout<<"DecayChain::init(): - initcov"<<std::endl;}
137  status |= m_mother->initCov(par) ;
138 
139  if(vtxverbose>=2){ std::cout << "status after init: "; status.Print(std::cout); std::cout<< std::endl ;}
140 
141  return status ;
142 }
143 
144 ErrCode
146 {
147  if(vtxverbose>=4){std::cout<<"DecayChain::filter(): - ok, let's do this! Btw. we're "<<( firstpass ? "" : "not ")<<"on first pass."<<std::endl;}
148  ErrCode status ;
149  if(m_constraintlist.empty()){
150  if(vtxverbose>=4){std::cout<<"DecayChain::filter(): - init constrains"<<std::endl;}
151  initConstraintList() ;
152  }
153 
154  par->resetCov(1000) ; //FIXME: this scales the cov with a factor 1000. WHY???
155  //par->resetCov(100) ; //FIXME: this scales the cov with a factor 1000. WHY???
156  if(firstpass || !par->testCov()){
157  status |= m_mother->initCov(par) ;
158  if(vtxverbose>=3){std::cout<<"DecayChain::filter(): - initcov done"<<std::endl;}
159  }
160 
161  if( vtxverbose>=4 || (vtxverbose>=2&&firstpass) ) {
162  std::cout << "DecayTreeFitter::DecayChain::filter, after initialization: " << std::endl ;
163  m_mother->print(par) ;
164  }
165 
166  FitParams* reference = new FitParams(*par) ;
167 
168  if(m_mergedconstraintlist.empty() ) {
169  for( ParticleBase::constraintlist::const_iterator it = m_constraintlist.begin() ;
170  it != m_constraintlist.end(); ++it) {
171  status |= it->filter(par,reference) ;
172  if( vtxverbose>=2 && status.failure() ) {
173  std::cout << "DecayChain::filter(): status is failure after parsing constraint: " ;
174  it->print() ;
175  }
176  }
177  } else {
178  for( std::vector<Constraint*>::const_iterator it = m_mergedconstraintlist.begin() ;
179  it != m_mergedconstraintlist.end(); ++it) {
180  status |= (*it)->filter(par,reference) ;
181  if( vtxverbose>=2 && status.failure() ) {
182  std::cout << "DecayChain::filter(): status is failure after parsing constraint: " ;
183  (*it)->print() ;
184  }
185  }
186  }
187 
188 
189  if(vtxverbose>=3) {std::cout << "DecayChain::filter: status = "; status.Print(std::cout); std::cout<< std::endl ;}
190  if(reference) delete reference;
191  return status ;
192 }
193 
194 double
196 {
197  return m_mother->chiSquareD(par) ;
198 }
199 
200 const ParticleBase*
202  const ParticleBase* rc(0) ;
203  // return m_mother->locate(bc) ;
204  ParticleMap::const_iterator it = m_particleMap.find(bc) ;
205  if( it == m_particleMap.end() ) {
206  rc = m_mother->locate(bc) ;
207  // used to add every candidate here, but something goes wrong
208  // somewhere. now only cache pointers that we internally reference.
209  if(rc) m_particleMap[rc->particle()] = rc ;
210  } else {
211  rc = it->second ;
212  }
213  return rc ;
214 }
215 
216 void
218 {
219  ParticleBase* part = const_cast<ParticleBase*>(locate(bc)) ;
220  if(part && part->setMassConstraint(add)) {
221  m_dim = 0 ;
222  m_constraintlist.clear() ;
223  }
224 }
225 
226 void
228 {
229  ParticleBase* part = const_cast<ParticleBase*>(locate(bc)) ;
230  if(part) {
231  part->setMassConstraint(mass) ;
232  m_dim = 0 ;
233  m_constraintlist.clear() ;
234  }
235 }
236 
237 // TODO is it a problem to not identify by "ID"?
238 // void
239 // DecayTreeFitter::DecayChain::setMassConstraint(RhoCandidateID& pid, bool add)
240 // {
241 // ParticleBase::ParticleContainer particles ;
242 // m_mother->locate( pid, particles ) ;
243 // bool changed(false) ;
244 // for(ParticleBase::ParticleContainer::iterator it = particles.begin() ;
245 // it != particles.end() ; ++it)
246 // { changed |= (*it)->setMassConstraint(add) ; }
247 // //
248 // if (changed) {
249 // m_dim = 0 ;
250 // m_constraintlist.clear() ;
251 // }
252 // }
253 //
254 // void
255 // DecayTreeFitter::DecayChain::setMassConstraint(RhoCandidateID& pid , double mass )
256 // {
257 // ParticleBase::ParticleContainer particles ;
258 // m_mother->locate( pid, particles ) ;
259 // bool changed(false) ;
260 // for(ParticleBase::ParticleContainer::iterator it = particles.begin() ;
261 // it != particles.end() ; ++it)
262 // { (*it)->setMassConstraint(mass) ; changed = true ; }
263 // //
264 // if (changed) {
265 // m_dim = 0 ;
266 // m_constraintlist.clear() ;
267 // }
268 // }
269 
270 
271 int
273  int rc = -1 ;
274  const ParticleBase* base = locate(bc) ;
275  if(base) rc = base->index() ;
276  return rc ;
277 }
278 
279 int
281  const ParticleBase* base = locate(bc) ;
282  return base ? base->posIndex() : -1 ;
283 }
284 
285 int
287  const ParticleBase* base = locate(bc) ;
288  return base ? base->momIndex() : -1 ;
289 }
290 
291 int
293  const ParticleBase* base = locate(bc) ;
294  return base ? base->lenIndex() : 0 ;
295 }
296 
297 ChiSquare
299  const ParticleBase* base = locate(bc) ;
300  ChiSquare chisq ;
301  if( base ) {
302  chisq = base->chiSquare(fitpars) ;
303  // uhh: need to subtract the lifetime dof if this particle has a
304  // mother with a different vertex
305  if( base->mother() && base->posIndex()>=0 &&
306  base->posIndex() != base->mother()->posIndex() )
307  chisq += ChiSquare(0,1) ;
308  }
309  return chisq ;
310 }
int momIndex(RhoCandidate *bc) const
Definition: DecayChain.cxx:286
int lenIndex(RhoCandidate *bc) const
Definition: DecayChain.cxx:292
ParticleBase * m_mother
Definition: DecayChain.h:67
ErrCode init(FitParams *par)
Definition: DecayChain.cxx:114
int vtxverbose
bool failure() const
Definition: ErrCode.h:45
const ParticleBase * locate(RhoCandidate *bc) const
RhoCandidate * particle() const
Definition: ParticleBase.h:57
virtual int momIndex() const
Definition: ParticleBase.h:71
Double_t par[3]
virtual int lenIndex() const
Definition: ParticleBase.h:70
void Print(std::ostream &os)
Definition: ErrCode.cxx:34
ErrCode filter(FitParams *par, bool firstpass=true)
Definition: DecayChain.cxx:145
virtual int index() const
Definition: ParticleBase.h:59
virtual int posIndex() const
Definition: ParticleBase.h:69
virtual void updateIndex(int &offset)
int index(RhoCandidate *bc) const
Definition: DecayChain.cxx:272
const ParticleBase * m_cand
Definition: DecayChain.h:68
ChiSquare chiSquare(const FitParams *fitparams) const
void resetCov(double scale=100)
Definition: FitParams.cxx:43
int posIndex(RhoCandidate *bc) const
Definition: DecayChain.cxx:280
void printConstraints(std::ostream &os=std::cout) const
Definition: DecayChain.cxx:21
void reset(int newdim)
Definition: FitParams.cxx:100
bool setMassConstraint(bool add)
Definition: ParticleBase.h:118
const ParticleBase * locate(RhoCandidate *bc) const
Definition: DecayChain.cxx:201
double chiSquare(const FitParams *par) const
Definition: DecayChain.cxx:195
ClassImp(DecayChain)
const ParticleBase * mother() const
Definition: ParticleBase.h:60
int status[10]
Definition: f_Init.h:28
void setMassConstraint(RhoCandidate *bc, bool add=true)
Definition: DecayChain.cxx:217