CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoTracker/TkSeedGenerator/plugins/SeedFromConsecutiveHitsCreator.cc

Go to the documentation of this file.
00001 #include "SeedFromConsecutiveHitsCreator.h"
00002 #include "RecoTracker/TkTrackingRegions/interface/TrackingRegion.h"
00003 
00004 #include "TrackingTools/KalmanUpdators/interface/KFUpdator.h"
00005 #include "RecoTracker/TkSeedGenerator/interface/FastHelix.h"
00006 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00009 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h" 
00010 #include "TrackingTools/Records/interface/TransientRecHitRecord.h" 
00011 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00012 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00013 #include "RecoTracker/TkSeedingLayers/interface/SeedComparitor.h"
00014 
00015 namespace {
00016 
00017   template <class T> 
00018   inline
00019   T sqr( T t) {return t*t;}
00020 
00021 }
00022 
00023 SeedFromConsecutiveHitsCreator::~SeedFromConsecutiveHitsCreator(){}
00024 
00025 void SeedFromConsecutiveHitsCreator::init(const TrackingRegion & iregion,
00026           const edm::EventSetup& es,
00027           const SeedComparitor *ifilter) {
00028   region = &iregion;
00029   filter = ifilter;
00030   // get tracker
00031   es.get<TrackerDigiGeometryRecord>().get(tracker);
00032   // get propagator
00033   es.get<TrackingComponentsRecord>().get(thePropagatorLabel, propagatorHandle);
00034   // mag field
00035   es.get<IdealMagneticFieldRecord>().get(bfield);
00036   nomField = bfield->nominalValue();
00037   isBOFF = (0==nomField);  
00038 }
00039 
00040 void SeedFromConsecutiveHitsCreator::makeSeed(TrajectorySeedCollection & seedCollection,
00041                                               const SeedingHitSet & hits) {
00042   if ( hits.size() < 2) return;
00043 
00044   GlobalTrajectoryParameters kine;
00045   if (!initialKinematic(kine, hits)) return;
00046 
00047   float sin2Theta = kine.momentum().perp2()/kine.momentum().mag2();
00048 
00049   CurvilinearTrajectoryError error = initialError(sin2Theta);
00050   FreeTrajectoryState fts(kine, error);
00051 
00052   buildSeed(seedCollection,hits,fts); 
00053 }
00054 
00055 
00056 
00057 bool SeedFromConsecutiveHitsCreator::initialKinematic(GlobalTrajectoryParameters & kine,
00058                                                       const SeedingHitSet & hits) const{
00059 
00060   TransientTrackingRecHit::ConstRecHitPointer tth1 = hits[0];
00061   TransientTrackingRecHit::ConstRecHitPointer tth2 = hits[1];
00062   const GlobalPoint& vertexPos = region->origin();
00063 
00064   FastHelix helix(tth2->globalPosition(), tth1->globalPosition(), vertexPos, nomField,&*bfield);
00065   if (helix.isValid()) {
00066     kine = helix.stateAtVertex();
00067   } else {
00068     GlobalVector initMomentum(tth2->globalPosition() - vertexPos);
00069     initMomentum *= (100./initMomentum.perp()); 
00070     kine = GlobalTrajectoryParameters(vertexPos, initMomentum, 1, &*bfield);
00071   } 
00072 
00073   if unlikely(isBOFF && (theBOFFMomentum > 0)) {
00074       kine = GlobalTrajectoryParameters(kine.position(),
00075                                         kine.momentum().unit() * theBOFFMomentum,
00076                                         kine.charge(),
00077                                         &*bfield);
00078   }
00079   return (filter ? filter->compatible(hits, kine, helix, *region) : true); 
00080 }
00081 
00082 
00083 
00084 CurvilinearTrajectoryError
00085 SeedFromConsecutiveHitsCreator::initialError(float sin2Theta) const
00086 {
00087   // Set initial uncertainty on track parameters, using only P.V. constraint and no hit
00088   // information.
00089   AlgebraicSymMatrix55 C = ROOT::Math::SMatrixIdentity();
00090 
00091 // FIXME: minC00. Prevent apriori uncertainty in 1/P from being too small, 
00092 // to avoid instabilities.
00093 // N.B. This parameter needs optimising ...
00094   // Probably OK based on quick study: KS 22/11/12.
00095   float sin2th = sin2Theta;
00096   float minC00 = sqr(theMinOneOverPtError);
00097   C[0][0] = std::max(sin2th/sqr(region->ptMin()), minC00);
00098   float zErr = sqr(region->originZBound());
00099   float transverseErr = sqr(theOriginTransverseErrorMultiplier*region->originRBound());
00100   C[3][3] = transverseErr;
00101   C[4][4] = zErr*sin2th + transverseErr*(1.f-sin2th);
00102 
00103   return CurvilinearTrajectoryError(C);
00104 }
00105 
00106 void SeedFromConsecutiveHitsCreator::buildSeed(
00107     TrajectorySeedCollection & seedCollection,
00108     const SeedingHitSet & hits,
00109     const FreeTrajectoryState & fts) const
00110 {
00111   const Propagator*  propagator = &(*propagatorHandle);
00112   
00113   // get updator
00114   KFUpdator  updator;
00115   
00116   // Now update initial state track using information from seed hits.
00117   
00118   TrajectoryStateOnSurface updatedState;
00119   edm::OwnVector<TrackingRecHit> seedHits;
00120   
00121   const TrackingRecHit* hit = 0;
00122   for ( unsigned int iHit = 0; iHit < hits.size(); iHit++) {
00123     hit = hits[iHit]->hit();
00124     TrajectoryStateOnSurface state = (iHit==0) ? 
00125       propagator->propagate(fts,tracker->idToDet(hit->geographicalId())->surface())
00126       : propagator->propagate(updatedState, tracker->idToDet(hit->geographicalId())->surface());
00127     if (!state.isValid()) return;
00128     
00129     TransientTrackingRecHit::ConstRecHitPointer const &  tth = hits[iHit]; 
00130     
00131     TransientTrackingRecHit::RecHitPointer const & newtth = refitHit( tth, state);
00132     
00133     if (!checkHit(state,newtth)) return;
00134 
00135     updatedState =  updator.update(state, *newtth);
00136     if (!updatedState.isValid()) return;
00137     
00138     seedHits.push_back(newtth->hit()->clone());
00139 
00140   } 
00141 
00142   
00143   PTrajectoryStateOnDet const & PTraj = 
00144     trajectoryStateTransform::persistentState(updatedState, hit->geographicalId().rawId());
00145   TrajectorySeed seed(PTraj,std::move(seedHits),alongMomentum); 
00146   if ( !filter || filter->compatible(seed)) seedCollection.push_back(seed);
00147 
00148 }
00149 
00150 TransientTrackingRecHit::RecHitPointer SeedFromConsecutiveHitsCreator::refitHit(
00151       const TransientTrackingRecHit::ConstRecHitPointer &hit, 
00152       const TrajectoryStateOnSurface &state) const
00153 {
00154   return hit->clone(state);
00155 }
00156 
00157 bool 
00158 SeedFromConsecutiveHitsCreator::checkHit(
00159       const TrajectoryStateOnSurface &tsos,
00160       const TransientTrackingRecHit::ConstRecHitPointer &hit) const 
00161 { 
00162     return (filter ? filter->compatible(tsos,hit) : true); 
00163 }
00164