CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/RecoTracker/CkfPattern/src/TransientInitialStateEstimator.cc

Go to the documentation of this file.
00001 #include "RecoTracker/CkfPattern/interface/TransientInitialStateEstimator.h"
00002 
00003 #include "DataFormats/Common/interface/Handle.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 #include "FWCore/Framework/interface/EventSetup.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 
00008 #include "MagneticField/Engine/interface/MagneticField.h"
00009 
00010 #include "TrackingTools/MaterialEffects/interface/PropagatorWithMaterial.h"
00011 #include "TrackingTools/KalmanUpdators/interface/KFUpdator.h"
00012 #include "TrackingTools/KalmanUpdators/interface/Chi2MeasurementEstimator.h"
00013 
00014 #include "TrackingTools/TrackFitters/interface/KFTrajectoryFitter.h"
00015 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00016 
00017 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
00018 
00019 using namespace std;
00020 
00021 TransientInitialStateEstimator::TransientInitialStateEstimator( const edm::EventSetup& es,
00022                                                                 const edm::ParameterSet& conf)
00023 {
00024   thePropagatorAlongName    = conf.getParameter<std::string>("propagatorAlongTISE");   
00025   thePropagatorOppositeName = conf.getParameter<std::string>("propagatorOppositeTISE");   
00026   theNumberMeasurementsForFit = conf.getParameter<int32_t>("numberMeasurementsForFit");   
00027 
00028 
00029   // let's avoid breaking compatibility now
00030   es.get<TrackingComponentsRecord>().get(thePropagatorAlongName,thePropagatorAlong);
00031   es.get<TrackingComponentsRecord>().get(thePropagatorOppositeName,thePropagatorOpposite);
00032 }
00033 
00034 void TransientInitialStateEstimator::setEventSetup( const edm::EventSetup& es ) {
00035   es.get<TrackingComponentsRecord>().get(thePropagatorAlongName,thePropagatorAlong);
00036   es.get<TrackingComponentsRecord>().get(thePropagatorOppositeName,thePropagatorOpposite);
00037 }
00038 
00039 std::pair<TrajectoryStateOnSurface, const GeomDet*> 
00040 TransientInitialStateEstimator::innerState( const Trajectory& traj, bool doBackFit) const
00041 {
00042   if (!doBackFit && traj.firstMeasurement().forwardPredictedState().isValid()){
00043     LogDebug("TransientInitialStateEstimator")
00044       <<"a backward fit will not be done. assuming that the state on first measurement is OK";
00045     TSOS firstStateFromForward = traj.firstMeasurement().forwardPredictedState();
00046     firstStateFromForward.rescaleError(100.);    
00047     return std::pair<TrajectoryStateOnSurface, const GeomDet*>( firstStateFromForward, 
00048                                                                 traj.firstMeasurement().recHit()->det());
00049   }
00050   if (!doBackFit){
00051     LogDebug("TransientInitialStateEstimator")
00052       <<"told to not do a back fit, but the forward state of the first measurement is not valid. doing a back fit.";
00053   }
00054 
00055   int nMeas = traj.measurements().size();
00056   int lastFitted = theNumberMeasurementsForFit >=0 ? theNumberMeasurementsForFit : nMeas; 
00057   if (nMeas-1 < lastFitted) lastFitted = nMeas-1;
00058 
00059   std::vector<TrajectoryMeasurement> measvec = traj.measurements();
00060   TransientTrackingRecHit::ConstRecHitContainer firstHits;
00061 
00062   bool foundLast = false;
00063   int actualLast = -99;
00064 
00065   for (int i=lastFitted; i >= 0; i--) {
00066     if(measvec[i].recHit()->det()){
00067       if(!foundLast){
00068         actualLast = i; 
00069         foundLast = true;
00070       }
00071       firstHits.push_back( measvec[i].recHit());
00072     }
00073   }
00074   TSOS startingState = measvec[actualLast].updatedState();
00075   startingState.rescaleError(100.);
00076 
00077   // avoid cloning...
00078   KFUpdator const aKFUpdator;
00079   Chi2MeasurementEstimator const aChi2MeasurementEstimator( 100., 3);
00080   KFTrajectoryFitter backFitter( thePropagatorAlong.product(),
00081                                  &aKFUpdator,
00082                                  &aChi2MeasurementEstimator,
00083                                  firstHits.size());
00084 
00085   PropagationDirection backFitDirection = traj.direction() == alongMomentum ? oppositeToMomentum: alongMomentum;
00086 
00087   // only direction matters in this contest
00088   TrajectorySeed fakeSeed = TrajectorySeed(PTrajectoryStateOnDet() , 
00089                                            edm::OwnVector<TrackingRecHit>(),
00090                                            backFitDirection);
00091 
00092   vector<Trajectory> fitres = backFitter.fit( fakeSeed, firstHits, startingState);
00093   
00094   LogDebug("TransientInitialStateEstimator")
00095     <<"using a backward fit of :"<<firstHits.size()<<" hits, starting from:\n"<<startingState
00096     <<" to get the estimate of the initial state of the track.";
00097 
00098   if (fitres.size() != 1) {
00099         LogDebug("TransientInitialStateEstimator")
00100           << "FitTester: first hits fit failed!";
00101     return std::pair<TrajectoryStateOnSurface, const GeomDet*>();
00102   }
00103 
00104   TrajectoryMeasurement firstMeas = fitres[0].lastMeasurement();
00105   TSOS firstState(firstMeas.updatedState().localParameters(),
00106                   firstMeas.updatedState().localError(),
00107                   firstMeas.updatedState().surface(),
00108                   thePropagatorAlong->magneticField());
00109   // I couldn't do: 
00110   //TSOS firstState = firstMeas.updatedState();
00111   // why????
00112 
00113 
00114   firstState.rescaleError(100.);
00115 
00116   LogDebug("TransientInitialStateEstimator")
00117     <<"the initial state is found to be:\n:"<<firstState
00118     <<"\n it's field pointer is: "<<firstState.magneticField()
00119     <<"\n the pointer from the state of the back fit was: "<<firstMeas.updatedState().magneticField();
00120 
00121 
00122   return std::pair<TrajectoryStateOnSurface, const GeomDet*>( firstState, 
00123                                                               firstMeas.recHit()->det());
00124 }
00125