CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/TrackingTools/GsfTools/src/MultiGaussianStateTransform.cc

Go to the documentation of this file.
00001 #include "TrackingTools/GsfTools/interface/MultiGaussianStateTransform.h"
00002 #include "TrackingTools/GsfTools/interface/MultiGaussianState1D.h"
00003 #include "DataFormats/TrackReco/interface/TrackExtraFwd.h"
00004 #include "DataFormats/GsfTrackReco/interface/GsfTrackExtraFwd.h"
00005 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00006 #include "FWCore/Utilities/interface/Exception.h"
00007 
00008 MultiGaussianState<MultiGaussianStateTransform::N>
00009 MultiGaussianStateTransform::outerMultiState (const reco::GsfTrack& tk)
00010 {
00011   const reco::GsfTrackExtraRef& extra(tk.gsfExtra());
00012   return multiState(extra->outerStateLocalParameters(),
00013                     extra->outerStateCovariances(),
00014                     extra->outerStateWeights());
00015 }
00016 
00017 MultiGaussianState<MultiGaussianStateTransform::N>
00018 MultiGaussianStateTransform::innerMultiState (const reco::GsfTrack& tk)
00019 {
00020   const reco::GsfTrackExtraRef& extra(tk.gsfExtra());
00021   return multiState(extra->innerStateLocalParameters(),
00022                extra->innerStateCovariances(),
00023                extra->innerStateWeights());
00024 }
00025 
00026 MultiGaussianState1D
00027 MultiGaussianStateTransform::outerMultiState1D (const reco::GsfTrack& tk,
00028                                                 unsigned int index)
00029 {
00030   if ( index>=N )  
00031     throw cms::Exception("LogicError") << "MultiGaussianStateTransform: index out of range";
00032 
00033   const reco::GsfTrackExtraRef& extra(tk.gsfExtra());
00034   return multiState1D(extra->outerStateLocalParameters(),
00035                       extra->outerStateCovariances(),
00036                       extra->outerStateWeights(),
00037                       index);
00038 }
00039 
00040 MultiGaussianState1D
00041 MultiGaussianStateTransform::innerMultiState1D (const reco::GsfTrack& tk,
00042                                                 unsigned int index)
00043 {
00044   if ( index>=N )  
00045     throw cms::Exception("LogicError") << "MultiGaussianStateTransform: index out of range";
00046 
00047   const reco::GsfTrackExtraRef& extra(tk.gsfExtra());
00048   return multiState1D(extra->innerStateLocalParameters(),
00049                       extra->innerStateCovariances(),
00050                       extra->innerStateWeights(),
00051                       index);
00052 }
00053 
00054 MultiGaussianState<MultiGaussianStateTransform::N> 
00055 MultiGaussianStateTransform::multiState (const std::vector<MultiGaussianState<N>::Vector>& parameters,
00056                                          const std::vector<MultiGaussianState<N>::Matrix>& covariances,
00057                                          const std::vector<double>& weights)
00058 {
00059   unsigned int nc = parameters.size();
00060   MultiGaussianState<N>::SingleStateContainer components;
00061   components.reserve(nc);
00062   for ( unsigned int i=0; i<nc; ++i ) {
00063     MultiGaussianState<N>::SingleStatePtr 
00064       sgs(new MultiGaussianState<N>::SingleState(parameters[i],covariances[i],weights[i]));
00065     components.push_back(sgs);
00066   }
00067   return MultiGaussianState<N>(components);
00068 }
00069 
00070 MultiGaussianState1D
00071 MultiGaussianStateTransform::multiState1D (const std::vector<MultiGaussianState<N>::Vector>& parameters,
00072                                            const std::vector<MultiGaussianState<N>::Matrix>& covariances,
00073                                            const std::vector<double>& weights, unsigned int index)
00074 {
00075   unsigned int nc = parameters.size();
00076   MultiGaussianState1D::SingleState1dContainer components;
00077   components.reserve(nc);
00078   for ( unsigned int i=0; i<nc; ++i ) {
00079     components.push_back(SingleGaussianState1D(parameters[i](index),
00080                                                covariances[i](index,index),
00081                                                weights[i]));
00082   }
00083   return MultiGaussianState1D(components);
00084 }
00085 
00086 MultiGaussianState<5> 
00087 MultiGaussianStateTransform::multiState (const TrajectoryStateOnSurface tsos)
00088 {
00089   std::vector<TrajectoryStateOnSurface> tsosComponents(tsos.components());
00090   MultiGaussianState<5>::SingleStateContainer components;
00091   components.reserve(tsosComponents.size());
00092   for ( std::vector<TrajectoryStateOnSurface>::const_iterator i=tsosComponents.begin();
00093         i!=tsosComponents.end(); ++i ) {
00094     MultiGaussianState<5>::SingleStatePtr 
00095       sgs(new MultiGaussianState<5>::SingleState(i->localParameters().vector(),
00096                                                  i->localError().matrix(),
00097                                                  i->weight()));
00098     components.push_back(sgs);
00099   }
00100   return MultiGaussianState<5>(components);
00101 }
00102 
00103 MultiGaussianState1D
00104 MultiGaussianStateTransform::multiState1D (const TrajectoryStateOnSurface tsos,
00105                                            unsigned int index)
00106 {
00107   if ( index>=N )  
00108     throw cms::Exception("LogicError") << "MultiGaussianStateTransform: index out of range";
00109   std::vector<TrajectoryStateOnSurface> tsosComponents(tsos.components());
00110   MultiGaussianState1D::SingleState1dContainer components;
00111   components.reserve(tsosComponents.size());
00112   for ( std::vector<TrajectoryStateOnSurface>::const_iterator i=tsosComponents.begin();
00113         i!=tsosComponents.end(); ++i ) {
00114     components.push_back(SingleGaussianState1D(i->localParameters().vector()(index),
00115                                                i->localError().matrix()(index,index),
00116                                                i->weight()));
00117   }
00118   return MultiGaussianState1D(components);
00119 }
00120 
00121 TrajectoryStateOnSurface
00122 MultiGaussianStateTransform::tsosFromSingleState (const SingleGaussianState<5>& singleState,
00123                                                   const TrajectoryStateOnSurface refTsos)
00124 {
00125   const LocalTrajectoryParameters& refPars(refTsos.localParameters());
00126   double pzSign = refPars.pzSign();
00127   bool charged = refPars.charge()!=0;
00128   LocalTrajectoryParameters pars(singleState.mean(),pzSign,charged);
00129   LocalTrajectoryError errs(singleState.covariance());
00130   // return state (doesn't use weight of the single state)
00131   return TrajectoryStateOnSurface(pars,errs,refTsos.surface(),refTsos.magneticField());
00132 }