CMS 3D CMS Logo

Functions
multiTrajectoryStateMode Namespace Reference

Functions

int chargeFromMode (TrajectoryStateOnSurface const &tsos)
 
bool momentumFromModeCartesian (TrajectoryStateOnSurface const &tsos, GlobalVector &momentum)
 
bool momentumFromModeLocal (TrajectoryStateOnSurface const &tsos, GlobalVector &momentum)
 
bool momentumFromModeP (TrajectoryStateOnSurface const &tsos, double &momentum)
 
bool momentumFromModePPhiEta (TrajectoryStateOnSurface const &tsos, GlobalVector &momentum)
 
bool momentumFromModeQP (TrajectoryStateOnSurface const &tsos, double &momentum)
 
bool positionFromModeCartesian (TrajectoryStateOnSurface const &tsos, GlobalPoint &position)
 
bool positionFromModeLocal (TrajectoryStateOnSurface const &tsos, GlobalPoint &position)
 

Function Documentation

int multiTrajectoryStateMode::chargeFromMode ( TrajectoryStateOnSurface const &  tsos)

Charge from 1D mode calculation in q/p. Q=0 in case of failure.

Definition at line 332 of file MultiTrajectoryStateMode.cc.

References TrajectoryStateOnSurface::isValid(), SingleGaussianState1D::mean(), GaussianSumUtilities1D::mean(), GaussianSumUtilities1D::mode(), GaussianSumUtilities1D::modeIsValid(), MultiGaussianStateTransform::multiState1D(), and mps_fire::result.

333 {
334  //
335  // clear result vector and check validity of the TSOS
336  //
337  if ( !tsos.isValid() ) {
338  edm::LogInfo("multiTrajectoryStateMode") << "Cannot calculate mode from invalid TSOS";
339  return 0;
340  }
341  //
342  // mode computation for local co-ordinates q/p
343  // extraction of multi-state using helper class
345  GaussianSumUtilities1D utils(state1D);
346  // mode (in case of failure: mean)
347  double result = utils.mode().mean();
348  if ( !utils.modeIsValid() ) result = utils.mean();
349 
350  return result>0. ? 1 : -1;
351 }
MultiGaussianState1D multiState1D(const std::vector< MultiGaussianState< N >::Vector > &, const std::vector< MultiGaussianState< N >::Matrix > &, const std::vector< double > &, unsigned int)
Definition: utils.py:1
bool multiTrajectoryStateMode::momentumFromModeCartesian ( TrajectoryStateOnSurface const &  tsos,
GlobalVector momentum 
)

Cartesian momentum from 1D mode calculation in cartesian co-ordinates. Return value true for success.

Definition at line 17 of file MultiTrajectoryStateMode.cc.

References makeMuonMisalignmentScenario::components, TrajectoryStateOnSurface::isValid(), SingleGaussianState1D::mean(), and GaussianSumUtilities1D::mode().

Referenced by PFTrackTransformer::addPointsAndBrems(), GsfElectronAlgo::ElectronData::calculateMode(), GsfTrackProducerBase::computeModeAtTM(), EgammaHLTGsfTrackVarProducer::TrackExtrapolator::extrapolateTrackMomToPoint(), MultiTrajectoryStateTransform::innerMomentumFromMode(), MultiTrajectoryStateTransform::outerMomentumFromMode(), EgammaHLTPixelMatchElectronAlgo::process(), and PFElecTkProducer::produce().

18 {
19  //
20  // clear result vector and check validity of the TSOS
21  //
22  momentum = GlobalVector(0.,0.,0.);
23  if ( !tsos.isValid() ) {
24  edm::LogInfo("multiTrajectoryStateMode") << "Cannot calculate mode from invalid TSOS";
25  return false;
26  }
27  //
28  // 1D mode computation for px, py and pz
29  //
30  GetComponents comps(tsos);
31  auto const & components = comps();
32  auto numb = components.size();
33  // vectors of components in x, y and z
34  std::vector<SingleGaussianState1D> pxStates; pxStates.reserve(numb);
35  std::vector<SingleGaussianState1D> pyStates; pyStates.reserve(numb);
36  std::vector<SingleGaussianState1D> pzStates; pzStates.reserve(numb);
37  // iteration over components
38  for ( std::vector<TrajectoryStateOnSurface>::const_iterator ic=components.begin();
39  ic!=components.end(); ++ic ) {
40  // extraction of parameters and variances
41  GlobalVector mom(ic->globalMomentum());
42  AlgebraicSymMatrix66 cov(ic->cartesianError().matrix());
43  pxStates.push_back(SingleGaussianState1D(mom.x(),cov(3,3),ic->weight()));
44  pyStates.push_back(SingleGaussianState1D(mom.y(),cov(4,4),ic->weight()));
45  pzStates.push_back(SingleGaussianState1D(mom.z(),cov(5,5),ic->weight()));
46  }
47  //
48  // transformation in 1D multi-states and creation of utility classes
49  //
50  MultiGaussianState1D pxState(pxStates);
51  MultiGaussianState1D pyState(pyStates);
52  MultiGaussianState1D pzState(pzStates);
53  GaussianSumUtilities1D pxUtils(pxState);
54  GaussianSumUtilities1D pyUtils(pyState);
55  GaussianSumUtilities1D pzUtils(pzState);
56  //
57  // cartesian momentum vector from modes
58  //
59  momentum = GlobalVector(pxUtils.mode().mean(),pyUtils.mode().mean(),pzUtils.mode().mean());
60  return true;
61 }
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
Global3DVector GlobalVector
Definition: GlobalVector.h:10
bool multiTrajectoryStateMode::momentumFromModeLocal ( TrajectoryStateOnSurface const &  tsos,
GlobalVector momentum 
)

Cartesian momentum from 1D mode calculation in local co-ordinates (q/p, dx/dz, dy/dz). Return value true for success.

Definition at line 112 of file MultiTrajectoryStateMode.cc.

References TrajectoryStateOnSurface::isValid(), TrajectoryStateOnSurface::localParameters(), SingleGaussianState1D::mean(), GaussianSumUtilities1D::mean(), GaussianSumUtilities1D::mode(), GaussianSumUtilities1D::modeIsValid(), MultiGaussianStateTransform::multiState1D(), LocalTrajectoryParameters::pzSign(), mps_fire::result, mathSSE::sqrt(), TrajectoryStateOnSurface::surface(), and Surface::toGlobal().

113 {
114  //
115  // clear result vector and check validity of the TSOS
116  //
117  momentum = GlobalVector(0.,0.,0.);
118  if ( !tsos.isValid() ) {
119  edm::LogInfo("multiTrajectoryStateMode") << "Cannot calculate mode from invalid TSOS";
120  return false;
121  }
122  //
123  // mode computation for local co-ordinates q/p, dx/dz, dy/dz
124  //
125  double qpMode(0);
126  double dxdzMode(0);
127  double dydzMode(0);
128  //
129  // first 3 elements of local parameters = q/p, dx/dz, dy/dz
130  //
131  for ( unsigned int iv=0; iv<3; ++iv ) {
132  // extraction of multi-state using helper class
134  GaussianSumUtilities1D utils(state1D);
135  // mode (in case of failure: mean)
136  double result = utils.mode().mean();
137  if ( !utils.modeIsValid() ) result = utils.mean();
138  if ( iv==0 ) qpMode = result;
139  else if ( iv==1 ) dxdzMode = result;
140  else dydzMode = result;
141  }
142  // local momentum vector from dx/dz, dy/dz and q/p + sign of local pz
143  LocalVector localP(dxdzMode,dydzMode,1.);
144  localP *= tsos.localParameters().pzSign()/fabs(qpMode)
145  /sqrt(dxdzMode*dxdzMode+dydzMode*dydzMode+1.);
146  // conversion to global coordinates
147  momentum = tsos.surface().toGlobal(localP);
148  return true;
149 }
MultiGaussianState1D multiState1D(const std::vector< MultiGaussianState< N >::Vector > &, const std::vector< MultiGaussianState< N >::Matrix > &, const std::vector< double > &, unsigned int)
T sqrt(T t)
Definition: SSEVec.h:18
Definition: utils.py:1
Global3DVector GlobalVector
Definition: GlobalVector.h:10
bool multiTrajectoryStateMode::momentumFromModeP ( TrajectoryStateOnSurface const &  tsos,
double &  momentum 
)

Momentum from 1D mode calculation in p. Return value true for sucess.

Definition at line 181 of file MultiTrajectoryStateMode.cc.

References MultiGaussianState1D::components(), mps_fire::i, TrajectoryStateOnSurface::isValid(), SingleGaussianState1D::mean(), GaussianSumUtilities1D::mean(), GaussianSumUtilities1D::mode(), GaussianSumUtilities1D::modeIsValid(), MultiGaussianStateTransform::multiState1D(), AlCaHLTBitMon_ParallelJobs::p, SingleGaussianState1D::variance(), and SingleGaussianState1D::weight().

182 {
183  //
184  // clear result vector and check validity of the TSOS
185  //
186  momentum = 0.;
187  if ( !tsos.isValid() ) {
188  edm::LogInfo("multiTrajectoryStateMode") << "Cannot calculate mode from invalid TSOS";
189  return false;
190  }
191  //
192  // first element of local parameters = q/p
193  //
194  // extraction of multi-state using helper class
196  std::vector<SingleGaussianState1D> states(qpMultiState.components());
197  // transform from q/p to p
198  for ( unsigned int i=0; i<states.size(); ++i ) {
199  SingleGaussianState1D& qpState = states[i];
200  double wgt = qpState.weight();
201  double qp = qpState.mean();
202  double varQp = qpState.variance();
203  double p = 1./fabs(qp);
204  double varP = p*p*p*p*varQp;
205  states[i] = SingleGaussianState1D(p,varP,wgt);
206  }
207  MultiGaussianState1D pMultiState(states);
208  GaussianSumUtilities1D utils(pMultiState);
209  // mode (in case of failure: mean)
210  momentum = utils.mode().mean();
211  if ( !utils.modeIsValid() ) momentum = utils.mean();
212 
213  return true;
214 }
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
double variance() const
variance
double weight() const
weight
const SingleState1dContainer & components() const
access to components
Definition: utils.py:1
bool multiTrajectoryStateMode::momentumFromModePPhiEta ( TrajectoryStateOnSurface const &  tsos,
GlobalVector momentum 
)

Cartesian momentum from 1D mode calculation in p, phi, eta. Return value true for success.

Definition at line 253 of file MultiTrajectoryStateMode.cc.

References makeMuonMisalignmentScenario::components, funct::cos(), PVValHelper::eta, JetChargeProducer_cfi::exp, TrajectoryStateOnSurface::isValid(), SingleGaussianState1D::mean(), GaussianSumUtilities1D::mean(), GaussianSumUtilities1D::mode(), GaussianSumUtilities1D::modeIsValid(), AlCaHLTBitMon_ParallelJobs::p, EnergyCorrector::pt, funct::sin(), and PV3DBase< T, PVType, FrameType >::x().

254 {
255  //
256  // clear result vector and check validity of the TSOS
257  //
258  momentum = GlobalVector(0.,0.,0.);
259  if ( !tsos.isValid() ) {
260  edm::LogInfo("multiTrajectoryStateMode") << "Cannot calculate mode from invalid TSOS";
261  return false;
262  }
263  //
264  // 1D mode computation for p, phi, eta
265  //
266  GetComponents comps(tsos);
267  auto const & components = comps();
268  auto numb = components.size();
269  // vectors of components in p, phi and eta
270  std::vector<SingleGaussianState1D> pStates; pStates.reserve(numb);
271  std::vector<SingleGaussianState1D> phiStates; phiStates.reserve(numb);
272  std::vector<SingleGaussianState1D> etaStates; etaStates.reserve(numb);
273  // covariances in cartesian and p-phi-eta and jacobian
274  AlgebraicMatrix33 jacobian;
275  AlgebraicSymMatrix33 covCart;
276  AlgebraicSymMatrix33 covPPhiEta;
277  // iteration over components
278  for ( std::vector<TrajectoryStateOnSurface>::const_iterator ic=components.begin();
279  ic!=components.end(); ++ic ) {
280  // parameters
281  GlobalVector mom(ic->globalMomentum());
282  auto px = mom.x();
283  auto py = mom.y();
284  auto pz = mom.z();
285  auto op = 1./mom.mag();
286  auto opt2 = 1./mom.perp2();
287  auto phi = mom.phi();
288  auto eta = mom.eta();
289  // jacobian
290  jacobian(0,0) = px*op;
291  jacobian(0,1) = py*op;
292  jacobian(0,2) = pz*op;
293  jacobian(1,0) = py*opt2;
294  jacobian(1,1) = -px*opt2;
295  jacobian(1,2) = 0;
296  jacobian(2,0) = px*pz*opt2*op;
297  jacobian(2,1) = py*pz*opt2*op;
298  jacobian(2,2) = -op;
299  // extraction of the momentum part from the 6x6 cartesian error matrix
300  // and conversion to p-phi-eta
301  covCart = ic->cartesianError().matrix().Sub<AlgebraicSymMatrix33>(3,3);
302  covPPhiEta = ROOT::Math::Similarity(jacobian,covCart);
303  pStates.push_back(SingleGaussianState1D(1/op,covPPhiEta(0,0),ic->weight()));
304  phiStates.push_back(SingleGaussianState1D(phi,covPPhiEta(1,1),ic->weight()));
305  etaStates.push_back(SingleGaussianState1D(eta,covPPhiEta(2,2),ic->weight()));
306  }
307  //
308  // transformation in 1D multi-states and creation of utility classes
309  //
310  MultiGaussianState1D pState(pStates);
311  MultiGaussianState1D phiState(phiStates);
312  MultiGaussianState1D etaState(etaStates);
313  GaussianSumUtilities1D pUtils(pState);
314  GaussianSumUtilities1D phiUtils(phiState);
315  GaussianSumUtilities1D etaUtils(etaState);
316  //
317  // parameters from mode (in case of failure: mean)
318  //
319  auto p = pUtils.modeIsValid() ? pUtils.mode().mean() : pUtils.mean();
320  auto phi = phiUtils.modeIsValid() ? phiUtils.mode().mean() : phiUtils.mean();
321  auto eta = etaUtils.modeIsValid() ? etaUtils.mode().mean() : etaUtils.mean();
322 // double theta = 2*atan(exp(-eta));
323  auto tanth2 = std::exp(-eta);
324  auto pt = p*2*tanth2/(1+tanth2*tanth2); // p*sin(theta)
325  auto pz = p*(1-tanth2*tanth2)/(1+tanth2*tanth2); // p*cos(theta)
326  // conversion to a cartesian momentum vector
327  momentum = GlobalVector(pt*cos(phi),pt*sin(phi),pz);
328  return true;
329 }
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
T x() const
Definition: PV3DBase.h:62
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepStd< double, 3, 3 > > AlgebraicMatrix33
Global3DVector GlobalVector
Definition: GlobalVector.h:10
bool multiTrajectoryStateMode::momentumFromModeQP ( TrajectoryStateOnSurface const &  tsos,
double &  momentum 
)

Momentum from 1D mode calculation in q/p. Return value true for sucess.

Definition at line 152 of file MultiTrajectoryStateMode.cc.

References TrajectoryStateOnSurface::isValid(), SingleGaussianState1D::mean(), GaussianSumUtilities1D::mean(), GaussianSumUtilities1D::mode(), GaussianSumUtilities1D::modeIsValid(), and MultiGaussianStateTransform::multiState1D().

153 {
154  //
155  // clear result vector and check validity of the TSOS
156  //
157  momentum = 0.;
158  if ( !tsos.isValid() ) {
159  edm::LogInfo("multiTrajectoryStateMode") << "Cannot calculate mode from invalid TSOS";
160  return false;
161  }
162  //
163  // mode computation for local co-ordinates q/p, dx/dz, dy/dz
164  //
165  double qpMode(0);
166  //
167  // first element of local parameters = q/p
168  //
169  // extraction of multi-state using helper class
171  GaussianSumUtilities1D utils(state1D);
172  // mode (in case of failure: mean)
173  qpMode = utils.mode().mean();
174  if ( !utils.modeIsValid() ) qpMode = utils.mean();
175 
176  momentum = 1./fabs(qpMode);
177  return true;
178 }
MultiGaussianState1D multiState1D(const std::vector< MultiGaussianState< N >::Vector > &, const std::vector< MultiGaussianState< N >::Matrix > &, const std::vector< double > &, unsigned int)
Definition: utils.py:1
bool multiTrajectoryStateMode::positionFromModeCartesian ( TrajectoryStateOnSurface const &  tsos,
GlobalPoint position 
)

Cartesian position from 1D mode calculation in cartesian co-ordinates. Return value true for success.

Definition at line 64 of file MultiTrajectoryStateMode.cc.

References makeMuonMisalignmentScenario::components, TrajectoryStateOnSurface::isValid(), SingleGaussianState1D::mean(), and GaussianSumUtilities1D::mode().

Referenced by PFTrackTransformer::addPointsAndBrems(), GsfElectronAlgo::ElectronData::calculateMode(), and EgammaHLTGsfTrackVarProducer::TrackExtrapolator::extrapolateTrackPosToPoint().

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 }
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
bool multiTrajectoryStateMode::positionFromModeLocal ( TrajectoryStateOnSurface const &  tsos,
GlobalPoint position 
)

Cartesian position from 1D mode calculation in local co-ordinates (x, y). Return value true for success.

Definition at line 217 of file MultiTrajectoryStateMode.cc.

References TrajectoryStateOnSurface::isValid(), SingleGaussianState1D::mean(), GaussianSumUtilities1D::mean(), GaussianSumUtilities1D::mode(), GaussianSumUtilities1D::modeIsValid(), MultiGaussianStateTransform::multiState1D(), mps_fire::result, TrajectoryStateOnSurface::surface(), and Surface::toGlobal().

218 {
219  //
220  // clear result vector and check validity of the TSOS
221  //
222  position = GlobalPoint(0.,0.,0.);
223  if ( !tsos.isValid() ) {
224  edm::LogInfo("multiTrajectoryStateMode") << "Cannot calculate mode from invalid TSOS";
225  return false;
226  }
227  //
228  // mode computation for local co-ordinates x, y
229  //
230  double xMode(0);
231  double yMode(0);
232  //
233  // last 2 elements of local parameters = x, y
234  //
235  for ( unsigned int iv=3; iv<5; ++iv ) {
236  // extraction of multi-state using helper class
238  GaussianSumUtilities1D utils(state1D);
239  // mode (in case of failure: mean)
240  double result = utils.mode().mean();
241  if ( !utils.modeIsValid() ) result = utils.mean();
242  if ( iv==3 ) xMode = result;
243  else yMode = result;
244  }
245  // local position vector from x, y
246  LocalPoint localP(xMode,yMode,0.);
247  // conversion to global coordinates
248  position = tsos.surface().toGlobal(localP);
249  return true;
250 }
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
MultiGaussianState1D multiState1D(const std::vector< MultiGaussianState< N >::Vector > &, const std::vector< MultiGaussianState< N >::Matrix > &, const std::vector< double > &, unsigned int)
Definition: utils.py:1