Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:31:37

0001 #include "TrackingTools/GsfTools/interface/MultiTrajectoryStateTransform.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 
0004 #include "DataFormats/TrackReco/interface/TrackExtraFwd.h"
0005 #include "DataFormats/GsfTrackReco/interface/GsfTrackExtraFwd.h"
0006 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0007 #include "TrackingTools/GsfTools/interface/BasicMultiTrajectoryState.h"
0008 #include "TrackingTools/TrajectoryParametrization/interface/LocalTrajectoryParameters.h"
0009 #include "TrackingTools/TrajectoryParametrization/interface/LocalTrajectoryError.h"
0010 #include "Geometry/CommonDetUnit/interface/TrackingGeometry.h"
0011 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0012 #include "TrackingTools/GeomPropagators/interface/AnalyticalPropagator.h"
0013 #include "TrackingTools/GsfTools/interface/GsfPropagatorAdapter.h"
0014 #include "TrackingTools/PatternTools/interface/TransverseImpactPointExtrapolator.h"
0015 #include "TrackingTools/GsfTools/interface/MultiTrajectoryStateMode.h"
0016 
0017 MultiTrajectoryStateTransform::~MultiTrajectoryStateTransform() { delete extrapolator_; }
0018 
0019 TrajectoryStateOnSurface MultiTrajectoryStateTransform::outerStateOnSurface(const reco::GsfTrack& tk) const {
0020   return checkGeometry() ? outerStateOnSurface(tk, *geometry_, field_) : TrajectoryStateOnSurface();
0021 }
0022 
0023 TrajectoryStateOnSurface MultiTrajectoryStateTransform::innerStateOnSurface(const reco::GsfTrack& tk) const {
0024   return checkGeometry() ? innerStateOnSurface(tk, *geometry_, field_) : TrajectoryStateOnSurface();
0025 }
0026 
0027 bool MultiTrajectoryStateTransform::outerMomentumFromMode(const reco::GsfTrack& tk, GlobalVector& momentum) const {
0028   return multiTrajectoryStateMode::momentumFromModeCartesian(outerStateOnSurface(tk), momentum);
0029 }
0030 
0031 bool MultiTrajectoryStateTransform::innerMomentumFromMode(const reco::GsfTrack& tk, GlobalVector& momentum) const {
0032   return multiTrajectoryStateMode::momentumFromModeCartesian(outerStateOnSurface(tk), momentum);
0033 }
0034 
0035 TrajectoryStateOnSurface MultiTrajectoryStateTransform::outerStateOnSurface(const reco::GsfTrack& tk,
0036                                                                             const TrackingGeometry& geom,
0037                                                                             const MagneticField* field) {
0038   const Surface& surface = geom.idToDet(DetId(tk.extra()->outerDetId()))->surface();
0039 
0040   const reco::GsfTrackExtraRef& extra(tk.gsfExtra());
0041   return stateOnSurface(extra->outerStateWeights(),
0042                         extra->outerStateLocalParameters(),
0043                         extra->outerStateCovariances(),
0044                         extra->outerStateLocalPzSign(),
0045                         surface,
0046                         field);
0047 }
0048 
0049 TrajectoryStateOnSurface MultiTrajectoryStateTransform::innerStateOnSurface(const reco::GsfTrack& tk,
0050                                                                             const TrackingGeometry& geom,
0051                                                                             const MagneticField* field) {
0052   const Surface& surface = geom.idToDet(DetId(tk.extra()->innerDetId()))->surface();
0053 
0054   const reco::GsfTrackExtraRef& extra(tk.gsfExtra());
0055   return stateOnSurface(extra->innerStateWeights(),
0056                         extra->innerStateLocalParameters(),
0057                         extra->innerStateCovariances(),
0058                         extra->innerStateLocalPzSign(),
0059                         surface,
0060                         field);
0061 }
0062 
0063 TrajectoryStateOnSurface MultiTrajectoryStateTransform::stateOnSurface(const std::vector<double>& weights,
0064                                                                        const std::vector<ParameterVector>& parameters,
0065                                                                        const std::vector<CovarianceMatrix>& covariances,
0066                                                                        const double& pzSign,
0067                                                                        const Surface& surface,
0068                                                                        const MagneticField* field) {
0069   if (weights.empty())
0070     return TrajectoryStateOnSurface();
0071 
0072   unsigned int nc(weights.size());
0073   AlgebraicVector5 pars;
0074   AlgebraicSymMatrix55 cov;
0075 
0076   std::vector<TrajectoryStateOnSurface> components;
0077   components.reserve(nc);
0078 
0079   // create components TSOSs
0080   for (unsigned int i = 0; i < nc; i++) {
0081     // convert parameter vector and covariance matrix
0082     for (unsigned int j1 = 0; j1 < dimension; j1++) {
0083       pars[j1] = parameters[i](j1);
0084       for (unsigned int j2 = 0; j2 <= j1; j2++)
0085         cov(j1, j2) = covariances[i](j1, j2);  //FIXME: SMatrix copy constructor should handle this!!
0086     }
0087     // create local parameters & errors
0088     LocalTrajectoryParameters lp(pars, pzSign);
0089     LocalTrajectoryError le(cov);
0090     // create component
0091     components.push_back(TrajectoryStateOnSurface(weights[i], lp, le, surface, field));
0092   }
0093   return TrajectoryStateOnSurface((BasicTrajectoryState*)(new BasicMultiTrajectoryState(components)));
0094 }
0095 
0096 bool MultiTrajectoryStateTransform::checkGeometry() const {
0097   if (geometry_ && field_)
0098     return true;
0099 
0100   edm::LogError("MultiTrajectoryStateTransform") << "Missing ES components";
0101   return false;
0102 }
0103 
0104 TrajectoryStateOnSurface MultiTrajectoryStateTransform::extrapolatedState(const TrajectoryStateOnSurface tsos,
0105                                                                           const GlobalPoint& point) const {
0106   return checkExtrapolator() ? extrapolator_->extrapolate(tsos, point) : TrajectoryStateOnSurface();
0107 }
0108 
0109 bool MultiTrajectoryStateTransform::checkExtrapolator() const {
0110   if (extrapolator_)
0111     return true;
0112 
0113   if (field_ == nullptr) {
0114     edm::LogError("MultiTrajectoryStateTransform") << "Missing magnetic field";
0115     return false;
0116   }
0117 
0118   GsfPropagatorAdapter gsfPropagator(AnalyticalPropagator(field_, anyDirection));
0119   extrapolator_ = new TransverseImpactPointExtrapolator(gsfPropagator);
0120   return true;
0121 }