CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
InvariantMassFromVertex.cc
Go to the documentation of this file.
3 
4 
6  const double mass) const
7 {
8  return p4(vertex, std::vector<double>(vertex.tracks().size(), mass));
9 }
10 
12  const std::vector<double> & masses) const
13 {
14 
15  LorentzVector totalP4;
16 
17  // Check that tkToTkCovarianceIsAvailable
18  if (!vertex.tkToTkCovarianceIsAvailable()) {
19  LogDebug("InvariantMassFromVertex")
20  << "Fit failed: vertex has not been smoothed\n";
21  return totalP4;
22  }
23 
24  if (vertex.tracks().size() != masses.size()) {
25  LogDebug("InvariantMassFromVertex")
26  << "Vector of masses does not have the same size as tracks in vertex\n";
27  return totalP4;
28  }
29 
30 
31  std::vector<RefCountedVertexTrack> refTracks = vertex.tracks();
32  std::vector<RefCountedVertexTrack>::const_iterator i_s = refTracks.begin();
33  std::vector<double>::const_iterator i_m = masses.begin();
34 
35  for( ;i_s !=refTracks.end(), i_m != masses.end(); ++i_s, ++i_m) {
36  GlobalVector momentum = (**i_s).refittedState()->freeTrajectoryState().momentum();
37  totalP4 += LorentzVector(momentum.x(), momentum.y(), momentum.z(), *i_m);
38  }
39  return totalP4;
40 }
41 
43 {
44  GlobalVector momentum_;
45 
46  // Check that tkToTkCovarianceIsAvailable
47  if (!vertex.tkToTkCovarianceIsAvailable()) {
48  LogDebug("InvariantMassFromVertex")
49  << "Fit failed: vertex has not been smoothed\n";
50  return momentum_;
51  }
52 
53  std::vector<RefCountedVertexTrack> refTracks = vertex.tracks();
54  std::vector<RefCountedVertexTrack>::const_iterator i_s = refTracks.begin();
55 
56  for( ;i_s !=refTracks.end() ; ++i_s) {
57  momentum_ += (**i_s).refittedState()->freeTrajectoryState().momentum();
58  }
59  return momentum_;
60 
61 }
62 
63 
65  const double mass) const
66 {
67  return invariantMass(vertex, std::vector<double>(vertex.tracks().size(), mass));
68 }
69 
70 
72  const std::vector<double> & masses) const
73 {
74 
75  // Check that tkToTkCovarianceIsAvailable
76  if (!vertex.tkToTkCovarianceIsAvailable()) {
77  LogDebug("InvariantMassFromVertex")
78  << "Fit failed: vertex has not been smoothed\n";
79  return Measurement1D(0.,0.);
80  }
81  if (vertex.tracks().size() != masses.size()) {
82  LogDebug("InvariantMassFromVertex")
83  << "Vector of masses does not have the same size as tracks in vertex\n";
84  return Measurement1D(0.,0.);
85  }
86 
87  LorentzVector totalP4 = p4(vertex, masses);
88  double u = uncertainty(totalP4, vertex, masses);
89  // std::cout << u<<std::endl;
90  return Measurement1D(totalP4.M(), u );
91 
92 }
93 
94 //method returning the full covariance matrix
95 //of new born kinematic particle
97  const CachingVertex<5>& vertex, const std::vector<double> & masses) const
98 {
99  std::vector<RefCountedVertexTrack> refTracks = vertex.tracks();
100  int size = refTracks.size();
101  AlgebraicMatrix cov(3*size,3*size);
102  AlgebraicMatrix jac(1,3*size);
103 
104  double energy_total = totalP4.E();
105 
106  std::vector<RefCountedVertexTrack>::const_iterator rt_i = refTracks.begin();
107  std::vector<double>::const_iterator i_m = masses.begin();
108 
109  int i_int = 0;
110  for( ;rt_i !=refTracks.end(), i_m != masses.end(); ++rt_i, ++i_m) {
111 
112  double a;
113  AlgebraicVector5 param = (**rt_i).refittedState()->parameters(); // rho, theta, phi,tr_im, z_im
114  double rho = param[0];
115  double theta = param[1];
116  double phi = param[2];
117  double mass = *i_m;
118 
119  if ((**rt_i).linearizedTrack()->charge()!=0) {
120  a = -(**rt_i).refittedState()->freeTrajectoryState().parameters().magneticFieldInInverseGeV(vertex.position()).z()
121  * (**rt_i).refittedState()->freeTrajectoryState().parameters ().charge();
122  if (a==0.) throw cms::Exception("InvariantMassFromVertex", "Field is 0");
123  } else {
124  a = 1;
125  }
126 
127  double energy_local = sqrt(a*a/(rho*rho)*(1+1/(tan(theta)*tan(theta))) + mass*mass);
128 
129  jac(1,i_int*3+1) = (-(energy_total/energy_local*a*a/(rho*rho*rho*sin(theta)*sin(theta)) )
130  + totalP4.X()*a/(rho*rho)*cos(phi) + totalP4.Y()*a/(rho*rho)*sin(phi)
131  + totalP4.Z()*a/(rho*rho*tan(theta)) )/totalP4.M(); //dm / drho
132 
133  jac(1,i_int*3+2) = (-(energy_total/energy_local*a*a/(rho*rho*sin(theta)*sin(theta)*tan(theta)) )
134  + totalP4.Z()*a/(rho*sin(theta)*sin(theta)) )/totalP4.M();//dm d theta
135 
136  jac(1,i_int*3+3) = ( totalP4.X()*sin(phi) - totalP4.Y()*cos(phi) )*a/(rho*totalP4.M()); //dm/dphi
137 
138  // momentum corellatons: diagonal elements of the matrix
139  cov.sub(i_int*3 + 1, i_int*3 + 1,asHepMatrix<6>((**rt_i).fullCovariance()).sub(4,6));
140 
141  //off diagonal elements: track momentum - track momentum corellations
142 
143  int j_int = 0;
144  for(std::vector<RefCountedVertexTrack>::const_iterator rt_j = refTracks.begin(); rt_j != refTracks.end(); rt_j++) {
145  if(i_int < j_int) {
146  AlgebraicMatrix i_k_cov_m = asHepMatrix<3,3>(vertex.tkToTkCovariance((*rt_i),(*rt_j)));
147  cov.sub(i_int*3 + 1, j_int*3 + 1,i_k_cov_m);
148  cov.sub(j_int*3 + 1, i_int*3 + 1,i_k_cov_m.T());
149  }
150  j_int++;
151  }
152  i_int++;
153  }
154 // std::cout<<"jac"<<jac<<std::endl;
155 // std::cout<<"cov"<<cov<<std::endl;
156 // std::cout << "final result"<<(jac*cov*jac.T())<<std::endl;
157 
158  return sqrt((jac*cov*jac.T())(1,1));
159 }
#define LogDebug(id)
ROOT::Math::PxPyPzMVector LorentzVector
std::vector< RefCountedVertexTrack > tracks() const
Definition: CachingVertex.h:91
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Definition: DDAxes.h:10
Geom::Theta< T > theta() const
T y() const
Definition: PV3DBase.h:62
LorentzVector p4(const CachingVertex< 5 > &vertex, const std::vector< double > &masses) const
double double double z
CLHEP::HepMatrix AlgebraicMatrix
T sqrt(T t)
Definition: SSEVec.h:46
T z() const
Definition: PV3DBase.h:63
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
double uncertainty(const LorentzVector &p4, const CachingVertex< 5 > &vertex, const std::vector< double > &masses) const
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
GlobalVector momentum(const CachingVertex< 5 > &vertex) const
AlgebraicMatrixMM tkToTkCovariance(const RefCountedVertexTrack t1, const RefCountedVertexTrack t2) const
ROOT::Math::SVector< double, 5 > AlgebraicVector5
bool tkToTkCovarianceIsAvailable() const
GlobalPoint position() const
double a
Definition: hdecay.h:121
tuple mass
Definition: scaleCards.py:27
T x() const
Definition: PV3DBase.h:61
tuple size
Write out results.
Measurement1D invariantMass(const CachingVertex< 5 > &vertex, const std::vector< double > &masses) const
Definition: DDAxes.h:10