25 using namespace DecayTreeFitter;
35 for(
int iDau=0;iDau<bc->
NDaughters();iDau++ ){
60 if(
vtxverbose>5){std::cout<<
"InternalParticle::initPar1(): - "<<std::endl;}
62 std::cout <<
"InternalParticle::initPar1(): "
64 << hasPosition() <<
" " << posIndex() << std::endl ;
67 int posindex = posIndex() ;
70 assert( hasPosition() ) ;
72 std::cout <<
"InternalParticle::initPar1(): assertion passed"<<std::endl;
78 for(daucontainer::const_iterator it = begin() ; it != end() ; ++it)
79 status |= (*it)->initPar1(fitparams) ;
83 if( fitparams->
par()(posindex+0)==0 && fitparams->
par()(posindex+1)==0 &&
84 fitparams->
par()(posindex+2)==0 ) {
89 if(
vtxverbose>=3) std::cout <<
"InternalParticle::initPar1(): A"<<std::endl;
92 fitparams->
par(posindex+0) = vtx.x() ;
93 fitparams->
par(posindex+1) = vtx.y() ;
94 fitparams->
par(posindex+2) = vtx.z() ;
96 std::cout <<
"using existing vertex: " << vtx << std::endl ;
99 if(
vtxverbose>=3) std::cout <<
"InternalParticle::initPar1: B"<<std::endl;
112 collectVertexDaughters( alldaughters, posindex ) ;
113 if(
vtxverbose>=3) std::cout <<
"InternalParticle::initPar1(): number of daughters for initializing vertex: "
114 <<
name() <<
" " << alldaughters.size() << std::endl ;
116 if(
vtxverbose>=3) std::cout <<
"InternalParticle::initPar1(): B - r?"<<std::endl;
119 std::vector<RecoTrack*> trkdaughters ;
120 for(daucontainer::const_iterator it = alldaughters.begin() ;
121 it != alldaughters.end() ; ++it) {
123 trkdaughters.push_back( static_cast<RecoTrack*>(*it) ) ;
124 }
else if( (*it)->hasPosition() && fitparams->
par((*it)->posIndex()+0)!=0 ) {
125 vtxdaughters.push_back( *it ) ;
128 if(
vtxverbose>=3) std::cout <<
"InternalParticle::initPar1(): B -daughters?"<<std::endl;
130 if( trkdaughters.size() >=2 ) {
131 if(
vtxverbose>=3) std::cout <<
"InternalParticle::initPar1(): B -a?"<<std::endl;
133 if( trkdaughters.size()>2 )
146 double mu1(0),mu2(0) ;
148 TVector3
p1 = line1.position(
mu1) ;
149 TVector3
p2 = line2.position(mu2) ;
150 fitparams->
par()(posindex+0) = 0.5*(p1.x()+p2.x()) ;
151 fitparams->
par()(posindex+1) = 0.5*(p1.y()+p2.y()) ;
152 fitparams->
par()(posindex+2) = 0.5*(p1.z()+p2.z()) ;
156 }
else if(trkdaughters.size()+vtxdaughters.size()>=2) {
157 if(
vtxverbose>=3) std::cout <<
"InternalParticle::initPar1(): B -b?"<<std::endl;
158 std::cout <<
"InternalParticle::initPar1(): InternalParticle: Trying new code!"<< std::endl ;
166 std::vector<DecayTreeFitter::Line> trajectories ;
167 for(std::vector<RecoTrack*>::const_iterator it = trkdaughters.begin() ; it != trkdaughters.end() ; ++it)
178 for(daucontainer::const_iterator it = vtxdaughters.begin() ; it != vtxdaughters.end() ; ++it)
181 int dauposindex = (*it)->posIndex() ;
182 int daumomindex = (*it)->momIndex() ;
183 TVector3
point(fitparams->
par()(dauposindex+0), fitparams->
par()(dauposindex+1), fitparams->
par()(dauposindex+2)) ;
184 TVector3 direction(fitparams->
par()(daumomindex+0), fitparams->
par()(daumomindex+1), fitparams->
par()(daumomindex+2)) ;
192 double docabest(99999);
193 for( std::vector<DecayTreeFitter::Line>::iterator it1 = trajectories.begin() ; it1 != trajectories.end(); ++it1 )
195 for( std::vector<DecayTreeFitter::Line>::iterator it2 = trajectories.begin() ; it2 != it1; ++it2 )
197 double mu1(0),mu2(0) ;
199 TVector3
p1 = (*it1).position(
mu1) ;
200 TVector3
p2 = (*it2).position(mu2) ;
201 double doca = (p1-
p2).Mag();
204 fitparams->
par()(posindex+0) = 0.5*(p1.x()+p2.x()) ;
205 fitparams->
par()(posindex+1) = 0.5*(p1.y()+p2.y()) ;
206 fitparams->
par()(posindex+2) = 0.5*(p1.z()+p2.z()) ;
212 }
else if( mother() && mother()->posIndex()>=0 ) {
213 if(
vtxverbose>=3) std::cout <<
"InternalParticle::initPar1(): B -c?"<<std::endl;
216 int posindexmother = mother()->posIndex() ;
217 for(
int ipos=0; ipos<3; ipos++) {
218 fitparams->
par()(posindex+ipos) =
219 fitparams->
par()(posindexmother+ipos) ;
222 if(
vtxverbose>=3) std::cout <<
"InternalParticle::initPar1(): B -d?"<<std::endl;
224 std::cout <<
"InternalParticle::initPar1(): There are not sufficient geometric constraints to fit "
225 <<
"this decay tree. Perhaps you should add a beam constraint. "
232 if(
vtxverbose>=3) std::cout <<
"InternalParticle::initPar1(): C ?"<<std::endl;
236 std::cout <<
"InternalParticle::initPar1(): big code chunk passed"<<std::endl;
239 if(
vtxverbose>5){std::cout<<
"InternalParticle::initPar1(): - calling all initPar2()"<<std::endl;}
240 for(daucontainer::const_iterator it = daughters().begin() ;
241 it != daughters().end() ; ++it)
242 (*it)->initPar2(fitparams) ;
248 std::cout <<
"InternalParticle::initPar1(): End of initpar: "
249 <<
name() <<
" fitpar pos("
250 << fitparams->
par()(posindex+0) <<
","
251 << fitparams->
par()(posindex+1) <<
","
252 << fitparams->
par()(posindex+2) <<
")" << std::endl ;
260 if(
vtxverbose>5){std::cout<<
"InternalParticle::initPar2: - "<<std::endl;}
263 int posindex = posIndex() ;
264 if( hasPosition() && mother() && fitparams->
par(posindex+0)==0 &&
265 fitparams->
par(posindex+1)==0 && fitparams->
par(posindex+2)==0 ) {
266 int posindexmom = mother()->posIndex() ;
267 for(
int irow=0; irow<3; irow++)
268 fitparams->
par(posindex+irow) = fitparams->
par(posindexmom+irow) ;
271 return initTau(fitparams) ;
277 int momindex = momIndex() ;
279 for(
int irow=0; irow<4; irow++)
280 fitparams->
par(momindex+irow) = 0 ;
283 for(daucontainer::const_iterator it = begin() ; it != end() ; ++it) {
284 int daumomindex = (*it)->momIndex() ;
286 int maxrow = (*it)->hasEnergy() && !hasMassConstraint() ? 4 : 3 ;
287 for(
int irow=0; irow<maxrow; irow++) {
288 double px = fitparams->
par()(daumomindex+irow) ;
290 fitparams->
par(momindex+irow) += px ;
293 double mass = (*it)->pdtMass() ;
294 fitparams->
par(momindex+3) +=
sqrt(e2+mass*mass) ;
295 if(
vtxverbose>6){std::cout<<
"InternalParticle::initMom: mass="<<mass<<
", p^2="<<e2<<
", E="<<
sqrt(e2+mass*mass)<<
" from daughter momindex "<<daumomindex<<
" p=("<<fitparams->
par()(daumomindex+0)<<
","<<fitparams->
par()(daumomindex+1)<<
","<<fitparams->
par()(daumomindex+2)<<
")"<<std::endl;}
305 if(
vtxverbose>6){std::cout<<
"InternalParticle::projectKineConstraint():"<<std::endl;}
311 int momindex = momIndex() ;
312 for(
int imom=0; imom<4; imom++) {
313 p.
r(imom) = fitparams->
par()(momindex+imom) ;
314 p.
H(imom,momindex+imom) = 1 ;
318 for(daucontainer::const_iterator it = daughters().begin() ;
319 it != daughters().end() ; ++it) {
320 int daulenindex = (*it)->lenIndex() ;
321 int daumomindex = (*it)->momIndex() ;
322 double mass = (*it)->pdtMass() ;
323 double e2=mass*mass ;
324 int maxrow = (*it)->hasEnergy() ? 4 : 3 ;
325 for(
int imom=0; imom<maxrow; ++imom) {
326 double px = fitparams->
par()(daumomindex+imom) ;
329 p.
H(imom,daumomindex+imom) = -1 ;
336 for(
int jmom=0; jmom<3; ++jmom) {
337 double px = fitparams->
par()(daumomindex+jmom) ;
338 p.
H(3,daumomindex+jmom) = -px/
energy ;
340 }
else if(
false && daulenindex>=0 && (*it)->charge()!=0) {
342 double tau = fitparams->
par()(daulenindex) ;
343 double lambda = bFieldOverC() * (*it)->charge() ;
344 double px0 = fitparams->
par()(daumomindex) ;
345 double py0 = fitparams->
par()(daumomindex+1) ;
346 double pt0 =
sqrt(px0*px0+py0*py0) ;
347 const double posprecision = 1e-4 ;
348 if(
fabs(pt0*lambda*tau*tau) > posprecision ) {
349 double sinlt =
sin(lambda*tau) ;
350 double coslt =
cos(lambda*tau) ;
351 double px = px0*coslt - py0*sinlt ;
352 double py = py0*coslt + px0*sinlt ;
355 p.
H(0,daumomindex+0) += 1 - coslt ;
356 p.
H(0,daumomindex+1) += sinlt ;
357 p.
H(0,daulenindex+0) += lambda*py ;
358 p.
H(1,daumomindex+0) += -sinlt ;
359 p.
H(1,daumomindex+1) += 1 - coslt ;
360 p.
H(1,daulenindex+0) += -lambda*px ;
371 if(
vtxverbose>6){std::cout<<
"InternalParticle::projectLifeTimeConstraint():"<<std::endl;}
372 std::cout <<
"Not yet implemented lifetime constraint!" << std::endl ;
386 if(
vtxverbose>6){std::cout<<
"InternalParticle::projectConversionConstraint():"<<std::endl;}
389 assert(m_isconversion) ;
392 int daumomindexA = dauA->
momIndex() ;
393 int daumomindexB = dauB->
momIndex() ;
396 double momA2(0),momB2(0) ;
397 for(
int irow=0; irow<3; irow++) {
398 double pxA = fitparams->
par(daumomindexA+irow) ;
400 double pxB = fitparams->
par(daumomindexB+irow) ;
403 double momA(
sqrt(momA2)), momB(
sqrt(momB2)) ;
406 p.
r(1) = -momA*momB ;
407 for(
int irow=0; irow<3; irow++) {
408 double pxA = fitparams->
par(daumomindexA+irow) ;
409 double pxB = fitparams->
par(daumomindexB+irow) ;
411 p.
H(1,daumomindexA+irow) = pxB - pxA/momA * momB ;
412 p.
H(1,daumomindexB+irow) = pxA - pxB/momB * momA ;
432 aStatus |= projectMassConstraint(fitparams,p) ;
436 aStatus |= projectGeoConstraint(fitparams,p) ;
439 aStatus |= projectKineConstraint(fitparams,p) ;
442 aStatus |= projectLifeTimeConstraint(fitparams,p) ;
445 aStatus |= projectConversionConstraint(fitparams,p) ;
451 std::cout<<
"InternalParticle::projectConstraint(): projection is:"<<std::endl;
452 std::cout<<
"r "; p.
r().Print();
453 std::cout<<
"V "; p.
V().Print();
462 if(
vtxverbose>6){std::cout<<
"InternalParticle::projectMassConstraintTwoBody():"<<std::endl;}
473 double mass = pdtMass() ;
481 double px1 = fitparams->
par()(momindex1+0) ;
482 double py1 = fitparams->
par()(momindex1+1) ;
483 double pz1 = fitparams->
par()(momindex1+2) ;
485 double px2 = fitparams->
par()(momindex2+0) ;
486 double py2 = fitparams->
par()(momindex2+1) ;
487 double pz2 = fitparams->
par()(momindex2+2) ;
489 double E1 =
std::sqrt( m1*m1 + px1*px1 + py1*py1 + pz1*pz1 ) ;
490 double E2 =
std::sqrt( m2*m2 + px2*px2 + py2*py2 + pz2*pz2 ) ;
492 p.
r(0) = m1*m1 + m2*m2 + 2 * (E1*E2 - px1*px2 - py1*py2 - pz1*pz2 ) - mass* mass ;
495 p.
H(0,momindex1+0) = 2 * (E2 * px1/E1 - px2 ) ;
496 p.
H(0,momindex1+1) = 2 * (E2 * py1/E1 - py2 ) ;
497 p.
H(0,momindex1+2) = 2 * (E2 * pz1/E1 - pz2 ) ;
498 p.
H(0,momindex2+0) = 2 * (E1 * px2/E2 - px1 ) ;
499 p.
H(0,momindex2+1) = 2 * (E1 * py2/E2 - py1 ) ;
500 p.
H(0,momindex2+2) = 2 * (E1 * pz2/E2 - pz1 ) ;
503 double width = pdtWidth() ;
504 p.
Vfast(0,0) = 4*mass*mass*width*width ;
513 for(daucontainer::const_iterator it = daughters().begin() ;
514 it != daughters().end() ; ++it)
515 (*it)->addToConstraintList(alist,depth-1) ;
521 if(lenIndex()>=0 && m_lifetimeconstraint)
527 if(mother() && lenIndex()>=0)
530 if(hasMassConstraint()) {
531 if( !m_isconversion )
543 if(!mother() &&
id>=3) ++id ;
virtual ErrCode initPar1(FitParams *)
friend F32vec4 cos(const F32vec4 &a)
std::vector< DecayTreeFitter::Constraint > constraintlist
const TVectorD & r() const
Double_t lambda(Double_t x, Double_t y, Double_t z)
friend F32vec4 sqrt(const F32vec4 &a)
friend F32vec4 sin(const F32vec4 &a)
ErrCode projectConversionConstraint(const FitParams *, Projection &p) const
virtual std::string parname(int index) const
TVector3 position() const
virtual ErrCode projectConstraint(Constraint::Type type, const FitParams *fitparams, Projection &p) const
virtual int momIndex() const
RhoCandidate * Daughter(Int_t n)
ErrCode projectLifeTimeConstraint(const FitParams *, Projection &) const
virtual bool hasEnergy() const
const TMatrixD & H() const
virtual ErrCode initPar2(FitParams *)
const TMatrixDSym & V() const
TString m2(TString pts, TString exts="e px py pz")
ErrCode projectKineConstraint(const FitParams *, Projection &) const
void setFlightLength(double flt)
ErrCode projectMassConstraintTwoBody(const FitParams *fitparams, Projection &p) const
friend F32vec4 fabs(const F32vec4 &a)
virtual ErrCode projectConstraint(Constraint::Type, const FitParams *, Projection &) const
virtual std::string parname(int index) const
virtual void addToConstraintList(constraintlist &alist, int depth) const
ErrCode initMom(FitParams *fitparams) const
std::vector< ParticleBase * > daucontainer
InternalParticle(RhoCandidate *bc, const ParticleBase *mother, const Configuration &config)
bool m_lifetimeconstraint
ParticleBase * addDaughter(RhoCandidate *, const Configuration &config)
bool compTrkTransverseMomentum(const RecoTrack *lhs, const RecoTrack *rhs)
const daucontainer & daughters() const
bool closestPointParams(const Line &line0, const Line &line1, double &mu0, double &mu1)
const DecayTreeFitter::State & state() const
double & Vfast(int row, int col)