Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef TrackingTools_TrackingRecHitPropagator_h
0002 #define TrackingTools_TrackingRecHitPropagator_h
0003 
0004 #include "DataFormats/TrackingRecHit/interface/InvalidTrackingRecHit.h"
0005 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
0006 #include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h"
0007 #include "RecoTracker/TransientTrackingRecHit/interface/TkClonerImpl.h"
0008 
0009 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
0010 #include "TrackingTools/KalmanUpdators/interface/TrackingRecHitPropagator.h"
0011 #include "TrackingTools/GeomPropagators/interface/AnalyticalPropagator.h"
0012 #include "MagneticField/Engine/interface/MagneticField.h"
0013 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015 
0016 /* propagates the RecHit position from the original reference frame
0017    to the reference frame of another detector.
0018    Useful for algorithms like the DAF or the MTF    
0019 */
0020 
0021 class TrackingRecHitPropagator {
0022 public:
0023   TrackingRecHitPropagator(const MagneticField* magf) {
0024     thePropagator = new AnalyticalPropagator(magf, anyDirection, 1.6);
0025   };
0026 
0027   ~TrackingRecHitPropagator() { delete thePropagator; }
0028 
0029   template <class ResultingHit>
0030   TrackingRecHit::RecHitPointer project(const TrackingRecHit::ConstRecHitPointer hit,
0031                                         const GeomDet& det,
0032                                         const TrajectoryStateOnSurface ts,
0033                                         const TransientTrackingRecHitBuilder* builder) const {
0034     TkClonerImpl hc = static_cast<TkTransientTrackingRecHitBuilder const*>(builder)->cloner();
0035 
0036     //1) propagate the best possible track parameters to the surface of the hit you want to "move" using a AnalyticalPropagator ;
0037     //2) create LocalTrajectoryParameters with the local x,y of the hit and direction + momentum from the propagated track parameters;
0038     //3) create a LocalTrajectoryError matrix which is 0 except for the local x,y submatrix, which is filled with the hit errors;
0039     //4) create a TSOS from the result of 2) and 3) and propagate it to the reference surface;
0040     //5) create a new hit with the local x,y subspace of the result of 4)
0041     if (!ts.isValid())
0042       return std::make_shared<InvalidTrackingRecHit>(*hit->det(), TrackingRecHit::missing);
0043     //    LogTrace("SiTrackerMultiRecHitUpdator") << "the tsos is valid";
0044     //check if the ts lays or not on the destination surface and in case propagate it
0045     TrajectoryStateOnSurface propagated = ts;
0046     if (hit->surface() != &(ts.surface()))
0047       propagated = thePropagator->propagate(ts, *(hit->surface()));
0048     if (!propagated.isValid())
0049       return std::make_shared<InvalidTrackingRecHit>(*hit->det(), TrackingRecHit::missing);
0050     //    LogTrace("SiTrackerMultiRecHitUpdator") << "the propagate tsos is valid";
0051     //      LogTrace("SiTrackerMultiRecHitUpdator") << "Original: position: "<<hit->parameters()<<" error: "<<hit->parametersError()<<std::endl;
0052     //clone the original hit with this state
0053     TrackingRecHit::RecHitPointer updatedOriginal = hc.makeShared(hit, propagated);
0054     //      LogTrace("SiTrackerMultiRecHitUpdator") << "New: position: "<<updatedOriginal->parameters()<<" error: "<<updatedOriginal->parametersError()<<std::endl;
0055 
0056     //    LogTrace("SiTrackerMultiRecHitUpdator") << "rechit cloned";
0057     LocalTrajectoryParameters ltp(updatedOriginal->localPosition(), propagated.localMomentum(), propagated.charge());
0058     AlgebraicSymMatrix55 ltem;
0059     ltem(3, 3) = (updatedOriginal->parametersError())(1, 1);
0060     ltem(4, 4) = (updatedOriginal->parametersError())(2, 2);
0061     ltem(3, 4) = (updatedOriginal->parametersError())(1, 2);
0062     //      LogTrace("SiTrackerMultiRecHitUpdator") <<"The cov matrix: "<<ltem<<std::endl;
0063     LocalTrajectoryError lte(ltem);
0064     //      LogTrace("SiTrackerMultiRecHitUpdator") <<"Original cov matrix: "<<lte.matrix()<<std::endl;
0065     TrajectoryStateOnSurface hit_state(ltp, lte, propagated.surface(), propagated.magneticField());
0066     TrajectoryStateOnSurface projected_hit_state = thePropagator->propagate(hit_state, det.surface());
0067     if (!projected_hit_state.isValid())
0068       return std::make_shared<InvalidTrackingRecHit>(*hit->det(), TrackingRecHit::missing);
0069     LocalPoint p = projected_hit_state.localPosition();
0070     LocalError e = projected_hit_state.localError().positionError();
0071     //      LogTrace("SiTrackerMultiRecHitUpdator") << "position: "<<p<<" error: "<<e<<std::endl;
0072     //AlgebraicSymMatrix55 projm=projected_hit_state.localError().matrix();
0073     //      for(int i=0;i<5;i++){
0074     //      LogTrace("SiTrackerMultiRecHitUpdator") <<"cov matrix: "<<projm<<std::endl;
0075     //      }
0076     return ResultingHit::build(p, e, &det, updatedOriginal->det(), updatedOriginal, this);
0077   }
0078 
0079 private:
0080   const AnalyticalPropagator* thePropagator;
0081 };
0082 
0083 #endif