CMS 3D CMS Logo

MultiTrajectoryStateMode.cc
Go to the documentation of this file.
3 
5 
11 
12 #include <iostream>
13 
14 bool
16  GlobalVector& momentum) const
17 {
18  //
19  // clear result vector and check validity of the TSOS
20  //
21  momentum = GlobalVector(0.,0.,0.);
22  if ( !tsos.isValid() ) {
23  edm::LogInfo("MultiTrajectoryStateMode") << "Cannot calculate mode from invalid TSOS";
24  return false;
25  }
26  //
27  // 1D mode computation for px, py and pz
28  //
29  GetComponents comps(tsos);
30  auto const & components = comps();
31  auto numb = components.size();
32  // vectors of components in x, y and z
33  std::vector<SingleGaussianState1D> pxStates; pxStates.reserve(numb);
34  std::vector<SingleGaussianState1D> pyStates; pyStates.reserve(numb);
35  std::vector<SingleGaussianState1D> pzStates; pzStates.reserve(numb);
36  // iteration over components
37  for ( std::vector<TrajectoryStateOnSurface>::const_iterator ic=components.begin();
38  ic!=components.end(); ++ic ) {
39  // extraction of parameters and variances
40  GlobalVector mom(ic->globalMomentum());
41  AlgebraicSymMatrix66 cov(ic->cartesianError().matrix());
42  pxStates.push_back(SingleGaussianState1D(mom.x(),cov(3,3),ic->weight()));
43  pyStates.push_back(SingleGaussianState1D(mom.y(),cov(4,4),ic->weight()));
44  pzStates.push_back(SingleGaussianState1D(mom.z(),cov(5,5),ic->weight()));
45  }
46  //
47  // transformation in 1D multi-states and creation of utility classes
48  //
49  MultiGaussianState1D pxState(pxStates);
50  MultiGaussianState1D pyState(pyStates);
51  MultiGaussianState1D pzState(pzStates);
52  GaussianSumUtilities1D pxUtils(pxState);
53  GaussianSumUtilities1D pyUtils(pyState);
54  GaussianSumUtilities1D pzUtils(pzState);
55  //
56  // cartesian momentum vector from modes
57  //
58  momentum = GlobalVector(pxUtils.mode().mean(),pyUtils.mode().mean(),pzUtils.mode().mean());
59  return true;
60 }
61 
62 bool
64  GlobalPoint& position) const
65 {
66  //
67  // clear result vector and check validity of the TSOS
68  //
69  position = GlobalPoint(0.,0.,0.);
70  if ( !tsos.isValid() ) {
71  edm::LogInfo("MultiTrajectoryStateMode") << "Cannot calculate mode from invalid TSOS";
72  return false;
73  }
74  //
75  // 1D mode computation for x, y and z
76  //
77 
78  GetComponents comps(tsos);
79  auto const & components = comps();
80  auto numb = components.size();
81  // vectors of components in x, y and z
82  std::vector<SingleGaussianState1D> xStates; xStates.reserve(numb);
83  std::vector<SingleGaussianState1D> yStates; yStates.reserve(numb);
84  std::vector<SingleGaussianState1D> zStates; zStates.reserve(numb);
85  // iteration over components
86  for ( std::vector<TrajectoryStateOnSurface>::const_iterator ic=components.begin();
87  ic!=components.end(); ++ic ) {
88  // extraction of parameters and variances
89  GlobalPoint pos(ic->globalPosition());
90  AlgebraicSymMatrix66 cov(ic->cartesianError().matrix());
91  xStates.push_back(SingleGaussianState1D(pos.x(),cov(0,0),ic->weight()));
92  yStates.push_back(SingleGaussianState1D(pos.y(),cov(1,1),ic->weight()));
93  zStates.push_back(SingleGaussianState1D(pos.z(),cov(2,2),ic->weight()));
94  }
95  //
96  // transformation in 1D multi-states and creation of utility classes
97  //
98  MultiGaussianState1D xState(xStates);
99  MultiGaussianState1D yState(yStates);
100  MultiGaussianState1D zState(zStates);
101  GaussianSumUtilities1D xUtils(xState);
102  GaussianSumUtilities1D yUtils(yState);
103  GaussianSumUtilities1D zUtils(zState);
104  //
105  // cartesian position vector from modes
106  //
107  position = GlobalPoint(xUtils.mode().mean(),yUtils.mode().mean(),zUtils.mode().mean());
108  return true;
109 }
110 
111 bool
113  GlobalVector& momentum) const
114 {
115  //
116  // clear result vector and check validity of the TSOS
117  //
118  momentum = GlobalVector(0.,0.,0.);
119  if ( !tsos.isValid() ) {
120  edm::LogInfo("MultiTrajectoryStateMode") << "Cannot calculate mode from invalid TSOS";
121  return false;
122  }
123  //
124  // mode computation for local co-ordinates q/p, dx/dz, dy/dz
125  //
126  double qpMode(0);
127  double dxdzMode(0);
128  double dydzMode(0);
129  //
130  // first 3 elements of local parameters = q/p, dx/dz, dy/dz
131  //
132  for ( unsigned int iv=0; iv<3; ++iv ) {
133  // extraction of multi-state using helper class
135  GaussianSumUtilities1D utils(state1D);
136  // mode (in case of failure: mean)
137  double result = utils.mode().mean();
138  if ( !utils.modeIsValid() ) result = utils.mean();
139  if ( iv==0 ) qpMode = result;
140  else if ( iv==1 ) dxdzMode = result;
141  else dydzMode = result;
142  }
143  // local momentum vector from dx/dz, dy/dz and q/p + sign of local pz
144  LocalVector localP(dxdzMode,dydzMode,1.);
145  localP *= tsos.localParameters().pzSign()/fabs(qpMode)
146  /sqrt(dxdzMode*dxdzMode+dydzMode*dydzMode+1.);
147  // conversion to global coordinates
148  momentum = tsos.surface().toGlobal(localP);
149  return true;
150 }
151 
152 bool
154  double& momentum) const
155 {
156  //
157  // clear result vector and check validity of the TSOS
158  //
159  momentum = 0.;
160  if ( !tsos.isValid() ) {
161  edm::LogInfo("MultiTrajectoryStateMode") << "Cannot calculate mode from invalid TSOS";
162  return false;
163  }
164  //
165  // mode computation for local co-ordinates q/p, dx/dz, dy/dz
166  //
167  double qpMode(0);
168  //
169  // first element of local parameters = q/p
170  //
171  // extraction of multi-state using helper class
173  GaussianSumUtilities1D utils(state1D);
174  // mode (in case of failure: mean)
175  qpMode = utils.mode().mean();
176  if ( !utils.modeIsValid() ) qpMode = utils.mean();
177 
178  momentum = 1./fabs(qpMode);
179  return true;
180 }
181 
182 bool
184  double& momentum) const
185 {
186  //
187  // clear result vector and check validity of the TSOS
188  //
189  momentum = 0.;
190  if ( !tsos.isValid() ) {
191  edm::LogInfo("MultiTrajectoryStateMode") << "Cannot calculate mode from invalid TSOS";
192  return false;
193  }
194  //
195  // first element of local parameters = q/p
196  //
197  // extraction of multi-state using helper class
199  std::vector<SingleGaussianState1D> states(qpMultiState.components());
200  // transform from q/p to p
201  for ( unsigned int i=0; i<states.size(); ++i ) {
202  SingleGaussianState1D& qpState = states[i];
203  double wgt = qpState.weight();
204  double qp = qpState.mean();
205  double varQp = qpState.variance();
206  double p = 1./fabs(qp);
207  double varP = p*p*p*p*varQp;
208  states[i] = SingleGaussianState1D(p,varP,wgt);
209  }
210  MultiGaussianState1D pMultiState(states);
211  GaussianSumUtilities1D utils(pMultiState);
212  // mode (in case of failure: mean)
213  momentum = utils.mode().mean();
214  if ( !utils.modeIsValid() ) momentum = utils.mean();
215 
216  return true;
217 }
218 
219 bool
221  GlobalPoint& position) const
222 {
223  //
224  // clear result vector and check validity of the TSOS
225  //
226  position = GlobalPoint(0.,0.,0.);
227  if ( !tsos.isValid() ) {
228  edm::LogInfo("MultiTrajectoryStateMode") << "Cannot calculate mode from invalid TSOS";
229  return false;
230  }
231  //
232  // mode computation for local co-ordinates x, y
233  //
234  double xMode(0);
235  double yMode(0);
236  //
237  // last 2 elements of local parameters = x, y
238  //
239  for ( unsigned int iv=3; iv<5; ++iv ) {
240  // extraction of multi-state using helper class
242  GaussianSumUtilities1D utils(state1D);
243  // mode (in case of failure: mean)
244  double result = utils.mode().mean();
245  if ( !utils.modeIsValid() ) result = utils.mean();
246  if ( iv==3 ) xMode = result;
247  else yMode = result;
248  }
249  // local position vector from x, y
250  LocalPoint localP(xMode,yMode,0.);
251  // conversion to global coordinates
252  position = tsos.surface().toGlobal(localP);
253  return true;
254 }
255 
256 bool
258  GlobalVector& momentum) const
259 {
260  //
261  // clear result vector and check validity of the TSOS
262  //
263  momentum = GlobalVector(0.,0.,0.);
264  if ( !tsos.isValid() ) {
265  edm::LogInfo("MultiTrajectoryStateMode") << "Cannot calculate mode from invalid TSOS";
266  return false;
267  }
268  //
269  // 1D mode computation for p, phi, eta
270  //
271  GetComponents comps(tsos);
272  auto const & components = comps();
273  auto numb = components.size();
274  // vectors of components in p, phi and eta
275  std::vector<SingleGaussianState1D> pStates; pStates.reserve(numb);
276  std::vector<SingleGaussianState1D> phiStates; phiStates.reserve(numb);
277  std::vector<SingleGaussianState1D> etaStates; etaStates.reserve(numb);
278  // covariances in cartesian and p-phi-eta and jacobian
279  AlgebraicMatrix33 jacobian;
280  AlgebraicSymMatrix33 covCart;
281  AlgebraicSymMatrix33 covPPhiEta;
282  // iteration over components
283  for ( std::vector<TrajectoryStateOnSurface>::const_iterator ic=components.begin();
284  ic!=components.end(); ++ic ) {
285  // parameters
286  GlobalVector mom(ic->globalMomentum());
287  auto px = mom.x();
288  auto py = mom.y();
289  auto pz = mom.z();
290  auto op = 1./mom.mag();
291  auto opt2 = 1./mom.perp2();
292  auto phi = mom.phi();
293  auto eta = mom.eta();
294  // jacobian
295  jacobian(0,0) = px*op;
296  jacobian(0,1) = py*op;
297  jacobian(0,2) = pz*op;
298  jacobian(1,0) = py*opt2;
299  jacobian(1,1) = -px*opt2;
300  jacobian(1,2) = 0;
301  jacobian(2,0) = px*pz*opt2*op;
302  jacobian(2,1) = py*pz*opt2*op;
303  jacobian(2,2) = -op;
304  // extraction of the momentum part from the 6x6 cartesian error matrix
305  // and conversion to p-phi-eta
306  covCart = ic->cartesianError().matrix().Sub<AlgebraicSymMatrix33>(3,3);
307  covPPhiEta = ROOT::Math::Similarity(jacobian,covCart);
308  pStates.push_back(SingleGaussianState1D(1/op,covPPhiEta(0,0),ic->weight()));
309  phiStates.push_back(SingleGaussianState1D(phi,covPPhiEta(1,1),ic->weight()));
310  etaStates.push_back(SingleGaussianState1D(eta,covPPhiEta(2,2),ic->weight()));
311  }
312  //
313  // transformation in 1D multi-states and creation of utility classes
314  //
315  MultiGaussianState1D pState(pStates);
316  MultiGaussianState1D phiState(phiStates);
317  MultiGaussianState1D etaState(etaStates);
318  GaussianSumUtilities1D pUtils(pState);
319  GaussianSumUtilities1D phiUtils(phiState);
320  GaussianSumUtilities1D etaUtils(etaState);
321  //
322  // parameters from mode (in case of failure: mean)
323  //
324  auto p = pUtils.modeIsValid() ? pUtils.mode().mean() : pUtils.mean();
325  auto phi = phiUtils.modeIsValid() ? phiUtils.mode().mean() : phiUtils.mean();
326  auto eta = etaUtils.modeIsValid() ? etaUtils.mode().mean() : etaUtils.mean();
327 // double theta = 2*atan(exp(-eta));
328  auto tanth2 = std::exp(-eta);
329  auto pt = p*2*tanth2/(1+tanth2*tanth2); // p*sin(theta)
330  auto pz = p*(1-tanth2*tanth2)/(1+tanth2*tanth2); // p*cos(theta)
331  // conversion to a cartesian momentum vector
332  momentum = GlobalVector(pt*cos(phi),pt*sin(phi),pz);
333  return true;
334 }
335 
336 int
338 {
339  //
340  // clear result vector and check validity of the TSOS
341  //
342  if ( !tsos.isValid() ) {
343  edm::LogInfo("MultiTrajectoryStateMode") << "Cannot calculate mode from invalid TSOS";
344  return 0;
345  }
346  //
347  // mode computation for local co-ordinates q/p
348  // extraction of multi-state using helper class
350  GaussianSumUtilities1D utils(state1D);
351  // mode (in case of failure: mean)
352  double result = utils.mode().mean();
353  if ( !utils.modeIsValid() ) result = utils.mean();
354 
355  return result>0. ? 1 : -1;
356 }
357 
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:106
bool positionFromModeCartesian(const TrajectoryStateOnSurface tsos, GlobalPoint &position) const
const LocalTrajectoryParameters & localParameters() const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
bool momentumFromModeCartesian(const TrajectoryStateOnSurface tsos, GlobalVector &momentum) const
bool momentumFromModeP(const TrajectoryStateOnSurface tsos, double &momentum) const
const SurfaceType & surface() const
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
MultiGaussianState1D multiState1D(const std::vector< MultiGaussianState< N >::Vector > &, const std::vector< MultiGaussianState< N >::Matrix > &, const std::vector< double > &, unsigned int)
double mean() const
parameter vector
T sqrt(T t)
Definition: SSEVec.h:18
double variance() const
variance
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
const SingleGaussianState1D & mode() const
bool positionFromModeLocal(const TrajectoryStateOnSurface tsos, GlobalPoint &position) const
bool momentumFromModeLocal(const TrajectoryStateOnSurface tsos, GlobalVector &momentum) const
double weight() const
weight
double mean(unsigned int i) const
mean value of a component
bool momentumFromModeQP(const TrajectoryStateOnSurface tsos, double &momentum) const
const SingleState1dContainer & components() const
access to components
Definition: utils.py:1
static int position[264][3]
Definition: ReadPGInfo.cc:509
float pzSign() const
Sign of the z-component of the momentum in the local frame.
T x() const
Definition: PV3DBase.h:62
int chargeFromMode(const TrajectoryStateOnSurface tsos) const
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepStd< double, 3, 3 > > AlgebraicMatrix33
bool modeIsValid() const
mode status
Global3DVector GlobalVector
Definition: GlobalVector.h:10
bool momentumFromModePPhiEta(const TrajectoryStateOnSurface tsos, GlobalVector &momentum) const