CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
ConstrainedTreeBuilder Class Reference

#include <ConstrainedTreeBuilder.h>

Public Member Functions

RefCountedKinematicTree buildTree (const std::vector< RefCountedKinematicParticle > &initialParticles, const std::vector< KinematicState > &finalStates, const RefCountedKinematicVertex vtx, const AlgebraicMatrix &fCov) const
 
 ConstrainedTreeBuilder ()
 
 ~ConstrainedTreeBuilder ()
 

Private Member Functions

RefCountedKinematicTree buildTree (const RefCountedKinematicParticle virtualParticle, const RefCountedKinematicVertex vtx, const std::vector< RefCountedKinematicParticle > &particles) const
 
AlgebraicMatrix covarianceMatrix (const std::vector< RefCountedKinematicParticle > &rPart, const AlgebraicVector7 &newPar, const AlgebraicMatrix &fitCov) const
 

Private Attributes

VirtualKinematicParticleFactorypFactory
 
KinematicVertexFactoryvFactory
 

Detailed Description

Class constructing te final output tree for the constrained vertex fitter. 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.

Constructor & Destructor Documentation

ConstrainedTreeBuilder::ConstrainedTreeBuilder ( )
ConstrainedTreeBuilder::~ConstrainedTreeBuilder ( )

Definition at line 11 of file ConstrainedTreeBuilder.cc.

References pFactory, and vFactory.

12 {
13  delete pFactory;
14  delete vFactory;
15 }
KinematicVertexFactory * vFactory
VirtualKinematicParticleFactory * pFactory

Member Function Documentation

RefCountedKinematicTree ConstrainedTreeBuilder::buildTree ( const std::vector< RefCountedKinematicParticle > &  initialParticles,
const std::vector< KinematicState > &  finalStates,
const RefCountedKinematicVertex  vtx,
const AlgebraicMatrix fCov 
) const

Method constructing tree out of set of refitted states, vertex, and full covariance matrix.

Definition at line 18 of file ConstrainedTreeBuilder.cc.

References a, ALCARECOTkAlJpsiMuMu_cff::charge, HiEvtPlane_cfi::chi2, covarianceMatrix(), mps_fire::i, LogDebug, gen::n, hcaldqm::flag::nState, AlCaHLTBitMon_ParallelJobs::p, VirtualKinematicParticleFactory::particle(), pFactory, mathSSE::sqrt(), badGlobalMuonTaggersAOD_cff::vtx, and z.

Referenced by KinematicConstrainedVertexFitter::fit().

21 {
22  if (!vertex->vertexIsValid()) {
23  LogDebug("ConstrainedTreeBuilder")
24  << "Vertex is invalid\n";
26  }
28  vtx(0) = vertex->position().x();
29  vtx(1) = vertex->position().y();
30  vtx(2) = vertex->position().z();
31  AlgebraicMatrix33 vertexCov = asSMatrix<3,3>(fullCov.sub(1,3,1,3));
32 
33 // cout << fullCov<<endl;
34 // cout << "RecoVertex/ConstrainedTreeBuilder"<<vtx<<endl;
35 
36  double ent = 0.;
37  int charge = 0;
38  AlgebraicVector7 virtualPartPar;
39  virtualPartPar(0) = vertex->position().x();
40  virtualPartPar(1) = vertex->position().y();
41  virtualPartPar(2) = vertex->position().z();
42 
43 //making refitted particles out of refitted states.
44 //none of the operations above violates the order of particles
45 
46  ROOT::Math::SMatrix<double,7,7,ROOT::Math::MatRepStd<double,7,7> > aMatrix;
47  aMatrix(3,3) = 1;
48  aMatrix(4,4) = 1;
49  aMatrix(5,5) = 1;
50  aMatrix(6,6) = 1;
51  ROOT::Math::SMatrix<double,7,3,ROOT::Math::MatRepStd<double,7,3> > bMatrix;
52  bMatrix(0,0) = 1;
53  bMatrix(1,1) = 1;
54  bMatrix(2,2) = 1;
55  AlgebraicMatrix77 trackParCov;
56  ROOT::Math::SMatrix<double,3,7,ROOT::Math::MatRepStd<double,3,7> > vtxTrackCov;
57  AlgebraicMatrix77 nCovariance;
58 
59  std::vector<RefCountedKinematicParticle>::const_iterator i = initialParticles.begin();
60  std::vector<KinematicState>::const_iterator iStates = finalStates.begin();
61  std::vector<RefCountedKinematicParticle> rParticles;
62  int n=0;
63  for( ; i != initialParticles.end() && iStates != finalStates.end(); ++i,++iStates)
64  {
65  AlgebraicVector7 p = iStates->kinematicParameters().vector();
66  double a = - iStates->particleCharge() *
67  iStates->magneticField()->inInverseGeV(iStates->globalPosition()).z();
68 
69  aMatrix(4,0) = -a;
70  aMatrix(3,1) = a;
71  bMatrix(4,0) = a;
72  bMatrix(3,1) = -a;
73 
74  AlgebraicVector7 par = aMatrix*p + bMatrix * vtx;
75 
76  trackParCov = asSMatrix<7,7>(fullCov.sub(4+n*7,10+n*7,4+n*7,10+n*7));
77  vtxTrackCov = asSMatrix<3,7>(fullCov.sub(1,3,4+n*7,10+n*7));;
78  nCovariance = aMatrix * trackParCov * ROOT::Math::Transpose(aMatrix) +
79  aMatrix * ROOT::Math::Transpose(vtxTrackCov) * ROOT::Math::Transpose(bMatrix) +
80  bMatrix * vtxTrackCov * ROOT::Math::Transpose(aMatrix)+
81  bMatrix * vertexCov * ROOT::Math::Transpose(bMatrix);
82 
83  KinematicState stateAtVertex(KinematicParameters(par),
84  KinematicParametersError(AlgebraicSymMatrix77(nCovariance.LowerBlock())),
85  iStates->particleCharge(), iStates->magneticField());
86  rParticles.push_back((*i)->refittedParticle(stateAtVertex, vertex->chiSquared(), vertex->degreesOfFreedom()));
87 
88  virtualPartPar(3) += par(3);
89  virtualPartPar(4) += par(4);
90  virtualPartPar(5) += par(5);
91  ent += sqrt(par(6)*par(6) + par(3)*par(3)+par(4)*par(4)+par(5)*par(5) );
92  charge += iStates->particleCharge();
93 
94  ++n;
95 
96  }
97 
98  //total reconstructed mass
99  double differ = ent*ent - (virtualPartPar(3)*virtualPartPar(3) + virtualPartPar(5)*virtualPartPar(5) + virtualPartPar(4)*virtualPartPar(4));
100  if(differ>0.) {
101  virtualPartPar(6) = sqrt(differ);
102  } else {
103  LogDebug("ConstrainedTreeBuilder")
104  << "Fit failed: Current precision does not allow to calculate the mass\n";
106  }
107 
108  // covariance matrix:
109 
110  AlgebraicMatrix77 cov = asSMatrix<7,7>(covarianceMatrix(rParticles,virtualPartPar,fullCov));
111 
112  KinematicState nState(KinematicParameters(virtualPartPar),
114  charge, initialParticles[0]->magneticField());
115 
116  //newborn kinematic particle
117  float chi2 = vertex->chiSquared();
118  float ndf = vertex->degreesOfFreedom();
119  KinematicParticle * zp = 0;
120  RefCountedKinematicParticle virtualParticle = pFactory->particle(nState,chi2,ndf,zp);
121 
122  return buildTree(virtualParticle, vertex, rParticles);
123 }
#define LogDebug(id)
RefCountedKinematicParticle particle(const KinematicState &kineState, float &chiSquared, float &degreesOfFr, ReferenceCountingPointer< KinematicParticle > previousParticle, KinematicConstraint *lastConstraint=0) const
RefCountedKinematicTree buildTree(const std::vector< RefCountedKinematicParticle > &initialParticles, const std::vector< KinematicState > &finalStates, const RefCountedKinematicVertex vtx, const AlgebraicMatrix &fCov) const
ROOT::Math::SMatrix< double, 7, 7, ROOT::Math::MatRepSym< double, 7 > > AlgebraicSymMatrix77
Definition: Matrices.h:9
ROOT::Math::SVector< double, 7 > AlgebraicVector7
Definition: Matrices.h:8
T sqrt(T t)
Definition: SSEVec.h:18
ROOT::Math::SVector< double, 3 > AlgebraicVector3
AlgebraicMatrix covarianceMatrix(const std::vector< RefCountedKinematicParticle > &rPart, const AlgebraicVector7 &newPar, const AlgebraicMatrix &fitCov) const
ROOT::Math::SMatrix< double, 7, 7, ROOT::Math::MatRepStd< double, 7, 7 > > AlgebraicMatrix77
Definition: Matrices.h:10
double a
Definition: hdecay.h:121
VirtualKinematicParticleFactory * pFactory
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepStd< double, 3, 3 > > AlgebraicMatrix33
RefCountedKinematicTree ConstrainedTreeBuilder::buildTree ( const RefCountedKinematicParticle  virtualParticle,
const RefCountedKinematicVertex  vtx,
const std::vector< RefCountedKinematicParticle > &  particles 
) const
private

Definition at line 126 of file ConstrainedTreeBuilder.cc.

References KinematicTree::movePointerToTheTop(), KinematicTree::replaceCurrentParticle(), KinematicVertexFactory::vertex(), and vFactory.

128 {
129 
130 //making a resulting tree:
132 
133 //fake production vertex:
135  resTree->addParticle(fVertex, vtx, virtualParticle);
136 
137 //adding final state
138  for(std::vector<RefCountedKinematicParticle>::const_iterator il = particles.begin(); il != particles.end(); il++)
139  {
140  if((*il)->previousParticle()->correspondingTree() != 0)
141  {
142  KinematicTree * tree = (*il)->previousParticle()->correspondingTree();
143  tree->movePointerToTheTop();
144  tree->replaceCurrentParticle(*il);
145  RefCountedKinematicVertex cdVertex = resTree->currentDecayVertex();
146  resTree->addTree(cdVertex, tree);
147  }else{
149  resTree->addParticle(vtx,ffVertex,*il);
150  }
151  }
152  return resTree;
153 }
void replaceCurrentParticle(RefCountedKinematicParticle newPart) const
KinematicVertexFactory * vFactory
void movePointerToTheTop() const
static RefCountedKinematicVertex vertex(const VertexState &state, float totalChiSq, float degreesOfFr)
Definition: tree.py:1
AlgebraicMatrix ConstrainedTreeBuilder::covarianceMatrix ( const std::vector< RefCountedKinematicParticle > &  rPart,
const AlgebraicVector7 newPar,
const AlgebraicMatrix fitCov 
) const
private

Metod to reconstructing the full covariance matrix of the resulting particle.

Definition at line 155 of file ConstrainedTreeBuilder.cc.

References mps_fire::i, findQualityFiles::size, mathSSE::sqrt(), create_public_lumi_plots::transform, pileupCalc::upper, and z.

Referenced by buildTree().

157 {
158 //constructing the full matrix using the simple fact
159 //that we have never broken the order of tracks
160 // during our fit.
161 
162  int size = rPart.size();
163 //global propagation to the vertex position
164 //Jacobian is done for all the parameters together
165  AlgebraicMatrix jac(3+7*size,3+7*size,0);
166  jac(1,1) = 1;
167  jac(2,2) = 1;
168  jac(3,3) = 1;
169  int i_int=0;
170  for(std::vector<RefCountedKinematicParticle>::const_iterator i = rPart.begin(); i != rPart.end(); i++)
171  {
172 
173 //vertex position related components of the matrix
174  double a_i = - (*i)->currentState().particleCharge() * (*i)->magneticField()->inInverseGeV((*i)->currentState().globalPosition()).z();
175 
176  AlgebraicMatrix upper(3,7,0);
177  AlgebraicMatrix diagonal(7,7,0);
178  upper(1,1) = 1;
179  upper(2,2) = 1;
180  upper(3,3) = 1;
181  upper(2,4) = -a_i;
182  upper(1,5) = a_i;
183  jac.sub(1,4+i_int*7,upper);
184 
185  diagonal(4,4) = 1;
186  diagonal(5,5) = 1;
187  diagonal(6,6) = 1;
188  diagonal(7,7) = 1;
189  diagonal(2,4) = a_i;
190  diagonal(1,5) = -a_i;
191  jac.sub(4+i_int*7,4+i_int*7,diagonal);
192  i_int++;
193  }
194 
195 // jacobian is constructed in such a way, that
196 // right operation for transformation will be
197 // fitCov.similarityT(jac)
198 // WARNING: normal similarity operation is
199 // not valid in this case
200 //now making reduced matrix:
201  int vSize = rPart.size();
202  AlgebraicSymMatrix fit_cov_sym(7*vSize+3,0);
203  for(int i = 1; i<7*vSize+4; ++i)
204  {
205  for(int j = 1; j<7*vSize+4; ++j)
206  {if(i<=j) fit_cov_sym(i,j) = fitCov(i,j);}
207  }
208 
209 
210  AlgebraicMatrix reduced(3+4*size,3+4*size,0);
211  AlgebraicMatrix transform = fit_cov_sym.similarityT(jac);
212 
213 //jacobian to add matrix components
214  AlgebraicMatrix jac_t(7,7+4*(size-1));
215  jac_t(1,1) = 1.;
216  jac_t(2,2) = 1.;
217  jac_t(3,3) = 1.;
218 
219 //debug code:
220 //CLHEP bugs: avoiding the
221 // HepMatrix::sub method use
222  AlgebraicMatrix reduced_tm(7,7,0);
223  for(int i = 1; i<8;++i)
224  {
225  for(int j =1; j<8; ++j)
226  {reduced_tm(i,j) = transform(i+3, j+3);}
227  }
228 
229 //left top corner
230 // reduced.sub(1,1,transform.sub(4,10,4,10));
231 
232 //debug code:
233 //CLHEP bugs: avoiding the
234 // HepMatrix::sub method use
235  reduced.sub(1,1,reduced_tm);
236 
237 // cout<<"reduced matrix"<<reduced<<endl;
238  int il_int = 0;
239  double energy_global = sqrt(newPar(3)*newPar(3)+newPar(4)*newPar(4) + newPar(5)*newPar(5)+newPar(6)*newPar(6));
240  for(std::vector<RefCountedKinematicParticle>::const_iterator rs = rPart.begin();
241  rs!=rPart.end();rs++)
242  {
243 //jacobian components:
244  AlgebraicMatrix jc_el(4,4,0);
245  jc_el(1,1) = 1.;
246  jc_el(2,2) = 1.;
247  jc_el(3,3) = 1.;
248 
249 //non-trival elements: mass correlations:
250  AlgebraicVector7 l_Par = (*rs)->currentState().kinematicParameters().vector();
251  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));
252  jc_el(4,4) = energy_global*l_Par(6)/(newPar(6)*energy_local);
253  jc_el(4,1) = ((energy_global*l_Par(3)/energy_local) - newPar(3))/newPar(6);
254  jc_el(4,2) = ((energy_global*l_Par(4)/energy_local) - newPar(4))/newPar(6);
255  jc_el(4,3) = ((energy_global*l_Par(5)/energy_local) - newPar(5))/newPar(6);
256  jac_t.sub(4,il_int*4+4,jc_el);
257  il_int++;
258  }
259 // cout<<"jac_t"<<jac_t<<endl;
260 //debug code
261 //CLHEP bugs workaround
262 // cout<<"Transform matrix"<< transform<<endl;
263 
264  for(int i = 1; i<size; i++)
265  {
266 
267 //non-trival elements: mass correlations:
268 //upper row and right column
269  AlgebraicMatrix transform_sub1(3,4,0);
270  AlgebraicMatrix transform_sub2(4,3,0);
271  for(int l1 = 1; l1<4;++l1)
272  {
273  for(int l2 = 1; l2<5;++l2)
274  {transform_sub1(l1,l2) = transform(3+l1,6+7*i +l2);}
275  }
276 
277  for(int l1 = 1; l1<5;++l1)
278  {
279  for(int l2 = 1; l2<4;++l2)
280  {transform_sub2(l1,l2) = transform(6+7*i+l1,3+l2);}
281  }
282 
283  AlgebraicMatrix transform_sub3(4,4,0);
284  for(int l1 = 1; l1<5;++l1)
285  {
286  for(int l2 = 1; l2<5;++l2)
287  {transform_sub3(l1,l2) = transform(6+7*i+l1, 6+7*i+l2); }
288  }
289 
290  reduced.sub(1,4+4*i,transform_sub1);
291  reduced.sub(4+4*i,1,transform_sub2);
292 
293 //diagonal elements
294  reduced.sub(4+4*i,4+4*i,transform_sub3);
295 
296 //off diagonal elements
297  for(int j = 1; j<size; j++)
298  {
299  AlgebraicMatrix transform_sub4(4,4,0);
300  AlgebraicMatrix transform_sub5(4,4,0);
301  for(int l1 = 1; l1<5;++l1)
302  {
303  for(int l2 = 1; l2<5;++l2)
304  {
305  transform_sub4(l1,l2) = transform(6+7*(i-1)+l1,6+7*j+l2);
306  transform_sub5(l1,l2) = transform(6+7*j+l1, 6+7*(i-1)+l2);
307  }
308  }
309  reduced.sub(4+4*(i-1),4+4*j,transform_sub4);
310  reduced.sub(4+4*j,4+4*(i-1),transform_sub5);
311  }
312  }
313 
314  return jac_t*reduced*jac_t.T();
315 }
size
Write out results.
ROOT::Math::SVector< double, 7 > AlgebraicVector7
Definition: Matrices.h:8
CLHEP::HepMatrix AlgebraicMatrix
T sqrt(T t)
Definition: SSEVec.h:18
CLHEP::HepSymMatrix AlgebraicSymMatrix

Member Data Documentation

VirtualKinematicParticleFactory* ConstrainedTreeBuilder::pFactory
private
KinematicVertexFactory* ConstrainedTreeBuilder::vFactory
private