CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/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/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00007 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include "MagneticField/Engine/interface/MagneticField.h"
00010 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00011 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h" 
00012 #include "TrackingTools/Records/interface/TransientRecHitRecord.h" 
00013 #include "TrackingTools/MaterialEffects/interface/PropagatorWithMaterial.h"
00014 #include "FWCore/Framework/interface/ESHandle.h"
00015 #include "TrackingTools/GeomPropagators/interface/PropagationExceptions.h"
00016 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00017 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00018 #include "RecoTracker/TkSeedingLayers/interface/SeedComparitor.h"
00019 
00020 template <class T> T sqr( T t) {return t*t;}
00021 
00022 const TrajectorySeed * SeedFromConsecutiveHitsCreator::trajectorySeed(
00023     TrajectorySeedCollection & seedCollection,
00024     const SeedingHitSet & hits,
00025     const TrackingRegion & region,
00026     const edm::EventSetup& es,
00027     const SeedComparitor *filter)
00028 {
00029   if ( hits.size() < 2) return 0;
00030 
00031   bool passesFilter = true;
00032   GlobalTrajectoryParameters kine = initialKinematic(hits, region, es, filter, passesFilter);
00033   if (!passesFilter) return 0;
00034 
00035   float sinTheta = sin(kine.momentum().theta());
00036 
00037   CurvilinearTrajectoryError error = initialError(region,  sinTheta);
00038   FreeTrajectoryState fts(kine, error);
00039 
00040   return buildSeed(seedCollection,hits,fts,es,filter); 
00041 }
00042 
00043 
00044 GlobalTrajectoryParameters SeedFromConsecutiveHitsCreator::initialKinematic(
00045       const SeedingHitSet & hits, 
00046       const TrackingRegion & region, 
00047       const edm::EventSetup& es,
00048       const SeedComparitor *filter,
00049       bool                 &passesFilter) const
00050 {
00051   edm::ESHandle<MagneticField> bfield;
00052   es.get<IdealMagneticFieldRecord>().get(bfield);
00053 
00054   GlobalTrajectoryParameters kine;
00055 
00056   TransientTrackingRecHit::ConstRecHitPointer tth1 = hits[0];
00057   TransientTrackingRecHit::ConstRecHitPointer tth2 = hits[1];
00058   const GlobalPoint& vertexPos = region.origin();
00059 
00060   FastHelix helix(tth2->globalPosition(), tth1->globalPosition(), vertexPos, es);
00061   if (helix.isValid()) {
00062     kine = helix.stateAtVertex().parameters();
00063   } else {
00064     GlobalVector initMomentum(tth2->globalPosition() - vertexPos);
00065     initMomentum *= (100./initMomentum.perp()); 
00066     kine = GlobalTrajectoryParameters(vertexPos, initMomentum, 1, &*bfield);
00067   } 
00068 
00069   bool isBOFF = ( std::abs(bfield->inTesla(GlobalPoint(0,0,0)).z()) < 1e-3 );
00070   if (isBOFF && (theBOFFMomentum > 0)) {
00071     kine = GlobalTrajectoryParameters(kine.position(),
00072                               kine.momentum().unit() * theBOFFMomentum,
00073                               kine.charge(),
00074                               &*bfield);
00075   }
00076   passesFilter = (filter ? filter->compatible(hits, kine, helix, region) : true); 
00077   return kine;
00078 }
00079 
00080 
00081 
00082 CurvilinearTrajectoryError SeedFromConsecutiveHitsCreator::
00083    initialError( const TrackingRegion& region, float sinTheta) const
00084 {
00085   // Set initial uncertainty on track parameters, using only P.V. constraint and no hit
00086   // information.
00087   GlobalError vertexErr( sqr(region.originRBound()), 0, sqr(region.originRBound()),
00088                    0, 0, sqr(region.originZBound()));
00089 
00090   float ptMin = region.ptMin();
00091 
00092 
00093   AlgebraicSymMatrix55 C = ROOT::Math::SMatrixIdentity();
00094 
00095 // FIXME: minC00. Prevent apriori uncertainty in 1/P from being too small, 
00096 // to avoid instabilities.
00097 // N.B. This parameter needs optimising ...
00098   float sin2th = sqr(sinTheta);
00099   float minC00 = 1.0;
00100   C[0][0] = std::max(sin2th/sqr(ptMin), minC00);
00101   float zErr = vertexErr.czz();
00102   float transverseErr = vertexErr.cxx(); // assume equal cxx cyy
00103   C[3][3] = transverseErr;
00104   C[4][4] = zErr*sin2th + transverseErr*(1-sin2th);
00105 
00106   return CurvilinearTrajectoryError(C);
00107 }
00108 
00109 const TrajectorySeed * SeedFromConsecutiveHitsCreator::buildSeed(
00110     TrajectorySeedCollection & seedCollection,
00111     const SeedingHitSet & hits,
00112     const FreeTrajectoryState & fts,
00113     const edm::EventSetup& es,
00114     const SeedComparitor *filter) const
00115 {
00116   // get tracker
00117   edm::ESHandle<TrackerGeometry> tracker;
00118   es.get<TrackerDigiGeometryRecord>().get(tracker);
00119   
00120   // get propagator
00121   edm::ESHandle<Propagator>  propagatorHandle;
00122   es.get<TrackingComponentsRecord>().get(thePropagatorLabel, propagatorHandle);
00123   const Propagator*  propagator = &(*propagatorHandle);
00124   
00125   // get updator
00126   KFUpdator  updator;
00127   
00128   // Now update initial state track using information from seed hits.
00129   
00130   TrajectoryStateOnSurface updatedState;
00131   edm::OwnVector<TrackingRecHit> seedHits;
00132   
00133   const TrackingRecHit* hit = 0;
00134   for ( unsigned int iHit = 0; iHit < hits.size(); iHit++) {
00135     hit = hits[iHit]->hit();
00136     TrajectoryStateOnSurface state = (iHit==0) ? 
00137       propagator->propagate(fts,tracker->idToDet(hit->geographicalId())->surface())
00138       : propagator->propagate(updatedState, tracker->idToDet(hit->geographicalId())->surface());
00139     if (!state.isValid()) return 0;
00140     
00141     TransientTrackingRecHit::ConstRecHitPointer tth = hits[iHit]; 
00142     
00143     TransientTrackingRecHit::RecHitPointer newtth = refitHit( tth, state);
00144     
00145     if (!checkHit(state,newtth,es,filter)) return 0;
00146 
00147     updatedState =  updator.update(state, *newtth);
00148     if (!updatedState.isValid()) return 0;
00149     
00150     seedHits.push_back(newtth->hit()->clone());
00151   } 
00152 
00153   
00154   PTrajectoryStateOnDet const & PTraj = 
00155       trajectoryStateTransform::persistentState(updatedState, hit->geographicalId().rawId());
00156   TrajectorySeed seed(PTraj,std::move(seedHits),alongMomentum); 
00157   if (filter != 0 && !filter->compatible(seed)) return 0;
00158   seedCollection.push_back(seed);
00159   return &seedCollection.back();
00160 }
00161 
00162 TransientTrackingRecHit::RecHitPointer SeedFromConsecutiveHitsCreator::refitHit(
00163       const TransientTrackingRecHit::ConstRecHitPointer &hit, 
00164       const TrajectoryStateOnSurface &state) const
00165 {
00166   return hit->clone(state);
00167 }
00168 
00169 bool 
00170 SeedFromConsecutiveHitsCreator::checkHit(
00171       const TrajectoryStateOnSurface &tsos,
00172       const TransientTrackingRecHit::ConstRecHitPointer &hit,
00173       const edm::EventSetup& es,
00174       const SeedComparitor *filter) const 
00175 { 
00176     return (filter ? filter->compatible(tsos,hit) : true); 
00177 }
00178