25 #include "TParticlePDG.h"
27 #include "TMatrixDSym.h"
48 : m_particle(aParticle),m_mother(aMother),
49 m_prop(aParticle->PdtEntry()),
50 m_index(0),m_pdtMass(0),m_pdtWidth(0),m_pdtCLifeTime(0),m_charge(0),
51 m_name(
"Unknown"), m_hasMassConstraint(false)
57 double fltcharge =
m_prop->Charge()/3. ;
58 m_charge = fltcharge < 0 ? int(fltcharge-0.5) : int(fltcharge+0.5) ;
68 : m_particle(0),m_mother(0),
70 m_index(0),m_pdtMass(0),m_pdtWidth(0),m_pdtCLifeTime(0),m_charge(0),
71 m_name(aname), m_hasMassConstraint(false)
77 for(daucontainer::iterator it = m_daughters.begin() ;
78 it != m_daughters.end() ; ++it)
85 if(
vtxverbose>=5){std::cout<<
"ParticleBase::updateIndex() start"<<std::endl;}
87 for(
const_iterator it = begin(); it!= end(); ++it) (*it)->updateIndex(offset) ;
91 if(
vtxverbose>=5){std::cout<<
"ParticleBase::updateIndex() end"<<std::endl;}
97 return m_daughters.back() ;
102 daucontainer::iterator it = std::find(m_daughters.begin(),m_daughters.end(),pb) ;
103 if(it != m_daughters.end() ) {
105 m_daughters.erase(it) ;
108 std::cout <<
"ERROR: cannot remove particle, because not found ..." << std::endl ;
120 const TParticlePDG* prop = particle->
PdtEntry();
123 std::cout <<
"DecayTreeFitter::ParticleBase::createParticle from " <<particle->
PdgCode() <<
" | " << particle->
Uid() << std::endl ;
129 bool validfit = particle->
IsLocked();
130 bool iscomposite = (particle->
NDaughters()>0) ;
131 bool isresonance = iscomposite && prop && isAResonance(prop) ;
143 std::cout <<
"DecayTreeFitter::ParticleBase::createParticle: You are fitting a decay tree that exists of "
144 <<
"a single, non-composite particle and which does not have a beamconstraint."
145 <<
"I do not understand what you want me to do with this." << std::endl ;
149 }
else if( !iscomposite ) {
151 bool ischarged = (
fabs(particle->
Charge())>0 );
159 rc =
new RecoTrack(particle,mother,config) ;
164 }
else if( validfit ) {
188 rc =
new Resonance(particle,mother,config) ;
196 std::cout <<
"DecayTreeFitter::ParticleBase::createParticle finished " <<particle->
PdgCode() <<
" | " << particle->
Uid() << std::endl ;
199 std::cout <<
"DecayTreeFitter::ParticleBase::createParticle returns type=" << rc->
type()
200 <<
" index=" << rc->
index() <<
" with name \""<< rc->
name() <<
"\""<<std::endl ;
207 switch(prop->PdgCode()) {
217 rc = (prop->Lifetime()>0) && (100.*
TMath::C()*prop->Lifetime() < 0.0001);
219 if(
vtxverbose>4)std::cout<<
"ParticleBase::isAResonance l."<<__LINE__<<
": ctau="<<100.*
TMath::C()*prop->Lifetime()<<
" cm"<<std::endl;
220 if(prop->Stable())
return false;
231 std::cout <<
"DecayTreeFitter::ParticleBase::collectVertexDaughters " << posindex << std::endl ;
234 if( mother() && mother()->posIndex() == posindex && type()!=kRecoResonance && type()!=kResonance )
236 particles.push_back(
this ) ;
238 std::cout <<
"DecayTreeFitter::ParticleBase::collectVertexDaughters - added a particle "<<
name()<<
" to vertex " << posindex << std::endl ;
241 for( daucontainer::const_iterator idau = daughters().begin() ;
242 idau != daughters().end() ; ++idau )
243 (*idau)->collectVertexDaughters(particles,posindex ) ;
253 std::cout <<
"DecayTreeFitter::ParticleBase::initCov for " <<
name() << std::endl ;
257 int posindex = posIndex() ;
259 const double sigx = 10;
260 const double sigy = 10;
261 const double sigz = 50;
262 fitparams->
cov()(posindex+0,posindex+0) = sigx*sigx ;
263 fitparams->
cov()(posindex+1,posindex+1) = sigy*sigy ;
264 fitparams->
cov()(posindex+2,posindex+2) = sigz*sigz ;
268 int momindex = momIndex() ;
271 const double sigmom = 10;
272 int maxrow = hasEnergy() ? 4 : 3 ;
273 for(
int row=momindex;
row<momindex+maxrow;
row++)
274 fitparams->
cov()(
row,
row) = sigmom*sigmom ;
278 int lenindex = lenIndex() ;
280 const double sigz = 50;
281 fitparams->
cov()(lenindex,lenindex) = sigz*sigz ;
284 for(daucontainer::const_iterator it = m_daughters.begin() ;
285 it != m_daughters.end() ; ++it)
286 status |= (*it)->initCov(fitparams) ;
293 std::string rc =
name() ;
295 case 0: rc +=
" x " ; break ;
296 case 1: rc +=
" y " ; break ;
297 case 2: rc +=
" z " ; break ;
298 case 3: rc +=
" len" ; break ;
299 case 4: rc +=
" px " ; break ;
300 case 5: rc +=
" py " ; break ;
301 case 6: rc +=
" pz " ; break ;
302 case 7: rc +=
" E " ; break ;
311 std::cout << std::setw(5) <<
"[" << type() <<
"]" << std::setw(15) << std::flush <<
name().c_str()
312 << std::setw(15)<<
" val" << std::setw(15)<<
"err" << std::setw(15) <<
"sigma^2"<< std::endl ;
313 std::cout << std::setprecision(5) ;
314 for(
int i=0;
i<dim();
i++) {
315 int theindex = index()+
i ;
316 std::cout << std::setw(2) << theindex <<
" "
317 << std::setw(20) << parname(
i).c_str()
318 << std::setw(15) << fitpar->
par()(theindex)
319 << std::setw(15) <<
sqrt(fitpar->
cov()(theindex,theindex))
320 << std::setw(15) << fitpar->
cov()(theindex,theindex) <<std::endl ;
323 int momindex = momIndex() ;
324 double E = fitpar->
par()(momindex+3) ;
325 double px = fitpar->
par()(momindex+0) ;
326 double py = fitpar->
par()(momindex+1) ;
327 double pz = fitpar->
par()(momindex+2) ;
328 double mass2 = E*E-px*px-py*py-pz*
pz ;
329 double mass = mass2>0 ?
sqrt(mass2) : -
sqrt(-mass2) ;
332 TMatrixDSym cov = fitpar->
cov().GetSub(momindex+0,momindex+3,momindex+0,momindex+3);
339 double massvar = cov.Similarity(G) ;
340 std::cout << std::setw(2)<<
"-"<<
" " << std::setw(20) <<
"mass: "
341 << std::setw(15) << mass
342 << std::setw(15) <<
sqrt(massvar)
343 << std::setw(15) << massvar << std::endl ;
346 for(daucontainer::const_iterator it = m_daughters.begin() ;
347 it != m_daughters.end() ; ++it)
348 (*it)->print(fitpar) ;
357 for(daucontainer::const_iterator it = m_daughters.begin() ;
358 !rc && it != m_daughters.
end(); ++it)
380 anindexmap.push_back(std::pair<const ParticleBase*,int>(
this,index())) ;
381 for(daucontainer::const_iterator it = m_daughters.begin() ;
382 it != m_daughters.end() ; ++it)
383 (*it)->retrieveIndexMap(anindexmap) ;
393 int posindexmother = mother()->posIndex() ;
394 int posindex = posIndex();
395 int lenindex = lenIndex() ;
396 int momindex = momIndex() ;
397 assert(posindexmother>=0 && posindex>=0 && lenindex>=0 && momindex>=0) ;
401 double px = fitparams->
par()(momindex+0) ;
402 double py = fitparams->
par()(momindex+1) ;
403 double pz = fitparams->
par()(momindex+2) ;
404 double p2 = px*px+py*py+pz*
pz ;
407 double dvx = fitparams->
par()(posindexmother+0) - fitparams->
par()(posindex+0);
408 double dvy = fitparams->
par()(posindexmother+1) - fitparams->
par()(posindex+1);
409 double dvz = fitparams->
par()(posindexmother+2) - fitparams->
par()(posindex+2);
410 double len=dvx*dvx+dvy*dvy+dvz*dvz;
415 double posxmother = fitparams->
par()(posindexmother+
row) ;
416 double posx = fitparams->
par()(posindex+
row) ;
417 double momx = fitparams->
par()(momindex+
row) ;
418 p.
r(
row) = posxmother - posx + len*momx/
mom ;
419 p.
H(
row,posindexmother+
row) = 1 ;
424 p.
H(0,momindex+0) = len/mom*( 1 - px*px/
p2 ) ;
425 p.
H(0,momindex+1) = len/mom*( 0 - px*py/
p2 ) ;
426 p.
H(0,momindex+2) = len/mom*( 0 - px*pz/
p2 ) ;
427 p.
H(1,momindex+0) = len/mom*( 0 - py*px/
p2 ) ;
428 p.
H(1,momindex+1) = len/mom*( 1 - py*py/
p2 ) ;
429 p.
H(1,momindex+2) = len/mom*( 0 - py*pz/
p2 ) ;
430 p.
H(2,momindex+0) = len/mom*( 0 - pz*px/
p2 ) ;
431 p.
H(2,momindex+1) = len/mom*( 0 - pz*py/
p2 ) ;
432 p.
H(2,momindex+2) = len/mom*( 1 - pz*pz/
p2 ) ;
469 std::cout<<
"ParticleBase::projectConstraint(): projection is:"<<std::endl;
470 std::cout<<
"r "; p.
r().Print();
471 std::cout<<
"V "; p.
V().Print();
480 if(
vtxverbose>6){std::cout<<
"ParticleBase::projectMassConstraint():"<<std::endl;}
481 double mass = pdtMass() ;
482 double mass2 = mass*mass ;
483 int momindex = momIndex() ;
486 double px = fitparams->
par()(momindex+0) ;
487 double py = fitparams->
par()(momindex+1) ;
488 double pz = fitparams->
par()(momindex+2) ;
489 double E = fitparams->
par()(momindex+3) ;
490 if(
vtxverbose>6){std::cout<<
"px="<<px<<
", py="<<py<<
", pz="<<pz<<
", E="<<E<<
", pdtmass="<<mass<<std::endl;}
491 p.
r(0) = E*E-px*px-py*py-pz*pz-mass2 ;
494 p.
H(0,momindex+0) = -2.0*px ;
495 p.
H(0,momindex+1) = -2.0*py ;
496 p.
H(0,momindex+2) = -2.0*
pz ;
497 p.
H(0,momindex+3) = 2.0*E ;
500 double width = pdtWidth() ;
501 p.
Vfast(0,0) = 4*mass*mass*width*width ;
509 std::cout <<
"ParticleBase::projectConstraint(): no method to project this constaint: "
510 <<
name() <<
" " << type() <<
" " << atype << std::endl ;
524 int lenindex = lenIndex() ;
525 if(lenindex>=0 && hasPosition() ) {
527 int momposindex = amother ? amother->
posIndex() : -1 ;
528 int posindex = posIndex() ;
529 int momindex = momIndex() ;
530 assert(momposindex>=0) ;
536 for(
int irow=0; irow<3; irow++) {
537 dX(irow) = fitparams->
par(posindex+irow) - fitparams->
par(momposindex+irow) ;
538 double px = fitparams->
par(momindex+irow) ;
542 double tau = dX.Dot(mom)/mom2 ;
544 if( tau==0 ) tau=pdtTau() ;
546 fitparams->
par(lenindex) = tau ;
554 for(daucontainer::const_iterator it = m_daughters.begin() ;
555 it != m_daughters.end(); ++it)
556 rc += (*it)->chiSquareD(fitparams) ;
562 for(daucontainer::const_iterator it = m_daughters.begin() ;
563 it != m_daughters.end() ; ++it)
564 rc +=(*it)->nFinalChargedCandidates() ;
572 for(daucontainer::const_iterator it = m_daughters.begin() ;
573 it != m_daughters.end() ; ++it) {
574 chi2 += (*it)->chiSquare(fitparams) ;
584 TVector3
pos(0.,0.,0.);
const TVectorD & r() const
const ParticleBase * locate(RhoCandidate *bc) const
friend F32vec4 sqrt(const F32vec4 &a)
PndPidCandidate * GetRecoCandidate() const
static bool isAResonance(const TParticlePDG *bc)
virtual ErrCode initCov(FitParams *) const
const TMatrixD & H() const
virtual double chiSquareD(const FitParams *) const
std::vector< std::pair< const ParticleBase *, int > > indexmap
virtual ErrCode projectGeoConstraint(const FitParams *, Projection &) const
const TMatrixDSym & V() const
static double bFieldOverC()
daucontainer::const_iterator const_iterator
void collectVertexDaughters(daucontainer &particles, int posindex)
const std::string & name() const
virtual int index() const
virtual int posIndex() const
const_iterator end() const
virtual void updateIndex(int &offset)
const TParticlePDG * PdtEntry() const
ParticleBase(RhoCandidate *bc, const ParticleBase *mother)
virtual int nFinalChargedCandidates() const
void removeDaughter(const ParticleBase *pb)
ChiSquare chiSquare(const FitParams *fitparams) const
friend F32vec4 fabs(const F32vec4 &a)
virtual ErrCode projectConstraint(Constraint::Type, const FitParams *, Projection &) const
virtual std::string parname(int index) const
const TParticlePDG * m_prop
virtual int type() const =0
std::vector< ParticleBase * > daucontainer
ParticleBase * addDaughter(RhoCandidate *, const Configuration &config)
ErrCode initTau(FitParams *par) const
virtual ErrCode projectMassConstraint(const FitParams *, Projection &) const
static ParticleBase * createParticle(RhoCandidate *bc, const ParticleBase *mother, const Configuration &config)
virtual void print(const FitParams *) const
virtual void retrieveIndexMap(indexmap &anindexmap) const
double & Vfast(int row, int col)