#include <RecoVertex/KinematicFit/interface/ConstrainedTreeBuilder.h>
Public Member Functions | |
RefCountedKinematicTree | buildTree (vector< RefCountedKinematicParticle > prt, RefCountedKinematicVertex vtx, const AlgebraicMatrix &fCov) const |
Method constructing tree out of set of refitted particles, vertex, and full vertex - all tracks covariance matrix. | |
ConstrainedTreeBuilder () | |
~ConstrainedTreeBuilder () | |
Private Member Functions | |
AlgebraicMatrix | momentumPart (vector< RefCountedKinematicParticle > rPart, const AlgebraicVector &newPar, const AlgebraicMatrix &fitCov) const |
Private Attributes | |
VirtualKinematicParticleFactory * | pFactory |
KinematicVertexFactory * | vFactory |
To be used by corresponding fitter only. Tree builders are scheduled for generalization: They should be inherited from the single generic class in the next version of the library.
Definition at line 15 of file ConstrainedTreeBuilder.h.
ConstrainedTreeBuilder::ConstrainedTreeBuilder | ( | ) |
Definition at line 5 of file ConstrainedTreeBuilder.cc.
References pFactory, and vFactory.
00006 { 00007 pFactory = new VirtualKinematicParticleFactory(); 00008 vFactory = new KinematicVertexFactory(); 00009 }
ConstrainedTreeBuilder::~ConstrainedTreeBuilder | ( | ) |
RefCountedKinematicTree ConstrainedTreeBuilder::buildTree | ( | vector< RefCountedKinematicParticle > | prt, | |
RefCountedKinematicVertex | vtx, | |||
const AlgebraicMatrix & | fCov | |||
) | const |
Method constructing tree out of set of refitted particles, vertex, and full vertex - all tracks covariance matrix.
Particles (not states!) are passed since only particle "knows" how to construct itself out of refitted state (which factory/propagator should be used).
Definition at line 17 of file ConstrainedTreeBuilder.cc.
References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), i, j, momentumPart(), KinematicTree::movePointerToTheTop(), VirtualKinematicParticleFactory::particle(), pFactory, KinematicTree::replaceCurrentParticle(), funct::sqrt(), tree, KinematicVertexFactory::vertex(), vFactory, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().
Referenced by KinematicConstrainedVertexFitter::fit().
00019 { 00020 00021 //now making a new virtual particle out of refitted states 00022 AlgebraicVector par(7,0); 00023 par(1) = vtx->position().x(); 00024 par(2) = vtx->position().y(); 00025 par(3) = vtx->position().z(); 00026 double ent = 0.; 00027 int charge = 0; 00028 const MagneticField* field=prt.front()->magneticField(); 00029 for(vector<RefCountedKinematicParticle>::iterator i = prt.begin(); i != prt.end(); i++) 00030 { 00031 charge += (*i)->currentState().particleCharge(); 00032 // GlobalVector rMom = (*i)->currentState().globalMomentum(); 00033 // ParticleMass mm = (*i)->currentState().mass(); 00034 //temporary hack 00035 00036 GlobalVector rMom = (*i)->stateAtPoint(vtx->position()).globalMomentum(); 00037 ParticleMass mm = (*i)->stateAtPoint(vtx->position()).mass(); 00038 par(4) += rMom.x(); 00039 par(5) += rMom.y(); 00040 par(6) += rMom.z(); 00041 ent += sqrt(mm*mm +rMom.x()*rMom.x() + rMom.y()*rMom.y() + rMom.z()*rMom.z()); 00042 } 00043 00044 //total reconstructed mass 00045 double differ = ent*ent - (par(6)*par(6) + par(5)*par(5) + par(4)*par(4)); 00046 if(differ>0.) 00047 { 00048 par(7) = sqrt(differ); 00049 }else{ 00050 cout<<"warning! current precision does not allow to calculate the mass"<<endl; 00051 par(7) = 0.; 00052 throw VertexException("warning! current precision does not allow to calculate the mass"); 00053 00054 } 00055 00056 //now making covariance matrix: 00057 00058 // cout<<"fCov"<<fCov<<endl; 00059 AlgebraicMatrix cov = momentumPart(prt,par,fCov); 00060 // cout<<"Momentum part"<<cov<<endl; 00061 00062 //covariance sym matrix 00063 AlgebraicSymMatrix sCov(7,0); 00064 for(int i = 1; i<8; i++) 00065 { 00066 for(int j = 1; j<8; j++) 00067 {if(i<=j) sCov(i,j) = cov(i,j);} 00068 } 00069 KinematicParameters nP(asSVector<7>(par)); 00070 KinematicParametersError nE(asSMatrix<7>(sCov)); 00071 00072 KinematicState nState(nP,nE,charge, field); 00073 00074 //new born kinematic particle 00075 float chi2 = vtx->chiSquared(); 00076 float ndf = vtx->degreesOfFreedom(); 00077 KinematicParticle * zp = 0; 00078 RefCountedKinematicParticle pPart = ReferenceCountingPointer<KinematicParticle>(zp); 00079 RefCountedKinematicParticle nPart = pFactory->particle(nState,chi2,ndf,zp); 00080 00081 //making a resulting tree: 00082 RefCountedKinematicTree resTree = ReferenceCountingPointer<KinematicTree>(new KinematicTree()); 00083 00084 //fake production vertex: 00085 RefCountedKinematicVertex fVertex = vFactory->vertex(); 00086 resTree->addParticle(fVertex,vtx,nPart); 00087 00088 //adding final state 00089 for(vector<RefCountedKinematicParticle>::const_iterator il = prt.begin(); il != prt.end(); il++) 00090 { 00091 if((*il)->previousParticle()->correspondingTree() != 0) 00092 { 00093 KinematicTree * tree = (*il)->previousParticle()->correspondingTree(); 00094 tree->movePointerToTheTop(); 00095 tree->replaceCurrentParticle(*il); 00096 RefCountedKinematicVertex cdVertex = resTree->currentDecayVertex(); 00097 resTree->addTree(cdVertex, tree); 00098 }else{ 00099 RefCountedKinematicVertex ffVertex = vFactory->vertex(); 00100 resTree->addParticle(vtx,ffVertex,*il); 00101 } 00102 } 00103 return resTree; 00104 }
AlgebraicMatrix ConstrainedTreeBuilder::momentumPart | ( | vector< RefCountedKinematicParticle > | rPart, | |
const AlgebraicVector & | newPar, | |||
const AlgebraicMatrix & | fitCov | |||
) | const [private] |
Definition at line 106 of file ConstrainedTreeBuilder.cc.
References i, j, l1, l2, size, funct::sqrt(), and z.
Referenced by buildTree().
00108 { 00109 //constructing the full matrix using the simple fact 00110 //that we have never broken the order of tracks 00111 // during our fit. 00112 00113 int size = rPart.size(); 00114 //global propagation to the vertex position 00115 //Jacobian is done for all the parameters together 00116 AlgebraicMatrix jac(3+7*size,3+7*size,0); 00117 jac(1,1) = 1; 00118 jac(2,2) = 1; 00119 jac(3,3) = 1; 00120 int i_int=0; 00121 for(vector<RefCountedKinematicParticle>::iterator i = rPart.begin(); i != rPart.end(); i++) 00122 { 00123 00124 //vertex position related components of the matrix 00125 TrackCharge ch = (*i)->currentState().particleCharge(); 00126 double field = (*i)->magneticField()->inInverseGeV((*i)->currentState().globalPosition()).z(); 00127 double a_i = -0.29979246*ch*field; 00128 AlgebraicMatrix upper(3,7,0); 00129 AlgebraicMatrix diagonal(7,7,0); 00130 upper(1,1) = 1; 00131 upper(2,2) = 1; 00132 upper(3,3) = 1; 00133 upper(2,4) = -a_i; 00134 upper(1,5) = a_i; 00135 jac.sub(1,4+i_int*7,upper); 00136 00137 diagonal(4,4) = 1; 00138 diagonal(5,5) = 1; 00139 diagonal(6,6) = 1; 00140 diagonal(7,7) = 1; 00141 diagonal(2,4) = a_i; 00142 diagonal(1,5) = -a_i; 00143 jac.sub(4+i_int*7,4+i_int*7,diagonal); 00144 i_int++; 00145 } 00146 00147 // jacobian is constructed in such a way, that 00148 // right operation for transformation will be 00149 // fitCov.similarityT(jac) 00150 // WARNING: normal similarity operation is 00151 // not valid in this case 00152 //now making reduced matrix: 00153 int vSize = rPart.size(); 00154 AlgebraicSymMatrix fit_cov_sym(7*vSize+3,0); 00155 for(int i = 1; i<7*vSize+4; ++i) 00156 { 00157 for(int j = 1; j<7*vSize+4; ++j) 00158 {if(i<=j) fit_cov_sym(i,j) = fitCov(i,j);} 00159 } 00160 00161 00162 AlgebraicMatrix reduced(3+4*size,3+4*size,0); 00163 AlgebraicMatrix transform = fit_cov_sym.similarityT(jac); 00164 00165 //jacobian to add matrix components 00166 AlgebraicMatrix jac_t(7,7+4*(size-1)); 00167 jac_t(1,1) = 1.; 00168 jac_t(2,2) = 1.; 00169 jac_t(3,3) = 1.; 00170 00171 //debug code: 00172 //CLHEP bugs: avoiding the 00173 // HepMatrix::sub method use 00174 AlgebraicMatrix reduced_tm(7,7,0); 00175 for(int i = 1; i<8;++i) 00176 { 00177 for(int j =1; j<8; ++j) 00178 {reduced_tm(i,j) = transform(i+3, j+3);} 00179 } 00180 00181 //left top corner 00182 // reduced.sub(1,1,transform.sub(4,10,4,10)); 00183 00184 //debug code: 00185 //CLHEP bugs: avoiding the 00186 // HepMatrix::sub method use 00187 reduced.sub(1,1,reduced_tm); 00188 00189 // cout<<"reduced matrix"<<reduced<<endl; 00190 int il_int = 0; 00191 for(vector<RefCountedKinematicParticle>::const_iterator rs = rPart.begin(); 00192 rs!=rPart.end();rs++) 00193 { 00194 //jacobian components: 00195 AlgebraicMatrix jc_el(4,4,0); 00196 jc_el(1,1) = 1.; 00197 jc_el(2,2) = 1.; 00198 jc_el(3,3) = 1.; 00199 00200 //non-trival elements: mass correlations: 00201 AlgebraicVector7 l_Par = (*rs)->currentState().kinematicParameters().vector(); 00202 double energy_local = sqrt(l_Par(6)*l_Par(6) + l_Par(3)*l_Par(3) + l_Par(4)*l_Par(4) + l_Par(5)*l_Par(5)); 00203 00204 double energy_global = sqrt(newPar(7)*newPar(7)+newPar(6)*newPar(6) + newPar(5)*newPar(5)+newPar(4)*newPar(4)); 00205 00206 jc_el(4,4) = energy_global*l_Par(6)/(newPar(7)*energy_local); 00207 jc_el(4,1) = ((energy_global*l_Par(3)/energy_local) - newPar(4))/newPar(7); 00208 jc_el(4,2) = ((energy_global*l_Par(4)/energy_local) - newPar(5))/newPar(7); 00209 jc_el(4,3) = ((energy_global*l_Par(5)/energy_local) - newPar(6))/newPar(7); 00210 00211 jac_t.sub(4,il_int*4+4,jc_el); 00212 il_int++; 00213 } 00214 // cout<<"jac_t"<<jac_t<<endl; 00215 //debug code 00216 //CLHEP bugs workaround 00217 // cout<<"Transform matrix"<< transform<<endl; 00218 00219 for(int i = 1; i<size; i++) 00220 { 00221 00222 //non-trival elements: mass correlations: 00223 //upper row and right column 00224 AlgebraicMatrix transform_sub1(3,4,0); 00225 AlgebraicMatrix transform_sub2(4,3,0); 00226 for(int l1 = 1; l1<4;++l1) 00227 { 00228 for(int l2 = 1; l2<5;++l2) 00229 {transform_sub1(l1,l2) = transform(3+l1,6+7*i +l2);} 00230 } 00231 00232 for(int l1 = 1; l1<5;++l1) 00233 { 00234 for(int l2 = 1; l2<4;++l2) 00235 {transform_sub2(l1,l2) = transform(6+7*i+l1,3+l2);} 00236 } 00237 00238 AlgebraicMatrix transform_sub3(4,4,0); 00239 for(int l1 = 1; l1<5;++l1) 00240 { 00241 for(int l2 = 1; l2<5;++l2) 00242 {transform_sub3(l1,l2) = transform(6+7*i+l1, 6+7*i+l2); } 00243 } 00244 00245 reduced.sub(1,4+4*i,transform_sub1); 00246 reduced.sub(4+4*i,1,transform_sub2); 00247 00248 //diagonal elements 00249 reduced.sub(4+4*i,4+4*i,transform_sub3); 00250 00251 //off diagonal elements 00252 for(int j = 1; j<size; j++) 00253 { 00254 AlgebraicMatrix transform_sub4(4,4,0); 00255 AlgebraicMatrix transform_sub5(4,4,0); 00256 for(int l1 = 1; l1<5;++l1) 00257 { 00258 for(int l2 = 1; l2<5;++l2) 00259 { 00260 transform_sub4(l1,l2) = transform(6+7*(i-1)+l1,6+7*j+l2); 00261 transform_sub5(l1,l2) = transform(6+7*j+l1, 6+7*(i-1)+l2); 00262 } 00263 } 00264 reduced.sub(4+4*(i-1),4+4*j,transform_sub4); 00265 reduced.sub(4+4*j,4+4*(i-1),transform_sub5); 00266 } 00267 } 00268 00269 return jac_t*reduced*jac_t.T(); 00270 }
Definition at line 42 of file ConstrainedTreeBuilder.h.
Referenced by buildTree(), ConstrainedTreeBuilder(), and ~ConstrainedTreeBuilder().
Definition at line 43 of file ConstrainedTreeBuilder.h.
Referenced by buildTree(), ConstrainedTreeBuilder(), and ~ConstrainedTreeBuilder().