CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoVertex/GaussianSumVertexFit/src/MultiRefittedTS.cc

Go to the documentation of this file.
00001 #include "RecoVertex/GaussianSumVertexFit/interface/MultiRefittedTS.h"
00002 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00003 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00004 #include "TrackingTools/GsfTools/interface/BasicMultiTrajectoryState.h"
00005 #include "RecoVertex/VertexPrimitives/interface/VertexException.h"
00006 #include "TrackingTools/PatternTools/interface/TransverseImpactPointExtrapolator.h"
00007 #include "TrackingTools/TransientTrack/interface/TransientTrackFromFTSFactory.h"
00008 #include <cfloat>
00009 using namespace std;
00010 
00011 
00012 MultiRefittedTS::MultiRefittedTS(const std::vector<RefCountedRefittedTrackState> & prtsComp,
00013         const Surface & referenceSurface) :
00014         theComponents(prtsComp), ftsAvailable(false), refSurface(&referenceSurface),
00015         surf(true) {}
00016 
00017 
00018 MultiRefittedTS::MultiRefittedTS(const std::vector<RefCountedRefittedTrackState> & prtsComp,
00019         const GlobalPoint & referencePosition) :
00020         theComponents(prtsComp), ftsAvailable(false), refPosition(referencePosition),
00021         surf(false) {}
00022 
00027 FreeTrajectoryState MultiRefittedTS::freeTrajectoryState() const
00028 {
00029   if (!ftsAvailable) computeFreeTrajectoryState();
00030   return fts;
00031 }
00032 
00033 void MultiRefittedTS::computeFreeTrajectoryState() const
00034 {
00035   if (surf) {
00036     fts =  *(trajectoryStateOnSurface(*refSurface).freeTrajectoryState());
00037   } else {
00038     double maxWeight = -1.;
00039     RTSvector::const_iterator maxIt;
00040     for (RTSvector::const_iterator it = theComponents.begin(); 
00041           it != theComponents.end(); it++) {
00042       if ( (**it).weight() > maxWeight ) {
00043         maxWeight = (**it).weight();
00044         maxIt = it;
00045       }
00046     }
00047 
00048     TransverseImpactPointExtrapolator tipe(&((**maxIt).freeTrajectoryState().parameters().magneticField()));
00049     TrajectoryStateOnSurface initialTSOS = tipe.extrapolate((**maxIt).freeTrajectoryState(), refPosition);
00050 
00051     fts = *(trajectoryStateOnSurface(initialTSOS.surface()).freeTrajectoryState());
00052   }
00053   ftsAvailable = true;
00054 }
00055 
00062 MultiRefittedTS::AlgebraicVectorN MultiRefittedTS::parameters() const
00063 {
00064   throw VertexException
00065     ("MultiRefittedTS::freeTrajectoryState(): Don't know how to do that yet...");
00066 }
00067 
00072 MultiRefittedTS::AlgebraicSymMatrixNN  MultiRefittedTS::covariance() const
00073 {
00074   throw VertexException
00075     ("MultiRefittedTS::freeTrajectoryState(): Don't know how to do that yet...");
00076 }
00077 
00082 GlobalPoint MultiRefittedTS::position() const
00083 {
00084   throw VertexException
00085     ("MultiRefittedTS::freeTrajectoryState(): Don't know how to do that yet...");
00086 }
00087 
00093 MultiRefittedTS::AlgebraicVectorM MultiRefittedTS::momentumVector() const
00094 {
00095   throw VertexException
00096     ("MultiRefittedTS::freeTrajectoryState(): Don't know how to do that yet...");
00097 }
00098 
00099 double MultiRefittedTS::weight() const
00100 {
00101   if (!totalWeightAvailable)
00102   {
00103     totalWeight = 0.;
00104     if (theComponents.empty()) {
00105       cout << "Asking for weight of empty MultiRefittedTS, returning zero!" << endl;
00106     }
00107     for (RTSvector::const_iterator it = theComponents.begin(); 
00108           it != theComponents.end(); it++) {
00109       totalWeight += (**it).weight();
00110     }
00111   }
00112   return totalWeight;
00113 }
00114 
00115 
00116 ReferenceCountingPointer<RefittedTrackState<5> > 
00117 MultiRefittedTS::stateWithNewWeight(const double newWeight) const
00118 {
00119   if (weight() < DBL_MIN) {
00120   throw VertexException
00121     ("MultiRefittedTS::stateWithNewWeight(): Can not reweight multi-state with total weight < DBL_MIN");
00122   }
00123   double factor = newWeight/weight();
00124 
00125   RTSvector reWeightedRTSC;
00126   reWeightedRTSC.reserve(theComponents.size());
00127 
00128   for (RTSvector::const_iterator it = theComponents.begin(); 
00129         it != theComponents.end(); it++) {
00130     reWeightedRTSC.push_back((**it).stateWithNewWeight((**it).weight()*factor));
00131   }
00132   if (surf) {
00133     return RefCountedRefittedTrackState(new MultiRefittedTS(reWeightedRTSC, *refSurface));
00134   } else {
00135     return RefCountedRefittedTrackState(new MultiRefittedTS(reWeightedRTSC, refPosition));
00136   }
00137 }
00138 
00142 TrajectoryStateOnSurface MultiRefittedTS::trajectoryStateOnSurface(
00143                 const Surface & surface) const
00144 {
00145   vector<TrajectoryStateOnSurface> tsosComponents;
00146   tsosComponents.reserve(theComponents.size());
00147   for (RTSvector::const_iterator it = theComponents.begin(); 
00148         it != theComponents.end(); it++) {
00149     tsosComponents.push_back((**it).trajectoryStateOnSurface(surface));
00150   }
00151 // #ifndef CMS_NO_COMPLEX_RETURNS
00152   return TrajectoryStateOnSurface(new BasicMultiTrajectoryState(tsosComponents));
00153 // #else
00154 //   TrajectoryStateOnSurface result(new BasicMultiTrajectoryState(tsosComponents));
00155 //   return result;
00156 // #endif
00157 }
00158 
00159 TrajectoryStateOnSurface MultiRefittedTS::trajectoryStateOnSurface(
00160                 const Surface & surface, const Propagator & propagator) const
00161 { //fixme... is the propagation done correctly? Is there a gsf propagator?
00162   vector<TrajectoryStateOnSurface> tsosComponents;
00163   tsosComponents.reserve(theComponents.size());
00164   for (RTSvector::const_iterator it = theComponents.begin(); 
00165         it != theComponents.end(); it++) {
00166     tsosComponents.push_back((**it).trajectoryStateOnSurface(surface, propagator));
00167   }
00168 // #ifndef CMS_NO_COMPLEX_RETURNS
00169   return TrajectoryStateOnSurface(new BasicMultiTrajectoryState(tsosComponents));
00170 // #else
00171 //   TrajectoryStateOnSurface result(new BasicMultiTrajectoryState(tsosComponents));
00172 //   return result;
00173 // #endif
00174 }
00175 
00176 reco::TransientTrack MultiRefittedTS::transientTrack() const
00177 {
00178   TransientTrackFromFTSFactory factory;
00179   return factory.build(freeTrajectoryState());
00180 }